1
1
import { useQuery } from '@tanstack/react-query' ;
2
+ import { BigNumber } from 'bignumber.js' ;
2
3
import { useStacksClient } from '~/queries/stacks/stacks-client' ;
3
4
import { useStacksNetwork } from '~/store/stacks-network' ;
4
5
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' ;
11
8
12
9
import { useMempoolTxsBalance } from './use-mempool-txs-balance' ;
13
10
@@ -16,12 +13,11 @@ function useStxBalanceQuery(address: string) {
16
13
const { networkPreference } = useStacksNetwork ( ) ;
17
14
18
15
return useQuery ( {
19
- ...createGetStacksAccountBalanceQueryOptions ( {
16
+ ...createGetStxAddressBalanceQueryOptions ( {
20
17
address,
21
18
client,
22
19
network : networkPreference . chain . stacks . url ,
23
20
} ) ,
24
- select : resp => createStxMoney ( resp ) ,
25
21
} ) ;
26
22
}
27
23
@@ -34,13 +30,13 @@ export function useStxCryptoAssetBalance(address: string) {
34
30
const { inboundBalance, outboundBalance, query } = useMempoolTxsBalance ( [ address ] ) ;
35
31
36
32
const filteredBalanceQuery = useQuery ( {
37
- ...createGetStacksAccountBalanceQueryOptions ( {
33
+ ...createGetStxAddressBalanceQueryOptions ( {
38
34
address,
39
35
client,
40
36
network : networkPreference . chain . stacks . url ,
41
37
} ) ,
42
38
select : resp => {
43
- const initialBalance = createStxMoney ( resp ) ;
39
+ const initialBalance = createMoney ( new BigNumber ( resp . balance ) , 'STX' ) ;
44
40
return createStxCryptoAssetBalance ( initialBalance , inboundBalance , outboundBalance ) ;
45
41
} ,
46
42
enabled : ! ! initialBalanceQuery . data ,
@@ -64,17 +60,3 @@ export function useStxAvailableUnlockedBalance(address: string) {
64
60
65
61
return stxBalance . filteredBalanceQuery . data ?. unlockedBalance ?? createMoney ( 0 , 'STX' ) ;
66
62
}
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