Skip to content

Commit

Permalink
docs(react): spendable balance (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
tien authored Nov 13, 2024
1 parent a638b48 commit 3de1e82
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apps/docs/docs/guides/number-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,25 @@ const amountFromPlanck = useNativeTokenAmountFromPlanck();
// DOT 2.00
// DOT 3.00
```

## Spendable balance

The [`useSpendableBalance`](/api/react/function/useSpendableBalance) hook can be used to get the [spendable balance](https://wiki.polkadot.network/docs/learn-account-balances) of an account(s).

```ts
import { useSpendableBalance } from "@reactive-dot/react";

const spendableBalance = useSpendableBalance(ACCOUNT_ADDRESS);

console.log(spendableBalance.toLocaleString("en-NZ")); // DOT 10.00

const spendableBalances = useSpendableBalance([
ACCOUNT_ADDRESS_1,
ACCOUNT_ADDRESS_2,
ACCOUNT_ADDRESS_3,
]);

console.log(
spendableBalances.map((balance) => balance.toLocaleString("en-NZ")),
); // ["DOT 10.00", "DOT 20.00", "DOT 30.00"]
```

0 comments on commit 3de1e82

Please sign in to comment.