11import { useQuery } from '@tanstack/react-query' ;
2+ import { BigNumber } from 'bignumber.js' ;
23import { useStacksClient } from '~/queries/stacks/stacks-client' ;
34import { useStacksNetwork } from '~/store/stacks-network' ;
45
5- import {
6- createGetStacksAccountBalanceQueryOptions ,
7- createStxCryptoAssetBalance ,
8- createStxMoney ,
9- } from '@leather.io/query' ;
10- import { createMoney } from '@leather.io/utils' ;
6+ import { createGetStxAddressBalanceQueryOptions } from '@leather.io/query' ;
7+ import { createMoney , createStxCryptoAssetBalance } from '@leather.io/utils' ;
118
129import { useMempoolTxsBalance } from './use-mempool-txs-balance' ;
1310
@@ -16,12 +13,11 @@ function useStxBalanceQuery(address: string) {
1613 const { networkPreference } = useStacksNetwork ( ) ;
1714
1815 return useQuery ( {
19- ...createGetStacksAccountBalanceQueryOptions ( {
16+ ...createGetStxAddressBalanceQueryOptions ( {
2017 address,
2118 client,
2219 network : networkPreference . chain . stacks . url ,
2320 } ) ,
24- select : resp => createStxMoney ( resp ) ,
2521 } ) ;
2622}
2723
@@ -34,13 +30,13 @@ export function useStxCryptoAssetBalance(address: string) {
3430 const { inboundBalance, outboundBalance, query } = useMempoolTxsBalance ( [ address ] ) ;
3531
3632 const filteredBalanceQuery = useQuery ( {
37- ...createGetStacksAccountBalanceQueryOptions ( {
33+ ...createGetStxAddressBalanceQueryOptions ( {
3834 address,
3935 client,
4036 network : networkPreference . chain . stacks . url ,
4137 } ) ,
4238 select : resp => {
43- const initialBalance = createStxMoney ( resp ) ;
39+ const initialBalance = createMoney ( new BigNumber ( resp . balance ) , 'STX' ) ;
4440 return createStxCryptoAssetBalance ( initialBalance , inboundBalance , outboundBalance ) ;
4541 } ,
4642 enabled : ! ! initialBalanceQuery . data ,
@@ -64,17 +60,3 @@ export function useStxAvailableUnlockedBalance(address: string) {
6460
6561 return stxBalance . filteredBalanceQuery . data ?. unlockedBalance ?? createMoney ( 0 , 'STX' ) ;
6662}
67-
68- export function useStacksAccountBalanceFungibleTokens ( address : string ) {
69- const client = useStacksClient ( ) ;
70- const { networkPreference } = useStacksNetwork ( ) ;
71-
72- return useQuery ( {
73- ...createGetStacksAccountBalanceQueryOptions ( {
74- address,
75- client,
76- network : networkPreference . chain . stacks . url ,
77- } ) ,
78- select : resp => resp . fungible_tokens ,
79- } ) ;
80- }
0 commit comments