Skip to content

Commit

Permalink
propsed adding a constant for supported protocols and a helper functi…
Browse files Browse the repository at this point in the history
…on that returns a boolean if it is found or not and added back ternary
  • Loading branch information
jjwoz committed Dec 14, 2021
1 parent 5b4409d commit c834a5b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
11 changes: 6 additions & 5 deletions app/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -481,10 +478,14 @@ Promise<any[]> => {
}
};

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}`);
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/views/GrantRegistryGrantDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) || '';
Expand Down

0 comments on commit c834a5b

Please sign in to comment.