From c834a5b4afea034b1ac3987f0877d80b40f2e069 Mon Sep 17 00:00:00 2001 From: git Date: Tue, 14 Dec 2021 11:47:57 -0500 Subject: [PATCH] propsed adding a constant for supported protocols and a helper function that returns a boolean if it is found or not and added back ternary --- app/src/utils/constants.ts | 3 +++ app/src/utils/utils.ts | 11 ++++++----- app/src/views/GrantRegistryGrantDetail.vue | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/utils/constants.ts b/app/src/utils/constants.ts index bf77bac4..b827bd5d 100644 --- a/app/src/utils/constants.ts +++ b/app/src/utils/constants.ts @@ -44,6 +44,9 @@ export const DefaultForageConfig: LocalForageConfig = { version: 3, }; +// --- Constants --- +export const retrievalEndpoint = 'https://scopelift.b-cdn.net/ipfs'; + // LocalForage keys export const allGrantsKey = 'AllGrants'; export const allGrantRoundsKey = 'AllGrantRounds'; diff --git a/app/src/utils/utils.ts b/app/src/utils/utils.ts index d35bde5a..fdc2f637 100644 --- a/app/src/utils/utils.ts +++ b/app/src/utils/utils.ts @@ -9,7 +9,7 @@ import { BatchFilterQuery, EtherscanGroup } from 'src/types'; import useWalletStore from 'src/store/wallet'; import { Grant, GrantRound, MetaPtr } from '@dgrants/types'; import { formatUnits } from 'src/utils/ethers'; -import { ETH_ADDRESS } from 'src/utils/constants'; +import { ETH_ADDRESS, retrievalEndpoint } from 'src/utils/constants'; import { DEFAULT_PROVIDER, ETHERSCAN_BASE_URL, @@ -19,9 +19,6 @@ import { } from 'src/utils/chains'; import { Ref } from 'vue'; -// --- Constants --- -const retrievalEndpoint = 'https://scopelift.b-cdn.net/ipfs'; - // --- Formatters --- // Returns an address with the following format: 0x1234…abcd export function formatAddress(address: string) { @@ -481,10 +478,14 @@ Promise => { } }; +const supportedProtocols = ['1']; +const isSupportedProtocol = (protocol: string) => supportedProtocols.includes(protocol); + export function assertIPFSPointer(logoPtr: MetaPtr | undefined) { if (!logoPtr) throw new Error('assertIPFSPointer: logoPtr is undefined'); const protocol = BigNumber.from(logoPtr.protocol).toString(); - if (!['0', '1'].includes(protocol)) + + if (!isSupportedProtocol(protocol)) throw new Error(`assertIPFSPointer: Expected protocol ID of 0 or 1, found ${protocol}`); } diff --git a/app/src/views/GrantRegistryGrantDetail.vue b/app/src/views/GrantRegistryGrantDetail.vue index 99412ce8..85c5332c 100644 --- a/app/src/views/GrantRegistryGrantDetail.vue +++ b/app/src/views/GrantRegistryGrantDetail.vue @@ -649,7 +649,7 @@ function useGrantDetail() { form.value.payee = grant.value?.payee || ''; form.value.name = grantMetadata.value?.name || ''; form.value.description = grantMetadata.value?.description || ''; - form.value.logoURI = getMetaPtr({ cid }) : 'placeholder_grant.svg' + form.value.logoURI = cid ? getMetaPtr({ cid }) : 'placeholder_grant.svg'; form.value.website = grantMetadata.value?.properties?.websiteURI || ''; form.value.github = grantMetadata.value?.properties?.githubURI || ''; form.value.twitter = cleanTwitterUrl(grantMetadata.value?.properties?.twitterURI) || '';