diff --git a/frontend/lib/formatting.ts b/frontend/lib/formatting.ts index ddf4215d..260f7c39 100644 --- a/frontend/lib/formatting.ts +++ b/frontend/lib/formatting.ts @@ -1,5 +1,4 @@ import _ from "lodash"; -import { HypercertClient } from "@hypercerts-org/sdk"; export const formatScope = (scopeLabel: string) => scopeLabel.toLowerCase().replaceAll(/\s+/g, "-").trim(); @@ -74,10 +73,13 @@ export const formatAddress = (address: string) => export const cidToIpfsUri = (cid: string) => cid.startsWith("ipfs://") ? cid : `ipfs://${cid}`; -export const formatExternalUrl = ( - client: HypercertClient, - externalUrl?: string, -) => { +const getIpfsGatewayUri = (cidOrIpfsUri: string) => { + const NFT_STORAGE_IPFS_GATEWAY = "https://nftstorage.link/ipfs/{cid}"; + const cid = cidOrIpfsUri.replace("ipfs://", ""); + return NFT_STORAGE_IPFS_GATEWAY.replace("{cid}", cid); +}; + +export const formatExternalUrl = (externalUrl?: string) => { if (!externalUrl) { return ""; } @@ -85,7 +87,5 @@ export const formatExternalUrl = ( return externalUrl; } - return client.storage.getNftStorageGatewayUri( - externalUrl.replace("ipfs://", ""), - ); + return getIpfsGatewayUri(externalUrl); }; diff --git a/frontend/lib/hypercert.ts b/frontend/lib/hypercert.ts index fd4eb87e..0f2be7da 100644 --- a/frontend/lib/hypercert.ts +++ b/frontend/lib/hypercert.ts @@ -42,10 +42,7 @@ export async function loadHypercert( const metadata = await client.storage.getMetadata(metadataUri); hypercert.metadata = { ...metadata, - external_url_formatted: formatExternalUrl( - client, - metadata.external_url, - ), + external_url_formatted: formatExternalUrl(metadata.external_url), }; } return hypercert; @@ -54,10 +51,7 @@ export async function loadHypercert( const metadata = await client.storage.getMetadata(options.metadataUri); return new MetadataOnlyHypercert(options.metadataUri, { ...metadata, - external_url_formatted: formatExternalUrl( - client, - metadata.external_url, - ), + external_url_formatted: formatExternalUrl(metadata.external_url), }); } throw new Error(