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
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ index d4a40bea9e4ed3c28e347d96e309efe1ff889e81..fab280760de6bd5cdfdbecf01495c2d5
},
[utils_1.KnownCaipNamespace.Solana]: {
[keyring_api_1.SolScope.Mainnet]: true,
diff --git a/dist/constants.cjs b/dist/constants.cjs
index d45d861dd20777a9c767ef6a4272d0b4fd53f895..145d00f5deec1d79b145bdab8a940e4a6c71230e 100644
--- a/dist/constants.cjs
+++ b/dist/constants.cjs
@@ -15,5 +15,6 @@ exports.POPULAR_NETWORKS = [
'0x2a15c308d',
'0x3e7',
'0x8f', // Monad (143)
+ '0x10e6', // MegaETH (4326)
];
//# sourceMappingURL=constants.cjs.map
\ No newline at end of file
48 changes: 43 additions & 5 deletions app/__mocks__/react-native-vision-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,53 @@ const mockPermission = {
requestPermission: jest.fn().mockResolvedValue('granted'),
};

const mockCodeScanner = {
codeTypes: ['qr'],
onCodeScanned: jest.fn(),
let capturedOnCodeScanned:
| ((codes: { value: string; type: string }[]) => Promise<void> | void)
| null = null;
let capturedOnError: ((error: Error) => Promise<void> | void) | null = null;

export const resetCapturedCallbacks = () => {
capturedOnCodeScanned = null;
capturedOnError = null;
};

const Camera = React.forwardRef(() => null);
export const getCapturedCallbacks = () => ({
onCodeScanned: capturedOnCodeScanned,
onError: capturedOnError,
});

const Camera = React.forwardRef(
(
props: {
onError?: (error: Error) => Promise<void> | void;
codeScanner?: {
onCodeScanned: (
codes: { value: string; type: string }[],
) => Promise<void> | void;
};
},
_ref: unknown,
) => {
if (props.onError) {
capturedOnError = props.onError;
}
if (props.codeScanner?.onCodeScanned) {
capturedOnCodeScanned = props.codeScanner.onCodeScanned;
}
return React.createElement('View', { testID: 'camera-mock' });
},
);

const useCameraDevice = jest.fn(() => mockDevice);
const useCameraPermission = jest.fn(() => mockPermission);
const useCodeScanner = jest.fn(() => mockCodeScanner);
const useCodeScanner = jest.fn((config) => {
if (config?.onCodeScanned) {
capturedOnCodeScanned = config.onCodeScanned;
}
return {
codeTypes: ['qr'],
onCodeScanned: config?.onCodeScanned || jest.fn(),
};
});

export { Camera, useCameraDevice, useCameraPermission, useCodeScanner };
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import MultichainAddWalletActions from './MultichainAddWalletActions';
import { MOCK_ACCOUNTS_CONTROLLER_STATE } from '../../../../util/test/accountsControllerTestUtils';
import { MOCK_KEYRING_CONTROLLER } from '../../../../selectors/keyringController/testUtils';
import Routes from '../../../../constants/navigation/Routes';
import { MetaMetricsEvents } from '../../../../core/Analytics';

const mockedNavigate = jest.fn();
jest.mock('@react-navigation/native', () => {
Expand All @@ -18,6 +19,18 @@ jest.mock('@react-navigation/native', () => {
};
});

const mockTrackEvent = jest.fn();
const mockCreateEventBuilder = jest.fn((event) => ({
build: jest.fn(() => event),
}));

jest.mock('../../../../components/hooks/useMetrics', () => ({
useMetrics: () => ({
trackEvent: mockTrackEvent,
createEventBuilder: mockCreateEventBuilder,
}),
}));

const mockInitialState = {
engine: {
backgroundState: {
Expand Down Expand Up @@ -147,4 +160,78 @@ describe('MultichainAddWalletActions', () => {
expect(mockedNavigate).toHaveBeenCalledWith(Routes.MULTI_SRP.IMPORT);
expect(mockProps.onBack).toHaveBeenCalled();
});

describe('Analytics', () => {
it('tracks event when import wallet button is pressed', () => {
renderScreen(
() => <MultichainAddWalletActions {...mockProps} />,
{
name: 'MultichainAddWalletActions',
},
{
state: mockInitialState,
},
);

const importWalletButton = screen.getByTestId(
AddAccountBottomSheetSelectorsIDs.IMPORT_SRP_BUTTON,
);
fireEvent.press(importWalletButton);

expect(mockCreateEventBuilder).toHaveBeenCalledWith(
MetaMetricsEvents.IMPORT_SECRET_RECOVERY_PHRASE_CLICKED,
);
expect(mockTrackEvent).toHaveBeenCalledWith(
MetaMetricsEvents.IMPORT_SECRET_RECOVERY_PHRASE_CLICKED,
);
});

it('tracks event when import account button is pressed', () => {
renderScreen(
() => <MultichainAddWalletActions {...mockProps} />,
{
name: 'MultichainAddWalletActions',
},
{
state: mockInitialState,
},
);

const importAccountButton = screen.getByTestId(
AddAccountBottomSheetSelectorsIDs.IMPORT_ACCOUNT_BUTTON,
);
fireEvent.press(importAccountButton);

expect(mockCreateEventBuilder).toHaveBeenCalledWith(
MetaMetricsEvents.ACCOUNTS_IMPORTED_NEW_ACCOUNT,
);
expect(mockTrackEvent).toHaveBeenCalledWith(
MetaMetricsEvents.ACCOUNTS_IMPORTED_NEW_ACCOUNT,
);
});

it('tracks event when hardware wallet button is pressed', () => {
renderScreen(
() => <MultichainAddWalletActions {...mockProps} />,
{
name: 'MultichainAddWalletActions',
},
{
state: mockInitialState,
},
);

const hardwareWalletButton = screen.getByTestId(
AddAccountBottomSheetSelectorsIDs.ADD_HARDWARE_WALLET_BUTTON,
);
fireEvent.press(hardwareWalletButton);

expect(mockCreateEventBuilder).toHaveBeenCalledWith(
MetaMetricsEvents.ADD_HARDWARE_WALLET,
);
expect(mockTrackEvent).toHaveBeenCalledWith(
MetaMetricsEvents.ADD_HARDWARE_WALLET,
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const MultichainAddWalletActions = ({
iconName: IconName.Usb,
testID: AddAccountBottomSheetSelectorsIDs.ADD_HARDWARE_WALLET_BUTTON,
isVisible: true,
analyticsEvent: MetaMetricsEvents.CONNECT_HARDWARE_WALLET,
analyticsEvent: MetaMetricsEvents.ADD_HARDWARE_WALLET,
navigationAction: () => {
navigate(Routes.HW.CONNECT);
onBack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,6 @@ describe('BridgeDestNetworkSelector - ChainPopularity fallback', () => {
// Optimism (popularity 10) should appear before Palm and zkSync Era (both Infinity)
expect(getByText('Optimism')).toBeTruthy();
expect(getByText('Palm')).toBeTruthy();
expect(getByText('zkSync Era')).toBeTruthy();
expect(getByText('zkSync')).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Routes from '../../../../../constants/navigation/Routes';
import { selectChainId } from '../../../../../selectors/networkController';
import { BridgeViewMode } from '../../types';
import { ChainPopularity } from '../BridgeDestNetworksBar';
import { NETWORK_TO_SHORT_NETWORK_NAME_MAP } from '../../../../../constants/bridge';

export interface BridgeDestNetworkSelectorRouteParams {
shouldGoToTokens?: boolean;
Expand Down Expand Up @@ -80,7 +81,12 @@ export const BridgeDestNetworkSelector: React.FC = () => {
onPress={() => handleChainSelect(chain.chainId)}
>
<ListItem verticalAlignment={VerticalAlignment.Center}>
<NetworkRow chainId={chain.chainId} chainName={chain.name} />
<NetworkRow
chainId={chain.chainId}
chainName={
NETWORK_TO_SHORT_NETWORK_NAME_MAP[chain.chainId] ?? chain.name
}
/>
</ListItem>
</TouchableOpacity>
)),
Expand Down
10 changes: 5 additions & 5 deletions app/components/UI/Bridge/components/BridgeDestNetworksBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { CHAIN_IDS } from '@metamask/transaction-controller';
import { NETWORKS_CHAIN_ID } from '../../../../constants/network';
import { CaipChainId, Hex } from '@metamask/utils';
import { NETWORK_TO_SHORT_NETWORK_NAME_MAP } from '../../../../constants/bridge';
import { Box } from '../../Box/Box';
import { getNetworkImageSource } from '../../../../util/networks';
import { AlignItems, FlexDirection } from '../../Box/box.types';
Expand Down Expand Up @@ -80,10 +81,6 @@ export const ChainPopularity: Record<Hex | CaipChainId, number> = {
[NETWORKS_CHAIN_ID.MONAD]: 13,
};

const ShortChainNames: Record<Hex | CaipChainId, string> = {
[CHAIN_IDS.MAINNET]: 'Ethereum',
};

export const BridgeDestNetworksBar = () => {
const navigation = useNavigation();
const dispatch = useDispatch();
Expand Down Expand Up @@ -140,7 +137,10 @@ export const BridgeDestNetworksBar = () => {
size={AvatarSize.Xs}
/>
) : null}
<Text>{ShortChainNames[chain.chainId] ?? chain.name}</Text>
<Text>
{NETWORK_TO_SHORT_NETWORK_NAME_MAP[chain.chainId] ??
chain.name}
</Text>
</Box>
}
style={
Expand Down
Loading
Loading