Skip to content

fix: skip insufficient balance alert when fiat payment method is selected#30444

Merged
OGPoyraz merged 3 commits into
mainfrom
fix/skip-insufficient-balance-alert-for-fiat-payment
May 20, 2026
Merged

fix: skip insufficient balance alert when fiat payment method is selected#30444
OGPoyraz merged 3 commits into
mainfrom
fix/skip-insufficient-balance-alert-for-fiat-payment

Conversation

@OGPoyraz

@OGPoyraz OGPoyraz commented May 20, 2026

Copy link
Copy Markdown
Member

Description

Fixes an issue where the insufficient_balance blocking alert fires during MoneyAccountDeposit confirmation when a fiat payment method (e.g., Apple Pay, debit card) is selected in the PayWith section.

Related Issue

https://consensyssoftware.atlassian.net/browse/CONF-1410

Root Cause

The useInsufficientBalanceAlert hook checks isUsingPay (from useTransactionPayHasSourceAmount) to skip the alert when the user is paying with crypto via bridge/swap. However, when a fiat payment method is selected, there are no crypto source amounts — fiat goes through a completely different path (useFiatConfirmstartHeadlessBuy). So isUsingPay remains false, and the hook proceeds to check the native token balance, which is expected to be low for fiat-only users. This causes the blocking alert to fire incorrectly.

The IGNORE_TYPES array only includes withdraw types (moneyAccountWithdraw, perpsWithdraw, predictWithdraw), so moneyAccountDeposit is not excluded either.

Changes

  • Added a isFiatPaymentSelected guard to the early-return in useInsufficientBalanceAlert, reading from useTransactionPayFiatPayment().selectedPaymentMethodId. When a fiat payment method is active, the native balance check is irrelevant and the alert is skipped.
  • Removed a leftover debug console.log statement.
  • Added a dedicated test case verifying the alert returns an empty array when a fiat payment method is selected.

Manual testing steps

  1. Open MoneyAccountDeposit confirmation flow
  2. In the PayWith section, select a fiat payment method (e.g., Apple Pay)
  3. Enter an amount and press Done
  4. Verify the insufficient_balance alert does not appear
  5. Verify the confirm button is enabled and the fiat confirm flow proceeds normally
  6. Switch back to a crypto payment method with insufficient balance
  7. Verify the insufficient_balance alert does appear correctly

Screenshots/Recordings

N/A - logic-only change

Pre-merge author checklist

  • I have followed MetaMask Contributor Docs
  • I have completed the PR template to the best of my ability
  • I have included tests if applicable
  • I have documented my code using JSDoc format if applicable
  • I have applied the right labels on the PR
  • I have properly set the title of this PR
  • If applicable, I have included the "BREAKING CHANGE" label

Note

Low Risk
Low risk: adds a narrow guard to suppress a blocking alert only when a fiat payment method is selected, with a targeted unit test covering the new behavior.

Overview
Prevents the insufficient_balance blocking alert from showing during confirmations when a fiat PayWith method is selected by adding an early-return guard in useInsufficientBalanceAlert based on useTransactionPayFiatPayment().selectedPaymentMethodId.

Updates tests to mock useTransactionPayFiatPayment and adds coverage asserting the hook returns [] when a fiat payment method is active.

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

@OGPoyraz OGPoyraz requested a review from a team as a code owner May 20, 2026 13:40
@github-actions github-actions Bot added pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. size-S labels May 20, 2026
@OGPoyraz OGPoyraz added team-confirmations Push issues to confirmations team no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed labels May 20, 2026
@OGPoyraz OGPoyraz enabled auto-merge May 20, 2026 14:11
@metamaskbotv2 metamaskbotv2 Bot added INVALID-PR-TEMPLATE PR's body doesn't match template labels May 20, 2026
@OGPoyraz OGPoyraz removed the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label May 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are confined to two files: the useInsufficientBalanceAlert hook and its test file. The change adds a new condition to suppress the insufficient balance alert when a fiat payment method is selected (isFiatPaymentSelected). This is a targeted bug fix/feature enhancement in the confirmation alert system.

Why SmokeConfirmations: The useInsufficientBalanceAlert hook is part of the confirmation alerts system (useConfirmationAlerts.ts imports it). Any change to alert logic in confirmations should be validated with confirmation E2E tests to ensure the alert suppression works correctly and doesn't break other confirmation flows.

Why SmokeMoney: The change specifically targets fiat payment flows (checking useTransactionPayFiatPayment for a selectedPaymentMethodId). This is directly related to the MetaMask Card/fiat payment integration. The SmokeMoney tests cover card and fiat on/off-ramp flows where this fiat payment selection would be active.

Risk is low because:

  • The change only adds a new early-return condition; it doesn't modify existing logic
  • It's well-tested with a new unit test case
  • The isUsingPay guard was already partially covering pay flows; this is a more specific refinement
  • No shared infrastructure, controllers, or navigation components are affected

Performance Test Selection:
This change only modifies alert suppression logic in a React hook. There is no UI rendering, list rendering, data loading, or state management change that would impact performance metrics. No performance tests are warranted.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@OGPoyraz OGPoyraz added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit 239daae May 20, 2026
134 of 140 checks passed
@OGPoyraz OGPoyraz deleted the fix/skip-insufficient-balance-alert-for-fiat-payment branch May 20, 2026 17:04
@github-actions github-actions Bot locked and limited conversation to collaborators May 20, 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.

2 participants