Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c6e3040
Adding code to capture metrics for uniswap shield
jpuri Oct 14, 2025
ac4116b
update
jpuri Oct 16, 2025
6d9b5bd
merge
jpuri Oct 16, 2025
4f5a040
update
jpuri Oct 16, 2025
df5310c
Merge branch 'main' into uni_shield
jpuri Oct 16, 2025
69bf689
updates
jpuri Oct 16, 2025
a20fbc6
Merge branch 'uni_shield' of https://github.com/MetaMask/metamask-ext…
jpuri Oct 16, 2025
097da15
updates
jpuri Oct 16, 2025
a5a9c8d
Merge branch 'main' into uni_shield
jpuri Oct 16, 2025
85b196f
update
jpuri Oct 16, 2025
ed0efc0
Merge branch 'uni_shield' of https://github.com/MetaMask/metamask-ext…
jpuri Oct 16, 2025
c7f4536
Merge branch 'main' into uni_shield
jpuri Oct 16, 2025
431e2c2
update
jpuri Oct 16, 2025
20be473
Merge branch 'uni_shield' of https://github.com/MetaMask/metamask-ext…
jpuri Oct 16, 2025
78488b9
update
jpuri Oct 16, 2025
c5177d1
update
jpuri Oct 16, 2025
bec49c0
update
jpuri Oct 16, 2025
dddb6bc
Merge branch 'main' into uni_shield
jpuri Oct 16, 2025
68908f3
update
jpuri Oct 16, 2025
761438f
Merge branch 'uni_shield' of https://github.com/MetaMask/metamask-ext…
jpuri Oct 16, 2025
cb5ecd7
update
jpuri Oct 16, 2025
2bc194b
Merge branch 'main' into uni_shield
jpuri Oct 16, 2025
e8b0252
update
jpuri Oct 16, 2025
54ce7ff
Merge branch 'uni_shield' of https://github.com/MetaMask/metamask-ext…
jpuri Oct 16, 2025
a7a0225
update
jpuri Oct 16, 2025
0deb589
Merge branch 'main' into uni_shield
jpuri Oct 16, 2025
d32985d
update
jpuri Oct 16, 2025
e8c1115
Merge branch 'uni_shield' of https://github.com/MetaMask/metamask-ext…
jpuri Oct 16, 2025
b07c21a
update
jpuri Oct 17, 2025
7333da1
Merge branch 'main' into uni_shield
jpuri Oct 17, 2025
24a64ca
update
jpuri Oct 17, 2025
94f2e93
Merge branch 'uni_shield' of https://github.com/MetaMask/metamask-ext…
jpuri Oct 17, 2025
35bd6ca
update
jpuri Oct 17, 2025
79b7ca9
update
jpuri Oct 17, 2025
1274e71
update
jpuri Oct 17, 2025
42c9ecd
update
jpuri Oct 17, 2025
366dda6
update
jpuri Oct 17, 2025
a6c074c
Merge branch 'main' into uni_shield
jpuri Oct 17, 2025
9bd2d91
update
jpuri Oct 17, 2025
f9ef3e0
Merge branch 'uni_shield' of https://github.com/MetaMask/metamask-ext…
jpuri Oct 17, 2025
8dba70b
update
jpuri Oct 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2987,6 +2987,10 @@ export default class MetamaskController extends EventEmitter {
this.controllerMessenger,
`${BRIDGE_CONTROLLER_NAME}:${BridgeBackgroundAction.TRACK_METAMETRICS_EVENT}`,
),
[BridgeBackgroundAction.FETCH_QUOTES]: this.controllerMessenger.call.bind(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would go in the bridge-controller-init file in the api property.

this.controllerMessenger,
`${BRIDGE_CONTROLLER_NAME}:${BridgeBackgroundAction.FETCH_QUOTES}`,
),

