Skip to content

Commit 0e76ada

Browse files
authored
feat: fix button label for action button clicked event cp-7.69.0 (#27117)
## **Description** The sticky Buy and Sell buttons on the token details page were both firing ACTION_BUTTON_CLICKED with button_label: "Swap", making it impossible to distinguish between the two actions in Mixpanel. Changes: * Added an optional buttonLabel param to goToSwaps / goToNativeBridge in useSwapBridgeNavigation, falls back to "Swap" so all existing callers are unaffected * `handleBuyPress` now passes `button_label: "Buy"` and `handleSellPress` passes `button_label: "Sell"` ## **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: updated event property for ACTION_BUTTON_CLICKED ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin 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** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I've included tests if applicable - [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/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] > **Low Risk** > Low risk: changes only analytics event properties by threading an optional `buttonLabel` through navigation helpers; swap/bridge navigation behavior is unchanged due to a default fallback. > > **Overview** > Fixes token details *Buy*/*Sell* sticky buttons reporting `ACTION_BUTTON_CLICKED` with `button_label: "Swap"`. > > `useSwapBridgeNavigation` now accepts an optional `buttonLabel` in `goToNativeBridge`/`goToSwaps` and uses it for `trackActionButtonClick` (defaulting to the existing Swap label), and `useTokenActions` passes the correct localized Buy/Sell labels; tests were updated to assert the new arguments. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8c1b45d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent a290214 commit 0e76ada

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

app/components/UI/Bridge/hooks/useSwapBridgeNavigation/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export const useSwapBridgeNavigation = ({
140140
bridgeViewMode: BridgeViewMode,
141141
sourceTokenOverride?: BridgeToken,
142142
destTokenOverride?: BridgeToken,
143+
buttonLabel?: string,
143144
) => {
144145
// Use tokenOverride if provided, otherwise fall back to tokenBase
145146
const effectiveSourceTokenBase = sourceTokenOverride ?? sourceTokenBase;
@@ -283,7 +284,7 @@ export const useSwapBridgeNavigation = ({
283284
...(isFromNavbar
284285
? {}
285286
: { action_position: ActionPosition.SECOND_POSITION }),
286-
button_label: strings('asset_overview.swap'),
287+
button_label: buttonLabel ?? strings('asset_overview.swap'),
287288
location: isFromNavbar
288289
? ActionLocation.NAVBAR
289290
: ActionLocation.ASSET_DETAILS,
@@ -328,11 +329,16 @@ export const useSwapBridgeNavigation = ({
328329
const { networkModal } = useAddNetwork();
329330

330331
const goToSwaps = useCallback(
331-
(tokenOverride?: BridgeToken, destTokenOverride?: BridgeToken) => {
332+
(
333+
tokenOverride?: BridgeToken,
334+
destTokenOverride?: BridgeToken,
335+
buttonLabel?: string,
336+
) => {
332337
goToNativeBridge(
333338
BridgeViewMode.Unified,
334339
tokenOverride,
335340
destTokenOverride,
341+
buttonLabel,
336342
);
337343
},
338344
[goToNativeBridge],

app/components/UI/TokenDetails/hooks/useTokenActions.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ describe('useTokenActions', () => {
655655
chainId: defaultToken.chainId,
656656
symbol: defaultToken.symbol,
657657
}),
658+
'Buy',
658659
);
659660
expect(mockGoToBuy).not.toHaveBeenCalled();
660661
});
@@ -692,6 +693,7 @@ describe('useTokenActions', () => {
692693
expect.objectContaining({
693694
address: defaultToken.address,
694695
}),
696+
'Buy',
695697
);
696698
});
697699

@@ -743,6 +745,7 @@ describe('useTokenActions', () => {
743745
chainId: '0x1',
744746
symbol: 'ETH',
745747
}),
748+
'Buy',
746749
);
747750
expect(mockGoToBuy).not.toHaveBeenCalled();
748751
});
@@ -767,6 +770,7 @@ describe('useTokenActions', () => {
767770
symbol: defaultToken.symbol,
768771
}),
769772
undefined,
773+
'Sell',
770774
);
771775
});
772776
});

app/components/UI/TokenDetails/hooks/useTokenActions.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ export const useTokenActions = ({
437437
}
438438

439439
if (!goToSwaps) return;
440-
goToSwaps(buySourceToken, currentTokenAsBridgeToken);
440+
goToSwaps(
441+
buySourceToken,
442+
currentTokenAsBridgeToken,
443+
strings('asset_overview.buy_button'),
444+
);
441445
}, [
442446
goToSwaps,
443447
goToBuy,
@@ -450,7 +454,11 @@ export const useTokenActions = ({
450454
// Sell: current token as source, let swap UI compute default dest
451455
const handleSellPress = useCallback(() => {
452456
if (!goToSwaps) return;
453-
goToSwaps(currentTokenAsBridgeToken, undefined);
457+
goToSwaps(
458+
currentTokenAsBridgeToken,
459+
undefined,
460+
strings('asset_overview.sell_button'),
461+
);
454462
}, [goToSwaps, currentTokenAsBridgeToken]);
455463

456464
return {

0 commit comments

Comments
 (0)