feat: increase swap submission friction when price impact is high#40586
feat: increase swap submission friction when price impact is high#40586
Conversation
✨ Files requiring CODEOWNER review ✨🔄 @MetaMask/swaps-engineers (11 files, +1015 -113)
|
Builds ready [6bf0778]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
ab1c96b to
369df73
Compare
Builds ready [369df73]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
Builds ready [3312657]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
| try { | ||
| if (isHardwareWalletAccount) { | ||
| const isDeviceReady = await ensureDeviceReady(); |
There was a problem hiding this comment.
This try-catch block was moved over from bridge-cta-button so that the same submission flow can be used by the price impact modal Proceed button
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Builds ready [b651eb7]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|



Description
Changes
0%when price impact is negativeChangelog
CHANGELOG entry: feat: increase swap submission friction when price impact is high
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/SWAPS-4023
Manual testing steps
See acceptance criteria: https://docs.google.com/document/d/1bCKM-dJgJOYBfzPYdcsjDncvr0fL01IWbaWJGzRv8Is/edit?tab=t.0
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Updates bridge transaction submission flow (including hardware-wallet routing) to add a new high price-impact confirmation step, which could affect when/if transactions are sent. Risk is mitigated by added selectors and extensive unit/snapshot test coverage, but mistakes could still block valid swaps or allow unintended submissions.
Overview
Bridge now computes and surfaces price impact as a first-class validation signal. New selectors parse
quote.priceData.priceImpact, format it for display, and deriveisPriceImpactWarning/isPriceImpactErrorusing feature-flag thresholds (with defaults forwarning/error). Negative/invalid price impact is now treated as0%.High price impact submissions add friction via a new modal.
BridgeCTAButtonopensBridgePriceImpactWarningModalinstead of submitting whenisPriceImpactError, and the quote card always shows a Price impact row with warning/error styling plus a details button that opens the modal.Submission logic is centralized and hardened.
useSubmitBridgeTransactionnow ownsisSubmitting, performs hardware-walletensureDeviceReady()checks, routes hardware wallets to the awaiting-signatures page, and prevents duplicate submits; tests and mocks were updated accordingly.Localization and tests updated. Adds new
bridgePriceImpact*strings (andproceed) inen/en_GB, removes the oldbridgePriceImpactNormalWarningstring from many locales, updates mock quote/store data to includepriceData.priceImpactandpriceImpactThreshold, and adds/updates unit and snapshot tests (including baseline adjustments).Written by Cursor Bugbot for commit b651eb7. This will update automatically on new commits. Configure here.