diff --git a/packages/wallet/src/App.tsx b/packages/wallet/src/App.tsx index 321b032b3..6836d5d4e 100644 --- a/packages/wallet/src/App.tsx +++ b/packages/wallet/src/App.tsx @@ -14,6 +14,7 @@ import { Details } from "./components/Details" import Transactions from "./components/Transactions" import { Assets } from "./components/Assets" import { SideBar } from "./components/Sidebar" +import { BalanceContext } from "./components/Utils/BalanceContext" export default function App() { try { @@ -23,32 +24,36 @@ export default function App() { return (
-

Bitcoin Computer Wallet

+

+ Bitcoin Computer Wallet +

) - + return ( - -
-
- - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - + + +
+
+ + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + +
-
+ diff --git a/packages/wallet/src/components/Send.tsx b/packages/wallet/src/components/Send.tsx index a8242f93b..509d6764c 100644 --- a/packages/wallet/src/components/Send.tsx +++ b/packages/wallet/src/components/Send.tsx @@ -5,6 +5,7 @@ import { Computer } from "@bitcoin-computer/lib" import { HiRefresh } from "react-icons/hi" import TransactionTable from "./TransactionTable" import { TableTxs } from "../types/common" +import { BalanceContext } from "./Utils/BalanceContext" export function SentTransactions({ computer }: { computer: Computer }) { const [txs, setTxs] = useState({ sentTxs: [], receivedTxs: [] }) @@ -36,6 +37,7 @@ export function SendForm({ computer }: { computer: Computer }) { const [amount, setAmount] = useState("") const [fee, setFee] = useState("2") const { showSnackBar } = UtilsContext.useUtilsComponents() + const { setBalance } = BalanceContext.useBalance() useEffect(() => { initFlowbite() @@ -46,6 +48,7 @@ export function SendForm({ computer }: { computer: Computer }) { computer.setFee(Number(fee)) try { const txId = await computer.send(Number(amount) * 1e8, to) + setBalance((await computer.getBalance()).balance) showSnackBar(`Sent ${amount} ${computer.getChain()} to ${to} via transaction ${txId}`, true) } catch (err) { showSnackBar(`Something went wrong ${err instanceof Error ? err.message : ""}`, false) diff --git a/packages/wallet/src/components/Sidebar.tsx b/packages/wallet/src/components/Sidebar.tsx index 7c484ef4a..66c3e955a 100644 --- a/packages/wallet/src/components/Sidebar.tsx +++ b/packages/wallet/src/components/Sidebar.tsx @@ -2,11 +2,12 @@ import { Link } from "react-router-dom" import { Computer } from "@bitcoin-computer/lib" import { HiRefresh } from "react-icons/hi" import { initFlowbite } from "flowbite" -import { useCallback, useContext, useEffect, useState } from "react" +import { useCallback, useContext, useEffect } from "react" import { Auth, ComputerContext } from "@bitcoin-computer/components" +import { BalanceContext } from "./Utils/BalanceContext" function Balance({ computer }: { computer: Computer }) { - const [balance, setBalance] = useState(0) + const { balance, setBalance } = BalanceContext.useBalance() const updateBalance = useCallback(async () => { if (Auth.isLoggedIn()) setBalance((await computer.getBalance()).balance) @@ -23,20 +24,30 @@ function Balance({ computer }: { computer: Computer }) { }, [computer, updateBalance]) return ( -