CP-14874: change deposit options to 25%/50%/Max percentages - #4003
CP-14874: change deposit options to 25%/50%/Max percentages#4003bogdandobritoiu wants to merge 8 commits into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Drop the fixed $100/$250/$500 presets override so TokenUnitInputWidget falls back to its built-in 25%/50%/Max buttons computed from the wallet USDC balance. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…e balance
Both deposit and withdraw stored value.toDisplay({asNumber: true}) (4dp
round-half-up) as the amount, so Max on e.g. a 44.148877 withdrawable
became 44.1489 and was rejected as exceeding the maximum. Quantize
amounts at exact USDC precision via toSubUnit() (floors, and drops the
fractional subunits percentage presets produce) and floor the
withdrawable->balance conversion.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates the perps deposit/withdraw amount handling so quick-amount buttons use percentage presets (25% / 50% / Max) and “Max” amounts are kept at exact USDC precision (avoiding display-rounding that can exceed available balances).
Changes:
- Removes fixed $100/$250/$500 deposit presets so
TokenUnitInputWidgetfalls back to its built-in 25%/50%/Max buttons. - Introduces shared USDC amount helpers and applies them to deposit/withdraw to avoid 4-decimal display rounding on submit.
- Adds Jest coverage to lock in the precision behavior for both screens.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core-mobile/app/new/features/trade/perpetuals/utils/usdcAmount.ts | Adds helper functions to quantize TokenUnit inputs and floor withdrawable balances to USDC precision. |
| packages/core-mobile/app/new/features/trade/perpetuals/screens/PerpetualsWithdrawScreen.tsx | Uses flooring + quantization helpers so “Max” never exceeds withdrawable due to rounding. |
| packages/core-mobile/app/new/features/trade/perpetuals/screens/PerpetualsWithdrawScreen.test.tsx | Adds tests ensuring Max/percentage amounts aren’t display-rounded and withdrawable is floored. |
| packages/core-mobile/app/new/features/trade/perpetuals/screens/PerpetualsDepositScreen.tsx | Removes fixed deposit presets and quantizes widget output to USDC precision. |
| packages/core-mobile/app/new/features/trade/perpetuals/screens/PerpetualsDepositScreen.test.tsx | Adds tests ensuring default percentage presets are used and amounts are floored/precise. |
| docs/superpowers/specs/2026-07-22-cp14874-deposit-percentage-presets-design.md | Documents design/behavior notes for percentage presets + precision fix. |
| docs/superpowers/plans/2026-07-22-cp14874-deposit-percentage-presets.md | Documents implementation plan for the change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage report ✅2/2 packages passed thresholds 🟢 @avalabs/core-mobile
🟢 @avalabs/k2-alpine
Artifacts and threshold sources
Source run: Mobile PR |
…eposit Math.floor(amount * 1e6) under-floors some floats by a subunit (8.2 * 1e6 === 8199999.999999999); floor through TokenUnit's big.js decimal math instead. Correct docs to the actual MIN_DEPOSIT_USDC = 5. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…doc comment Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ing never overstates the max Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
packages/core-mobile/app/new/features/trade/perpetuals/screens/PerpetualsWithdrawScreen.tsx:242
- Even with
usdcAmountFromTokenUnitpreventing the stored amount from being 4dp display-rounded,TokenUnitInputWidgetstill sets the input field text from quick-amount button presses usingvalueUnit.toDisplay({ asNumber: true }), which rounds to 4 decimals. That means tapping Max/percent can still show a rounded-up value in the input UI that doesn’t match the exact amount this screen submits. Fix likely belongs in the shared widget (TokenUnitInputWidget/TokenUnitInput) so it sets/syncs the exact display string (e.g.toDisplay()).
<TokenUnitInputWidget
sx={{ width: '100%' }}
autoFocus
token={USDC_TOKEN}
balance={availableBalance}
amount={amount > 0 ? toUsdc(amount) : undefined}
onChange={handleAmountChange}
formatInCurrency={formatInCurrency}
valid={!exceedsBalance}
/>
Description
Ticket: CP-14874
presetsoverride soTokenUnitInputWidgetfalls back to its built-in percentage buttons.value.toDisplay({ asNumber: true })— 4-decimal round-half-up — as the amount, so Max on e.g. a 44.148877 USDC withdrawable became 44.1489 and was rejected with "Maximum withdrawal is 44.15 USDC". Amounts are now quantized at exact USDC precision viatoSubUnit()(floors; also drops the fractional subunits percentage presets produce, whichparseUnits(…, 6)would reject), and the withdrawable→balance conversion floors instead of rounding.utils/usdcAmount.tshelper.Screenshots/Videos
Pending device verification — will add iOS/Android captures.
Testing
Dev Testing
QA Testing
Checklist
Please check all that apply (if applicable)
🤖 Generated with Claude Code