Skip to content

CP-14874: change deposit options to 25%/50%/Max percentages - #4003

Open
bogdandobritoiu wants to merge 8 commits into
mainfrom
CP-14874
Open

CP-14874: change deposit options to 25%/50%/Max percentages#4003
bogdandobritoiu wants to merge 8 commits into
mainfrom
CP-14874

Conversation

@bogdandobritoiu

@bogdandobritoiu bogdandobritoiu commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

Ticket: CP-14874

  • Switches the perps deposit quick-amount buttons from fixed $100/$250/$500 to percentages 25% / 50% / Max of the wallet's C-Chain USDC balance, by dropping the presets override so TokenUnitInputWidget falls back to its built-in percentage buttons.
  • Fixes a Max rounding bug this surfaced (also reproducible on withdraw today): both perps screens stored 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 via toSubUnit() (floors; also drops the fractional subunits percentage presets produce, which parseUnits(…, 6) would reject), and the withdrawable→balance conversion floors instead of rounding.
  • No k2-alpine changes; scoped to the perps deposit/withdraw screens plus a small shared utils/usdcAmount.ts helper.

Screenshots/Videos

Pending device verification — will add iOS/Android captures.

Testing

Dev Testing

  • Trade → Perpetuals → Deposit: quick-amount buttons show 25% / 50% / Max; tapping each fills the proportional amount of your wallet USDC balance; amounts below the 5 USDC minimum show the existing inline error with the Deposit button disabled.
  • Deposit → tap Max: no "Insufficient USDC balance" error; button enables once a quote resolves.
  • Perpetuals → Withdraw → tap Max: fills the full withdrawable without the spurious "Maximum withdrawal is X USDC" error (previously reproduced whenever the withdrawable's 5th/6th decimal rounded the 4th up).
  • Bitrise dev build: pipeline #9376

QA Testing

  • Deposit quick amounts are percentages of the wallet USDC balance (25%, 50%, Max = 100%); fixed dollar presets are gone.
  • Max on both deposit and withdraw must be accepted (button enabled once quoted) for balances with 5–6 decimal places, e.g. 44.148877 USDC.
  • Typing an amount above the balance/withdrawable still shows the respective error and keeps the button disabled.

Checklist

Please check all that apply (if applicable)

  • I have performed a self-review of my code
  • I have verified the code works
  • I have included screenshots / videos of android and ios
  • I have added testing steps
  • I have added/updated necessary unit tests
  • I have updated the documentation

🤖 Generated with Claude Code

bogdandobritoiu and others added 3 commits July 22, 2026 15:07
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>
Copilot AI review requested due to automatic review settings July 22, 2026 12:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TokenUnitInputWidget falls 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.

Comment thread packages/core-mobile/app/new/features/trade/perpetuals/utils/usdcAmount.ts Outdated
Comment thread docs/superpowers/specs/2026-07-22-cp14874-deposit-percentage-presets-design.md Outdated
Comment thread docs/superpowers/plans/2026-07-22-cp14874-deposit-percentage-presets.md Outdated
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

Coverage report ✅

2/2 packages passed thresholds
Thresholds are shown inline against each package baseline.

🟢 @avalabs/core-mobile

St. Category Percentage Covered / Total
🟢 Statements 27.94% (+9.94% vs 18% ▲) 12338/44150
🟢 Branches 23.59% (+11.59% vs 12% ▲) 6056/25664
🟢 Functions 22.23% (+9.23% vs 13% ▲) 2267/10195
🟢 Lines 28.02% (+10.02% vs 18% ▲) 11816/42158

🟢 @avalabs/k2-alpine

St. Category Percentage Covered / Total
🟢 Statements 7.62% (+5.62% vs 2% ▲) 270/3539
🟢 Branches 7.02% (+6.02% vs 1% ▲) 151/2148
🟢 Functions 4.52% (+3.52% vs 1% ▲) 37/817
🟢 Lines 7.07% (+5.07% vs 2% ▲) 230/3251
Artifacts and threshold sources
  • @avalabs/core-mobile: summary core-mobile/coverage/coverage-summary.json, thresholds core-mobile/coverage-thresholds.json
  • @avalabs/k2-alpine: summary k2-alpine/coverage/coverage-summary.json, thresholds k2-alpine/coverage-thresholds.json

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>
Copilot AI review requested due to automatic review settings July 22, 2026 13:44
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread packages/core-mobile/app/new/features/trade/perpetuals/utils/usdcAmount.ts Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 13:49
…doc comment

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings July 22, 2026 13:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

…ing never overstates the max

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 22, 2026 21:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 usdcAmountFromTokenUnit preventing the stored amount from being 4dp display-rounded, TokenUnitInputWidget still sets the input field text from quick-amount button presses using valueUnit.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}
        />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants