From 334112b12d0639f73d580457ea4b000e7f6a8f20 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 15:25:44 +0200 Subject: [PATCH 1/2] fix(rain-sunset): reach the Withdraw button; show only what can be withdrawn Two bugs on the closing card, both from T-40. The bottom tab bar covered the Withdraw button on the closing card's withdraw screen, so the balance could not be moved off the card. The screen (and the move to the new card, which pins the same footer) now renders without the bar. The home banner, the card notice, the closing sheet, the new-card check and the withdraw screen all quoted the card's whole collateral. The part of it that pays for card payments already made cannot be withdrawn, so a card with $0.24 to withdraw said "Withdraw $11.14". They now show the collateral capped at spending power, the same rule as the backend's check before the move and the cap the withdrawal already applied. The withdraw screen lists what each token will move and names what stays on the card. The withdrawal itself is unchanged. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01RHaUoNtwo24YxcLrbSeYyE --- .../Card/RainSunset/RainClosingWithdraw.tsx | 75 +++++++---- components/tabBar/NewCustomTabBar.tsx | 6 + hooks/useRainSunset.ts | 16 ++- lib/utils/__tests__/rainSunset.test.ts | 127 ++++++++++++++++++ lib/utils/rainSunset.ts | 86 ++++++++++++ 5 files changed, 278 insertions(+), 32 deletions(-) diff --git a/components/Card/RainSunset/RainClosingWithdraw.tsx b/components/Card/RainSunset/RainClosingWithdraw.tsx index de3612516..4325ce146 100644 --- a/components/Card/RainSunset/RainClosingWithdraw.tsx +++ b/components/Card/RainSunset/RainClosingWithdraw.tsx @@ -29,6 +29,7 @@ import { showFailureSheet } from '@/lib/errors'; import getTokenIcon from '@/lib/getTokenIcon'; import { isCancelledByUser } from '@/lib/utils/passkeyErrors'; import { + closingWithdrawalPlan, floorCents, formatClosingBalance, formatClosingDate, @@ -76,6 +77,11 @@ type Phase = * reason to leave anything on it. Each token is its own collateral withdrawal — * today's `useWithdrawRainCollateral`, one `withdrawAsset` per token — so a card * holding two tokens asks for the passkey twice, and the screen says so. + * + * The amounts shown are what the withdrawal will move (`closingWithdrawalPlan`), + * never the card's whole collateral: the part of it set aside for card payments + * already made stays on the card, and the screen says how much that is. Showing + * the collateral put "Withdraw $11.14" on a card with $0.24 to withdraw. */ export function RainClosingWithdraw() { const router = useRouter(); @@ -93,7 +99,15 @@ export function RainClosingWithdraw() { ), [collateral], ); - const totalUsd = tokens.reduce((sum, token) => sum + token.balanceUsd, 0); + // What the withdrawal will move under the card's spending power, and what + // that leaves on the card; the rows, the total and the button all read this. + const plan = useMemo( + () => closingWithdrawalPlan(tokens, collateral?.spendingPowerUsd), + [tokens, collateral?.spendingPowerUsd], + ); + const movable = plan.rows.filter(row => row.units > 0n); + const totalUsd = Number(plan.movableCents) / 100; + const heldUsd = Number(plan.heldCents) / 100; const closesOn = formatClosingDate(sunset?.closesAt); // No answer at all is not an empty card: say so and offer to read it again. const unreadable = !collateral && isError; @@ -200,9 +214,10 @@ export function RainClosingWithdraw() { }; if (phase.kind === 'done' && phase.leftUsd > 0) { - // Rain capped the withdrawal below the card balance (it still holds some - // against pending payments). Say what moved and what did not, and lead - // back to the review, which shows what is still on the card. + // Rain capped the withdrawal below the card's collateral: the rest is set + // aside, nearly always for card payments already made. Say what moved and + // what did not, without promising the rest, and offer the review, which + // re-reads the card. return ( @@ -216,19 +231,20 @@ export function RainClosingWithdraw() { {formatClosingBalance(phase.usd)} is in your wallet - {formatClosingBalance(phase.leftUsd)} is still on your card, held for pending - payments. Withdraw it once they settle. + {formatClosingBalance(phase.leftUsd)} is still on your card. It is set aside, usually + for card payments you already made, and can’t be withdrawn. + - @@ -284,10 +300,18 @@ export function RainClosingWithdraw() { } const withdrawing = phase.kind === 'withdrawing'; + // One passkey confirmation per token that actually moves. const confirmations = - tokens.length > 1 - ? `You'll confirm with your passkey, once for each of the ${tokens.length} tokens.` + movable.length > 1 + ? `You'll confirm with your passkey, once for each of the ${movable.length} tokens.` : "You'll confirm with your passkey."; + // The collateral past the cap: named, so the total above is not read as an error. + const held = + heldUsd > 0 + ? movable.length > 0 + ? `Another ${formatClosingBalance(heldUsd)} on your card is set aside, usually for card payments you already made, and can’t be withdrawn.` + : `The ${formatClosingBalance(heldUsd)} on your card is set aside, usually for card payments you already made, and can’t be withdrawn.` + : null; const stays = closesOn ? ` Your card keeps working until ${closesOn.long}.` : ' Your card keeps working until it closes.'; @@ -318,29 +342,28 @@ export function RainClosingWithdraw() { {formatClosingBalance(totalUsd)} )} - All of it moves to your wallet + {movable.length > 0 || !held ? ( + All of it moves to your wallet + ) : null} - {tokens.length > 0 ? ( + {movable.length > 0 ? ( From your card - {tokens.map((token, index) => ( + {movable.map(({ token, index, units, cents }, position) => ( - {index > 0 ? : null} + {position > 0 ? : null} - + {token.symbol} - {Number( - formatUnits(BigInt(token.rawBalance || '0'), token.decimals), - ).toFixed(2)}{' '} - {token.symbol} + {Number(formatUnits(units, token.decimals)).toFixed(2)} {token.symbol} - {formatClosingBalance(token.balanceUsd)} + {formatClosingBalance(Number(cents) / 100)} {withdrawing && phase.step === index ? ( @@ -367,6 +390,8 @@ export function RainClosingWithdraw() { + {held ? {held} : null} + {confirmations} {stays} @@ -377,7 +402,7 @@ export function RainClosingWithdraw() {