Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 18 additions & 2 deletions app/components/UI/AccountOverview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import Text, {
} from '../../../component-library/components/Texts/Text';
import { withMetricsAwareness } from '../../../components/hooks/useMetrics';
import { isPortfolioUrl } from '../../../util/url';
import { buildPortfolioUrl } from '../../../util/browser';

const createStyles = (colors) =>
StyleSheet.create({
Expand Down Expand Up @@ -189,6 +190,10 @@ class AccountOverview extends PureComponent {
* Metrics injected by withMetricsAwareness HOC
*/
metrics: PropTypes.object,
/**
* Whether data collection for marketing is enabled
*/
isDataCollectionForMarketingEnabled: PropTypes.bool,
};

state = {
Expand Down Expand Up @@ -301,7 +306,7 @@ class AccountOverview extends PureComponent {
};

onOpenPortfolio = () => {
const { navigation, browserTabs } = this.props;
const { navigation, browserTabs, metrics } = this.props;
const existingPortfolioTab = browserTabs.find((tab) =>
isPortfolioUrl(tab.url),
);
Expand All @@ -310,7 +315,16 @@ class AccountOverview extends PureComponent {
if (existingPortfolioTab) {
existingTabId = existingPortfolioTab.id;
} else {
newTabUrl = `${AppConstants.PORTFOLIO.URL}/?metamaskEntry=mobile`;
const additionalParams = {
metricsEnabled: metrics.isEnabled(),
marketingEnabled:
this.props.isDataCollectionForMarketingEnabled ?? false,
};
const portfolioUrl = buildPortfolioUrl(
AppConstants.PORTFOLIO.URL,
additionalParams,
);
newTabUrl = portfolioUrl.href;
}
const params = {
...(newTabUrl && { newTabUrl }),
Expand Down Expand Up @@ -440,6 +454,8 @@ const mapStateToProps = (state) => ({
currentCurrency: selectCurrentCurrency(state),
chainId: selectChainId(state),
browserTabs: state.browser.tabs,
isDataCollectionForMarketingEnabled:
state.security.dataCollectionForMarketing,
});

const mapDispatchToProps = (dispatch) => ({
Expand Down
21 changes: 16 additions & 5 deletions app/components/UI/Bridge/hooks/useGoToPortfolioBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { BrowserParams } from '../../../Views/Browser/Browser.types';
import { getDecimalChainId } from '../../../../util/networks';
import { useMetrics } from '../../../hooks/useMetrics';
import { isBridgeUrl } from '../../../../util/url';
import { useBuildPortfolioUrl } from '../../../hooks/useBuildPortfolioUrl';

/**
* Returns a function that is used to navigate to the MetaMask Bridges webpage.
Expand All @@ -24,6 +25,7 @@ export default function useGoToPortfolioBridge(location: string) {
const browserTabs = useSelector((state: any) => state.browser.tabs);
const { navigate } = useNavigation();
const { trackEvent, createEventBuilder } = useMetrics();
const buildPortfolioUrlWithMetrics = useBuildPortfolioUrl();
return (address?: string) => {
const existingBridgeTab = browserTabs.find((tab: BrowserTab) =>
isBridgeUrl(tab.url),
Expand All @@ -37,11 +39,20 @@ export default function useGoToPortfolioBridge(location: string) {
params.newTabUrl = undefined;
params.existingTabId = existingBridgeTab.id;
} else {
params.newTabUrl = `${
AppConstants.BRIDGE.URL
}/?metamaskEntry=mobile&srcChain=${getDecimalChainId(chainId)}${
address ? `&token=${address}` : ''
}`;
const additionalParams: Record<string, string | number> = {
srcChain: getDecimalChainId(chainId),
};

if (address) {
additionalParams.token = address;
}

const bridgeUrl = buildPortfolioUrlWithMetrics(
AppConstants.BRIDGE.URL,
additionalParams,
);

params.newTabUrl = bridgeUrl.href;
}

navigate(Routes.BROWSER.HOME, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ export enum NetworkToCaipChainId {
LOCALHOST = 'eip155:1337',
ETHEREUM_SEPOLIA = 'eip155:11155111',
LINEA_SEPOLIA = 'eip155:59141',
SEI = 'eip155:1329',
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ jest.mock('@react-navigation/native', () => {

jest.mock('../../../../hooks/useMetrics');

jest.mock('../../../../hooks/useBuildPortfolioUrl', () => ({
useBuildPortfolioUrl: jest.fn(() => (baseUrl: string) => {
const url = new URL(baseUrl);
url.searchParams.set('metamaskEntry', 'mobile');
url.searchParams.set('marketingEnabled', 'true');
url.searchParams.set('metricsEnabled', 'true');
return url;
}),
}));

// Mock the environment variables
jest.mock('../../../../../util/environment', () => ({
isProduction: jest.fn().mockReturnValue(false),
Expand Down Expand Up @@ -256,7 +266,7 @@ describe('StakeButton', () => {
await waitFor(() => {
expect(mockNavigate).toHaveBeenCalledWith(Routes.BROWSER.HOME, {
params: {
newTabUrl: `${AppConstants.STAKE.URL}?metamaskEntry=mobile`,
newTabUrl: `${AppConstants.STAKE.URL}?metamaskEntry=mobile&marketingEnabled=true&metricsEnabled=true`,
timestamp: expect.any(Number),
},
screen: Routes.BROWSER.VIEW,
Expand Down
5 changes: 4 additions & 1 deletion app/components/UI/Stake/components/StakeButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Routes from '../../../../../constants/navigation/Routes';
import AppConstants from '../../../../../core/AppConstants';
import Engine from '../../../../../core/Engine';
import { RootState } from '../../../../../reducers';
import { useBuildPortfolioUrl } from '../../../../hooks/useBuildPortfolioUrl';
import {
selectEvmChainId,
selectNetworkConfigurationByChainId,
Expand Down Expand Up @@ -57,6 +58,7 @@ const StakeButtonContent = ({ asset }: StakeButtonProps) => {
const styles = createStyles(colors);
const navigation = useNavigation();
const { trackEvent, createEventBuilder } = useMetrics();
const buildPortfolioUrlWithMetrics = useBuildPortfolioUrl();

const browserTabs = useSelector((state: RootState) => state.browser.tabs);
const chainId = useSelector(selectEvmChainId);
Expand Down Expand Up @@ -149,7 +151,8 @@ const StakeButtonContent = ({ asset }: StakeButtonProps) => {
if (existingStakeTab) {
existingTabId = existingStakeTab.id;
} else {
newTabUrl = `${AppConstants.STAKE.URL}?metamaskEntry=mobile`;
const stakeUrl = buildPortfolioUrlWithMetrics(AppConstants.STAKE.URL);
newTabUrl = stakeUrl.href;
}
const params = {
...(newTabUrl && { newTabUrl }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import renderWithProvider from '../../../../../util/test/renderWithProvider';
import TrendingTokenRowItem from './TrendingTokenRowItem';
import type { TrendingAsset } from '@metamask/assets-controllers';

// Mock the trendingNetworksList module to avoid getNetworkImageSource errors
jest.mock('../../utils/trendingNetworksList', () => ({
TRENDING_NETWORKS_LIST: [],
}));

const mockNavigate = jest.fn();

jest.mock('@react-navigation/native', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@ jest.mock('../../../../../util/networks', () => ({
mockGetNetworkImageSource(params),
}));

const mockNetworks: ProcessedNetwork[] = [
{
id: 'eip155:1',
name: 'Ethereum Mainnet',
caipChainId: 'eip155:1' as CaipChainId,
imageSource: {
uri: 'https://example.com/ethereum.png',
} as ImageSourcePropType,
isSelected: false,
},
{
id: 'eip155:137',
name: 'Polygon',
caipChainId: 'eip155:137' as CaipChainId,
imageSource: {
uri: 'https://example.com/polygon.png',
} as ImageSourcePropType,
isSelected: false,
},
];

const mockUsePopularNetworks = jest.fn(() => mockNetworks);
// Mock the TRENDING_NETWORKS_LIST constant
jest.mock('../../utils/trendingNetworksList', () => {
const mockNetworks: ProcessedNetwork[] = [
{
id: 'eip155:1',
name: 'Ethereum Mainnet',
caipChainId: 'eip155:1' as CaipChainId,
imageSource: {
uri: 'https://example.com/ethereum.png',
} as ImageSourcePropType,
isSelected: false,
},
{
id: 'eip155:137',
name: 'Polygon',
caipChainId: 'eip155:137' as CaipChainId,
imageSource: {
uri: 'https://example.com/polygon.png',
} as ImageSourcePropType,
isSelected: false,
},
];

jest.mock('../../hooks/usePopularNetworks/usePopularNetworks', () => ({
usePopularNetworks: () => mockUsePopularNetworks(),
}));
return {
TRENDING_NETWORKS_LIST: mockNetworks,
};
});

let storedOnClose: (() => void) | undefined;

Expand Down Expand Up @@ -209,7 +210,6 @@ describe('TrendingTokenNetworkBottomSheet', () => {
storedOnClose = undefined;
mockOnClose.mockClear();
mockOnOpenBottomSheet.mockClear();
mockUsePopularNetworks.mockReturnValue(mockNetworks);
mockGetNetworkImageSource.mockImplementation(
(params: { chainId: string }) => {
if (params.chainId === 'eip155:1') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Avatar, {
import { strings } from '../../../../../../locales/i18n';
import { ProcessedNetwork } from '../../../../hooks/useNetworksByNamespace/useNetworksByNamespace';
import { CaipChainId } from '@metamask/utils';
import { usePopularNetworks } from '../../hooks/usePopularNetworks/usePopularNetworks';
import { TRENDING_NETWORKS_LIST } from '../../utils/trendingNetworksList';

export enum NetworkOption {
AllNetworks = 'all',
Expand Down Expand Up @@ -51,7 +51,7 @@ const TrendingTokenNetworkBottomSheet: React.FC<
}) => {
const sheetRef = useRef<BottomSheetRef>(null);
const { colors } = useTheme();
const networks = usePopularNetworks();
const networks = TRENDING_NETWORKS_LIST;

// Default to "All networks" if no selection
const [selectedNetwork, setSelectedNetwork] = useState<
Expand Down
Loading
Loading