Skip to content

Commit 9093654

Browse files
authored
Merge branch 'main' into ogp/block-burn-address-send
2 parents d587397 + 42d139d commit 9093654

File tree

4 files changed

+86
-19
lines changed

4 files changed

+86
-19
lines changed

app/components/UI/Transactions/TransactionsFooter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const TransactionsFooter = ({
9393
return null;
9494
}
9595

96-
if (isMainnetByChainId(chainId) || providerType !== RPC) {
96+
if (isMainnetByChainId(chainId) || (providerType && providerType !== RPC)) {
9797
return strings('transactions.view_full_history_on_etherscan');
9898
}
9999

app/components/Views/UnifiedTransactionsView/UnifiedTransactionsView.test.tsx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ jest.mock('../../../selectors/networkController', () => ({
9898
selectNetworkConfigurations: jest.fn(),
9999
selectProviderType: jest.fn(),
100100
selectRpcUrl: jest.fn(),
101+
selectProviderConfig: jest.fn(),
101102
}));
102103
jest.mock('../../../selectors/networkEnablementController', () => ({
103104
selectEVMEnabledNetworks: jest.fn(),
@@ -145,6 +146,16 @@ jest.mock('../../UI/Bridge/hooks/useBridgeHistoryItemBySrcTxHash', () => ({
145146
}),
146147
}));
147148

149+
const mockGetBlockExplorerUrl = jest.fn(() => undefined);
150+
const mockGetBlockExplorerName = jest.fn(() => 'Explorer');
151+
jest.mock('../../hooks/useBlockExplorer', () => ({
152+
__esModule: true,
153+
default: () => ({
154+
getBlockExplorerUrl: mockGetBlockExplorerUrl,
155+
getBlockExplorerName: mockGetBlockExplorerName,
156+
}),
157+
}));
158+
148159
const mockTransactionsFooter = jest.fn((props: unknown) => {
149160
const ReactActual = jest.requireActual('react');
150161
const { Text } = jest.requireActual('react-native');
@@ -183,6 +194,7 @@ jest.mock('../../../core/Multichain/utils', () => ({
183194
__esModule: true,
184195
getAddressUrl: (address: string, chainId: string) =>
185196
mockGetAddressUrl(address, chainId),
197+
isNonEvmChainId: jest.fn((chainId: string) => chainId.includes(':')),
186198
}));
187199

188200
// Mock refresh util
@@ -292,6 +304,7 @@ const {
292304
selectNetworkConfigurations,
293305
selectProviderType,
294306
selectRpcUrl,
307+
selectProviderConfig,
295308
} = jest.requireMock('../../../selectors/networkController');
296309
const { selectEVMEnabledNetworks, selectNonEVMEnabledNetworks } =
297310
jest.requireMock('../../../selectors/networkEnablementController');
@@ -312,6 +325,10 @@ describe('UnifiedTransactionsView', () => {
312325
mockTransactionsFooter.mockClear();
313326
mockMultichainTransactionsFooter.mockClear();
314327
mockGetAddressUrl.mockClear();
328+
mockGetBlockExplorerUrl.mockClear();
329+
mockGetBlockExplorerUrl.mockReturnValue(undefined);
330+
mockGetBlockExplorerName.mockClear();
331+
mockGetBlockExplorerName.mockReturnValue('Explorer');
315332
mockGetAddressUrl.mockImplementation(
316333
(address?: string) => `https://solscan.io/account/${address}`,
317334
);
@@ -350,6 +367,8 @@ describe('UnifiedTransactionsView', () => {
350367
if (selector === selectNetworkConfigurations) return {};
351368
if (selector === selectProviderType) return 'rpc';
352369
if (selector === selectRpcUrl) return 'https://rpc.example';
370+
if (selector === selectProviderConfig)
371+
return { type: 'rpc', rpcUrl: 'https://rpc.example' };
353372
if (selector === selectEVMEnabledNetworks) return ['0x1'];
354373
if (selector === selectNonEVMEnabledNetworks) return ['solana:mainnet'];
355374
if (selector === selectCurrentCurrency) return 'USD';
@@ -410,8 +429,10 @@ describe('UnifiedTransactionsView', () => {
410429

411430
it('pull-to-refresh calls updateIncomingTransactions', async () => {
412431
const { UNSAFE_getAllByType } = render(<UnifiedTransactionsView />);
432+
413433
const [rc] = UNSAFE_getAllByType(RefreshControl);
414-
rc.props.onRefresh();
434+
await rc.props.onRefresh();
435+
415436
expect(updateIncomingTransactions).toHaveBeenCalled();
416437
});
417438

@@ -583,6 +604,8 @@ describe('UnifiedTransactionsView', () => {
583604
if (selector === selectNetworkConfigurations) return {};
584605
if (selector === selectProviderType) return 'rpc';
585606
if (selector === selectRpcUrl) return 'https://rpc.example';
607+
if (selector === selectProviderConfig)
608+
return { type: 'rpc', rpcUrl: 'https://rpc.example' };
586609
if (selector === selectEVMEnabledNetworks) return ['0x1', '0x5'];
587610
if (selector === selectNonEVMEnabledNetworks) return [];
588611
if (selector === selectCurrentCurrency) return 'USD';
@@ -599,12 +622,9 @@ describe('UnifiedTransactionsView', () => {
599622
expect(footerProps.rpcBlockExplorer).toBeUndefined();
600623

601624
footerProps.onViewBlockExplorer?.();
602-
expect(networksMock.getBlockExplorerAddressUrl).toHaveBeenCalledWith(
603-
'rpc',
604-
'0xabc',
605-
undefined,
606-
);
607-
expect(networksMock.getBlockExplorerAddressUrl).toHaveBeenCalledTimes(1);
625+
// When configBlockExplorerUrl is undefined (multiple chains case),
626+
// the component uses blockExplorerUrl directly without calling getBlockExplorerAddressUrl
627+
expect(networksMock.getBlockExplorerAddressUrl).not.toHaveBeenCalled();
608628
isRemoveGlobalNetworkSelectorEnabled.mockReturnValue(false);
609629
});
610630
});
@@ -635,6 +655,8 @@ describe('UnifiedTransactionsView', () => {
635655
if (selector === selectNetworkConfigurations) return {};
636656
if (selector === selectProviderType) return 'rpc';
637657
if (selector === selectRpcUrl) return 'https://rpc.example';
658+
if (selector === selectProviderConfig)
659+
return { type: 'rpc', rpcUrl: 'https://rpc.example' };
638660
if (selector === selectEVMEnabledNetworks) return [];
639661
if (selector === selectNonEVMEnabledNetworks) return ['solana:mainnet'];
640662
if (selector === selectCurrentCurrency) return 'USD';
@@ -682,6 +704,8 @@ describe('UnifiedTransactionsView', () => {
682704
if (selector === selectNetworkConfigurations) return {};
683705
if (selector === selectProviderType) return 'rpc';
684706
if (selector === selectRpcUrl) return 'https://rpc.example';
707+
if (selector === selectProviderConfig)
708+
return { type: 'rpc', rpcUrl: 'https://rpc.example' };
685709
if (selector === selectEVMEnabledNetworks) return [];
686710
if (selector === selectNonEVMEnabledNetworks)
687711
return ['bip122:000000000019d6689c085ae165831e93'];
@@ -720,6 +744,8 @@ describe('UnifiedTransactionsView', () => {
720744
if (selector === selectTokens) return [];
721745
if (selector === selectChainId) return '0x1';
722746
if (selector === selectIsPopularNetwork) return false;
747+
if (selector === selectProviderConfig)
748+
return { type: 'rpc', rpcUrl: 'https://rpc.example' };
723749
if (selector === selectEVMEnabledNetworks) return [];
724750
if (selector === selectNonEVMEnabledNetworks) return [];
725751
if (selector === selectCurrentCurrency) return 'USD';
@@ -754,6 +780,8 @@ describe('UnifiedTransactionsView', () => {
754780
if (selector === selectTokens) return [];
755781
if (selector === selectChainId) return '0x1';
756782
if (selector === selectIsPopularNetwork) return false;
783+
if (selector === selectProviderConfig)
784+
return { type: 'rpc', rpcUrl: 'https://rpc.example' };
757785
if (selector === selectEVMEnabledNetworks) return [];
758786
if (selector === selectNonEVMEnabledNetworks) return [];
759787
if (selector === selectCurrentCurrency) return 'USD';

app/components/Views/UnifiedTransactionsView/UnifiedTransactionsView.tsx

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { getAddressUrl } from '../../../core/Multichain/utils';
6161
import UpdateEIP1559Tx from '../confirmations/legacy/components/UpdateEIP1559Tx';
6262
import styleSheet from './UnifiedTransactionsView.styles';
6363
import { useUnifiedTxActions } from './useUnifiedTxActions';
64+
import useBlockExplorer from '../../hooks/useBlockExplorer';
6465

6566
type SmartTransactionWithId = SmartTransaction & { id: string };
6667
type EvmTransaction = TransactionMeta | SmartTransactionWithId;
@@ -357,7 +358,12 @@ const UnifiedTransactionsView = ({
357358
currentEvmChainId,
358359
]);
359360

360-
const blockExplorerUrl = useMemo(() => {
361+
const hasEvmChainsEnabled = enabledEVMChainIds.length > 0;
362+
const popularListBlockExplorer = useBlockExplorer(
363+
hasEvmChainsEnabled ? enabledEVMChainIds[0] : undefined,
364+
);
365+
366+
const configBlockExplorerUrl = useMemo(() => {
361367
// When using the per-dapp/multiselect network selector, only return a block
362368
// explorer if exactly one EVM chain is selected. Otherwise, undefined.
363369
if (isRemoveGlobalNetworkSelectorEnabled()) {
@@ -377,7 +383,24 @@ const UnifiedTransactionsView = ({
377383
return config.blockExplorerUrls?.[index];
378384
}, [enabledEVMChainIds, evmNetworkConfigurationsByChainId]);
379385

380-
const hasEvmChainsEnabled = enabledEVMChainIds.length > 0;
386+
const blockExplorerUrl = useMemo(() => {
387+
// configBlockExplorerUrl contains block explorer urls only for networks added by default after fresh install
388+
// other networks should use PopularList, which is used by useBlockExplorer hook
389+
if (configBlockExplorerUrl) {
390+
return configBlockExplorerUrl;
391+
}
392+
return hasEvmChainsEnabled
393+
? popularListBlockExplorer.getBlockExplorerUrl(
394+
selectedAccountGroupEvmAddress,
395+
) || undefined
396+
: undefined;
397+
}, [
398+
configBlockExplorerUrl,
399+
popularListBlockExplorer,
400+
selectedAccountGroupEvmAddress,
401+
hasEvmChainsEnabled,
402+
]);
403+
381404
const hasNonEvmChainsEnabled = enabledNonEVMChainIds.length > 0;
382405

383406
const showEvmFooter = hasEvmChainsEnabled && !hasNonEvmChainsEnabled;
@@ -388,14 +411,25 @@ const UnifiedTransactionsView = ({
388411
return;
389412
}
390413

391-
const { url, title } = getBlockExplorerAddressUrl(
392-
providerType,
393-
selectedAccountGroupEvmAddress,
394-
blockExplorerUrl,
395-
);
414+
let url;
415+
let title;
416+
if (configBlockExplorerUrl) {
417+
const result = getBlockExplorerAddressUrl(
418+
providerType,
419+
selectedAccountGroupEvmAddress,
420+
blockExplorerUrl,
421+
);
422+
url = result.url;
423+
title = result.title;
396424

397-
if (!url) {
398-
return;
425+
if (!url) {
426+
return;
427+
}
428+
} else {
429+
url = blockExplorerUrl;
430+
title = hasEvmChainsEnabled
431+
? popularListBlockExplorer.getBlockExplorerName(enabledEVMChainIds[0])
432+
: undefined;
399433
}
400434

401435
navigation.navigate('Webview', {
@@ -410,6 +444,10 @@ const UnifiedTransactionsView = ({
410444
providerType,
411445
blockExplorerUrl,
412446
selectedAccountGroupEvmAddress,
447+
popularListBlockExplorer,
448+
enabledEVMChainIds,
449+
configBlockExplorerUrl,
450+
hasEvmChainsEnabled,
413451
]);
414452

415453
const allNonEvmChainsAreSolana = useMemo(
@@ -461,7 +499,7 @@ const UnifiedTransactionsView = ({
461499
return (
462500
<TransactionsFooter
463501
chainId={enabledEVMChainIds[0]}
464-
providerType={providerType}
502+
providerType={configBlockExplorerUrl ? providerType : undefined}
465503
rpcBlockExplorer={blockExplorerUrl}
466504
onViewBlockExplorer={onViewBlockExplorer}
467505
/>
@@ -494,6 +532,7 @@ const UnifiedTransactionsView = ({
494532
showEvmFooter,
495533
showNonEvmExplorerLink,
496534
showNonEvmFooter,
535+
configBlockExplorerUrl,
497536
]);
498537

499538
const [refreshing, setRefreshing] = useState(false);

app/util/networks/customNetworks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const PopularList = [
106106
rpcUrl: `https://palm-mainnet.infura.io/v3/${infuraProjectId}`,
107107
ticker: 'PALM',
108108
rpcPrefs: {
109-
blockExplorerUrl: 'https://explorer.palm.io',
109+
blockExplorerUrl: 'https://palm.chainlens.com',
110110
imageUrl: 'PALM',
111111
imageSource: require('../../images/palm.png'),
112112
},

0 commit comments

Comments
 (0)