Skip to content

Commit

Permalink
dont calculate TransferableBalance when balance is 0 (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharqiewicz authored Nov 1, 2024
1 parent e6f4702 commit 589851f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/Wallet/modals/DisconnectModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ const WalletDropdownMenu = ({
inline={true}
/>
</div>
<p className="my-6 truncate text-center text-2xl font-bold" title={`${balance} ${tokenSymbol}`}>
<p className="my-6 text-2xl font-bold text-center truncate" title={`${balance} ${tokenSymbol}`}>
{balance} {tokenSymbol}
</p>
<Button className="bg-base-300" size="sm" onClick={removeWalletAccount}>
<ArrowLeftEndOnRectangleIcon className="mr-2 w-5" />
<ArrowLeftEndOnRectangleIcon className="w-5 mr-2" />
Disconnect
</Button>
</Dropdown.Menu>
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const EXISTENTIAL_DEPOSIT = nativeToDecimal(1_000_000_000);
// Calculate the transferable balance. It's calculated as `transferable = free - max(frozen - reserved, ED)`,
// see [here](https://wiki.polkadot.network/docs/learn-guides-accounts#query-account-data-in-polkadot-js).
export function calculateTransferableBalance(free: Big, frozen: Big, reserved: Big) {
// Check if the free balance is zero to avoid negative results
if (free.lte(0)) {
return new Big(0);
}

// Emulate Math.max
const max = frozen.minus(reserved).gt(EXISTENTIAL_DEPOSIT) ? frozen.minus(reserved) : EXISTENTIAL_DEPOSIT;
return free.minus(max);
Expand Down

0 comments on commit 589851f

Please sign in to comment.