Skip to content

Commit ffdaba8

Browse files
authored
fix(activity-redesign): show token amount on indexed contract interaction activity (#32194)
## **Description** The redesigned Activity list (behind `tmcuActivityRedesignEnabled`) rendered some contract interactions without a token amount, while the extension showed it (e.g. `-0.5801 USDC`). The cause is in the API/indexed-history adapter: its `contractInteraction` branch never read the transaction's `valueTransfers`, so `data.token` was `undefined` and no amount was displayed. Every other branch already extracts the transfer via `getToken(...)`. This change extracts the user-involved transfer (sent first, else received) and attaches it as `data.token` when it has an amount, mirroring the extension's `api-evm-transactions` adapter. The local-transaction path already handled native value, so only the indexed path needed the fix. ## **Changelog** CHANGELOG entry: Fixed contract interactions in the redesigned Activity list not showing the token amount ## **Related issues** Fixes: [TMCU-935](https://consensyssoftware.atlassian.net/browse/TMCU-935) ## **Manual testing steps** ```gherkin Feature: Contract interaction activity amount Scenario: user views a contract interaction that moved an ERC-20 Given the activity redesign feature flag is enabled And the account has an indexed contract interaction that transferred an ERC-20 token When the user opens the Activity tab Then the contract interaction row shows the token amount (e.g. -0.01 aEthUSDC) And it matches what the extension displays ``` ## **Screenshots/Recordings** ### **Before** <img width="500" alt="Simulator Screenshot - iPhone 17 - 2026-06-22 at 16 29 24" src="https://github.com/user-attachments/assets/366e9dee-5122-4bf4-80d0-a67fa2646f24" /> ### **After** <img width="500" alt="Simulator Screenshot - iPhone 17 - 2026-06-23 at 09 53 55" src="https://github.com/user-attachments/assets/706d19d0-f60e-46f5-8464-55c6cc534437" /> ## **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 - [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. ## **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] > **Low Risk** > Narrow adapter change for activity display only; optional `data.token` on contract interactions with no auth or transaction execution impact. > > **Overview** > Fixes **contract interaction** rows in the redesigned Activity list showing no token amount when indexed history includes ERC-20 (or other) **value transfers**. > > The `mapApiEvmTransactions` fallback **`contractInteraction`** branch now picks the user’s **sent** transfer, or **received** if none, runs it through the existing **`getToken`** helper, and spreads **`data.token`** only when the result has an **`amount`**—same pattern as send/receive/swap branches. Interactions without a quantified transfer stay unchanged (no `token` field). > > Adds a unit test for a **GENERIC_CONTRACT_CALL** with an outbound USDC transfer asserting **`direction: 'out'`** and formatted amount metadata. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 58b6cc6. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> [TMCU-935]: https://consensyssoftware.atlassian.net/browse/TMCU-935?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 83d1e85 commit ffdaba8

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

app/util/activity-adapters/adapters/api-evm-transactions.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,4 +894,56 @@ describe('mapApiEvmTransactions', () => {
894894
},
895895
});
896896
});
897+
898+
it('maps a generic contract call to a contract interaction with its token amount', () => {
899+
const mainnetUsdc = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';
900+
const transaction = {
901+
hash: '0xd206cc6c16974409bae072ce4cd1559743041af40c2bae84775a0bbb4dff5fee',
902+
timestamp: '2026-05-01T13:39:47.000Z',
903+
chainId: 1,
904+
from: subjectAddress,
905+
to: subjectAddress,
906+
methodId: '0xe9ae5c53',
907+
value: '0',
908+
transactionCategory: 'CONTRACT_CALL',
909+
transactionType: 'GENERIC_CONTRACT_CALL',
910+
valueTransfers: [
911+
{
912+
from: subjectAddress,
913+
to: '0x4cd00e387622c35bddb9b4c962c136462338bc31',
914+
amount: '580060',
915+
decimal: 6,
916+
contractAddress: mainnetUsdc,
917+
symbol: 'USDC',
918+
name: 'USD Coin',
919+
transferType: 'erc20',
920+
},
921+
],
922+
} as unknown as V1TransactionByHashResponse;
923+
924+
expect(
925+
withoutRaw(mapApiEvmTransactions({ subjectAddress, transaction })),
926+
).toStrictEqual({
927+
type: 'contractInteraction',
928+
chainId: 'eip155:1',
929+
status: 'success',
930+
timestamp: 1777642787000,
931+
hash: '0xd206cc6c16974409bae072ce4cd1559743041af40c2bae84775a0bbb4dff5fee',
932+
data: {
933+
from: subjectAddress,
934+
methodId: '0xe9ae5c53',
935+
to: subjectAddress,
936+
transactionCategory: 'CONTRACT_CALL',
937+
transactionProtocol: undefined,
938+
transactionType: 'GENERIC_CONTRACT_CALL',
939+
token: {
940+
amount: '580060',
941+
assetId: toAssetId(mainnetUsdc, 'eip155:1'),
942+
decimals: 6,
943+
direction: 'out',
944+
symbol: 'USDC',
945+
},
946+
},
947+
});
948+
});
897949
});

app/util/activity-adapters/adapters/api-evm-transactions.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,15 @@ export function mapApiEvmTransactions({
462462
};
463463
}
464464

465+
const contractInteractionTransfer = sentTransfer ?? receivedTransfer;
466+
const contractInteractionToken = getToken(
467+
contractInteractionTransfer,
468+
sentTransfer ? 'out' : 'in',
469+
);
470+
const contractInteractionTokenWithAmount = contractInteractionToken?.amount
471+
? contractInteractionToken
472+
: undefined;
473+
465474
return {
466475
type: 'contractInteraction',
467476
chainId,
@@ -476,6 +485,9 @@ export function mapApiEvmTransactions({
476485
transactionCategory,
477486
transactionProtocol: transaction.transactionProtocol,
478487
transactionType: transaction.transactionType,
488+
...(contractInteractionTokenWithAmount
489+
? { token: contractInteractionTokenWithAmount }
490+
: {}),
479491
},
480492
};
481493
}

0 commit comments

Comments
 (0)