Skip to content

fix: handle BTC quote when BTC quote has missing or non-positive network fee data#30313

Merged
Battambang merged 3 commits into
mainfrom
fix-swap-inconsistent-btc-network-fees
May 19, 2026
Merged

fix: handle BTC quote when BTC quote has missing or non-positive network fee data#30313
Battambang merged 3 commits into
mainfrom
fix-swap-inconsistent-btc-network-fees

Conversation

@Battambang

@Battambang Battambang commented May 18, 2026

Copy link
Copy Markdown
Contributor

Description

This pull request improves how the Bridge UI handles and displays cases where the network fee is unavailable, especially for Bitcoin (BTC) bridges. It introduces a new hook to detect unavailable network fees, updates the logic for disabling/enabling the confirm button, and adjusts messaging and analytics accordingly. The changes also include comprehensive tests for these scenarios.

Key changes:

1. Handling Network Fee Unavailability in the UI

  • Added the useIsNetworkFeeUnavailable hook to detect when the network fee (especially for BTC) is unavailable and integrated it into both BridgeView and SwapsConfirmButton components. This disables the confirm button and updates the label to "Insufficient funds" when the fee is unavailable.

2. Analytics and Event Tracking

  • Updated the useBridgeQuoteEvents hook and its consumers to track when the network fee is unavailable, emitting a new network_fee_unavailable warning instead of the generic insufficient gas warning.

3. Gas Fee Calculation Logic

  • Modified useHasSufficientGas to use totalNetworkFee.amount for BTC quotes instead of gasFee.effective.amount, ensuring correct balance validation for Bitcoin transactions.

4. Testing and Coverage

  • Added and updated tests for both the UI and hooks to cover scenarios where the BTC network fee is unavailable, ensuring proper button states, messaging, and analytics events. This includes new test cases for SwapsConfirmButton and useBridgeQuoteEvents, and additional BTC-specific tests for useHasSufficientGas.

These updates ensure that users are clearly informed when a bridge transaction cannot proceed due to unavailable network fees, especially for Bitcoin, and that analytics accurately reflect this state.

Changelog

CHANGELOG entry: fixed BTC quote when BTC quote has missing or non-positive network fee data

Related issues

Fixes: Bridging BTC is failing at the transaction crafting in certain cases

Manual testing steps

BTC quote with unavailable fee

  1. Open the Bridge/Swap flow.
  2. Select BTC as the source token and ETH as the destination token.
  3. Enter an amount that can produce a BTC quote.
  4. Simulate or reproduce a quote where the BTC network fee is 0 or unavailable.
  5. Confirm the CTA shows Insufficient funds.

Screenshots/Recordings

Before

After

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
Updates bridge confirmation disablement, labeling, and analytics around fee/gas validation, which can block submissions and alter event warnings; impact is mostly limited to BTC and UI state handling but affects core swap/bridge CTA logic.

Overview
Improves BTC quote handling when network fee data is missing/invalid. Adds useIsNetworkFeeUnavailable to detect BTC quotes with missing, non-finite, or non-positive totalNetworkFee.amount, and uses it to disable submission and show Insufficient funds (instead of Insufficient gas) in BridgeView, SwapsConfirmButton, and Quick Buy.

Adjusts fee validation + analytics. useHasSufficientGas now prefers totalNetworkFee.amount for BTC when checking gas sufficiency, and useBridgeQuoteEvents emits a new network_fee_unavailable warning (taking precedence over insufficient gas).

Expands test coverage. Adds/updates unit tests to cover BTC network-fee-unavailable cases across confirm button states, “Get new quote” enablement, quote warnings, Quick Buy button errors, and BTC gas validation.

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

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

@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-M labels May 18, 2026
@Battambang Battambang changed the title fix: handle BTC quote when BTC quote has missing or non-positive netw… fix: handle BTC quote when BTC quote has missing or non-positive network fee data May 18, 2026
@Battambang Battambang force-pushed the fix-swap-inconsistent-btc-network-fees branch from 0d46ab0 to bd1cace Compare May 18, 2026 14:51
@Battambang Battambang marked this pull request as ready for review May 18, 2026 14:51
@Battambang Battambang requested a review from a team as a code owner May 18, 2026 14:51
@Battambang Battambang force-pushed the fix-swap-inconsistent-btc-network-fees branch 2 times, most recently from bd1cace to 4027284 Compare May 18, 2026 14:52
@Battambang Battambang added team-networks Networks team and removed pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. labels May 18, 2026
@Battambang Battambang force-pushed the fix-swap-inconsistent-btc-network-fees branch from 4027284 to 7a67c3e Compare May 18, 2026 15:55

