Skip to content

Commit 8ccc77c

Browse files
committed
complete header functionality
1 parent 1811c93 commit 8ccc77c

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

packages/demo-wallet/src/App/Actions.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export async function syncStateWithWallet(
2727
if (chainHeight) {
2828
dispatch({ type: "set-chain-height", payload: chainHeight });
2929
}
30+
dispatch({ type: "set-active-account", payload: summary?.account_balances[0][0] });
3031
}
3132

3233
export async function triggerRescan(

packages/demo-wallet/src/App/components/Header.tsx

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,28 @@ import { WalletContext } from "../App";
88
import { syncStateWithWallet, triggerRescan } from "../Actions";
99
import { Button } from "react-bootstrap";
1010

11-
export function Header() {
11+
import { zatsToZec } from "../../utils";
1212

13+
export function Header() {
1314
const { state, dispatch } = useContext(WalletContext);
1415

16+
let activeBalanceReport =
17+
state.summary?.account_balances.find(
18+
([id]) => id === state.activeAccount
19+
);
20+
console.log(activeBalanceReport);
21+
22+
let totalBalance = activeBalanceReport ? activeBalanceReport[1].sapling_balance + activeBalanceReport[1].orchard_balance : 0
1523
return (
1624
<Stack direction="horizontal" gap={3}>
1725
<Form.Select
1826
value={state.activeAccount}
19-
onChange={(e) => dispatch({ type: "set-active-account", payload: parseInt(e.target.value)})}
27+
onChange={(e) =>
28+
dispatch({
29+
type: "set-active-account",
30+
payload: parseInt(e.target.value),
31+
})
32+
}
2033
>
2134
{state.summary?.account_balances.map(([id]) => (
2235
<option key={id} value={id}>
@@ -25,16 +38,31 @@ export function Header() {
2538
))}
2639
</Form.Select>
2740
<Card style={{ width: "30rem" }}>
28-
<Card.Title>Balance: {0} ZEC</Card.Title>
29-
<Card.Text>Available Balance: {0} ZEC</Card.Text>
41+
<Card.Title>Balance: {zatsToZec(totalBalance)} ZEC</Card.Title>
42+
<Card.Text>Available Balance: {zatsToZec(0)} ZEC</Card.Text>
3043
</Card>
3144
<Card style={{ width: "30rem" }}>
32-
<Card.Text>Chain Height: {state.chainHeight ? ""+state.chainHeight : '?'}</Card.Text>
33-
<Card.Text>Synced Height: {state.summary?.fully_scanned_height ? state.summary?.fully_scanned_height : '?'}</Card.Text>
45+
<Card.Text>
46+
Chain Height: {state.chainHeight ? "" + state.chainHeight : "?"}
47+
</Card.Text>
48+
<Card.Text>
49+
Synced Height:{" "}
50+
{state.summary?.fully_scanned_height
51+
? state.summary?.fully_scanned_height
52+
: "?"}
53+
</Card.Text>
3454
</Card>
3555
<Stack>
36-
<Button onClick={async () => await syncStateWithWallet(state.webWallet, dispatch)}>Refresh</Button>
37-
<Button onClick={() => triggerRescan(state.webWallet, dispatch)}>Sync</Button>
56+
<Button
57+
onClick={async () =>
58+
await syncStateWithWallet(state.webWallet, dispatch)
59+
}
60+
>
61+
Refresh
62+
</Button>
63+
<Button onClick={() => triggerRescan(state.webWallet, dispatch)}>
64+
Sync
65+
</Button>
3866
</Stack>
3967
</Stack>
4068
);

packages/demo-wallet/src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export function zatsToZec(zats: number): number {
3+
return zats / 100_000_000;
4+
}

0 commit comments

Comments
 (0)