Skip to content

Commit

Permalink
Don't automatically throw on API status, gecko, and account names
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Aug 9, 2024
1 parent 9fe4a38 commit bc66fc4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/app/components/OfflineBanner/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { UseQueryResult } from '@tanstack/react-query'
export const useIsApiReachable = (
network: Network,
): { reachable: true } | { reachable: false; reason: 'userOffline' | 'apiOffline' } => {
const query = useGetStatus(network)
const query = useGetStatus(network, { query: { useErrorBoundary: false } })
if (query.isPaused) return { reachable: false, reason: 'userOffline' }
if (query.isFetched && !query.isSuccess) return { reachable: false, reason: 'apiOffline' }
return { reachable: true }
Expand Down Expand Up @@ -80,7 +80,7 @@ export const useConsensusFreshness = (
queryParams: { polling?: boolean } = {},
): FreshnessInfo => {
const query = useGetStatus(network, {
query: { refetchInterval: queryParams.polling ? 8000 : undefined },
query: { refetchInterval: queryParams.polling ? 8000 : undefined, useErrorBoundary: false },
})

return useFreshness(network, query)
Expand All @@ -95,7 +95,7 @@ export const useRuntimeFreshness = (
}

const query = useGetRuntimeStatus(scope.network, scope.layer, {
query: { refetchInterval: queryParams.polling ? 8000 : undefined },
query: { refetchInterval: queryParams.polling ? 8000 : undefined, useErrorBoundary: false },
})

return useFreshness(scope.network, query)
Expand Down
7 changes: 4 additions & 3 deletions src/app/data/oasis-account-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,20 @@ const getOasisAccountsMetadata = async (network: Network, layer: Layer): Promise
export const useOasisAccountsMetadata = (
network: Network,
layer: Layer,
queryOptions: { enabled: boolean },
queryOptions: { enabled: boolean; useErrorBoundary?: boolean },
) => {
return useQuery(['oasisAccounts', network, layer], () => getOasisAccountsMetadata(network, layer), {
enabled: queryOptions.enabled,
staleTime: Infinity,
useErrorBoundary: queryOptions.useErrorBoundary,
})
}

export const useOasisAccountMetadata = (
network: Network,
layer: Layer,
address: string,
queryOptions: { enabled: boolean },
queryOptions: { enabled: boolean; useErrorBoundary?: boolean },
): AccountMetadataInfo => {
const { isLoading, isError, error, data: allData } = useOasisAccountsMetadata(network, layer, queryOptions)
if (isError) {
Expand All @@ -101,7 +102,7 @@ export const useSearchForOasisAccountsByName = (
isError: isMetadataError,
error: metadataError,
data: namedAccounts,
} = useOasisAccountsMetadata(network, layer, queryOptions)
} = useOasisAccountsMetadata(network, layer, { ...queryOptions, useErrorBoundary: false })
if (isMetadataError) {
console.log('Failed to load Oasis account metadata', metadataError)
}
Expand Down
10 changes: 7 additions & 3 deletions src/app/data/pontusx-account-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ const getPontusXAccountsMetadata = async () => {
}
}

export const usePontusXAccountsMetadata = (queryOptions: { enabled: boolean }) => {
export const usePontusXAccountsMetadata = (queryOptions: {
enabled: boolean
useErrorBoundary?: boolean
}) => {
return useQuery(['pontusXNames'], getPontusXAccountsMetadata, {
enabled: queryOptions.enabled,
staleTime: Infinity,
useErrorBoundary: queryOptions.useErrorBoundary,
})
}

export const usePontusXAccountMetadata = (
address: string,
queryOptions: { enabled: boolean },
queryOptions: { enabled: boolean; useErrorBoundary?: boolean },
): AccountMetadataInfo => {
const { isLoading, isError, error, data: allData } = usePontusXAccountsMetadata(queryOptions)
if (isError) {
Expand All @@ -66,7 +70,7 @@ export const useSearchForPontusXAccountsByName = (
isError: isMetadataError,
error: metadataError,
data: namedAccounts,
} = usePontusXAccountsMetadata(queryOptions)
} = usePontusXAccountsMetadata({ ...queryOptions, useErrorBoundary: false })
if (isMetadataError) {
console.log('Failed to load Pontus-X account names', metadataError)
}
Expand Down
1 change: 1 addition & 0 deletions src/coin-gecko/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function useGetTokenPricesFromGecko(tokenIds: string[], fiatCurrency: str
}),
{
staleTime,
useErrorBoundary: false,
},
)
}
Expand Down

0 comments on commit bc66fc4

Please sign in to comment.