Skip to content

Commit 242a728

Browse files
authored
feat: update balance hook (#110)
* feat: update balance hook * Create swift-peas-film.md
1 parent 292c509 commit 242a728

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

.changeset/swift-peas-film.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@gobob/sats-wagmi": patch
3+
---
4+
5+
feat: update balance hook

packages/sats-wagmi/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"dependencies": {
5050
"@bitcoin-js/tiny-secp256k1-asmjs": "^2.2.3",
51-
"@gobob/bob-sdk": "^2.3.8",
51+
"@gobob/bob-sdk": "^3.0.0",
5252
"@metamask/providers": "^12.0.0",
5353
"@scure/base": "^1.1.6",
5454
"@scure/btc-signer": "^1.3.1",

packages/sats-wagmi/src/hooks/useBalance.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import { INTERVAL } from '../utils';
88

99
import { useAccount } from './useAccount';
1010

11-
type GetBalanceReturnType = {
12-
value: bigint;
13-
};
11+
type GetBalanceReturnType = { confirmed: bigint; unconfirmed: bigint; total: bigint };
1412

1513
type UseBalanceProps = Omit<
1614
UseQueryOptions<GetBalanceReturnType, unknown, GetBalanceReturnType, (string | undefined)[]>,
@@ -23,17 +21,19 @@ const useBalance = (props: UseBalanceProps = {}) => {
2321

2422
return useQuery({
2523
enabled: Boolean(address),
26-
queryKey: ['sats-balance', address],
24+
queryKey: ['sats-balance', network, address],
2725
queryFn: async () => {
28-
if (!address) return { value: BigInt(0) };
26+
if (!address) {
27+
return { confirmed: BigInt(0), unconfirmed: BigInt(0), total: BigInt(0) };
28+
}
2929

3030
const esploraClient = new EsploraClient(network);
3131

32-
const balance = await esploraClient.getBalance(address);
32+
const { confirmed, unconfirmed, total } = await esploraClient.getBalance(address);
3333

34-
return { value: BigInt(balance) };
34+
return { confirmed: BigInt(confirmed), unconfirmed: BigInt(unconfirmed), total: BigInt(total) };
3535
},
36-
refetchInterval: INTERVAL.SECONDS_10,
36+
refetchInterval: INTERVAL.SECONDS_30,
3737
...props
3838
});
3939
};

pnpm-lock.yaml

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)