From 0bd385826621cb3034a6952e7a181dd175084107 Mon Sep 17 00:00:00 2001 From: Leandro Boscariol Date: Thu, 6 Jan 2022 15:59:50 -0800 Subject: [PATCH] Pr2052/follow up (#2055) * Removing debug logging statements * Improved logging for error conditions including both account & chain * Refactored _repoNetworkIdMapping to use SupportedChainId enum * Removed duplicated import added during merge Co-authored-by: Leandro --- src/custom/state/claim/hooks/index.ts | 17 +++++++---------- src/custom/state/claim/hooks/utils.ts | 10 +++++----- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/custom/state/claim/hooks/index.ts b/src/custom/state/claim/hooks/index.ts index 4003e6117..9bf326cc7 100644 --- a/src/custom/state/claim/hooks/index.ts +++ b/src/custom/state/claim/hooks/index.ts @@ -99,8 +99,6 @@ export function useUserAvailableClaims(account: Account): UserClaims { // So not sure if this is in plan to be implemented or it doesn't work currently const results = useSingleContractMultipleData(contract, 'isClaimed', claimIndexes) - // console.log(`useUserAvailableClaims::re-render`, userClaims, claimIndexes, results) - return useMemo(() => { if (!userClaims || userClaims.length === 0) { // user has no claims @@ -511,7 +509,7 @@ function fetchClaimsMapping(chainId: number): Promise { (FETCH_CLAIM_MAPPING_PROMISES[chainId] = fetch(`${getClaimsRepoPath(chainId)}mapping.json`) .then((res) => res.json()) .catch((error) => { - console.error('Failed to get claims mapping', error) + console.error(`Failed to get claims mapping for chain ${chainId}`, error) FETCH_CLAIM_MAPPING_PROMISES[chainId] = null })) ) @@ -523,14 +521,13 @@ const FETCH_CLAIM_FILE_PROMISES: { [startingAddress: string]: Promise<{ [address * Customized fetchClaimFile function */ function fetchClaimsFile(address: string, chainId: number): Promise<{ [address: string]: RepoClaims }> { - console.log(`fetching key`, address) const key = getClaimKey(address, chainId) return ( FETCH_CLAIM_FILE_PROMISES[key] ?? (FETCH_CLAIM_FILE_PROMISES[key] = fetch(`${getClaimsRepoPath(chainId)}chunks/${address}.json`) // mod .then((res) => res.json()) .catch((error) => { - console.error(`Failed to get claim file mapping for starting address ${address}`, error) + console.error(`Failed to get claim file mapping on chain ${chainId} for starting address ${address}`, error) delete FETCH_CLAIM_FILE_PROMISES[key] })) ) @@ -546,7 +543,7 @@ function fetchClaims(account: string, chainId: number): Promise { const formatted = isAddress(account) if (!formatted) return Promise.reject(new Error('Invalid address')) - const claimKey = getClaimKey(account, chainId) + const claimKey = getClaimKey(formatted, chainId) return ( FETCH_CLAIM_PROMISES[claimKey] ?? @@ -561,18 +558,18 @@ function fetchClaims(account: string, chainId: number): Promise { return startingAddress } } else { - throw new Error(`Claim for ${formatted} was not found in partial search`) + throw new Error(`Claim for ${claimKey} was not found in partial search`) } } - throw new Error(`Claim for ${formatted} was not found after searching all mappings`) + throw new Error(`Claim for ${claimKey} was not found after searching all mappings`) }) .then((address) => fetchClaimsFile(address, chainId)) .then((result) => { if (result[formatted]) return transformRepoClaimsToUserClaims(result[formatted]) // mod - throw new Error(`Claim for ${formatted} was not found in claim file!`) + throw new Error(`Claim for ${claimKey} was not found in claim file!`) }) .catch((error) => { - console.debug('Claim fetch failed', error) + console.debug(`Claim fetch failed for ${claimKey}`, error) throw error })) ) diff --git a/src/custom/state/claim/hooks/utils.ts b/src/custom/state/claim/hooks/utils.ts index e621ed1b7..f4184306e 100644 --- a/src/custom/state/claim/hooks/utils.ts +++ b/src/custom/state/claim/hooks/utils.ts @@ -137,17 +137,17 @@ export function getIndexes(data: UserClaims): number[] { * Helper function to get the repo path for the corresponding network id * Throws when passed an unknown network id */ -export function getClaimsRepoPath(id: number): string { +export function getClaimsRepoPath(id: SupportedChainId): string { return `${CLAIMS_REPO}${_repoNetworkIdMapping(id)}/` } -function _repoNetworkIdMapping(id: number): string { +function _repoNetworkIdMapping(id: SupportedChainId): string { switch (id) { - case 1: + case SupportedChainId.MAINNET: return 'mainnet' - case 4: + case SupportedChainId.RINKEBY: return 'rinkeby' - case 100: + case SupportedChainId.XDAI: return 'gnosis-chain' default: throw new Error('Network not supported')