Skip to content

Commit dbf4184

Browse files
chore(runway): cherry-pick fix(activity): align EVM activity with account group and network filter cp-7.77.0 (#29994)
- fix(activity): align EVM activity with account group and network filter cp-7.77.0 (#29983) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until this PR meets the canonical Definition of Ready For Review in `docs/readme/ready-for-review.md`. In short: the template must be materially complete (not just section titles present), all status checks must be currently passing, and the only expected follow-up commits must be reviewer-driven. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> Activity’s unified transaction list used the globally selected account for the Accounts API infinite query (`selectEvmAddress`). When a **non-EVM** account stayed selected (e.g. Bitcoin) but the network filter returned to **all popular networks**, the query had no EVM address and stayed disabled, so the UI showed **only non-EVM** rows. This PR resolves the query to the **selected account group’s EVM internal account** when present, falling back to the global EVM address otherwise. It also **filters confirmed and pending EVM** rows to the currently **enabled EVM chain IDs** so the list matches the Activity network filter (including single-chain vs multi-chain). **ConfirmedEvm** rows use the same **group EVM `selectedAddress`** as pending EVM rows for consistent decode/display with multichain selection. This builds on the earlier Activity fixes in [#29794](#29794) (TransactionElement / token map); this branch carries the remaining **UnifiedTransactionsView** and **useTransactionsQuery** alignment. ## **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: Fixed Activity transaction list not showing EVM history after switching back from a non-EVM network filter to all popular networks, and tightened EVM rows to the enabled network filter. ## **Related issues** Fixes #29952 Refs: #28035 ## **Manual testing steps** ```gherkin Feature: Activity unified transactions and network filter Scenario: EVM history returns when non-EVM account is selected and filter is all popular networks Given the user has an account group with both EVM and non-EVM accounts And the globally selected account is non-EVM (e.g. Bitcoin) When the user opens Activity then sets the network filter to all popular networks Then EVM and non-EVM transactions appear in the unified list as expected Scenario: Single EVM chain filter only shows that chain Given Activity Transactions is open with multiple EVM networks available When the user sets the filter to one EVM chain (e.g. Linea) then to another (e.g. Ethereum) Then the list updates to transactions for the selected chain only Scenario: Pending EVM rows respect enabled chains Given the user has a submitted EVM transaction on one chain When the user filters Activity to a different single EVM chain Then pending rows for other chains do not appear at the top of the list ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** https://github.com/user-attachments/assets/de557bf5-4caf-4ba2-bcf4-8a4459e53b3d ## **Pre-merge author checklist** <!-- Every checklist item must be consciously assessed before marking this PR as "Ready for review". A checked box means you deliberately considered that responsibility, not that you literally performed every action listed. Unchecked boxes are ambiguous: they are not an implicit "N/A" and they are not a silent "skip". See `docs/readme/ready-for-review.md` for the full checklist semantics. --> - [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 - [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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. #### Performance checks (if applicable) - [ ] I've tested on Android - Ideally on a mid-range device; emulator is acceptable - [ ] I've tested with a power user scenario - Use these [power-user SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93) to import wallets with many accounts and tokens - [ ] I've instrumented key operations with Sentry traces for production performance metrics - See [`trace()`](/app/util/trace.ts) for usage and [`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274) for an example For performance guidelines and tooling, see the [Performance Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers). ## **Pre-merge reviewer checklist** <!-- Reviewer checklist items follow the same semantics as the author checklist: an unchecked box is ambiguous, a checked box means the reviewer consciously assessed that responsibility. See `docs/readme/ready-for-review.md`. --> - [ ] 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] > **Medium Risk** > Changes how Activity selects the EVM account/address for history queries and tightens EVM pending/confirmed filtering by enabled chain IDs, which can affect transaction visibility in the main Activity list. > > **Overview** > Fixes unified Activity EVM history loading by resolving the Accounts API query address from the *selected account group’s* EVM internal account (falling back to the global `selectEvmAddress`), so EVM activity still loads when a non-EVM account is selected. > > Aligns the unified list with the network filter by **filtering both confirmed (API) and pending (local) EVM transactions** to the currently enabled EVM chain IDs (including guarding against stale paged results), and ensures confirmed EVM rows pass the same group-based `selectedAddress` into `TransactionElement` as pending rows. > > Adds targeted tests covering EVM chain-filter behavior for pending/confirmed rows and the new address-selection precedence rules in `useTransactionsQuery`. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 67fb3e1. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> [664cf53](664cf53) Co-authored-by: Pedro Pablo Aste Kompen <wachunei@gmail.com>
1 parent 0417b30 commit dbf4184

4 files changed

Lines changed: 379 additions & 10 deletions

File tree

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

Lines changed: 276 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import React, { ComponentType } from 'react';
22
import { RefreshControl } from 'react-native';
33
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
44
import type { V1TransactionByHashResponse } from '@metamask/core-backend';
5-
import { TransactionStatus } from '@metamask/transaction-controller';
5+
import {
6+
TransactionStatus,
7+
type TransactionMeta,
8+
} from '@metamask/transaction-controller';
69
import { Hex } from '@metamask/utils';
710
import UnifiedTransactionsView from './UnifiedTransactionsView';
811
import _renderWithProvider from '../../../util/test/renderWithProvider';
@@ -615,6 +618,278 @@ describe('UnifiedTransactionsView with transactions', () => {
615618
});
616619
});
617620

