Skip to content

Commit fe91d51

Browse files
authored
fix(activity): correct EVM rows when non-EVM account selected (#29794)
<!-- 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 passes `selectedAddress` into `TransactionElement` and Redux token selectors keyed by account. Those paths previously used the **globally selected** internal account. After switching the Activity network filter from a non-EVM network (e.g. Bitcoin) back to **all popular networks**, the selected account could still be non-EVM while EVM transactions remained in the list. EVM sends were compared against a non-EVM address (wrong direction / “Received”), and token metadata was looked up under the wrong account key on each chain (“Not available”). This change passes the account group’s **EVM** address for EVM rows (`UnifiedTransactionsView`), re-decodes when `selectedAddress` changes (`TransactionElement`), and adds `selectTokensByChainIdAndWalletAddress` so token maps match the same wallet address used for decoding. ## **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 showing incorrect Sent/Received labels and "Not available" amounts after switching from a non-EVM network filter back to all popular networks. ## **Related issues** Fixes: #28035 Refs: https://consensyssoftware.atlassian.net/browse/TMCU-602 ## **Manual testing steps** ```gherkin Feature: Activity unified list after network filter change Scenario: EVM sends stay correct after non-EVM filter then popular networks Given the user has confirmed token sends on an EVM network (e.g. Linea) And Activity Transactions tab is open with the network filter set to that EVM chain When the user switches the filter to a non-EVM network (e.g. Bitcoin) And the user switches the filter back to all popular networks Then top EVM transactions still show Sent (not Received) with token amounts and fiat where applicable (not "Not available") ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** see video on [this comment](#28035 (comment)) from #28035 ### **After** https://github.com/user-attachments/assets/6e44a38c-9830-4aa4-a08d-63439533e74c ## **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 derives the address used to classify EVM transactions and fetch per-chain token metadata, which can alter Sent/Received labeling and displayed amounts across the unified list. Risk is limited to UI/state selection logic and is covered by added selector tests. > > **Overview** > Fixes unified Activity rendering when a non-EVM account remains selected by ensuring EVM list rows use the account group’s **EVM address** for direction/decoding and token metadata. > > `UnifiedTransactionsView` now passes the account group EVM address into `TransactionElement`, `TransactionElement` re-decodes when `selectedAddress` changes, and token lookup is switched to a new selector `selectTokensByChainIdAndWalletAddress` (with tests) so token maps are keyed by the same explicit wallet address rather than the globally selected account. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7910a16. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent ba4c881 commit fe91d51

4 files changed

Lines changed: 94 additions & 19 deletions

File tree

app/components/UI/TransactionElement/index.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import {
2626
} from '@metamask/transaction-controller';
2727
import { ThemeContext, mockTheme } from '../../../util/theme';
2828
import { selectTickerByChainId } from '../../../selectors/networkController';
29-
import { selectSelectedInternalAccount } from '../../../selectors/accountsController';
29+
import {
30+
selectSelectedInternalAccount,
31+
selectSelectedInternalAccountAddress,
32+
} from '../../../selectors/accountsController';
3033
import { selectSelectedAccountGroupInternalAccounts } from '../../../selectors/multichainAccounts/accountTreeController';
3134
import { selectPrimaryCurrency } from '../../../selectors/settings';
3235
import {
@@ -56,7 +59,7 @@ import {
5659
selectCurrencyRates,
5760
} from '../../../selectors/currencyRateController';
5861
import { selectContractExchangeRatesByChainId } from '../../../selectors/tokenRatesController';
59-
import { selectTokensByChainIdAndAddress } from '../../../selectors/tokensController';
62+
import { selectTokensByChainIdAndWalletAddress } from '../../../selectors/tokensController';
6063
import Routes from '../../../constants/navigation/Routes';
6164
import {
6265
hasGasFeeTokenSelected,
@@ -224,6 +227,10 @@ class TransactionElement extends PureComponent {
224227
* Chain Id
225228
*/
226229
txChainId: PropTypes.string,
230+
/**
231+
* Selected wallet address for decoding and token map (optional override from parent)
232+
*/
233+
selectedAddress: PropTypes.string,
227234
/**
228235
* Ticker
229236
*/
@@ -278,7 +285,8 @@ class TransactionElement extends PureComponent {
278285
componentDidUpdate(prevProps) {
279286
if (
280287
prevProps.txChainId !== this.props.txChainId ||
281-
prevProps.swapsTransactions !== this.props.swapsTransactions
288+
prevProps.swapsTransactions !== this.props.swapsTransactions ||
289+
prevProps.selectedAddress !== this.props.selectedAddress
282290
) {
283291
this.componentDidMount();
284292
}
@@ -738,21 +746,29 @@ class TransactionElement extends PureComponent {
738746
}
739747
}
740748

741-
const mapStateToProps = (state, ownProps) => ({
742-
selectedInternalAccount: selectSelectedInternalAccount(state),
743-
selectSelectedAccountGroupInternalAccounts:
744-
selectSelectedAccountGroupInternalAccounts(state),
745-
primaryCurrency: selectPrimaryCurrency(state),
746-
swapsTransactions: selectSwapsTransactions(state),
747-
ticker: selectTickerByChainId(state, ownProps.txChainId),
748-
conversionRate: selectConversionRateByChainId(state, ownProps.txChainId),
749-
currencyRates: selectCurrencyRates(state),
750-
contractExchangeRates: selectContractExchangeRatesByChainId(
751-
state,
752-
ownProps.txChainId,
753-
),
754-
tokens: selectTokensByChainIdAndAddress(state, ownProps.txChainId),
755-
});
749+
const mapStateToProps = (state, ownProps) => {
750+
const walletAddressForTokens =
751+
ownProps.selectedAddress ?? selectSelectedInternalAccountAddress(state);
752+
return {
753+
selectedInternalAccount: selectSelectedInternalAccount(state),
754+
selectSelectedAccountGroupInternalAccounts:
755+
selectSelectedAccountGroupInternalAccounts(state),
756+
primaryCurrency: selectPrimaryCurrency(state),
757+
swapsTransactions: selectSwapsTransactions(state),
758+
ticker: selectTickerByChainId(state, ownProps.txChainId),
759+
conversionRate: selectConversionRateByChainId(state, ownProps.txChainId),
760+
currencyRates: selectCurrencyRates(state),
761+
contractExchangeRates: selectContractExchangeRatesByChainId(
762+
state,
763+
ownProps.txChainId,
764+
),
765+
tokens: selectTokensByChainIdAndWalletAddress(
766+
state,
767+
ownProps.txChainId,
768+
walletAddressForTokens,
769+
),
770+
};
771+
};
756772

757773
TransactionElement.contextType = ThemeContext;
758774

app/components/Views/UnifiedTransactionsView/UnifiedTransactionsView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,9 @@ const UnifiedTransactionsView = ({
632632
i={index}
633633
navigation={navigation}
634634
txChainId={getEvmChainId(item.tx)}
635-
selectedAddress={selectedInternalAccount?.address}
635+
selectedAddress={
636+
selectedAccountGroupEvmAddress || selectedInternalAccount?.address
637+
}
636638
onSpeedUpAction={onSpeedUpAction}
637639
onCancelAction={onCancelAction}
638640
signQRTransaction={signQRTransaction}

app/selectors/tokensController.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
selectAllDetectedTokensForSelectedAddress,
1111
selectAllDetectedTokensFlat,
1212
selectTokensByChainIdAndAddress,
13+
selectTokensByChainIdAndWalletAddress,
1314
getChainIdsToPoll,
1415
selectSingleTokenByAddressAndChainId,
1516
} from './tokensController';
@@ -337,6 +338,34 @@ describe('TokensController Selectors', () => {
337338
});
338339
});
339340

341+
describe('selectTokensByChainIdAndWalletAddress', () => {
342+
it('returns tokens for the given chain and explicit wallet address', () => {
343+
expect(
344+
selectTokensByChainIdAndWalletAddress(
345+
mockRootState,
346+
'0x1',
347+
'0xAddress2',
348+
),
349+
).toStrictEqual({ '0xToken2': mockToken2 });
350+
});
351+
352+
it('returns empty object when wallet address has no tokens on that chain', () => {
353+
expect(
354+
selectTokensByChainIdAndWalletAddress(
355+
mockRootState,
356+
'0x2',
357+
'0xAddress1',
358+
),
359+
).toStrictEqual({});
360+
});
361+
362+
it('returns empty object when wallet address is undefined', () => {
363+
expect(
364+
selectTokensByChainIdAndWalletAddress(mockRootState, '0x1', undefined),
365+
).toStrictEqual({});
366+
});
367+
});
368+
340369
describe('getChainIdsToPoll', () => {
341370
const mockNetworkConfigurations = {
342371
'0x1': { chainId: '0x1' } as unknown as NetworkConfiguration,

app/selectors/tokensController.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,34 @@ export const selectTokensByChainIdAndAddress = createDeepEqualSelector(
5353
) ?? {},
5454
);
5555

56+
/**
57+
* Like {@link selectTokensByChainIdAndAddress} but uses an explicit account
58+
* address (e.g. the EVM address for the account group) instead of the globally
59+
* selected account. Needed when the UI shows EVM activity while a non-EVM
60+
* account is still selected.
61+
*/
62+
export const selectTokensByChainIdAndWalletAddress = createDeepEqualSelector(
63+
getTokensControllerAllTokens,
64+
(_state: RootState, chainId: Hex, _walletAddress: Hex | string | undefined) =>
65+
chainId,
66+
(_state: RootState, _chainId: Hex, walletAddress: Hex | string | undefined) =>
67+
walletAddress,
68+
(
69+
allTokens: TokensControllerState['allTokens'],
70+
chainId: Hex,
71+
walletAddress: Hex | string | undefined,
72+
) =>
73+
!walletAddress
74+
? {}
75+
: (allTokens[chainId]?.[walletAddress as Hex]?.reduce(
76+
(tokensMap: { [address: string]: Token }, token: Token) => ({
77+
...tokensMap,
78+
[token.address]: token,
79+
}),
80+
{},
81+
) ?? {}),
82+
);
83+
5684
export const selectTokensByAddress = createSelector(
5785
selectTokens,
5886
(tokens: Token[]) =>

0 commit comments

Comments
 (0)