Skip to content

Commit

Permalink
Merge branch 'main' into fix/update-default-button-base-label-text-va…
Browse files Browse the repository at this point in the history
…riant
  • Loading branch information
Matt561 authored Dec 20, 2024
2 parents cc319e1 + 59d72d8 commit c14d18f
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const mockuseRampSDKInitialValues: Partial<RampSDK> = {
isBuy: true,
isSell: false,
rampType: RampType.BUY,
setIntent: jest.fn(),
};

let mockUseRampSDKValues: Partial<RampSDK> = {
Expand Down Expand Up @@ -275,12 +276,12 @@ describe('NetworkSwitcher View', () => {
expect(cancelButtons3.length).toBe(1);
});

it('switches network by calling setProviderType', async () => {
it('switches network by calling setActiveNetwork', async () => {
render(NetworkSwitcher);
const lineaNetworkText = screen.getByText('Linea Main Network');
fireEvent.press(lineaNetworkText);
expect(
(Engine.context.NetworkController.setProviderType as jest.Mock).mock
(Engine.context.NetworkController.setActiveNetwork as jest.Mock).mock
.calls,
).toMatchInlineSnapshot(`
[
Expand All @@ -290,6 +291,7 @@ describe('NetworkSwitcher View', () => {
]
`);

jest.clearAllMocks();
render(NetworkSwitcher);
const polygonNetworkTest = screen.getByText('Polygon Mainnet');
fireEvent.press(polygonNetworkTest);
Expand Down
23 changes: 17 additions & 6 deletions app/components/UI/Ramp/Views/NetworkSwitcher/NetworkSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function NetworkSwitcher() {
} = useRampNetworksDetail();
const supportedNetworks = useSelector(getRampNetworks);
const [isCurrentNetworkRampSupported] = useRampNetwork();
const { selectedChainId, isBuy, intent } = useRampSDK();
const { selectedChainId, isBuy, intent, setIntent } = useRampSDK();

const networkConfigurations = useSelector(selectNetworkConfigurations);
const [networkToBeAdded, setNetworkToBeAdded] = useState<Network>();
Expand Down Expand Up @@ -145,7 +145,7 @@ function NetworkSwitcher() {
const switchToMainnet = useCallback(
(type: 'mainnet' | 'linea-mainnet') => {
const { NetworkController } = Engine.context;
NetworkController.setProviderType(type);
NetworkController.setActiveNetwork(type);
navigateToGetStarted();
},
[navigateToGetStarted],
Expand Down Expand Up @@ -173,13 +173,23 @@ function NetworkSwitcher() {

const handleNetworkPress = useCallback(
(networkConfiguration) => {
setIntent((prevIntent) => ({
...prevIntent,
chainId: networkConfiguration.chainId,
}));

const networkConfigurationWithHexChainId = {
...networkConfiguration,
chainId: toHex(networkConfiguration.chainId),
};

if (networkConfiguration.isAdded) {
switchNetwork(networkConfiguration);
switchNetwork(networkConfigurationWithHexChainId);
} else {
setNetworkToBeAdded(networkConfiguration);
setNetworkToBeAdded(networkConfigurationWithHexChainId);
}
},
[switchNetwork],
[setIntent, switchNetwork],
);

const handleIntentChainId = useCallback(
Expand All @@ -199,7 +209,8 @@ function NetworkSwitcher() {
(networkConfiguration) => {
const isAdded = Object.values(networkConfigurations).some(
(savedNetwork) =>
savedNetwork.chainId === networkConfiguration.chainId,
toHex(savedNetwork.chainId) ===
toHex(networkConfiguration.chainId),
);
return {
...networkConfiguration,
Expand Down
11 changes: 9 additions & 2 deletions app/components/Views/ErrorBoundary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
} from '../../../components/hooks/useMetrics';
import AppConstants from '../../../core/AppConstants';
import { useSelector } from 'react-redux';

import { isTest } from '../../../util/test/utils';
// eslint-disable-next-line import/no-commonjs
const WarningIcon = require('./warning-icon.png');

Expand Down Expand Up @@ -246,7 +246,6 @@ export const Fallback = (props) => {
captureSentryFeedback({ sentryId: props.sentryId, comments: feedback });
Alert.alert(strings('error_screen.bug_report_thanks'));
};

return (
<View style={styles.container}>
<View style={styles.header}>
Expand All @@ -270,6 +269,14 @@ export const Fallback = (props) => {
</Text>
}
/>

{isTest && (
<Text style={styles.text}>
<Text onPress={props.showExportSeedphrase} style={styles.link}>
{strings('error_screen.save_seedphrase_2')}
</Text>
</Text>
)}
<View style={styles.errorContentWrapper}>
<Text style={styles.errorBoxTitle}>
{strings('error_screen.error_message')}
Expand Down
22 changes: 22 additions & 0 deletions app/components/Views/Login/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,28 @@ exports[`Login should render correctly 1`] = `
</Text>
</View>
</View>
<Text
style={
{
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
"lineHeight": 20,
}
}
>
<Text
onPress={[Function]}
style={
{
"color": "#0376c9",
}
}
>
save your Secret Recovery Phrase
</Text>
</Text>
<View
style={
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import NetworkModals from '../../../../../UI/NetworkModal';
import { View, TouchableOpacity } from 'react-native';
import { useSelector } from 'react-redux';
import WarningIcon from 'react-native-vector-icons/FontAwesome';
import { toHex } from '@metamask/controller-utils';
import CustomText from '../../../../../Base/Text';
import EmptyPopularList from '../emptyList';
import { useNavigation } from '@react-navigation/native';
Expand Down Expand Up @@ -46,7 +47,7 @@ const CustomNetwork = ({
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(savedNetwork: any) =>
savedNetwork.chainId === networkConfiguration.chainId,
toHex(savedNetwork.chainId) === toHex(networkConfiguration.chainId),
);
return {
...networkConfiguration,
Expand Down
10 changes: 9 additions & 1 deletion e2e/pages/Browser/TestDApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class TestDApp {
TestDappSelectorsWebIDs.APPROVE_ERC_20_TOKENS_BUTTON_ID,
);
}
get invalidSignature() {
return Matchers.getElementByWebID(
BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID,
'signInvalidType',
);
}

get ApproveERC721TokenButton() {
return Matchers.getElementByWebID(
Expand Down Expand Up @@ -144,7 +150,9 @@ class TestDApp {
async tapApproveERC721TokenButton() {
await this.tapButton(this.ApproveERC721TokenButton);
}

async tapInvalidSigButton() {
await this.tapButton(this.invalidSignature);
}
async tapIncreaseAllowanceButton() {
await this.tapButton(this.increaseAllowanceButton);
}
Expand Down
21 changes: 21 additions & 0 deletions e2e/pages/ErrorBoundaryView/ErrorBoundaryView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Matchers from '../../utils/Matchers';
import Gestures from '../../utils/Gestures';
import { ErrorBoundarySelectorsText } from '../../selectors/ErrorBoundary/ErrorBoundaryView.selectors';

class ErrorBoundaryView {
get title() {
return Matchers.getElementByText(ErrorBoundarySelectorsText.TITLE);
}

get srpLinkText() {
return Matchers.getElementByText(
ErrorBoundarySelectorsText.SAVE_YOUR_SRP_TEXT,
);
}

async tapSRPLinkText() {
await Gestures.waitAndTap(this.srpLinkText);
}
}

export default new ErrorBoundaryView();
12 changes: 11 additions & 1 deletion e2e/pages/Network/NetworkApprovalBottomSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ import Gestures from '../../utils/Gestures';

class NetworkApprovalBottomSheet {
get container() {
return Matchers.getElementByID(NetworkApprovalBottomSheetSelectorsIDs.CONTAINER);
return Matchers.getElementByID(
NetworkApprovalBottomSheetSelectorsIDs.CONTAINER,
);
}

get approvedButton() {
return Matchers.getElementByID(
NetworkApprovalBottomSheetSelectorsIDs.APPROVE_BUTTON,
);
}
get cancelButton() {
return Matchers.getElementByID(
NetworkApprovalBottomSheetSelectorsIDs.CANCEL_BUTTON,
);
}

get displayName() {
return Matchers.getElementByID(
Expand All @@ -22,6 +29,9 @@ class NetworkApprovalBottomSheet {
async tapApproveButton() {
await Gestures.tap(this.approvedButton);
}
async tapCancelButton() {
await Gestures.tap(this.cancelButton);
}
}

export default new NetworkApprovalBottomSheet();
9 changes: 9 additions & 0 deletions e2e/selectors/ErrorBoundary/ErrorBoundaryView.selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import enContent from '../../../locales/languages/en.json';

export const ErrorBoundarySelectorsIDs = {
CONTAINER: 'error-boundary-container-id',
};
export const ErrorBoundarySelectorsText = {
SAVE_YOUR_SRP_TEXT: enContent.error_screen.save_seedphrase_2,
TITLE: enContent.error_screen.title,
};
56 changes: 56 additions & 0 deletions e2e/specs/accounts/error-boundary-srp-backup.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';
import Browser from '../../pages/Browser/BrowserView';
import TabBarComponent from '../../pages/wallet/TabBarComponent';
import { loginToApp } from '../../viewHelper';
import TestDApp from '../../pages/Browser/TestDApp';
import FixtureBuilder from '../../fixtures/fixture-builder';
import {
withFixtures,
defaultGanacheOptions,
} from '../../fixtures/fixture-helper';
import { SmokeAccounts } from '../../tags';
import TestHelpers from '../../helpers';
import Assertions from '../../utils/Assertions';
import RevealSecretRecoveryPhrase from '../../pages/Settings/SecurityAndPrivacy/RevealSecretRecoveryPhrase';
import ErrorBoundaryView from '../../pages/ErrorBoundaryView/ErrorBoundaryView';
const PASSWORD = '123123123';

describe(SmokeAccounts('Error Boundary Screen'), () => {
beforeAll(async () => {
jest.setTimeout(2500000);
await TestHelpers.reverseServerPort();
});

it('should trigger error boundary screen to reveal SRP', async () => {
await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder()
.withGanacheNetwork()
.withPermissionControllerConnectedToTestDapp()
.build(),
restartDevice: true,
ganacheOptions: defaultGanacheOptions,
},
async () => {
await loginToApp();

await TabBarComponent.tapBrowser();
await Browser.navigateToTestDApp();

await TestDApp.tapInvalidSigButton();
await Assertions.checkIfVisible(ErrorBoundaryView.title);
await ErrorBoundaryView.tapSRPLinkText();

await RevealSecretRecoveryPhrase.enterPasswordToRevealSecretCredential(
PASSWORD,
);
// If the following step fails, ensure you are using a test build with tap and hold to reveal animation disabled
await RevealSecretRecoveryPhrase.tapToReveal();
await Assertions.checkIfVisible(RevealSecretRecoveryPhrase.container);

await Assertions.checkIfTextIsDisplayed(defaultGanacheOptions.mnemonic);
},
);
});
});

0 comments on commit c14d18f

Please sign in to comment.