621+
describe('UnifiedTransactionsView - EVM network filter for unified list', () => {
622+
const WALLET = '0xabc';
623+
624+
/** Required so selectLocalTransactions includes pending txs for UnifiedTransactionsView filtering. */
625+
const accountsControllerForWallet = {
626+
...backgroundState.AccountsController,
627+
internalAccounts: {
628+
accounts: {
629+
'wallet-evm-id': {
630+
id: 'wallet-evm-id',
631+
type: 'eip155:eoa' as const,
632+
address: WALLET,
633+
options: {},
634+
methods: [],
635+
metadata: {
636+
name: 'Account 1',
637+
keyring: { type: 'HD Key Tree' },
638+
},
639+
},
640+
},
641+
selectedAccount: 'wallet-evm-id',
642+
},
643+
};
644+
645+
const emptyEvmChainsState = {
646+
engine: {
647+
backgroundState: {
648+
...backgroundState,
649+
AccountsController: accountsControllerForWallet,
650+
NetworkEnablementController: {
651+
...backgroundState.NetworkEnablementController,
652+
enabledNetworkMap: {
653+
...backgroundState.NetworkEnablementController.enabledNetworkMap,
654+
eip155: {},
655+
},
656+
},
657+
},
658+
},
659+
};
660+
661+
const stateOnlyOptimism = {
662+
engine: {
663+
backgroundState: {
664+
...backgroundState,
665+
AccountsController: accountsControllerForWallet,
666+
NetworkEnablementController: {
667+
...backgroundState.NetworkEnablementController,
668+
enabledNetworkMap: {
669+
...backgroundState.NetworkEnablementController.enabledNetworkMap,
670+
eip155: { '0xa': true },
671+
},
672+
},
673+
},
674+
},
675+
};
676+
677+
const stateOnlyMainnet = {
678+
engine: {
679+
backgroundState: {
680+
...backgroundState,
681+
AccountsController: accountsControllerForWallet,
682+
NetworkEnablementController: {
683+
...backgroundState.NetworkEnablementController,
684+
enabledNetworkMap: {
685+
...backgroundState.NetworkEnablementController.enabledNetworkMap,
686+
eip155: { '0x1': true },
687+
},
688+
},
689+
},
690+
},
691+
};
692+
693+
const createOutgoingMainnetConfirmed = (): V1TransactionByHashResponse =>
694+
({
695+
accountId: `eip155:1:${WALLET}`,
696+
blockHash: '0xblock',
697+
blockNumber: 1,
698+
chainId: 1,
699+
cumulativeGasUsed: 21000,
700+
effectiveGasPrice: '1',
701+
from: WALLET,
702+
gas: 21000,
703+
gasPrice: '1',
704+
gasUsed: 21000,
705+
hash: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
706+
isError: false,
707+
logs: [],
708+
methodId: '0x',
709+
nonce: 1,
710+
readable: 'Transfer',
711+
timestamp: '2026-04-29T19:28:41.000Z',
712+
to: '0x1111111111111111111111111111111111111111',
713+
transactionCategory: 'TRANSFER',
714+
transactionType: 'SIMPLE_SEND',
715+
value: '1',
716+
valueTransfers: [],
717+
}) as V1TransactionByHashResponse;
718+
719+
const queryDataMainnetConfirmed = selectTransactions({
720+
address: WALLET,
721+
})({
722+
pageParams: [undefined],
723+
pages: [
724+
{
725+
data: [createOutgoingMainnetConfirmed()],
726+
unprocessedNetworks: [],
727+
pageInfo: {
728+
count: 1,
729+
endCursor: undefined,
730+
hasNextPage: false,
731+
},
732+
},
733+
],
734+
});
735+
736+
beforeEach(() => {
737+
jest.clearAllMocks();
738+
mockUseTransactionsQuery();
739+
(useUnifiedTxActions as jest.Mock).mockImplementation(
740+
() => mockDefaultUnifiedTxActionsReturn,
741+
);
742+
});
743+
744+
it('hides confirmed EVM rows when no EVM chains are enabled', () => {
745+
mockUseTransactionsQuery(queryDataMainnetConfirmed);
746+
747+
const { getByText } = renderWithProvider(<UnifiedTransactionsView />, {
748+
state: emptyEvmChainsState,
749+
});
750+
751+
expect(getByText('You have no transactions')).toBeOnTheScreen();
752+
});
753+
754+
it('hides confirmed EVM rows when their chain is not in the enabled filter', () => {
755+
mockUseTransactionsQuery(queryDataMainnetConfirmed);
756+
757+
const { getByText } = renderWithProvider(<UnifiedTransactionsView />, {
758+
state: stateOnlyOptimism,
759+
});
760+
761+
expect(getByText('You have no transactions')).toBeOnTheScreen();
762+
});
763+
764+
it('shows confirmed EVM rows when their chain matches the enabled filter', () => {
765+
mockUseTransactionsQuery(queryDataMainnetConfirmed);
766+
767+
const { UNSAFE_queryAllByType } = renderWithProvider(
768+
<UnifiedTransactionsView />,
769+
{ state: stateOnlyMainnet },
770+
);
771+
772+
expect(
773+
UNSAFE_queryAllByType(asComponentType('TransactionElement')).length,
774+
).toBeGreaterThanOrEqual(1);
775+
});
776+
777+
it('hides pending EVM transactions when their chain is not in the enabled filter', () => {
778+
mockUseTransactionsQuery(emptyTransactionsQueryData);
779+
780+
const stateWithPendingMainnet = {
781+
engine: {
782+
backgroundState: {
783+
...backgroundState,
784+
AccountsController: accountsControllerForWallet,
785+
NetworkEnablementController:
786+
stateOnlyOptimism.engine.backgroundState
787+
.NetworkEnablementController,
788+
TransactionController: {
789+
...backgroundState.TransactionController,
790+
transactions: [
791+
{
792+
id: 'pending-mainnet',
793+
chainId: '0x1' as const,
794+
status: TransactionStatus.submitted,
795+
time: Date.now(),
796+
txParams: {
797+
from: WALLET,
798+
to: '0x1111111111111111111111111111111111111111',
799+
value: '0x0',
800+
nonce: '0x1',
801+
},
802+
},
803+
],
804+
},
805+
},
806+
},
807+
};
808+
809+
const { getByText } = renderWithProvider(<UnifiedTransactionsView />, {
810+
state: stateWithPendingMainnet,
811+
});
812+
813+
expect(getByText('You have no transactions')).toBeOnTheScreen();
814+
});
815+
816+
it('hides pending EVM transactions when no EVM chains are enabled', () => {
817+
mockUseTransactionsQuery(emptyTransactionsQueryData);
818+
819+
const stateWithPendingButNoEvmNetworks = {
820+
engine: {
821+
backgroundState: {
822+
...backgroundState,
823+
AccountsController: accountsControllerForWallet,
824+
NetworkEnablementController:
825+
emptyEvmChainsState.engine.backgroundState
826+
.NetworkEnablementController,
827+
TransactionController: {
828+
...backgroundState.TransactionController,
829+
transactions: [
830+
{
831+
id: 'pending-no-enabled-evm',
832+
chainId: '0x1' as const,
833+
status: TransactionStatus.submitted,
834+
time: Date.now(),
835+
txParams: {
836+
from: WALLET,
837+
to: '0x1111111111111111111111111111111111111111',
838+
value: '0x0',
839+
nonce: '0x1',
840+
},
841+
},
842+
],
843+
},
844+
},
845+
},
846+
};
847+
848+
const { getByText } = renderWithProvider(<UnifiedTransactionsView />, {
849+
state: stateWithPendingButNoEvmNetworks,
850+
});
851+
852+
expect(getByText('You have no transactions')).toBeOnTheScreen();
853+
});
854+
855+
it('hides pending EVM transactions when chainId is missing', () => {
856+
mockUseTransactionsQuery(emptyTransactionsQueryData);
857+
858+
const pendingWithoutChainId = {
859+
id: 'pending-missing-chain',
860+
status: TransactionStatus.submitted,
861+
time: Date.now(),
862+
txParams: {
863+
from: WALLET,
864+
to: '0x1111111111111111111111111111111111111111',
865+
value: '0x0',
866+
nonce: '0x1',
867+
},
868+
} as unknown as TransactionMeta;
869+
870+
const stateWithPendingMissingChainId = {
871+
engine: {
872+
backgroundState: {
873+
...backgroundState,
874+
AccountsController: accountsControllerForWallet,
875+
NetworkEnablementController:
876+
stateOnlyMainnet.engine.backgroundState.NetworkEnablementController,
877+
TransactionController: {
878+
...backgroundState.TransactionController,
879+
transactions: [pendingWithoutChainId],
880+
},
881+
},
882+
},
883+
};
884+
885+
const { getByText } = renderWithProvider(<UnifiedTransactionsView />, {
886+
state: stateWithPendingMissingChainId,
887+
});
888+
889+
expect(getByText('You have no transactions')).toBeOnTheScreen();
890+
});
891+
});
892+
618893
describe('UnifiedTransactionsView - Speed up / Cancel modal', () => {
619894
const initialState = {
620895
engine: {

app/components/Views/UnifiedTransactionsView/UnifiedTransactionsView.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ const UnifiedTransactionsView = ({
167167
[enabledNonEVMNetworks],
168168
);
169169

170+
/** Drop confirmed rows not on currently enabled EVM chains (guards stale query pages). */
171+
const allConfirmedForEnabledChains = useMemo<TransactionViewModel[]>(() => {
172+
const chains = enabledEVMChainIds ?? [];
173+
if (chains.length === 0) {
174+
return [];
175+
}
176+
const allowed = new Set(chains.map((c) => c.toLowerCase()));
177+
return allConfirmedFiltered.filter(
178+
(tx) =>
179+
typeof tx.hexChainId === 'string' &&
180+
allowed.has(tx.hexChainId.toLowerCase()),
181+
);
182+
}, [allConfirmedFiltered, enabledEVMChainIds]);
183+
170184
const { maliciousTokenKeys } =
171185
useMultichainActivityMaliciousTokenKeys(nonEvmTransactions);
172186

@@ -183,13 +197,22 @@ const UnifiedTransactionsView = ({
183197
chainFilteredNonEvmTransactionsForSelectedChain: NonEvmTransaction[];
184198
}>(() => {
185199
const bridgeHistoryValues = Object.values(bridgeHistory ?? {});
200+
const enabledEvmSet = new Set(
201+
(enabledEVMChainIds ?? []).map((id) => id.toLowerCase()),
202+
);
186203
const submittedTxsFiltered = submittedTxs.filter(
187204
(tx): tx is EvmTransaction => {
188205
if (!isTransactionMetaLike(tx)) {
189206
return false;
190207
}
191208

192209
const { chainId: _chainId, txParams } = tx;
210+
if (!enabledEvmSet.size) {
211+
return false;
212+
}
213+
if (!_chainId || !enabledEvmSet.has(String(_chainId).toLowerCase())) {
214+
return false;
215+
}
193216
const isBridgeTransaction = isBridgeHistoryForEvmTransaction(
194217
tx,
195218
bridgeHistoryValues,
@@ -198,17 +221,17 @@ const UnifiedTransactionsView = ({
198221
const { from, nonce } = txParams || {};
199222
const hasNonce = nonce !== undefined && nonce !== null;
200223

201-
const matchingConfirmedByHash = allConfirmedFiltered.some(
224+
const matchingConfirmedByHash = allConfirmedForEnabledChains.some(
202225
(confirmedTx) =>
203226
typeof hash === 'string' &&
204227
confirmedTx.hash.toLowerCase() === hash.toLowerCase() &&
205-
confirmedTx.hexChainId === _chainId,
228+
confirmedTx.hexChainId?.toLowerCase() === _chainId?.toLowerCase(),
206229
);
207-
const matchingConfirmedByNonce = allConfirmedFiltered.some(
230+
const matchingConfirmedByNonce = allConfirmedForEnabledChains.some(
208231
(confirmedTx) =>
209232
hasNonce &&
210233
confirmedTx.nonce === nonce &&
211-
confirmedTx.hexChainId === _chainId &&
234+
confirmedTx.hexChainId?.toLowerCase() === _chainId?.toLowerCase() &&
212235
Boolean(from) &&
213236
areAddressesEqual(confirmedTx.from, from),
214237
);
@@ -250,11 +273,11 @@ const UnifiedTransactionsView = ({
250273

251274
return {
252275
evmPendingTxs: evmPendingFirst,
253-
evmConfirmedTxs: allConfirmedFiltered,
276+
evmConfirmedTxs: allConfirmedForEnabledChains,
254277
chainFilteredNonEvmTransactionsForSelectedChain,
255278
};
256279
}, [
257-
allConfirmedFiltered,
280+
allConfirmedForEnabledChains,
258281
submittedTxs,
259282
nonEvmTransactions,
260283
enabledEVMChainIds,
@@ -609,7 +632,9 @@ const UnifiedTransactionsView = ({
609632
i={index}
610633
navigation={navigation}
611634
txChainId={item.tx.hexChainId}
612-
selectedAddress={selectedInternalAccount?.address}
635+
selectedAddress={
636+
selectedAccountGroupEvmAddress || selectedInternalAccount?.address
637+
}
613638
currentCurrency={currentCurrency}
614639
showBottomBorder
615640
location={location}

0 commit comments

Comments
 (0)