diff --git a/packages/query/src/stacks/token-metadata/non-fungible-tokens/non-fungible-token-metadata.query.ts b/packages/query/src/stacks/token-metadata/non-fungible-tokens/non-fungible-token-metadata.query.ts index d5a675779..63d307e8a 100644 --- a/packages/query/src/stacks/token-metadata/non-fungible-tokens/non-fungible-token-metadata.query.ts +++ b/packages/query/src/stacks/token-metadata/non-fungible-tokens/non-fungible-token-metadata.query.ts @@ -2,7 +2,7 @@ import { hexToCV } from '@stacks/transactions'; import { QueryFunctionContext, type UseQueryResult, useQueries } from '@tanstack/react-query'; import { AxiosError } from 'axios'; -import { getPrincipalFromContractId } from '@leather.io/utils'; +import { getPrincipalFromContractId, oneMonthInMs, oneWeekInMs } from '@leather.io/utils'; import { StacksQueryPrefixes } from '../../../query-prefixes'; import { StacksClient, useStacksClient } from '../../stacks-client'; @@ -12,7 +12,8 @@ import { useGetNonFungibleTokenHoldingsQuery } from './non-fungible-token-holdin const queryOptions = { refetchOnWindowFocus: false, refetchOnMount: false, - staleTime: 10 * 1000, + staleTime: oneWeekInMs, + gcTime: oneMonthInMs, } as const; function getTokenId(hex: string) { @@ -34,10 +35,21 @@ export function createGetNonFungibleTokenMetadataQueryOptions({ client, tokenId, }: CreateGetNonFungibleTokenMetadataQueryOptionsArgs) { + const queryKey = [StacksQueryPrefixes.GetNftMetadata, address, tokenId]; + return { enabled: !!tokenId, - queryKey: [StacksQueryPrefixes.GetNftMetadata, address, tokenId], - queryFn: ({ signal }: QueryFunctionContext) => client.getNftMetadata(address, tokenId, signal), + queryKey, + queryFn: async ({ signal }: QueryFunctionContext) => { + try { + return await client.getNftMetadata(address, tokenId, signal); + } catch (error) { + if (statusCodeNotFoundOrNotProcessable((error as AxiosError).request.status)) { + return null; + } + throw error; + } + }, retry(_count: number, error: AxiosError) { if (statusCodeNotFoundOrNotProcessable(error.request.status)) return false; return true; diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index a41ef4672..a809b8d61 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -8,6 +8,8 @@ export * from './math'; export * from './money'; export * from './sort-assets'; export * from './truncate-middle'; +export * from './time'; + export { spamFilter } from './spam-filter/spam-filter'; export { extractPhraseFromString } from './extract-phrase-from-string/extract-phrase-from-string'; export { pxStringToNumber } from './px-string-to-number/px-string-to-number'; diff --git a/packages/utils/src/time.ts b/packages/utils/src/time.ts new file mode 100644 index 000000000..267fb0a99 --- /dev/null +++ b/packages/utils/src/time.ts @@ -0,0 +1,4 @@ +export const fiveMinInMs = 5 * 60 * 1000; +export const oneDayInMs = 24 * 60 * 60 * 1000; +export const oneWeekInMs = 7 * oneDayInMs; +export const oneMonthInMs = 30 * oneDayInMs;