Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Pr2052/follow up (#2055)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
alfetopito and Leandro authored Jan 6, 2022
1 parent efcb9ad commit 0bd3858
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
17 changes: 7 additions & 10 deletions src/custom/state/claim/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -511,7 +509,7 @@ function fetchClaimsMapping(chainId: number): Promise<ClaimAddressMapping> {
(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
}))
)
Expand All @@ -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]
}))
)
Expand All @@ -546,7 +543,7 @@ function fetchClaims(account: string, chainId: number): Promise<UserClaims> {
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] ??
Expand All @@ -561,18 +558,18 @@ function fetchClaims(account: string, chainId: number): Promise<UserClaims> {
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
}))
)
Expand Down
10 changes: 5 additions & 5 deletions src/custom/state/claim/hooks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 0bd3858

Please sign in to comment.