ghost-portal/packages/react-hooks/src/useIpfsLink.ts
Jaco 2c69be6ebc
Introduce alliance motions (#7925)
* Introduce alliance motions

* Quick-and-dirty motion import

* Adjust motion submission with filtering

* Adjust hooks

* Thresholds

* Align tech comm threshold

* Adjust threshold calcs

* Display announcements

* Adjust incomplete

* url calc

* Display encoded ipfsCid

* useIpfsLink with rule link

* Adjust tags

* Cleanups

* Adjust for prime type
2022-07-29 12:08:00 +03:00

29 lines
723 B
TypeScript

// Copyright 2017-2022 @polkadot/app-accounts authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { useMemo } from 'react';
import { createNamedHook } from './createNamedHook';
interface Result {
ipfsHash: string;
ipfsShort: string;
ipfsUrl: string;
}
function useIpfsLinkImpl (ipfsHash?: string | null): Result | null {
return useMemo(
() => ipfsHash
? {
ipfsHash,
ipfsShort: `${ipfsHash.substring(0, 4)}…${ipfsHash.slice(-4)}`,
// ipfsUrl: `https://cloudflare-ipfs.com/ipfs/${ipfs}`
ipfsUrl: `https://ipfs.io/ipfs/${ipfsHash}`
}
: null,
[ipfsHash]
);
}
export const useIpfsLink = createNamedHook('useIpfsLink', useIpfsLinkImpl);