Skip to content

Commit 78b6874

Browse files
dbransdan437
andauthored
cherrypick feat: stx opt-in modal "Manage in settings" variation (#24771) into v11.16.1 (#24841)
cherrypick feat: stx opt-in modal "Manage in settings" variation 82fe51c (#24771) into v11.16.1 No merge conflicts Co-authored-by: Daniel <[email protected]>
1 parent 358859a commit 78b6874

File tree

7 files changed

+102
-19
lines changed

7 files changed

+102
-19
lines changed

app/_locales/en/messages.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/mmi/pageObjects/mmi-signup-page.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class MMISignUpPage {
1313

1414
readonly agreeBtn: Locator;
1515

16-
readonly noThanksBtn: Locator;
16+
readonly enableBtn: Locator;
1717

1818
readonly passwordTxt: Locator;
1919

@@ -44,9 +44,7 @@ export class MMISignUpPage {
4444
'button:has-text("Confirm Secret Recovery Phrase")',
4545
);
4646
this.agreeBtn = page.locator('button:has-text("I agree")');
47-
this.noThanksBtn = page.locator(
48-
'button:has-text("Don\'t enable enhanced protection")',
49-
);
47+
this.enableBtn = page.locator('button:has-text("Enable")'); // It shows in the Smart Transactions Opt-In Modal.
5048
this.passwordTxt = page.getByTestId('create-password-new');
5149
this.passwordConfirmTxt = page.getByTestId('create-password-confirm');
5250
this.agreeCheck = page.getByTestId('create-new-vault__terms-checkbox');

test/e2e/vault-decryption-chrome.spec.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ async function getExtensionStorageFilePath(driver) {
5050
*/
5151
async function closePopoverIfPresent(driver) {
5252
const popoverButtonSelector = '[data-testid="popover-close"]';
53-
const linkNoThanks = {
54-
text: "Don't enable enhanced protection",
53+
// It shows in the Smart Transactions Opt-In Modal.
54+
const enableButtonSelector = {
55+
text: 'Enable',
5556
tag: 'button',
5657
};
5758
await driver.clickElementSafe(popoverButtonSelector);
58-
await driver.clickElementSafe(linkNoThanks);
59+
await driver.clickElementSafe(enableButtonSelector);
5960
}
6061

6162
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`SmartTransactionsOptInModal displays the correct text in the modal 1`] = `<div />`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from 'react';
2+
import { fireEvent } from '@testing-library/react';
3+
import thunk from 'redux-thunk';
4+
import configureMockStore from 'redux-mock-store';
5+
import { useHistory } from 'react-router-dom';
6+
7+
import {
8+
renderWithProvider,
9+
createSwapsMockStore,
10+
} from '../../../../test/jest';
11+
import { setSmartTransactionsOptInStatus } from '../../../store/actions';
12+
import { ADVANCED_ROUTE } from '../../../helpers/constants/routes';
13+
import SmartTransactionsOptInModal from './smart-transactions-opt-in-modal';
14+
15+
const middleware = [thunk];
16+
17+
jest.mock('../../../store/actions');
18+
19+
describe('SmartTransactionsOptInModal', () => {
20+
it('displays the correct text in the modal', () => {
21+
const store = configureMockStore(middleware)(createSwapsMockStore());
22+
const { getByText, container } = renderWithProvider(
23+
<SmartTransactionsOptInModal
24+
isOpen={true}
25+
hideWhatsNewPopup={jest.fn()}
26+
/>,
27+
store,
28+
);
29+
expect(getByText('Enable')).toBeInTheDocument();
30+
expect(getByText('Manage in settings')).toBeInTheDocument();
31+
expect(container).toMatchSnapshot();
32+
});
33+
34+
it('calls setSmartTransactionsOptInStatus with false when the "Manage in settings" link is clicked and redirects to Advanced Settings', () => {
35+
(setSmartTransactionsOptInStatus as jest.Mock).mockImplementationOnce(() =>
36+
jest.fn(),
37+
);
38+
const historyPushMock = jest.fn();
39+
(useHistory as jest.Mock).mockImplementationOnce(() => ({
40+
push: historyPushMock,
41+
}));
42+
const store = configureMockStore(middleware)(createSwapsMockStore());
43+
const { getByText } = renderWithProvider(
44+
<SmartTransactionsOptInModal
45+
isOpen={true}
46+
hideWhatsNewPopup={jest.fn()}
47+
/>,
48+
store,
49+
);
50+
const manageInSettingsLink = getByText('Manage in settings');
51+
fireEvent.click(manageInSettingsLink);
52+
expect(setSmartTransactionsOptInStatus).toHaveBeenCalledWith(false);
53+
expect(historyPushMock).toHaveBeenCalledWith(
54+
`${ADVANCED_ROUTE}#smart-transactions`,
55+
);
56+
});
57+
58+
it('calls setSmartTransactionsOptInStatus with true when the "Enable" button is clicked', () => {
59+
(setSmartTransactionsOptInStatus as jest.Mock).mockImplementationOnce(() =>
60+
jest.fn(),
61+
);
62+
const store = configureMockStore(middleware)(createSwapsMockStore());
63+
const { getByText } = renderWithProvider(
64+
<SmartTransactionsOptInModal
65+
isOpen={true}
66+
hideWhatsNewPopup={jest.fn()}
67+
/>,
68+
store,
69+
);
70+
const enableButton = getByText('Enable');
71+
fireEvent.click(enableButton);
72+
expect(setSmartTransactionsOptInStatus).toHaveBeenCalledWith(true);
73+
});
74+
});

ui/components/app/smart-transactions/smart-transactions-opt-in-modal.tsx

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useCallback, useEffect } from 'react';
2+
import { useHistory } from 'react-router-dom';
23
import { useDispatch } from 'react-redux';
34

45
import { useI18nContext } from '../../../hooks/useI18nContext';
@@ -30,6 +31,7 @@ import {
3031
} from '../../component-library';
3132
import { setSmartTransactionsOptInStatus } from '../../../store/actions';
3233
import { SMART_TRANSACTIONS_LEARN_MORE_URL } from '../../../../shared/constants/smartTransactions';
34+
import { ADVANCED_ROUTE } from '../../../helpers/constants/routes';
3335

3436
export type SmartTransactionsOptInModalProps = {
3537
isOpen: boolean;
@@ -73,10 +75,10 @@ const EnableSmartTransactionsButton = ({
7375
);
7476
};
7577

76-
const NoThanksLink = ({
77-
handleNoThanksLinkClick,
78+
const ManageInSettingsLink = ({
79+
handleManageInSettingsLinkClick,
7880
}: {
79-
handleNoThanksLinkClick: () => void;
81+
handleManageInSettingsLinkClick: () => void;
8082
}) => {
8183
const t = useI18nContext();
8284
return (
@@ -85,11 +87,11 @@ const NoThanksLink = ({
8587
type="link"
8688
variant={ButtonVariant.Link}
8789
color={TextColor.textAlternative}
88-
onClick={handleNoThanksLinkClick}
90+
onClick={handleManageInSettingsLinkClick}
8991
width={BlockSize.Full}
9092
className="mm-smart-transactions-opt-in-modal__no-thanks-link"
9193
>
92-
{t('dontEnableEnhancedProtection')}
94+
{t('manageInSettings')}
9395
</Button>
9496
);
9597
};
@@ -164,13 +166,16 @@ export default function SmartTransactionsOptInModal({
164166
}: SmartTransactionsOptInModalProps) {
165167
const t = useI18nContext();
166168
const dispatch = useDispatch();
169+
const history = useHistory();
167170

168171
const handleEnableButtonClick = useCallback(() => {
169172
dispatch(setSmartTransactionsOptInStatus(true));
170173
}, [dispatch]);
171174

172-
const handleNoThanksLinkClick = useCallback(() => {
175+
const handleManageInSettingsLinkClick = useCallback(() => {
176+
// Set the Smart Transactions opt-in status to false, so the opt-in modal is not shown again.
173177
dispatch(setSmartTransactionsOptInStatus(false));
178+
history.push(`${ADVANCED_ROUTE}#smart-transactions`);
174179
}, [dispatch]);
175180

176181
useEffect(() => {
@@ -210,7 +215,9 @@ export default function SmartTransactionsOptInModal({
210215
<EnableSmartTransactionsButton
211216
handleEnableButtonClick={handleEnableButtonClick}
212217
/>
213-
<NoThanksLink handleNoThanksLinkClick={handleNoThanksLinkClick} />
218+
<ManageInSettingsLink
219+
handleManageInSettingsLinkClick={handleManageInSettingsLinkClick}
220+
/>
214221
</Box>
215222
</ModalContent>
216223
</Modal>

ui/pages/settings/advanced-tab/__snapshots__/advanced-tab.component.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ exports[`AdvancedTab Component should match snapshot 1`] = `
8080
>
8181
<span>
8282
83-
Turn on Smart Transactions for more reliable and secure transactions on ETH Mainnet.
83+
Turn on Smart Transactions for more reliable and secure transactions on Ethereum Mainnet.
8484
<a
8585
class="mm-box mm-text mm-button-base mm-button-link mm-button-link--size-inherit mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
8686
href="https://support.metamask.io/transactions-and-gas/transactions/smart-transactions/"

0 commit comments

Comments
 (0)