Skip to content

Commit

Permalink
feat: update btc balance
Browse files Browse the repository at this point in the history
  • Loading branch information
naturexie committed Nov 28, 2024
1 parent 121c182 commit 01486b2
Show file tree
Hide file tree
Showing 4 changed files with 20,528 additions and 6 deletions.
14 changes: 9 additions & 5 deletions hooks/useBtcBalance.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { useEffect, useState } from "react";
import { useDebounce } from "react-use";
import Decimal from "decimal.js";
import { useBtcWalletSelector } from "btc-wallet";
import { useBtcWalletSelector, getBtcBalance } from "btc-wallet";

export function useBtcAction({ updater }: any) {
const [balance, setBalance] = useState<string | null>(null);
const [balance, setBalance] = useState<number>(0);
const btcSelector = useBtcWalletSelector();
useDebounce(
() => {
if (btcSelector?.account) {
btcSelector.getBalance().then((res) => {
const _balance = new Decimal(res).div(10 ** 8).toString();
setBalance(_balance);
// btcSelector.getBalance().then((res) => {
// const _balance = new Decimal(res).div(10 ** 8).toString();
// setBalance(_balance);
// });
getBtcBalance().then((res) => {
const { rawBalance, balance: btcBalance } = res;
setBalance(btcBalance);
});
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"babel-loader": "^9.1.3",
"bn.js": "^5.2.1",
"borsh": "^0.7.0",
"btc-wallet": "^0.3.3",
"btc-wallet": "^0.3.4",
"crypto-browserify": "3.12.0",
"decimal.js": "^10.4.1",
"eslint-plugin-prettier": "^4.2.1",
Expand Down
1 change: 1 addition & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { useEffect, useState } from "react";
import Head from "next/head";
import { Provider } from "react-redux";
Expand Down
Loading

0 comments on commit 01486b2

Please sign in to comment.