Skip to content

feat: swap add warning msg when EVM native reserve#29712

Merged
maxime-oe merged 1 commit into
mainfrom
feat/swap-evm-gasless-minimum-reserve-message
May 7, 2026
Merged

feat: swap add warning msg when EVM native reserve#29712
maxime-oe merged 1 commit into
mainfrom
feat/swap-evm-gasless-minimum-reserve-message

Conversation

@maxime-oe

@maxime-oe maxime-oe commented May 5, 2026

Copy link
Copy Markdown
Contributor

Description

Problem statement:

  • Some networks like Monad require a Reserve Balance to be kept at all times in a given account.
  • This constraint is usually not explicitly reflected in UX in most wallets, but the limit is real and a tx may fail if user accounts go below that minimum reserve. For example it is of 10 MON for Monad.
  • MetaMask Swap will always run a pre-flight simulation while fetching, triggering an error message when trying to swap MON in a swap that would put it's reserve below the 10 MON threshold.

Proposed solution

  • Keep showing quotes to the user when it this situation (same as the "not enough balance" situation) -> Lift this balance constraint during pre-flight simulation by setting the insufficientBal parameter to true.
  • Display a specific Banner Alert for this specific issue, explaining the constraint of the user.
  • (nice to have) Add a Use max available CTA in the Alert Banner that will prefill automatically balance - minimumReserve as source amount. This solution ticks three boxes:
  1. Preserves the "max" button original behavior without polluting it with per-chain logic.
  2. Avoids terrible UX where clicking on "max" would not select "max".
  3. Allows the user to be informed about the constraint, and be aware of the consequences.

Changelog

CHANGELOG entry: Swap/Bridge to warn user if native balance will go below a minimum threshold.

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/NEB-1113?atlOrigin=eyJpIjoiYmRkZGU5ZjE0MTRhNDM4OTgyNWZjOGJlMDU1YTliZDMiLCJwIjoiaiJ9

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Screenshot_2026-05-05-11-54-55-377_io metamask

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Medium risk: changes swap/bridge quote-request parameters and submit gating, which can affect quote fetching and transaction eligibility on gas-sponsored networks (especially for native-token swaps). Logic is new but scoped and covered by unit tests and copy additions.

Overview
Adds detection for native-token minimum reserve constraints on gas-sponsored EVM networks (e.g., Monad), via a new useInsufficientNativeReserveError hook that computes a required reserve and max swappable amount.

When triggered, the Bridge view shows a dedicated warning banner with a “Use max allowed” CTA that pre-fills the allowable amount, disables the confirm button (labeling it as insufficient funds), and includes the condition in quote analytics warnings. Quote requests now set insufficientBal=true when this reserve constraint is hit so quotes can still be fetched/displayed, and tests/i18n strings are added to cover the new behavior.

Reviewed by Cursor Bugbot for commit 1d06ecd. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented May 5, 2026

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.

@metamaskbotv2 metamaskbotv2 Bot added the team-networks Networks team label May 5, 2026
@maxime-oe maxime-oe marked this pull request as ready for review May 5, 2026 07:45
@maxime-oe maxime-oe requested a review from a team as a code owner May 5, 2026 07:45
@github-actions github-actions Bot added the size-M label May 5, 2026
Comment thread app/components/UI/Bridge/Views/BridgeView/index.tsx
@maxime-oe maxime-oe force-pushed the feat/swap-evm-gasless-minimum-reserve-message branch from 8d8b7da to 7afc3b1 Compare May 5, 2026 08:05

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7afc3b1. Configure here.

@maxime-oe maxime-oe force-pushed the feat/swap-evm-gasless-minimum-reserve-message branch from 7afc3b1 to dbb1325 Compare May 5, 2026 09:47
@maxime-oe maxime-oe force-pushed the feat/swap-evm-gasless-minimum-reserve-message branch from dbb1325 to 1d06ecd Compare May 5, 2026 10:02
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeSwap, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 92%
click to see 🤖 AI reasoning details

E2E Test Selection:
All changes are contained within the Bridge/Swap UI components:

  1. New useInsufficientNativeReserveError hook: Implements a minimum native reserve balance check for gas-sponsored networks (initially Monad chain requiring 10 MON reserve). Returns error details when user tries to swap more than the allowed amount.

  2. BridgeView/index.tsx: Integrates the new hook to display a warning banner with a "Use max allowed" CTA when the native reserve error is triggered. Also disables the submit button when this error is present.

  3. SwapsConfirmButton/index.tsx: Disables the confirm button and shows "Insufficient funds" label when the native reserve error is triggered.

  4. useBridgeQuoteRequest/index.ts: Prevents quote requests when the native reserve error is present (treats it as insufficient balance).

  5. useBridgeQuoteEvents/index.ts: Adds hasInsufficientNativeReserveError to analytics event tracking with a new 'insufficient_native_reserve' warning type.

  6. locales/languages/en.json: Adds 3 new localization strings for the insufficient native reserve error UI.

Tag Selection Rationale:

  • SmokeSwap: Directly impacts swap/bridge flows - the confirm button behavior, quote request logic, and BridgeView UI are all modified. This is the primary tag for bridge/swap functionality.
  • SmokeConfirmations: Per SmokeSwap's description, "When selecting SmokeSwap, also select SmokeConfirmations (transaction confirmations are part of the flow)."

No other tags are needed as changes are isolated to the Bridge/Swap UI components with no impact on accounts, networks, identity, snaps, browser, or other wallet features.

Performance Test Selection:
No performance-sensitive changes are present. The changes add a new hook for balance validation logic and UI warning banner in the Bridge flow. There are no changes to list rendering, state management at scale, app startup/initialization, or other performance-critical paths. The new hook performs simple arithmetic calculations that are negligible in terms of performance impact.

View GitHub Actions results

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.87%. Comparing base (8437791) to head (1d06ecd).
⚠️ Report is 70 commits behind head on main.

Files with missing lines Patch % Lines
...pp/components/UI/Bridge/Views/BridgeView/index.tsx 42.85% 3 Missing and 1 partial ⚠️
...e/hooks/useInsufficientNativeReserveError/index.ts 90.00% 0 Missing and 2 partials ⚠️
...ents/UI/Bridge/hooks/useBridgeQuoteEvents/index.ts 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #29712      +/-   ##
==========================================
+ Coverage   81.86%   81.87%   +0.01%     
==========================================
  Files        5255     5272      +17     
  Lines      138980   139498     +518     
  Branches    31518    31701     +183     
==========================================
+ Hits       113774   114216     +442     
- Misses      17465    17520      +55     
- Partials     7741     7762      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

sonarqubecloud Bot commented May 5, 2026

Copy link
Copy Markdown

@maxime-oe maxime-oe added this pull request to the merge queue May 7, 2026
Merged via the queue into main with commit d0e444a May 7, 2026
98 checks passed
@maxime-oe maxime-oe deleted the feat/swap-evm-gasless-minimum-reserve-message branch May 7, 2026 16:13
@github-actions github-actions Bot locked and limited conversation to collaborators May 7, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.77.0 Issue or pull request that will be included in release 7.77.0 label May 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.77.0 Issue or pull request that will be included in release 7.77.0 size-M team-networks Networks team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants