Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dont calculate TransferableBalance when balance is 0 #614

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading