From 13aa68f5f592abe3d036d64bce306f72b45158d6 Mon Sep 17 00:00:00 2001 From: Fara Woolf Date: Fri, 15 Dec 2023 08:19:16 -0600 Subject: [PATCH] fix: collectibles refetch, closes #4413 --- src/app/components/brc20-tokens-loader.tsx | 4 ++-- .../collectibles/hooks/use-is-fetching-collectibles.ts | 6 +++--- src/app/query/bitcoin/address/utxos-by-address.query.ts | 3 ++- .../query/bitcoin/ordinals/brc20/brc20-tokens.query.ts | 4 ++-- src/app/query/bitcoin/ordinals/inscriptions.query.ts | 4 ++-- src/app/query/query-prefixes.ts | 8 +++----- .../non-fungible-token-metadata.query.ts | 2 +- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/app/components/brc20-tokens-loader.tsx b/src/app/components/brc20-tokens-loader.tsx index e51b9807bca..042559d4670 100644 --- a/src/app/components/brc20-tokens-loader.tsx +++ b/src/app/components/brc20-tokens-loader.tsx @@ -1,13 +1,13 @@ import { Brc20Token, - useBrc20TokensQuery, + useGetBrc20TokensQuery, } from '@app/query/bitcoin/ordinals/brc20/brc20-tokens.query'; interface Brc20TokensLoaderProps { children(brc20Tokens: Brc20Token[]): React.JSX.Element; } export function Brc20TokensLoader({ children }: Brc20TokensLoaderProps) { - const { data: allBrc20TokensResponse } = useBrc20TokensQuery(); + const { data: allBrc20TokensResponse } = useGetBrc20TokensQuery(); const brc20Tokens = allBrc20TokensResponse?.pages .flatMap(page => page.brc20Tokens) .filter(token => token.length > 0) diff --git a/src/app/features/collectibles/hooks/use-is-fetching-collectibles.ts b/src/app/features/collectibles/hooks/use-is-fetching-collectibles.ts index af7006ec376..e1f341f1315 100644 --- a/src/app/features/collectibles/hooks/use-is-fetching-collectibles.ts +++ b/src/app/features/collectibles/hooks/use-is-fetching-collectibles.ts @@ -9,11 +9,11 @@ function areAnyQueriesFetching(...args: number[]) { export function useIsFetchingCollectiblesRelatedQuery() { // Ordinal inscriptions - const n1 = useIsFetching([QueryPrefixes.TaprootAddressUtxosMetadata]); - const n2 = useIsFetching([QueryPrefixes.InscriptionFromUtxo]); + const n1 = useIsFetching([QueryPrefixes.TaprootAddressUtxos]); + const n2 = useIsFetching([QueryPrefixes.InscriptionsByAddress]); const n3 = useIsFetching([QueryPrefixes.InscriptionMetadata]); const n4 = useIsFetching([QueryPrefixes.OrdinalTextContent]); - const n5 = useIsFetching([QueryPrefixes.InscriptionFromTxid]); + const n5 = useIsFetching([QueryPrefixes.GetInscriptions]); // BNS const n6 = useIsFetching([QueryPrefixes.BnsNamesByAddress]); diff --git a/src/app/query/bitcoin/address/utxos-by-address.query.ts b/src/app/query/bitcoin/address/utxos-by-address.query.ts index ced1322e951..61ac9a4da4d 100644 --- a/src/app/query/bitcoin/address/utxos-by-address.query.ts +++ b/src/app/query/bitcoin/address/utxos-by-address.query.ts @@ -4,6 +4,7 @@ import { getTaprootAddress } from '@shared/crypto/bitcoin/bitcoin.utils'; import { createCounter } from '@app/common/utils/counter'; import { AppUseQueryConfig } from '@app/query/query-config'; +import { QueryPrefixes } from '@app/query/query-prefixes'; import { useCurrentAccountIndex } from '@app/store/accounts/account'; import { useCurrentTaprootAccount } from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks'; import { useBitcoinClient } from '@app/store/common/api-clients.hooks'; @@ -45,7 +46,7 @@ export function useTaprootAccountUtxosQuery() { const currentAccountIndex = useCurrentAccountIndex(); return useQuery( - ['taproot-address-utxos-metadata', currentAccountIndex, network.id], + [QueryPrefixes.TaprootAddressUtxos, currentAccountIndex, network.id], async () => { let currentNumberOfAddressesWithoutOrdinals = 0; const addressIndexCounter = createCounter(0); diff --git a/src/app/query/bitcoin/ordinals/brc20/brc20-tokens.query.ts b/src/app/query/bitcoin/ordinals/brc20/brc20-tokens.query.ts index 4096b279438..fd3764aa92a 100644 --- a/src/app/query/bitcoin/ordinals/brc20/brc20-tokens.query.ts +++ b/src/app/query/bitcoin/ordinals/brc20/brc20-tokens.query.ts @@ -60,7 +60,7 @@ async function fetchBrc20TokensByAddress(address: string): Promise }); } -export function useBrc20TokensQuery() { +export function useGetBrc20TokensQuery() { const network = useCurrentNetwork(); const nativeSegwitSigner = useCurrentAccountNativeSegwitIndexZeroSigner(); const currentBitcoinAddress = nativeSegwitSigner.address; @@ -79,7 +79,7 @@ export function useBrc20TokensQuery() { [createSigner] ); const query = useInfiniteQuery({ - queryKey: [QueryPrefixes.Brc20InfiniteQuery, currentBitcoinAddress, network.id], + queryKey: [QueryPrefixes.GetBrc20Tokens, currentBitcoinAddress, network.id], async queryFn({ pageParam }) { const fromIndex: number = pageParam?.fromIndex ?? 0; let addressesWithoutTokens = pageParam?.addressesWithoutTokens ?? 0; diff --git a/src/app/query/bitcoin/ordinals/inscriptions.query.ts b/src/app/query/bitcoin/ordinals/inscriptions.query.ts index 2759b6feee0..7d91fdfe325 100644 --- a/src/app/query/bitcoin/ordinals/inscriptions.query.ts +++ b/src/app/query/bitcoin/ordinals/inscriptions.query.ts @@ -76,7 +76,7 @@ export function useGetInscriptionsInfiniteQuery() { ); const query = useInfiniteQuery({ - queryKey: [QueryPrefixes.InscriptionsFromApiInfiniteQuery, currentBitcoinAddress, network.id], + queryKey: [QueryPrefixes.GetInscriptions, currentBitcoinAddress, network.id], async queryFn({ pageParam }: InfiniteQueryPageParam) { const responsesArr: InscriptionsQueryResponse[] = []; let fromIndex = pageParam?.fromIndex ?? 0; @@ -179,7 +179,7 @@ export function useGetInscriptionsInfiniteQuery() { staleTime: 3 * 60 * 1000, refetchOnMount: false, refetchOnReconnect: false, - refetchOnWindowFocus: false, + refetchOnWindowFocus: true, }); return query; diff --git a/src/app/query/query-prefixes.ts b/src/app/query/query-prefixes.ts index b9114877d32..bf0602cb54a 100644 --- a/src/app/query/query-prefixes.ts +++ b/src/app/query/query-prefixes.ts @@ -5,17 +5,15 @@ export enum QueryPrefixes { Brc20TokenBalance = 'brc20-token-balance', OrdinalTextContent = 'ordinal-text-content', - TaprootAddressUtxosMetadata = 'taproot-address-utxos-metadata', - InscriptionFromUtxo = 'inscription-from-utxo', + TaprootAddressUtxos = 'taproot-address-utxos', BnsNamesByAddress = 'bns-names-by-address', InscriptionsByAddress = 'inscriptions-by-address', InscriptionMetadata = 'inscription-metadata', - InscriptionFromTxid = 'inscription-from-txid', - InscriptionsFromApiInfiniteQuery = 'inscriptions-from-api-infinite-query', + GetInscriptions = 'get-inscriptions', GetNftMetadata = 'get-nft-metadata', GetNftHoldings = 'get-nft-holdings', StampCollection = 'stamp-collection', StampsByAddress = 'stamps-by-address', - Brc20InfiniteQuery = 'brc20-infinite-query', + GetBrc20Tokens = 'get-brc20-tokens', } diff --git a/src/app/query/stacks/tokens/non-fungible-tokens/non-fungible-token-metadata.query.ts b/src/app/query/stacks/tokens/non-fungible-tokens/non-fungible-token-metadata.query.ts index a6b986716db..2dbdbc2493e 100644 --- a/src/app/query/stacks/tokens/non-fungible-tokens/non-fungible-token-metadata.query.ts +++ b/src/app/query/stacks/tokens/non-fungible-tokens/non-fungible-token-metadata.query.ts @@ -12,7 +12,7 @@ import { NftAssetResponse } from '../token-metadata.utils'; import useGetNonFungibleTokenHoldingsQuery from './non-fungible-token-holdings.query'; const queryOptions = { - refetchOnWindowFocus: true, + refetchOnWindowFocus: false, refetchOnMount: false, staleTime: 10 * 1000, };