Skip to content
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
22 changes: 16 additions & 6 deletions src/lib/components/Allocate/Allocate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
mdiShieldLock,
mdiShieldLockOpenOutline,
} from "@mdi/js";
import { formatUnits } from "viem";

import { areValidGasSettings } from "$lib/contracts";
import { duskToLux, luxToDusk } from "$lib/dusk/currency";
import { calculateAdaptiveCharCount, middleEllipsis } from "$lib/dusk/string";
Expand Down Expand Up @@ -41,7 +43,7 @@
/** @type {string} */
export let unshieldedAddress;

/** @type {bigint} */
/** @type {AddressBalance} */
export let shieldedBalance;

/** @type {bigint} */
Expand Down Expand Up @@ -109,13 +111,13 @@
let hasEnoughFunds = true;

// Constant total
const totalBalance = shieldedBalance + unshieldedBalance;
const totalBalance = shieldedBalance.spendable + unshieldedBalance;

// Used to keep the difference between the initial shielded balance and the current one
const initialShielded = shieldedBalance;
const initialShielded = shieldedBalance.spendable;

// Internal state of the balances
let shielded = shieldedBalance;
let shielded = shieldedBalance.spendable;
$: unshielded = totalBalance - shielded;

// Derived number states for UI Inputs
Expand All @@ -129,7 +131,7 @@
$: difference = shielded - initialShielded;

$: hasEnoughFunds = isUnshielding
? shieldedBalance - difference - fee >= 0n
? shieldedBalance.spendable - difference - fee >= 0n
: unshieldedBalance + difference - fee >= 0n;

$: isNextButtonDisabled =
Expand Down Expand Up @@ -193,7 +195,15 @@

<hr class="glyph" />

<p class="operation__label">Shielded</p>
<p class="operation__label">
Shielded<br />
<small
>({formatUnits(shieldedBalance.spendable, 9)} spendable out of {formatUnits(
shieldedBalance.value,
9
)} total)</small
>
</p>

<div class="operation__address-wrapper">
<Icon path={mdiShieldLock} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<Allocate
{shieldedAddress}
{unshieldedAddress}
shieldedBalance={balance.shielded.spendable}
shieldedBalance={balance.shielded}
unshieldedBalance={balance.unshielded.value}
formatter={duskFormatter}
{gasLimits}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ exports[`Allocate > should render the allocation page 1`] = `
class="operation__label svelte-eoztn2"
>
Shielded
<br />

<small>
(
0
spendable out of
0
total)
</small>
</p>

<div
Expand Down