Skip to content

Commit e7a93ce

Browse files
authored
fix(bridge): cp-7.67.0 display block explorer tx link for Popular networks in transaction details (#26659)
## **Description** `getBlockExplorerForChain()` in `TransactionDetails` only resolved block explorer URLs for hardcoded built-in networks (Mainnet, Linea, Sepolia) and user-added custom RPC networks. Popular networks (Arbitrum, Polygon, BNB Chain, etc.) are neither — they aren't stored in `networkConfigurations` — so the method fell through to `NO_RPC_BLOCK_EXPLORER`, hiding the "View on X" link entirely. The fix adds a `PopularList` lookup as a fallback, matching the pattern already used correctly in useBlockExplorer.ts. ## **Changelog** CHANGELOG entry: Fixed a bug where transactions on popular networks (Arbitrum, Polygon, BNB Chain, etc.) were missing the block explorer link in transaction details ## **Related issues** Fixes: #26419 ## **Manual testing steps** ```gherkin Feature: Block explorer link in transaction details Scenario: user views a transaction from a Popular network Given the user has transactions on Arbitrum, Polygon, or BNB Chain And the activity feed is filtered by "Popular networks" When user taps a confirmed transaction from one of those networks Then a "View on Arbiscan" / "View on Polygonscan" / "View on Bscscan" link appears And tapping it opens the correct block explorer tx URL in the webview Scenario: user views a transaction on Ethereum Mainnet Given the user has transactions on Ethereum Mainnet When user taps a confirmed transaction Then a "View on Etherscan" link still appears (regression check) ``` ## **Screenshots/Recordings** `~` ### **Before** https://github.com/user-attachments/assets/0b15c664-e62e-4811-94f6-e12687454025 ### **After** https://github.com/user-attachments/assets/8c71420a-f95a-4ebe-ba4c-dedd7cfebc0e ## **Pre-merge author checklist** - [x] 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). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [ ] 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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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 UI fix that only changes how the transaction details screen resolves a block explorer URL, with added test coverage to prevent regressions. > > **Overview** > Fixes missing **“View on …”** links in `TransactionDetails` for *popular networks* that aren’t present in `networkConfigurations` by falling back to `PopularList` to resolve `rpcPrefs.blockExplorerUrl`. > > Adds unit tests ensuring the correct explorer link text/URL is produced for Arbitrum, Polygon, and BNB Chain, alongside existing mainnet/custom-network coverage. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0e7e142. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent d7b7f79 commit e7a93ce

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

app/components/UI/TransactionElement/TransactionDetails/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {
6666
} from '../../../../constants/urls';
6767
import { CHAIN_IDS } from '@metamask/transaction-controller';
6868
import TagBase from '../../../../component-library/base-components/TagBase';
69+
import { PopularList } from '../../../../util/networks/customNetworks';
6970

7071
const createStyles = (colors) =>
7172
StyleSheet.create({
@@ -199,6 +200,16 @@ class TransactionDetails extends PureComponent {
199200
blockExplorer = SEPOLIA_BLOCK_EXPLORER;
200201
}
201202

203+
// Check PopularList for additional networks (e.g. Arbitrum, Polygon, BNB)
204+
if (blockExplorer === NO_RPC_BLOCK_EXPLORER) {
205+
const popularNetwork = PopularList.find(
206+
(network) => network.chainId === txChainId,
207+
);
208+
if (popularNetwork?.rpcPrefs?.blockExplorerUrl) {
209+
blockExplorer = popularNetwork.rpcPrefs.blockExplorerUrl;
210+
}
211+
}
212+
202213
// Check for non-EVM chain block explorer
203214
if (isNonEvmChainId(chainId)) {
204215
blockExplorer = findBlockExplorerForNonEvmChainId(chainId);

app/components/UI/TransactionElement/TransactionDetails/index.test.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,57 @@ describe('TransactionDetails', () => {
348348
});
349349
});
350350

351+
it('should display explorer link for arbitrum (popular network not in networkConfigurations)', () => {
352+
arrangeActAssertBlockExplorerTest({
353+
overrideMocks: (mocks) => {
354+
mocks.mockState.engine.backgroundState.NetworkController =
355+
mockNetworkState({
356+
chainId: '0x1',
357+
id: 'mainnet',
358+
nickname: 'Ethereum Mainnet',
359+
ticker: 'ETH',
360+
});
361+
mocks.mockProps.networkId = '0xa4b1';
362+
},
363+
buttonText: 'View on Arbiscan',
364+
expectedUrl: 'https://arbiscan.io/tx/0x3',
365+
});
366+
});
367+
368+
it('should display explorer link for polygon (popular network not in networkConfigurations)', () => {
369+
arrangeActAssertBlockExplorerTest({
370+
overrideMocks: (mocks) => {
371+
mocks.mockState.engine.backgroundState.NetworkController =
372+
mockNetworkState({
373+
chainId: '0x1',
374+
id: 'mainnet',
375+
nickname: 'Ethereum Mainnet',
376+
ticker: 'ETH',
377+
});
378+
mocks.mockProps.networkId = '0x89';
379+
},
380+
buttonText: 'View on Polygonscan',
381+
expectedUrl: 'https://polygonscan.com/tx/0x3',
382+
});
383+
});
384+
385+
it('should display explorer link for bnb chain (popular network not in networkConfigurations)', () => {
386+
arrangeActAssertBlockExplorerTest({
387+
overrideMocks: (mocks) => {
388+
mocks.mockState.engine.backgroundState.NetworkController =
389+
mockNetworkState({
390+
chainId: '0x1',
391+
id: 'mainnet',
392+
nickname: 'Ethereum Mainnet',
393+
ticker: 'ETH',
394+
});
395+
mocks.mockProps.networkId = '0x38';
396+
},
397+
buttonText: 'View on Bscscan',
398+
expectedUrl: 'https://bscscan.com/tx/0x3',
399+
});
400+
});
401+
351402
it('should render `Batched transactions` tag if there are nested transactions', async () => {
352403
const { getByText } = renderComponent({
353404
state: initialState,

0 commit comments

Comments
 (0)