From 26ae84cef1d9e7f4e07ad155a0adc06c3e24c2d2 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Tue, 21 Jul 2026 11:41:27 +0200 Subject: [PATCH 1/8] fix: compare LPT allowance and balance in wei /api/account-balance returns balance and allowance in wei, but the delegating widget compared them against the human-readable LPT input. Both checks were true for any realistic amount, so wallets holding a partial allowance never saw the approve flow, the bondWithHint simulation reverted, and the Delegate button became a silent no-op. Compare in wei with BigInt, and disable Delegate while the simulation has no config so a failed simulation cannot present as a working button. Fixes #737 Co-Authored-By: Claude Opus 4.8 (1M context) --- components/DelegatingWidget/Delegate.tsx | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/components/DelegatingWidget/Delegate.tsx b/components/DelegatingWidget/Delegate.tsx index 272f3b44..bd9ad5ec 100644 --- a/components/DelegatingWidget/Delegate.tsx +++ b/components/DelegatingWidget/Delegate.tsx @@ -167,19 +167,21 @@ const Delegate = ({ const [approvalSubmitted, setApprovalSubmitted] = useState(false); const amountIsNonEmpty = useMemo(() => amount, [amount]); + // `tokenBalance` and `transferAllowance` are wei, so compare in wei. + const amountWei = useMemo(() => { + try { + return amount ? parseEther(amount) : BigInt(0); + } catch { + return BigInt(0); + } + }, [amount]); const sufficientBalance = useMemo( - () => - amountIsNonEmpty && - parseFloat(amount) > 0 && - Number(tokenBalance) >= amount, - [amount, amountIsNonEmpty, tokenBalance] + () => amountWei > BigInt(0) && BigInt(tokenBalance ?? 0) >= amountWei, + [amountWei, tokenBalance] ); const sufficientTransferAllowance = useMemo( - () => - amountIsNonEmpty && - Number(transferAllowance) > 0 && - Number(transferAllowance) >= amount, - [amount, amountIsNonEmpty, transferAllowance] + () => amountWei > BigInt(0) && BigInt(transferAllowance ?? 0) >= amountWei, + [amountWei, transferAllowance] ); // show approve flow when: no error on inputs, not approved or pending, or approved in current session @@ -260,7 +262,7 @@ const Delegate = ({