diff --git a/src/app/data/oasis-account-names.ts b/src/app/data/oasis-account-names.ts index c3436b9b0..00200a308 100644 --- a/src/app/data/oasis-account-names.ts +++ b/src/app/data/oasis-account-names.ts @@ -1,5 +1,5 @@ import axios from 'axios' -import { useQuery } from '@tanstack/react-query' +import { useQuery, UseQueryOptions } from '@tanstack/react-query' import { Layer, useGetConsensusAccountsAddresses, @@ -65,12 +65,11 @@ const getOasisAccountsMetadata = async (network: Network, layer: Layer): Promise export const useOasisAccountsMetadata = ( network: Network, layer: Layer, - queryOptions: { enabled: boolean; useErrorBoundary?: boolean }, + queryOptions: UseQueryOptions, ) => { return useQuery(['oasisAccounts', network, layer], () => getOasisAccountsMetadata(network, layer), { - enabled: queryOptions.enabled, staleTime: Infinity, - useErrorBoundary: queryOptions.useErrorBoundary, + ...queryOptions, }) } @@ -78,7 +77,7 @@ export const useOasisAccountMetadata = ( network: Network, layer: Layer, address: string, - queryOptions: { enabled: boolean; useErrorBoundary?: boolean }, + queryOptions: UseQueryOptions, ): AccountMetadataInfo => { const { isLoading, isError, error, data: allData } = useOasisAccountsMetadata(network, layer, queryOptions) if (isError) { @@ -95,14 +94,14 @@ export const useSearchForOasisAccountsByName = ( network: Network, layer: Layer, nameFragment: string, - queryOptions: { enabled: boolean }, + queryOptions: { enabled: boolean } & UseQueryOptions, ): AccountNameSearchResults => { const { isLoading: isMetadataLoading, isError: isMetadataError, error: metadataError, data: namedAccounts, - } = useOasisAccountsMetadata(network, layer, { ...queryOptions, useErrorBoundary: false }) + } = useOasisAccountsMetadata(network, layer, { useErrorBoundary: false, ...queryOptions }) if (isMetadataError) { console.log('Failed to load Oasis account metadata', metadataError) } diff --git a/src/app/data/pontusx-account-names.ts b/src/app/data/pontusx-account-names.ts index be08fd988..a17732a28 100644 --- a/src/app/data/pontusx-account-names.ts +++ b/src/app/data/pontusx-account-names.ts @@ -1,5 +1,5 @@ import axios from 'axios' -import { useQuery } from '@tanstack/react-query' +import { useQuery, UseQueryOptions } from '@tanstack/react-query' import { AccountMetadata, AccountMap, @@ -14,7 +14,12 @@ import { getOasisAddress } from '../utils/helpers' const DATA_SOURCE_URL = 'https://raw.githubusercontent.com/deltaDAO/mvg-portal/main/pontusxAddresses.json' -const getPontusXAccountsMetadata = async () => { +type PontusXAccountsMetadata = { + map: AccountMap + list: AccountMetadata[] +} + +const getPontusXAccountsMetadata = async (): Promise => { const response = await axios.get(DATA_SOURCE_URL) if (response.status !== 200) throw new Error("Couldn't load names") if (!response.data) throw new Error("Couldn't load names") @@ -34,20 +39,18 @@ const getPontusXAccountsMetadata = async () => { } } -export const usePontusXAccountsMetadata = (queryOptions: { - enabled: boolean - useErrorBoundary?: boolean -}) => { +export const usePontusXAccountsMetadata = ( + queryOptions: UseQueryOptions, +) => { return useQuery(['pontusXNames'], getPontusXAccountsMetadata, { - enabled: queryOptions.enabled, staleTime: Infinity, - useErrorBoundary: queryOptions.useErrorBoundary, + ...queryOptions, }) } export const usePontusXAccountMetadata = ( address: string, - queryOptions: { enabled: boolean; useErrorBoundary?: boolean }, + queryOptions: UseQueryOptions, ): AccountMetadataInfo => { const { isLoading, isError, error, data: allData } = usePontusXAccountsMetadata(queryOptions) if (isError) { @@ -63,14 +66,19 @@ export const usePontusXAccountMetadata = ( export const useSearchForPontusXAccountsByName = ( network: Network, nameFragment: string, - queryOptions: { enabled: boolean }, + queryOptions: { enabled: boolean } & UseQueryOptions< + PontusXAccountsMetadata, + unknown, + PontusXAccountsMetadata, + string[] + >, ): AccountNameSearchRuntimeResults => { const { isLoading: isMetadataLoading, isError: isMetadataError, error: metadataError, data: namedAccounts, - } = usePontusXAccountsMetadata({ ...queryOptions, useErrorBoundary: false }) + } = usePontusXAccountsMetadata({ useErrorBoundary: false, ...queryOptions }) if (isMetadataError) { console.log('Failed to load Pontus-X account names', metadataError) }