@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 7a67c3e. Configure here.

Comment thread app/components/UI/Bridge/Views/BridgeView/index.tsx
@Battambang Battambang force-pushed the fix-swap-inconsistent-btc-network-fees branch from 7a67c3e to 797bf0f Compare May 18, 2026 17:45
@Battambang

Copy link
Copy Markdown
Contributor Author

@metamaskbot update-mobile-fixture

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Fixture update started. Running workflow from branch fix-swap-inconsistent-btc-network-fees. View workflow runs

@github-actions

Copy link
Copy Markdown
Contributor

E2E fixture update failed.\n\nCommon causes:\n- CI workflow is still running — wait for 'Build iOS Apps' to complete\n- CI workflow was skipped — ensure your PR has iOS-impacting changes or use skip-smart-e2e-selection label\n- iOS build failed — check the CI workflow for errors\n\nView logs and retry

@Battambang

Copy link
Copy Markdown
Contributor Author

@metamaskbot update-mobile-fixture

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Fixture update started. Running workflow from branch fix-swap-inconsistent-btc-network-fees. View workflow runs

@github-actions

Copy link
Copy Markdown
Contributor

E2E fixture update failed.\n\nCommon causes:\n- CI workflow is still running — wait for 'Build iOS Apps' to complete\n- CI workflow was skipped — ensure your PR has iOS-impacting changes or use skip-smart-e2e-selection label\n- iOS build failed — check the CI workflow for errors\n\nView logs and retry

@Battambang Battambang force-pushed the fix-swap-inconsistent-btc-network-fees branch 4 times, most recently from daa8400 to d4be510 Compare May 18, 2026 20:53
@github-project-automation github-project-automation Bot moved this to Needs dev review in PR review queue May 18, 2026
Comment thread app/components/UI/Bridge/hooks/useIsNetworkFeeUnavailable/index.ts
Comment thread app/components/UI/Bridge/hooks/useIsNetworkFeeUnavailable/index.ts Outdated
Comment thread app/components/UI/Bridge/hooks/useIsNetworkFeeUnavailable/index.ts Outdated
@Battambang Battambang force-pushed the fix-swap-inconsistent-btc-network-fees branch from d4be510 to 30e4c63 Compare May 19, 2026 13:12
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:

The PR introduces a new useIsNetworkFeeUnavailable hook for Bitcoin bridge scenarios and integrates it across the bridge/swap UI:

  1. Bridge/Swap flow changes (BridgeView, SwapsConfirmButton, useBridgeQuoteEvents): The confirm button disabled state, button labels, and quote event warnings are all updated to handle the case where network fee is unavailable (Bitcoin chains). This directly affects the swap/bridge user flow → SmokeSwap required. Per SmokeSwap description, SmokeConfirmations must also be selected.

  2. useHasSufficientGas: Updated to use totalNetworkFee for Bitcoin chains, changing gas sufficiency logic for Bitcoin bridge quotes.

  3. useQuickBuyBottomSheet (Social Leaderboard/Predictions): The same useIsNetworkFeeUnavailable pattern is applied here, changing button error states and disabled conditions for the QuickBuy flow used in Predictions → SmokePredictions required. Per SmokePredictions description, SmokeWalletPlatform (Trending section) and SmokeConfirmations must also be selected.

The changes are focused on Bitcoin bridge edge cases but modify core bridge UI logic (button states, labels) that runs for all bridge/swap flows. Risk is medium because the logic changes are well-scoped but touch critical user-facing confirm button behavior.

Performance Test Selection:
The changes are focused on bridge/swap UI logic for Bitcoin network fee unavailability - new hook, button state updates, and event tracking. These are conditional logic changes (not rendering performance, list rendering, or data loading changes) that don't meaningfully impact app performance metrics. No performance test tags are warranted.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@github-project-automation github-project-automation Bot moved this from Needs dev review to Review finalised - Ready to be merged in PR review queue May 19, 2026
@Battambang Battambang added this pull request to the merge queue May 19, 2026
Merged via the queue into main with commit 5042fdb May 19, 2026
189 of 200 checks passed
@Battambang Battambang deleted the fix-swap-inconsistent-btc-network-fees branch May 19, 2026 17:31
@github-project-automation github-project-automation Bot moved this from Review finalised - Ready to be merged to Merged, Closed or Archived in PR review queue May 19, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators May 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants