Skip to content

Commit

Permalink
Merge branch 'develop' into dr/update-btc-snap
Browse files Browse the repository at this point in the history
  • Loading branch information
danroc authored Jul 23, 2024
2 parents 2f3a8f7 + b262267 commit 2a52350
Show file tree
Hide file tree
Showing 24 changed files with 456 additions and 54 deletions.
286 changes: 286 additions & 0 deletions test/data/mock-data.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions test/e2e/flask/user-operations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
import { buildQuote, reviewQuote } from '../tests/swaps/shared';
import { Driver } from '../webdriver/driver';
import { Bundler } from '../bundler';
import { SWAP_TEST_ETH_USDC_TRADES_MOCK } from '../../data/mock-data';
import { Mockttp } from '../mock-e2e';

enum TransactionDetailRowIndex {
Nonce = 0,
Expand Down Expand Up @@ -102,6 +104,7 @@ async function createSwap(driver: Driver) {
swapFrom: 'TESTETH',
swapTo: 'USDC',
});

await driver.clickElement({ text: 'Swap', tag: 'button' });
await driver.clickElement({ text: 'Close', tag: 'button' });
}
Expand Down Expand Up @@ -167,6 +170,17 @@ async function expectTransactionDetailsMatchReceipt(
);
}

async function mockSwapsTransactionQuote(mockServer: Mockttp) {
return [
await mockServer
.forGet('https://swap.api.cx.metamask.io/networks/1/trades')
.thenCallback(() => ({
statusCode: 200,
json: SWAP_TEST_ETH_USDC_TRADES_MOCK,
})),
];
}

async function withAccountSnap(
{ title, paymaster }: { title?: string; paymaster?: string },
test: (driver: Driver, bundlerServer: Bundler) => Promise<void>,
Expand All @@ -183,6 +197,7 @@ async function withAccountSnap(
ganacheOptions: {
hardfork: 'london',
},
testSpecificMock: mockSwapsTransactionQuote,
},
async ({
driver,
Expand Down
12 changes: 5 additions & 7 deletions test/e2e/tests/bridge/bridge-click-from-asset-overview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import GanacheContractAddressRegistry from '../../seeder/ganache-contract-addres
import { Driver } from '../../webdriver/driver';
import { BridgePage, getBridgeFixtures } from './bridge-test-utils';

const EXPECTED_PORTFOLIO_URL =
'https://portfolio.metamask.io/bridge?metametricsId=null&metricsEnabled=false&marketingEnabled=false';

describe('Click bridge button from asset page @no-mmi', function (this: Suite) {
it('loads portfolio tab when flag is turned off', async function () {
await withFixtures(
Expand All @@ -25,18 +28,13 @@ describe('Click bridge button from asset page @no-mmi', function (this: Suite) {
// ETH
await bridgePage.loadAssetPage(contractRegistry);
await bridgePage.load('coin-overview');
await bridgePage.verifyPortfolioTab(
'https://portfolio.metamask.io/bridge?metametricsId=null',
);

await bridgePage.verifyPortfolioTab(EXPECTED_PORTFOLIO_URL);
await bridgePage.reloadHome();

// TST
await bridgePage.loadAssetPage(contractRegistry, 'TST');
await bridgePage.load('token-overview');
await bridgePage.verifyPortfolioTab(
'https://portfolio.metamask.io/bridge?metametricsId=null',
);
await bridgePage.verifyPortfolioTab(EXPECTED_PORTFOLIO_URL);
},
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Click bridge button from wallet overview @no-mmi', function (this: Sui
await logInWithBalanceValidation(driver, ganacheServer);
await bridgePage.load();
await bridgePage.verifyPortfolioTab(
'https://portfolio.metamask.io/bridge?metametricsId=null',
'https://portfolio.metamask.io/bridge?metametricsId=null&metricsEnabled=false&marketingEnabled=false',
);
},
);
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/tests/portfolio/portfolio-site.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ describe('Portfolio site', function () {
await driver.switchToWindowWithTitle('E2E Test Page', windowHandles);

// Verify site
assert.equal(
await driver.getCurrentUrl(),
'https://portfolio.metamask.io/?metamaskEntry=ext_portfolio_button&metametricsId=null',
);
const currentUrl = await driver.getCurrentUrl();
const expectedUrl =
'https://portfolio.metamask.io/?metamaskEntry=ext_portfolio_button&metametricsId=null&metricsEnabled=false&marketingEnabled=false';
assert.equal(currentUrl, expectedUrl);
},
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`Token Cell should match snapshot 1`] = `
href="#"
>
<div
class="mm-box mm-badge-wrapper mm-box--margin-right-3 mm-box--display-inline-block"
class="mm-box mm-badge-wrapper multichain-token-list-item__badge mm-box--margin-right-3 mm-box--display-inline-block"
>
<div
class="mm-box mm-text mm-avatar-base mm-avatar-base--size-md mm-avatar-token mm-avatar-token--with-halo mm-text--body-sm mm-text--text-transform-uppercase mm-box--display-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-full"
Expand Down
14 changes: 8 additions & 6 deletions ui/components/app/wallet-overview/btc-overview.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import configureMockStore from 'redux-mock-store';
import { fireEvent } from '@testing-library/react';
import { fireEvent, waitFor } from '@testing-library/react';
import thunk from 'redux-thunk';
import { Cryptocurrency } from '@metamask/assets-controllers';
import { BtcAccountType, BtcMethod } from '@metamask/keyring-api';
Expand Down Expand Up @@ -208,6 +208,7 @@ describe('BtcOverview', () => {
metamaskEntry: RampsMetaMaskEntry.BuySellButton,
chainId: MultichainNetworks.BITCOIN,
metametricsId: mockMetaMetricsId,
metricsEnabled: String(false),
}),
});
});
Expand All @@ -227,11 +228,12 @@ describe('BtcOverview', () => {
fireEvent.click(portfolioButton as HTMLElement);

expect(openTabSpy).toHaveBeenCalledTimes(1);
expect(openTabSpy).toHaveBeenCalledWith({
url: makePortfolioUrl('', {
metamaskEntry: 'ext_portfolio_button',
metametricsId: mockMetaMetricsId,
await waitFor(() =>
expect(openTabSpy).toHaveBeenCalledWith({
url: expect.stringContaining(
`?metamaskEntry=ext_portfolio_button&metametricsId=${mockMetaMetricsId}`,
),
}),
});
);
});
});
14 changes: 13 additions & 1 deletion ui/components/app/wallet-overview/coin-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import {
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
SwapsEthToken,
getCurrentKeyring,
getDataCollectionForMarketing,
getMetaMetricsId,
getParticipateInMetaMetrics,
///: END:ONLY_INCLUDE_IF
getUseExternalServices,
} from '../../../selectors';
Expand Down Expand Up @@ -97,6 +99,8 @@ const CoinButtons = ({
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
const location = useLocation();
const metaMetricsId = useSelector(getMetaMetricsId);
const isMetaMetricsEnabled = useSelector(getParticipateInMetaMetrics);
const isMarketingEnabled = useSelector(getDataCollectionForMarketing);
const keyring = useSelector(getCurrentKeyring);
const usingHardwareWallet = isHardwareKeyring(keyring?.type);
///: END:ONLY_INCLUDE_IF
Expand Down Expand Up @@ -287,6 +291,8 @@ const CoinButtons = ({
'bridge',
'ext_bridge_button',
metaMetricsId,
isMetaMetricsEnabled,
isMarketingEnabled,
);
global.platform.openTab({
url: `${portfolioUrl}${
Expand All @@ -307,7 +313,13 @@ const CoinButtons = ({
}, [isBridgeChain, chainId, metaMetricsId]);

const handlePortfolioOnClick = useCallback(() => {
const url = getPortfolioUrl('', 'ext_portfolio_button', metaMetricsId);
const url = getPortfolioUrl(
'',
'ext_portfolio_button',
metaMetricsId,
isMetaMetricsEnabled,
isMarketingEnabled,
);
global.platform.openTab({ url });
trackEvent({
category: MetaMetricsEventCategory.Navigation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`TokenListItem should render correctly 1`] = `
href="#"
>
<div
class="mm-box mm-badge-wrapper mm-box--margin-right-3 mm-box--display-inline-block"
class="mm-box mm-badge-wrapper multichain-token-list-item__badge mm-box--margin-right-3 mm-box--display-inline-block"
>
<div
class="mm-box mm-text mm-avatar-base mm-avatar-base--size-md mm-avatar-token mm-avatar-token--with-halo mm-text--body-sm mm-text--text-transform-uppercase mm-box--display-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-full mm-box--border-color-border-default box--border-style-solid box--border-width-1"
Expand Down
4 changes: 4 additions & 0 deletions ui/components/multichain/token-list-item/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
}
}
}

&__badge {
align-self: center;
}
}
15 changes: 13 additions & 2 deletions ui/components/multichain/token-list-item/token-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
getMetaMetricsId,
getTestNetworkBackgroundColor,
getTokensMarketData,
getParticipateInMetaMetrics,
getDataCollectionForMarketing,
} from '../../../selectors';
import {
getMultichainCurrentChainId,
Expand Down Expand Up @@ -82,8 +84,10 @@ export const TokenListItem = ({
const isEvm = useSelector(getMultichainIsEvm);
const primaryTokenImage = useSelector(getMultichainNativeCurrencyImage);
const trackEvent = useContext(MetaMetricsContext);
const metaMetricsId = useSelector(getMetaMetricsId);
const chainId = useSelector(getMultichainCurrentChainId);
const metaMetricsId = useSelector(getMetaMetricsId);
const isMetaMetricsEnabled = useSelector(getParticipateInMetaMetrics);
const isMarketingEnabled = useSelector(getDataCollectionForMarketing);

// Scam warning
const showScamWarning =
Expand Down Expand Up @@ -133,7 +137,13 @@ export const TokenListItem = ({
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
const url = getPortfolioUrl('stake', 'ext_stake_button', metaMetricsId);
const url = getPortfolioUrl(
'stake',
'ext_stake_button',
metaMetricsId,
isMetaMetricsEnabled,
isMarketingEnabled,
);
global.platform.openTab({ url });
trackEvent({
event: MetaMetricsEventName.StakingEntryPointClicked,
Expand Down Expand Up @@ -220,6 +230,7 @@ export const TokenListItem = ({
/>
}
marginRight={3}
className="multichain-token-list-item__badge"
>
<AvatarToken
name={tokenSymbol}
Expand Down
33 changes: 33 additions & 0 deletions ui/components/ui/icon-button/icon-button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import IconButton from './icon-button';
import { TextVariant } from '../../../helpers/constants/design-system';
import Tooltip from '../tooltip/tooltip';

const meta: Meta<typeof IconButton> = {
title: 'Components/UI/IconButton',
component: IconButton,
argTypes: {
onClick: { action: 'clicked' },
Icon: { control: 'object' },
disabled: { control: 'boolean' },
label: { control: 'text' },
tooltipRender: { control: 'function' },
className: { control: 'text' },
},
args: {
onClick: () => {},
Icon: <div>Icon</div>,
disabled: false,
label: 'Icon Button',
tooltipRender: undefined,
className: '',
},
};

export default meta;
type Story = StoryObj<typeof IconButton>;

export const Default: Story = {};

Default.storyName = 'Default';
6 changes: 6 additions & 0 deletions ui/components/ui/new-network-info/new-network-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
getMetaMetricsId,
getUseTokenDetection,
getUseExternalServices,
getParticipateInMetaMetrics,
getDataCollectionForMarketing,
} from '../../../selectors';
import { setFirstTimeUsedNetwork } from '../../../store/actions';
import {
Expand Down Expand Up @@ -49,6 +51,8 @@ export default function NewNetworkInfo() {
const currentNetwork = useSelector(getCurrentNetwork);
const metaMetricsId = useSelector(getMetaMetricsId);
const isBridgeChain = useSelector(getIsBridgeChain);
const isMetaMetricsEnabled = useSelector(getParticipateInMetaMetrics);
const isMarketingEnabled = useSelector(getDataCollectionForMarketing);

const onCloseClick = () => {
setShowPopup(false);
Expand Down Expand Up @@ -203,6 +207,8 @@ export default function NewNetworkInfo() {
'bridge',
'ext_bridge_new_network_info_link',
metaMetricsId,
isMetaMetricsEnabled,
isMarketingEnabled,
)}&destChain=${currentNetwork?.chainId}`}
target="_blank"
rel="noreferrer"
Expand Down
15 changes: 13 additions & 2 deletions ui/helpers/utils/portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ export function getPortfolioUrl(
endpoint = '',
metamaskEntry = '',
metaMetricsId = '',
metricsEnabled = false,
marketingEnabled = false,
) {
const portfolioUrl = process.env.PORTFOLIO_URL || '';
return `${portfolioUrl}/${endpoint}?metamaskEntry=${metamaskEntry}&metametricsId=${metaMetricsId}`;
const baseUrl = process.env.PORTFOLIO_URL || '';
const url = new URL(endpoint, baseUrl);

url.searchParams.append('metamaskEntry', metamaskEntry);
url.searchParams.append('metametricsId', metaMetricsId);

// Append privacy preferences for metrics + marketing on user navigation to Portfolio
url.searchParams.append('metricsEnabled', String(metricsEnabled));
url.searchParams.append('marketingEnabled', String(marketingEnabled));

return url.href;
}
6 changes: 3 additions & 3 deletions ui/hooks/ramps/useRamps/useRamps.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('useRamps', () => {
},
};

const mockBuyURI = `${process.env.PORTFOLIO_URL}/buy?metamaskEntry=${metaMaskEntry}&chainId=${mockChainId}&metametricsId=${mockedMetametricsId}`;
const mockBuyURI = `${process.env.PORTFOLIO_URL}/buy?metamaskEntry=${metaMaskEntry}&chainId=${mockChainId}&metametricsId=${mockedMetametricsId}&metricsEnabled=false`;
const openTabSpy = jest.spyOn(global.platform, 'openTab');

const { result } = renderHook(() => useRamps(), { wrapper }); // default metamask entry
Expand All @@ -68,7 +68,7 @@ describe('useRamps', () => {
},
};

const mockBuyURI = `${process.env.PORTFOLIO_URL}/buy?metamaskEntry=${metaMaskEntry}&chainId=${mockChainId}&metametricsId=${mockedMetametricsId}`;
const mockBuyURI = `${process.env.PORTFOLIO_URL}/buy?metamaskEntry=${metaMaskEntry}&chainId=${mockChainId}&metametricsId=${mockedMetametricsId}&metricsEnabled=false`;
const openTabSpy = jest.spyOn(global.platform, 'openTab');

const { result } = renderHook(
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('useRamps', () => {
},
};

const mockBuyURI = `${process.env.PORTFOLIO_URL}/buy?metamaskEntry=ext_buy_sell_button&chainId=${mockChainId}&metametricsId=${mockedMetametricsId}`;
const mockBuyURI = `${process.env.PORTFOLIO_URL}/buy?metamaskEntry=ext_buy_sell_button&chainId=${mockChainId}&metametricsId=${mockedMetametricsId}&metricsEnabled=false`;
const openTabSpy = jest.spyOn(global.platform, 'openTab');
const { result } = renderHook(() => useRamps(), { wrapper });

Expand Down
14 changes: 13 additions & 1 deletion ui/hooks/ramps/useRamps/useRamps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { useCallback } from 'react';
import { useSelector } from 'react-redux';
import { CaipChainId } from '@metamask/utils';
import { ChainId } from '../../../../shared/constants/network';
import { getCurrentChainId, getMetaMetricsId } from '../../../selectors';
import {
getCurrentChainId,
getDataCollectionForMarketing,
getMetaMetricsId,
getParticipateInMetaMetrics,
} from '../../../selectors';

type IUseRamps = {
openBuyCryptoInPdapp: (chainId?: ChainId | CaipChainId) => void;
Expand All @@ -23,6 +28,8 @@ const useRamps = (
): IUseRamps => {
const chainId = useSelector(getCurrentChainId);
const metaMetricsId = useSelector(getMetaMetricsId);
const isMetaMetricsEnabled = useSelector(getParticipateInMetaMetrics);
const isMarketingEnabled = useSelector(getDataCollectionForMarketing);

const getBuyURI = useCallback(
(_chainId: ChainId | CaipChainId) => {
Expand All @@ -32,6 +39,11 @@ const useRamps = (
if (metaMetricsId) {
params.set('metametricsId', metaMetricsId);
}
params.set('metricsEnabled', String(isMetaMetricsEnabled));
if (isMarketingEnabled) {
params.set('marketingEnabled', String(isMarketingEnabled));
}

return `${portfolioUrl}/buy?${params.toString()}`;
},
[metaMetricsId],
Expand Down
Loading

0 comments on commit 2a52350

Please sign in to comment.