Skip to content

Commit ddeb821

Browse files
authored
fix: UI improvements on dapp swap comparison banner (#38517)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** UI improvements on dapp swap comparison banner. ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: MetaMask/MetaMask-planning#6382 ## **Manual testing steps** 1. Submit swap 2. Check dapp-swap comparison banner ## **Screenshots/Recordings** <img width="395" height="604" alt="Screenshot 2025-12-03 at 5 25 55 PM" src="https://github.com/user-attachments/assets/84bb9c52-e1a9-46ac-9f99-ffdc7db97614" /> <img width="393" height="612" alt="Screenshot 2025-12-03 at 5 25 49 PM" src="https://github.com/user-attachments/assets/d4417e07-21be-4f79-8d77-51fb5824a343" /> ## **Pre-merge author checklist** - [X] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [X] I've completed the PR template to the best of my ability - [X] I’ve included tests if applicable - [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Refines the dapp swap comparison banner UI/behavior and adds robust error handling in comparison logic, plus a minor token amount calculation tweak. > > - **UI (banner)**: > - Banner now remains visible when switching tabs; close button/arrow only show on current tab. > - Restyles savings/rewards line using layout components; highlights savings in success color and separates rewards text. > - **Hooks (comparison info)**: > - Wraps best-quote selection, metrics capture, and value-difference calculations in try/catch with `captureException` and failure metrics. > - **Utils**: > - `calculateTokenAmount` multiplies by a `BigNumber` conversion rate for numeric safety. > - Temporarily comments out a catch-all `captureException` in `dapp-swap-util.ts` top-level error path. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a143a54. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent c7dcb27 commit ddeb821

File tree

5 files changed

+203
-154
lines changed

5 files changed

+203
-154
lines changed

app/scripts/lib/dapp-swap/dapp-swap-util.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ export function getQuotesForConfirmation({
157157
commands,
158158
});
159159
}
160-
captureException(
161-
`Error fetching bridge quotes: ${(error as Error).message}`,
162-
);
160+
// The error capturing to be uncommented as we address this issue:
161+
// https://github.com/MetaMask/MetaMask-planning/issues/6387
162+
// captureException(
163+
// `Error fetching bridge quotes: ${(error as Error).toString()}`,
164+
// );
163165
}
164166
}

ui/pages/confirmations/components/confirm/dapp-swap-comparison-banner/dapp-swap-comparison-banner.tsx

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import React, { useCallback, useEffect, useState } from 'react';
33
import {
44
Box,
5+
BoxAlignItems,
56
BoxBackgroundColor,
7+
BoxFlexDirection,
68
ButtonIcon,
79
ButtonIconSize,
810
IconName,
@@ -117,12 +119,10 @@ const DappSwapComparisonInner = () => {
117119
swap_mm_opened: 'true',
118120
});
119121
setSelectedSwapType(SwapType.Metamask);
120-
setShowDappSwapComparisonBanner(false);
121122
}, [
122123
captureDappSwapComparisonDisplayProperties,
123124
setQuotedSwapDisplayedInInfo,
124125
setSelectedSwapType,
125-
setShowDappSwapComparisonBanner,
126126
selectedQuote,
127127
]);
128128

@@ -163,7 +163,7 @@ const DappSwapComparisonInner = () => {
163163
return (
164164
<Box>
165165
<SwapTabs onTabClick={onTabClick} activeTabKey={selectedSwapType} />
166-
{showDappSwapComparisonBanner && dappTypeSelected && (
166+
{showDappSwapComparisonBanner && (
167167
<Box
168168
className="dapp-swap_callout"
169169
backgroundColor={BoxBackgroundColor.BackgroundSection}
@@ -172,31 +172,53 @@ const DappSwapComparisonInner = () => {
172172
role="button"
173173
onClick={updateSwapToSelectedQuote}
174174
>
175-
<ButtonIcon
176-
className="dapp-swap_close-button"
177-
iconName={IconName.Close}
178-
size={ButtonIconSize.Sm}
179-
onClick={hideDappSwapComparisonBanner}
180-
ariaLabel="close-dapp-swap-comparison-banner"
181-
/>
182-
<div className="dapp-swap_callout-arrow" />
175+
{dappTypeSelected && (
176+
<>
177+
<ButtonIcon
178+
className="dapp-swap_close-button"
179+
iconName={IconName.Close}
180+
size={ButtonIconSize.Sm}
181+
onClick={hideDappSwapComparisonBanner}
182+
ariaLabel="close-dapp-swap-comparison-banner"
183+
/>
184+
<div className="dapp-swap_callout-arrow" />
185+
</>
186+
)}
183187
<Text
184188
className="dapp-swap_callout-text"
185189
color={TextColor.TextDefault}
186190
variant={TextVariant.BodySm}
187191
>
188192
{rewards ? t('dappSwapAdvantage') : t('dappSwapAdvantageSaveOnly')}
189193
</Text>
190-
<Text
191-
className="dapp-swap_text-save"
192-
color={TextColor.TextAlternative}
193-
variant={TextVariant.BodyXs}
194+
<Box
195+
flexDirection={BoxFlexDirection.Row}
196+
alignItems={BoxAlignItems.Center}
197+
gap={2}
198+
marginBottom={2}
194199
>
195-
{t('dappSwapQuoteDifference', [
196-
`$${selectedQuoteValueDifference.toFixed(2)}`,
197-
])}
198-
{rewards && <span>{` • ${rewards.text}`}</span>}
199-
</Text>
200+
<Text color={TextColor.SuccessDefault} variant={TextVariant.BodyXs}>
201+
{t('dappSwapQuoteDifference', [
202+
`$${selectedQuoteValueDifference.toFixed(2)}`,
203+
])}
204+
</Text>
205+
{rewards && (
206+
<>
207+
<Text
208+
color={TextColor.TextAlternative}
209+
variant={TextVariant.BodyXs}
210+
>
211+
{` • `}
212+
</Text>
213+
<Text
214+
className="dapp-swap_text-rewards"
215+
variant={TextVariant.BodyXs}
216+
>
217+
{rewards.text}
218+
</Text>
219+
</>
220+
)}
221+
</Box>
200222
<Text color={TextColor.TextAlternative} variant={TextVariant.BodyXs}>
201223
{t('dappSwapBenefits')}
202224
</Text>

ui/pages/confirmations/components/confirm/dapp-swap-comparison-banner/index.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Disabling Stylelint's hex color rule here because the TypeScript migration dashb
4545
margin-bottom: 4px;
4646
}
4747

48-
&_text-save {
49-
margin-bottom: 4px;
48+
&_text-rewards {
49+
color: var(--color-accent01-light);
5050
}
5151

5252
&_callout-arrow {

0 commit comments

Comments
 (0)