Skip to content

fix: enable EXACT_INPUT Max for Money Account Send to Perps - #33974

Closed
jpuri wants to merge 3 commits into
mainfrom
fix/send-to-perps-max-money-account
Closed

fix: enable EXACT_INPUT Max for Money Account Send to Perps#33974
jpuri wants to merge 3 commits into
mainfrom
fix/send-to-perps-max-money-account

Conversation

@jpuri

@jpuri jpuri commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

Send to Perps Max (funded from Money account) needs isMaxAmount=true so TPC quotes use EXACT_INPUT and fees come out of the full withdrawable balance. That was previously unsafe because TPC substituted the pay token's bare on-chain mUSD balance for Max.

Depends on: MetaMask/core#9707 — TPC uses the typed required amount for Money Account max instead of on-chain mUSD.

This PR:

  1. Types Max from withdrawableFiatRaw (mUSD + vmUSD) — already present
  2. Sets isMaxAmount=true on Max for Money Account–funded deposits (Send to Perps) so quotes are EXACT_INPUT

Without core#9707, re-enabling isMaxAmount would collapse Max back to un-vaulted mUSD. Do not merge until that TPC change is available in mobile.

Changelog

CHANGELOG entry: Fixed Max Send to Perps from Money account so the full withdrawable balance can be sent after fees

Related issues

Refs: MetaMask/core#9707

Manual testing steps

Feature: Send to Perps Max from Money account

  Scenario: user taps Max on Send to Perps funded from Money account
    Given a Money account with both mUSD and vmUSD (withdrawable > bare mUSD)
    And the user opens Send to Perps paying with Money account

    When the user taps Max
    Then the amount shows the full withdrawable balance
    And the quote uses EXACT_INPUT (fees deducted from input)
    And the confirmation is not blocked by "Insufficient funds" solely due to fees on top of Max

Screenshots/Recordings

N/A — follow-up to prior Max amount fix; verify against Insufficient funds screenshot from Max + fees.

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards
  • I've completed the PR template to the best of my ability
  • I've included tests if applicable
  • I've documented my code using JSDoc format if applicable
  • I've applied the right labels on the PR

Performance checks (if applicable)

  • I've tested on Android
  • I've tested with a power user scenario
  • I've instrumented key operations with Sentry traces for production performance metrics — N/A for this change

Pre-merge reviewer checklist

Deposits funded from the Money account (e.g. Send to Perps) were setting
isMaxAmount=true on Max, causing TPC's calculatePostQuoteSourceAmounts to
substitute the pay token's raw balance (bare mUSD on Monad) as the source
amount. This collapsed Max to the un-vaulted mUSD portion instead of the
full withdrawable balance (mUSD + vmUSD), so a $4.70 balance showed $0.62.

Exclude the money-account payment override from shouldSetMax so these
deposits keep isMaxAmount=false and route the typed amount through as
token.amountRaw, matching money-account withdraw behavior. The
withdrawableFiatRaw balance source is unchanged.
@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamask-ci metamask-ci Bot added the team-confirmations Push issues to confirmations team label Jul 29, 2026
@metamask-ci

metamask-ci Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

PR template — items to address before "Ready for review"

Warnings — informational, address before merging:

See docs/readme/ready-for-review.md for the full Definition of Ready for Review.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

🧪 Flaky unit test detection

Run history flaky detection

View recent run history

Historical failure rate is a hint, not proof — review each suggestion in context. See the flaky-test-detection skill for the full pattern reference and manual audit workflow.

Failures / runs sampled per window:

File 7d 15d 30d
app/components/Views/confirmations/hooks/transactions/useTransactionCustomAmount.test.ts 0/202 0/329 0/380

AI-detected flaky patterns

app/components/Views/confirmations/hooks/transactions/useTransactionCustomAmount.test.ts

  • J10 — jest.spyOn() without restoreAllMocks()/mockRestore() afterward (medium)
    • The test uses jest.spyOn(Date, 'now') to pin a timestamp for metric calculation but does not call jest.restoreAllMocks() (or equivalent) afterward. The beforeEach only does jest.resetAllMocks(), which does not restore the original Date.now implementation. This shared mutable mock state can cause order-dependent behavior in later tests that rely on real timing (matches J10 exactly). No other J1-J10 patterns matched: all async updates are wrapped in act(), resetAllMocks() is present in beforeEach, no waitFor/sleeps/fake+waitFor combos/mutable module lets/incomplete stores/unstubbed non-determinism.
    • Suggested fix in app/components/Views/confirmations/hooks/transactions/useTransactionCustomAmount.test.ts:
      -    useTransactionPayHasSourceAmountMock.mockReturnValue(false);
      -    const { result, rerender } = runHook();
      -    jest.spyOn(Date, 'now').mockReturnValue(1746696741000);
      -    await act(async () => {
      +    useTransactionPayHasSourceAmountMock.mockReturnValue(false);
      +    const { result, rerender } = runHook();
      +    jest.setSystemTime(1746696741000);
      +    await act(async () => {

This check is informational only and does not block merging.

@jpuri jpuri added the no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed label Jul 30, 2026
With MetaMask/core#9707, TPC uses the typed required amount for Money
Account max instead of bare on-chain mUSD. Re-enable isMaxAmount on Max
for deposits funded from the money account so quotes use EXACT_INPUT and
fees are taken from the full withdrawable balance.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jpuri jpuri changed the title fix: correct Send to Perps Max amount when funded from Money account fix: enable EXACT_INPUT Max for Money Account Send to Perps Jul 30, 2026
@metamask-ci metamask-ci Bot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Jul 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: None (no tests recommended)
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 97%
click to see 🤖 AI reasoning details

E2E Test Selection:
The PR contains exactly two files:

  1. useTransactionCustomAmount.ts: The diff shows only comment changes — the comment block explaining the isMaxAmount logic was reworded/expanded. The actual functional code (shouldSetMax variable and its conditions) is completely unchanged. Per the cosmetic changes rule, comment-only changes have zero functional impact and must not trigger additional test selection.

  2. useTransactionCustomAmount.test.ts: A new unit test case is added to cover the isMaxAmount=true behavior for perpsDeposit with MoneyAccount payment override. This is a unit test file (.test.ts), not an E2E smoke spec. Adding unit tests does not affect E2E test selection.

Since the only functional change is a new unit test (no app logic changed, no UI changed, no E2E flows affected), no E2E smoke tags are warranted.

Performance Test Selection:
No app logic was changed — only a comment was updated in the .ts file and a unit test was added in the .test.ts file. Neither change affects any performance-sensitive code paths such as rendering, data fetching, or transaction execution timing.

View GitHub Actions results

@jpuri jpuri closed this Jul 30, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed size-S team-confirmations Push issues to confirmations team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant