Skip to content

Commit 1c025d7

Browse files
sktbrdclaude
andcommitted
fix(swap): always show balance line when connected
Previous gate (\`balance.value > 0n\`) hid the line entirely whenever the user had zero of the displayed token, which made the feature look broken — there was no signal that a balance lookup was even happening. Now the line is shown whenever a wallet is connected and renders in three states: loading (\"…\"), zero ("0"), and non-zero (formatted). The MAX button still only appears when the balance is actually > 0. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2ee099e commit 1c025d7

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

src/app/swap/SwapWidget.tsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,18 +569,25 @@ export function SwapWidget() {
569569
}}
570570
label="Sell token"
571571
/>
572-
{isConnected && sellBalance.data && sellBalance.data.value > 0n && (
572+
{isConnected && (
573573
<div className="flex items-center gap-1.5 text-[11px] text-muted-foreground">
574+
<span className="text-muted-foreground/60">Balance:</span>
574575
<span className="font-mono">
575-
{formatBalanceDisplay(sellBalance.data.displayValue)}
576+
{sellBalance.isLoading
577+
? "…"
578+
: sellBalance.data
579+
? formatBalanceDisplay(sellBalance.data.displayValue)
580+
: "—"}
576581
</span>
577-
<button
578-
type="button"
579-
onClick={handleUseMax}
580-
className="rounded-sm px-1.5 py-0.5 text-[10px] font-semibold tracking-wider text-blue-700 transition-colors hover:bg-blue-100 dark:text-blue-300 dark:hover:bg-blue-900/30"
581-
>
582-
MAX
583-
</button>
582+
{sellBalance.data && sellBalance.data.value > 0n && (
583+
<button
584+
type="button"
585+
onClick={handleUseMax}
586+
className="rounded-sm px-1.5 py-0.5 text-[10px] font-semibold tracking-wider text-blue-700 transition-colors hover:bg-blue-100 dark:text-blue-300 dark:hover:bg-blue-900/30"
587+
>
588+
MAX
589+
</button>
590+
)}
584591
</div>
585592
)}
586593
</div>
@@ -636,10 +643,17 @@ export function SwapWidget() {
636643
}}
637644
label="Buy token"
638645
/>
639-
{isConnected && buyBalance.data && buyBalance.data.value > 0n && (
640-
<span className="font-mono text-[11px] text-muted-foreground">
641-
{formatBalanceDisplay(buyBalance.data.displayValue)}
642-
</span>
646+
{isConnected && (
647+
<div className="flex items-center gap-1.5 text-[11px] text-muted-foreground">
648+
<span className="text-muted-foreground/60">Balance:</span>
649+
<span className="font-mono">
650+
{buyBalance.isLoading
651+
? "…"
652+
: buyBalance.data
653+
? formatBalanceDisplay(buyBalance.data.displayValue)
654+
: "—"}
655+
</span>
656+
</div>
643657
)}
644658
</div>
645659
<div className="flex items-baseline gap-3 border-b border-border pb-2.5">

0 commit comments

Comments
 (0)