Skip to content

Commit

Permalink
Merge branch 'main' into release/7.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sethkfman authored Feb 27, 2024
2 parents 73771cb + 7ef00e1 commit 1225bfd
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Third party dependencies.
import { StyleSheet, TextStyle, ViewStyle } from 'react-native';
import { StyleSheet, ViewStyle } from 'react-native';

// External dependencies.
import { colors } from '../../../../../../styles/common';
Expand All @@ -24,10 +24,7 @@ const styleSheet = (params: { vars: ButtonLinkStyleSheetVars }) => {
{ backgroundColor: colors.transparent },
style,
) as ViewStyle,
pressedText: Object.assign(
{ textDecorationLine: 'underline' } as TextStyle,
style,
) as TextStyle,
pressedText: { textDecorationLine: 'underline' },
});
};

Expand Down
27 changes: 16 additions & 11 deletions app/components/UI/NetworkModal/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,32 @@ exports[`NetworkDetails renders correctly 1`] = `
<View
style={
Object {
"backgroundColor": "#FFFFFF",
"alignItems": "center",
"backgroundColor": "#F2F4F6",
"borderRadius": 8,
"borderWidth": 1,
"height": 16,
"justifyContent": "center",
"overflow": "hidden",
"width": 16,
}
}
>
<Image
onError={[Function]}
resizeMode="contain"
source="image"
<Text
accessibilityRole="text"
style={
Object {
"flex": 1,
"height": undefined,
"width": undefined,
"color": "#24272A",
"fontFamily": "Euclid Circular B",
"fontSize": 10,
"fontWeight": "400",
"letterSpacing": 0,
"lineHeight": undefined,
}
}
testID="network-avatar-image"
/>
>
T
</Text>
</View>
<Text
accessibilityRole="text"
Expand Down Expand Up @@ -420,7 +425,7 @@ exports[`NetworkDetails renders correctly 1`] = `
}
}
>
https://localhost:8545
https:/
</Text>
<TouchableOpacity
activeOpacity={0.5}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/prop-types */
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { View, Linking } from 'react-native';
import { strings } from '../../../../locales/i18n';
import { CommonSelectorsIDs } from '../../../../e2e/selectors/Common.selectors';
Expand Down Expand Up @@ -28,8 +28,12 @@ import BottomSheetFooter, {
ButtonsAlignment,
} from '../../../component-library/components/BottomSheets/BottomSheetFooter';
import BottomSheetHeader from '../../../component-library/components/BottomSheets/BottomSheetHeader';
import { toggleUseSafeChainsListValidation } from '../../../util/networks';
import {
getNetworkImageSource,
toggleUseSafeChainsListValidation,
} from '../../../util/networks';
import { NetworkApprovalModalSelectorsIDs } from '../../../../e2e/selectors/Modals/NetworkApprovalModal.selectors';
import hideKeyFromUrl from '../../../util/hideKeyFromUrl';

