Skip to content

Commit

Permalink
Merge pull request #1585 from oasisprotocol/mz/error
Browse files Browse the repository at this point in the history
Ignore all account name fetching errors at the same level
  • Loading branch information
lukaw3d authored Oct 22, 2024
2 parents 5437dff + b23ef1c commit a6d3a95
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions .changelog/1585.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore all account name fetching errors at the same level
4 changes: 2 additions & 2 deletions src/app/data/oasis-account-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const getOasisAccountsMetadata = async (network: Network, layer: Layer): Promise
}
}

export const useOasisAccountsMetadata = (
const useOasisAccountsMetadata = (
network: Network,
layer: Layer,
queryOptions: UseQueryOptions<AccountData, unknown, AccountData, string[]>,
Expand Down Expand Up @@ -101,7 +101,7 @@ export const useSearchForOasisAccountsByName = (
isError: isMetadataError,
error: metadataError,
data: namedAccounts,
} = useOasisAccountsMetadata(network, layer, { useErrorBoundary: false, ...queryOptions })
} = useOasisAccountsMetadata(network, layer, queryOptions)
if (isMetadataError) {
console.log('Failed to load Oasis account metadata', metadataError)
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/data/pontusx-account-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const useSearchForPontusXAccountsByName = (
isError: isMetadataError,
error: metadataError,
data: namedAccounts,
} = usePontusXAccountsMetadata({ useErrorBoundary: false, ...queryOptions })
} = usePontusXAccountsMetadata(queryOptions)
if (isMetadataError) {
console.log('Failed to load Pontus-X account names', metadataError)
}
Expand Down
12 changes: 10 additions & 2 deletions src/app/hooks/useAccountMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ import { getOasisAddress } from '../utils/helpers'
*
* This is the entry point that should be used by the application,
* since this function also includes caching.
*
* Doesn't throw if it fails.
*/
export const useAccountMetadata = (scope: SearchScope, address: string): AccountMetadataInfo => {
const isPontusX = scope.layer === Layer.pontusxtest || scope.layer === Layer.pontusxdev
const pontusXData = usePontusXAccountMetadata(address, { enabled: isPontusX })
const oasisData = useOasisAccountMetadata(scope.network, scope.layer, getOasisAddress(address), {
const pontusXData = usePontusXAccountMetadata(address, {
enabled: isPontusX,
useErrorBoundary: false,
})
const oasisData = useOasisAccountMetadata(scope.network, scope.layer, getOasisAddress(address), {
enabled: !isPontusX,
useErrorBoundary: false,
})
return isPontusX ? pontusXData : oasisData
}

/** Doesn't throw if it fails. */
export const useSearchForAccountsByName = (
scope: SearchScope,
nameFragment = '',
Expand All @@ -29,10 +35,12 @@ export const useSearchForAccountsByName = (
const isValidPontusXSearch = isPontusX && !!nameFragment
const pontusXResults = useSearchForPontusXAccountsByName(scope.network, nameFragment, {
enabled: isValidPontusXSearch,
useErrorBoundary: false,
})
const isValidOasisSearch = !isPontusX && !!nameFragment
const oasisResults = useSearchForOasisAccountsByName(scope.network, scope.layer, nameFragment, {
enabled: isValidOasisSearch,
useErrorBoundary: false,
})
return {
isLoading:
Expand Down

0 comments on commit a6d3a95

Please sign in to comment.