// Bridge Tx submission
[BridgeStatusAction.SUBMIT_TX]: this.controllerMessenger.call.bind(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import configureMockStore from 'redux-mock-store';

import { getMockConfirmStateForTransaction } from '../../../../../../test/data/confirmations/helper';
import { renderWithConfirmContextProvider } from '../../../../../../test/lib/confirmations/render-helpers';
import { genUnapprovedContractInteractionConfirmation } from '../../../../../../test/data/confirmations/contract-interaction';
import { DappSwapComparisonBanner } from './dapp-swap-comparison-banner';

jest.mock('../../../hooks/transactions/useDappSwapComparisonInfo', () => ({
useDappSwapComparisonInfo: jest.fn(() => undefined),
}));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Mock Path Mismatch Causes Test Ineffectiveness

The jest.mock path for useDappSwapComparisonInfo (../../hooks/useDappSwapComparisonInfo) doesn't match the component's actual import path (../../../hooks/transactions/useDappSwapComparisonInfo). This prevents the mock from working, causing the test to use the real implementation and making it ineffective.

Fix in Cursor Fix in Web


function render() {
const state = getMockConfirmStateForTransaction(
genUnapprovedContractInteractionConfirmation(),
);

const mockStore = configureMockStore()(state);

return renderWithConfirmContextProvider(
<DappSwapComparisonBanner />,
mockStore,
);
}

describe('<DappSwapComparisonBanner />', () => {
it('renders component without errors', () => {
const { container } = render();
expect(container).toBeEmptyDOMElement();
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new folder structure we're using, should this just be in ui/pages/confirmations/components/dapp-swap-comparison-banner to avoid all the nesting inside /confirm?

Copy link
Contributor Author

@jpuri jpuri Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it from /info to /confirm, currently all confirmation related component are there.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'react';

import { useDappSwapComparisonInfo } from '../../../hooks/transactions/useDappSwapComparisonInfo';

// The component is conditionally included for dapp swap origin
// The only purpose of the component currently is to capture dapp swap comparison related metrics.

export const DappSwapComparisonBanner = () => {
useDappSwapComparisonInfo();

return null;
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { TransactionMeta } from '@metamask/transaction-controller';
import React from 'react';
import { useConfirmContext } from '../../../../context/confirm';
import { DappSwapComparisonBanner } from '../../dapp-swap-comparison-banner/dapp-swap-comparison-banner';
import { AdvancedDetails } from '../shared/advanced-details/advanced-details';
import { GasFeesSection } from '../shared/gas-fees-section/gas-fees-section';
import { TransactionDetails } from '../shared/transaction-details/transaction-details';
import { TransactionAccountDetails } from '../batch/transaction-account-details';
import { BatchSimulationDetails } from '../batch/batch-simulation-details/batch-simulation-details';

const DAPP_SWAP_COMPARISON_ORIGIN = 'https://app.uniswap.org';

const BaseTransactionInfo = () => {
const { currentConfirmation: transactionMeta } =
useConfirmContext<TransactionMeta>();
Expand All @@ -17,6 +20,9 @@ const BaseTransactionInfo = () => {

return (
<>
{transactionMeta.origin === DAPP_SWAP_COMPARISON_ORIGIN && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it cleaner to encapsulate this origin knowledge inside the DappSwapComparisonBanner itself so it can handle its own conditional rendering?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I put this condition here is that even if I keep it inside DappSwapComparisonBanner we will end up running few hooks like get decimal places for erc20, get USD rates, etc for a lot of confirmationations.

By keeping this condition here all that code execution is by-passed.

<DappSwapComparisonBanner />
)}
<TransactionAccountDetails />
<BatchSimulationDetails />
<TransactionDetails />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
selectConversionRateByChainId,
} from '../../../../selectors';
import { fetchTokenExchangeRates } from '../../../../helpers/utils/util';
import { ERC20_DEFAULT_DECIMALS, fetchErc20Decimals } from '../../utils/token';
import {
ERC20_DEFAULT_DECIMALS,
fetchAllErc20Decimals,
} from '../../utils/token';

import {
BalanceChange,
Expand Down Expand Up @@ -63,22 +66,6 @@ function getAssetAmount(
);
}

// Fetches token details for all the token addresses in the SimulationTokenBalanceChanges
async function fetchAllErc20Decimals(
addresses: Hex[],
chainId: Hex,
): Promise<Record<Hex, number>> {
const uniqueAddresses = [
...new Set(addresses.map((address) => address.toLowerCase() as Hex)),
];
const allDecimals = await Promise.all(
uniqueAddresses.map((address) => fetchErc20Decimals(address, chainId)),
);
return Object.fromEntries(
allDecimals.map((decimals, i) => [uniqueAddresses[i], decimals]),
);
}

async function fetchTokenFiatRates(
fiatCurrency: string,
erc20TokenAddresses: Hex[],
Expand Down
Loading
Loading