interface Alert {
alertError: string;
Expand Down Expand Up @@ -67,6 +71,15 @@ const NetworkVerificationInfo = ({

useEffect(() => setAlerts(alertsFromProps), [alertsFromProps]);

const networkImageSource = useMemo(
() =>
//@ts-expect-error - The utils/network file is still JS and this function expects a networkType, and should be optional
getNetworkImageSource({
chainId: customNetworkInformation.chainId,
}),
[customNetworkInformation],
);

const renderNetworkInfo = () => (
<ScrollView
nestedScrollEnabled
Expand Down Expand Up @@ -98,7 +111,9 @@ const NetworkVerificationInfo = ({
<Text variant={TextVariant.BodyMDBold}>
{strings('add_custom_network.network_url')}
</Text>
<Text style={styles.textSection}>{customNetworkInformation.rpcUrl}</Text>
<Text style={styles.textSection}>
{hideKeyFromUrl(customNetworkInformation.rpcUrl)}
</Text>

<Accordion
title={strings('spend_limit_edition.view_details')}
Expand Down Expand Up @@ -149,6 +164,7 @@ const NetworkVerificationInfo = ({
const renderAlerts = useCallback(() => {
if (!safeChainsListValidationEnabled) return null;
if (!alerts.length) return null;

return alerts.map(
(
networkAlert: {
Expand Down Expand Up @@ -229,7 +245,7 @@ const NetworkVerificationInfo = ({
</BottomSheetHeader>
<ScrollView style={styles.root}>
<PickerNetwork
imageSource={customNetworkInformation.icon}
imageSource={networkImageSource}
label={customNetworkInformation.chainName}
style={styles.networkSection}
disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,32 @@ exports[`NetworkVerificationInfo renders correctly 1`] = `
<View
style={
Object {
"backgroundColor": "#FFFFFF",
"alignItems": "center",
"backgroundColor": "#F2F4F6",
"borderRadius": 8,
"borderWidth": 1,
"height": 16,
"justifyContent": "center",
"overflow": "hidden",
"width": 16,
}
}
>
<Image
onError={[Function]}
resizeMode="contain"
source="test-icon"
<Text
accessibilityRole="text"
style={
Object {
"flex": 1,
"height": undefined,
"width": undefined,
"color": "#24272A",
"fontFamily": "Euclid Circular B",
"fontSize": 10,
"fontWeight": "400",
"letterSpacing": 0,
"lineHeight": undefined,
}
}
testID="network-avatar-image"
/>
>
T
</Text>
</View>
<Text
accessibilityRole="text"
Expand Down Expand Up @@ -379,7 +384,7 @@ exports[`NetworkVerificationInfo renders correctly 1`] = `
}
}
>
http://test.com
http:/
</Text>
<TouchableOpacity
activeOpacity={0.5}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,27 +1062,32 @@ exports[`NetworkSwitcher View renders and dismisses network modal when pressing
<View
style={
Object {
"backgroundColor": "#FFFFFF",
"alignItems": "center",
"backgroundColor": "#F2F4F6",
"borderRadius": 8,
"borderWidth": 1,
"height": 16,
"justifyContent": "center",
"overflow": "hidden",
"width": 16,
}
}
>
<Image
onError={[Function]}
resizeMode="contain"
source="https://static.metafi.codefi.network/api/v1/tokenIcons/42220/0x471ece3750da237f93b8e339c536989b8978a438.png"
<Text
accessibilityRole="text"
style={
Object {
"flex": 1,
"height": undefined,
"width": undefined,
"color": "#24272A",
"fontFamily": "Euclid Circular B",
"fontSize": 10,
"fontWeight": "400",
"letterSpacing": 0,
"lineHeight": undefined,
}
}
testID="network-avatar-image"
/>
>
C
</Text>
</View>
<Text
accessibilityRole="text"
Expand Down Expand Up @@ -1248,7 +1253,7 @@ exports[`NetworkSwitcher View renders and dismisses network modal when pressing
}
}
>
https://evm.cronos.org
https:/
</Text>
<TouchableOpacity
activeOpacity={0.5}
Expand Down
85 changes: 67 additions & 18 deletions app/components/UI/WalletAccount/WalletAccount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { createAccountSelectorNavDetails } from '../../../components/Views/Accou
// Internal dependencies
import WalletAccount from './WalletAccount';
import initialBackgroundState from '../../../util/test/initial-background-state.json';
import { Account } from '../../hooks/useAccounts';
import { KeyringTypes } from '@metamask/keyring-controller';

jest.mock('../../../core/Engine', () => ({
context: {
Expand All @@ -25,19 +27,21 @@ jest.mock('../../../core/Engine', () => ({
},
}));

const mockAccount: Account = {
name: 'Test account 1',
address: '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272',
type: KeyringTypes.hd,
yOffset: 0,
isSelected: true,
};

const mockInitialState = {
settings: {
useBlockieIcon: false,
},
engine: {
backgroundState: {
...initialBackgroundState,
PreferencesController: {
selectedAddress: '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272',
identities: {
'0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272': { name: 'Account 1' },
},
},
},
},
};
Expand Down Expand Up @@ -69,36 +73,81 @@ jest.mock('react-redux', () => ({

describe('WalletAccount', () => {
it('renders correctly', () => {
const { toJSON } = renderWithProvider(<WalletAccount />, {
state: mockInitialState,
});
const { toJSON } = renderWithProvider(
<WalletAccount account={mockAccount} />,
{
state: mockInitialState,
},
);
expect(toJSON()).toMatchSnapshot();
});

it('shows the account address', () => {
const { getByTestId } = renderWithProvider(<WalletAccount />, {
state: mockInitialState,
});
const { getByTestId } = renderWithProvider(
<WalletAccount account={mockAccount} />,
{
state: mockInitialState,
},
);
expect(getByTestId('wallet-account-address')).toBeDefined();
});

it('copies the account address to the clipboard when the copy button is pressed', async () => {
const { getByTestId } = renderWithProvider(<WalletAccount />, {
state: mockInitialState,
});
const { getByTestId } = renderWithProvider(
<WalletAccount account={mockAccount} />,
{
state: mockInitialState,
},
);

fireEvent.press(getByTestId('wallet-account-copy-button'));
expect(ClipboardManager.setString).toHaveBeenCalledTimes(1);
});

it('should navigate to the account selector screen on account press', () => {
const { getByTestId } = renderWithProvider(<WalletAccount />, {
state: mockInitialState,
});
const { getByTestId } = renderWithProvider(
<WalletAccount account={mockAccount} />,
{
state: mockInitialState,
},
);

fireEvent.press(getByTestId('account-picker'));
expect(mockNavigate).toHaveBeenCalledWith(
...createAccountSelectorNavDetails({}),
);
});
it('displays the correct account name', () => {
const { getByText } = renderWithProvider(
<WalletAccount account={mockAccount} />,
{
state: mockInitialState,
},
);
expect(getByText(mockAccount.name)).toBeDefined();
});
it('displays custom account name when ENS is defined but account name is not the default', () => {
const ensName = 'test.eth';
const { getByText } = renderWithProvider(
<WalletAccount account={mockAccount} ens={ensName} />,
{
state: mockInitialState,
},
);
expect(getByText(mockAccount.name)).toBeDefined();
});
it('displays ENS name when defined and account name is the default', () => {
const ensName = 'test.eth';
const mockAccountWithDefaultName: Account = {
...mockAccount,
name: 'Account 1',
};
const { getByText } = renderWithProvider(
<WalletAccount account={mockAccountWithDefaultName} ens={ensName} />,
{
state: mockInitialState,
},
);
expect(getByText(ensName)).toBeDefined();
});
});
Loading

0 comments on commit 1225bfd

Please sign in to comment.