import { useQueries , useQuery , UseQueryResult } from 'react-query' ; import { useApi , Api } from '@app/store/common/api-clients.hooks' ; import { BnsNamesOwnByAddressResponse } from '@stacks/blockchain-api-client' ; const STALE_TIME = 15 * 60 * 1000 ; const bnsQueryOptions = { keepPreviousData : true , cacheTime : STALE_TIME , staleTime : STALE_TIME , refetchOnMount : false , refetchInterval : false , refetchOnReconnect : false , } as const ; function getBnsNameFetcherFactory ( api ) { return ( address ) => ( ) => api . bnsApi . getNamesOwnedByAddress ( { address , blockchain : 'stacks' } ) ; } export function useGetBnsNamesOwnedByAddress ( address ) { const api = useApi ( ) ; return useQuery ( { queryKey : [ 'bns-names-by-address' , address ] , queryFn : getBnsNameFetcherFactory ( api ) ( address ) , ... bnsQueryOptions , } ) ; } export function useGetBnsNamesOwnedByAddressList ( addresses ) { const api = useApi ( ) ; return useQueries ( addresses . map ( address => ( { queryKey : [ 'bns-names-by-address' , address ] , queryFn : getBnsNameFetcherFactory ( api ) ( address ) , ... bnsQueryOptions , } ) ) ) as UseQueryResult < BnsNamesOwnByAddressResponse , Error > [ ] ; }