Skip to content

Commit a347e0b

Browse files
chore(runway): cherry-pick fix: check for non-evm chains before doing the toHex cp-7.62.0 (#24798)
- fix: check for non-evm chains before doing the toHex cp-7.62.0 (#24746) <!-- 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** Fixes a render error when viewing tokens on Tron chain by adding `isNonEvmChainId` guard before calling toHex on chainId in `useMusdCtaVisibility`. ## **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: null ## **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** <img width="418" height="746" alt="Screenshot 2026-01-16 at 11 59 58" src="https://github.com/user-attachments/assets/fe516368-e49b-48b0-af21-116781acb6e0" /> ### **After** <img width="410" height="671" alt="Screenshot 2026-01-16 at 12 01 27" src="https://github.com/user-attachments/assets/aedcab57-d0a1-4bb5-a12c-2897f9493725" /> ## **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] > Ensures mUSD conversion CTA only applies to EVM chains and avoids errors on non‑EVM networks. > > - Adds `isNonEvmChainId` guard in `useMusdCtaVisibility` to return `false` early in `shouldShowTokenListItemCta` for non‑EVM `chainId` > - Updates tests in `useMusdCtaVisibility.test.ts` to mock `isNonEvmChainId` and adds cases for Tron, plus defaulting to EVM in setup > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a774c30. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> [8a57626](8a57626) Co-authored-by: António Regadas <antonio.regadas@consensys.net>
1 parent f60a5e5 commit a347e0b

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

app/components/UI/Earn/hooks/useMusdCtaVisibility.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ jest.mock('react-redux', () => ({
2929
useSelector: jest.fn(),
3030
}));
3131
jest.mock('../selectors/featureFlags');
32+
jest.mock('../../../../core/Multichain/utils', () => ({
33+
isNonEvmChainId: jest.fn(),
34+
}));
35+
36+
import { isNonEvmChainId } from '../../../../core/Multichain/utils';
37+
const mockIsNonEvmChainId = isNonEvmChainId as jest.MockedFunction<
38+
typeof isNonEvmChainId
39+
>;
3240

3341
import { useSelector } from 'react-redux';
3442

@@ -109,6 +117,8 @@ describe('useMusdCtaVisibility', () => {
109117
mockIsMusdConversionTokenListItemCtaEnabled = false;
110118
mockIsMusdConversionAssetOverviewEnabled = false;
111119
mockMusdConversionCtaTokens = {};
120+
121+
mockIsNonEvmChainId.mockReturnValue(false);
112122
mockUseSelector.mockImplementation((selector) => {
113123
if (selector === selectIsMusdGetBuyCtaEnabledFlag) {
114124
return mockIsMusdCtaEnabled;
@@ -754,6 +764,59 @@ describe('useMusdCtaVisibility', () => {
754764
expect(isVisible).toBe(false);
755765
});
756766

767+
it('returns false when token is on a non-EVM chain like Tron', () => {
768+
const tronChainId = 'tron:728126428';
769+
const tronToken: TokenI = {
770+
...listItemToken,
771+
chainId: tronChainId,
772+
};
773+
mockIsNonEvmChainId.mockImplementation(
774+
(chainId) => chainId === tronChainId,
775+
);
776+
mockUseNetworksByCustomNamespace.mockReturnValue({
777+
...defaultNetworksByNamespace,
778+
areAllNetworksSelected: false,
779+
});
780+
mockUseMusdBalance.mockReturnValue({
781+
hasMusdBalanceOnAnyChain: true,
782+
balancesByChain: { [CHAIN_IDS.MAINNET]: '0x1234' },
783+
hasMusdBalanceOnChain: jest.fn().mockReturnValue(true),
784+
});
785+
786+
const { result } = renderHook(() => useMusdCtaVisibility());
787+
788+
const isVisible = result.current.shouldShowTokenListItemCta(tronToken);
789+
790+
expect(isVisible).toBe(false);
791+
expect(mockIsNonEvmChainId).toHaveBeenCalledWith(tronChainId);
792+
});
793+
794+
it('returns false for non-EVM chain even when all conditions are met', () => {
795+
const tronChainId = 'tron:728126428';
796+
const tronToken: TokenI = {
797+
...listItemToken,
798+
chainId: tronChainId,
799+
};
800+
mockIsNonEvmChainId.mockImplementation(
801+
(chainId) => chainId === tronChainId,
802+
);
803+
mockUseNetworksByCustomNamespace.mockReturnValue({
804+
...defaultNetworksByNamespace,
805+
areAllNetworksSelected: true,
806+
});
807+
mockUseMusdBalance.mockReturnValue({
808+
hasMusdBalanceOnAnyChain: true,
809+
balancesByChain: { [CHAIN_IDS.MAINNET]: '0x1234' },
810+
hasMusdBalanceOnChain: jest.fn().mockReturnValue(true),
811+
});
812+
813+
const { result } = renderHook(() => useMusdCtaVisibility());
814+
815+
const isVisible = result.current.shouldShowTokenListItemCta(tronToken);
816+
817+
expect(isVisible).toBe(false);
818+
});
819+
757820
it('returns true when all networks selected, user has mUSD on any chain, and token is configured for CTA', () => {
758821
mockUseNetworksByCustomNamespace.mockReturnValue({
759822
...defaultNetworksByNamespace,

app/components/UI/Earn/hooks/useMusdCtaVisibility.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { toHex } from '@metamask/controller-utils';
2424
import { AssetType } from '../../../Views/confirmations/types/token';
2525
import { useMusdConversionTokens } from './useMusdConversionTokens';
2626
import { isTokenInWildcardList } from '../utils/wildcardTokenList';
27+
import { isNonEvmChainId } from '../../../../core/Multichain/utils';
2728

2829
/**
2930
* Hook exposing helpers that decide whether to show various mUSD-related CTAs.
@@ -213,6 +214,11 @@ export const useMusdCtaVisibility = () => {
213214
return false;
214215
}
215216

217+
// mUSD needs to be available only on EVM chains
218+
if (isNonEvmChainId(asset.chainId)) {
219+
return false;
220+
}
221+
216222
if (isPopularNetworksFilterSelected) {
217223
return hasMusdBalanceOnAnyChain && isTokenWithCta(asset);
218224
}

0 commit comments

Comments
 (0)