import { useQuery , UseQueryOptions } from 'react-query' ; import { useCurrentAccountStxAddressState } from '@app/store/accounts/account.hooks' ; import { useCurrentNetworkState } from '@app/store/network/networks.hooks' ; import { AddressTransactionWithTransfers } from '@stacks/stacks-blockchain-api-types' ; import { useAccountTransactionsWithTransfersState } from '@app/store/accounts/transactions-with-transfer.hooks' ; import { DEFAULT_LIST_LIMIT , QueryRefreshRates } from '@shared/constants' ; import { PaginatedResults } from '@shared/models/types' ; import { useApi } from '@app/store/common/api-clients.hooks' ; const QUERY_OPTIONS = { refetchInterval : QueryRefreshRates . MEDIUM , refetchOnMount : 'always' , refetchOnReconnect : 'always' , refetchOnWindowFocus : 'always' , } ; enum AccountClientKeys { TransactionsWithTransfersClient = 'account/TransactionsWithTransfersClient' } function useGetAccountTransactionsWithTransfers ( reactQueryOptions = { } ) { const principal = useCurrentAccountStxAddressState ( ) ; const { url : networkUrl } = useCurrentNetworkState ( ) ; const api = useApi ( ) ; const fetch = ( ) => { if ( ! principal ) return ; return api . accountsApi . getAccountTransactionsWithTransfers ( { principal , limit : DEFAULT_LIST_LIMIT , } ) ; } ; return useQuery ( { queryKey : [ AccountClientKeys . TransactionsWithTransfersClient , principal , networkUrl ] , queryFn : fetch , enabled : ! ! principal || ! ! networkUrl , ... reactQueryOptions , } ) ; } export function useAccountTransactionsWithTransfers ( ) { const [ accountTransactionsWithTransfers , setAccountTransactionsWithTransfers ] = useAccountTransactionsWithTransfersState ( ) ; const onSuccess = ( data ) => { setAccountTransactionsWithTransfers ( data . results ) ; } ; useGetAccountTransactionsWithTransfers ( { ... QUERY_OPTIONS , onSuccess } as UseQueryOptions ) ; return accountTransactionsWithTransfers ; }