Skip to content

Commit cf42293

Browse files
committed
fix: srp backup navigation and quiz cp-12.22.0 (#33922)
1 parent 3bb4b59 commit cf42293

File tree

8 files changed

+60
-24
lines changed

8 files changed

+60
-24
lines changed

ui/pages/onboarding-flow/create-password/create-password.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import {
1515
} from '../../../helpers/constants/design-system';
1616
import {
1717
ONBOARDING_COMPLETION_ROUTE,
18+
ONBOARDING_IMPORT_WITH_SRP_ROUTE,
1819
ONBOARDING_METAMETRICS,
1920
ONBOARDING_SECURE_YOUR_WALLET_ROUTE,
21+
ONBOARDING_WELCOME_ROUTE,
2022
} from '../../../helpers/constants/routes';
2123
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
2224
import {
@@ -86,12 +88,18 @@ export default function CreatePassword({
8688
} else {
8789
history.replace(ONBOARDING_SECURE_YOUR_WALLET_ROUTE);
8890
}
91+
} else if (
92+
firstTimeFlowType === FirstTimeFlowType.import &&
93+
!secretRecoveryPhrase
94+
) {
95+
history.replace(ONBOARDING_IMPORT_WITH_SRP_ROUTE);
8996
}
9097
}, [
9198
currentKeyring,
9299
history,
93100
firstTimeFlowType,
94101
newAccountCreationInProgress,
102+
secretRecoveryPhrase,
95103
]);
96104

97105
const handleLearnMoreClick = (event) => {
@@ -134,9 +142,9 @@ export default function CreatePassword({
134142
});
135143

136144
if (getBrowserName() === PLATFORM_FIREFOX) {
137-
history.push(ONBOARDING_COMPLETION_ROUTE);
145+
history.replace(ONBOARDING_COMPLETION_ROUTE);
138146
} else {
139-
history.push(ONBOARDING_METAMETRICS);
147+
history.replace(ONBOARDING_METAMETRICS);
140148
}
141149
};
142150

@@ -164,7 +172,7 @@ export default function CreatePassword({
164172
},
165173
});
166174

167-
history.push(ONBOARDING_SECURE_YOUR_WALLET_ROUTE);
175+
history.replace(ONBOARDING_SECURE_YOUR_WALLET_ROUTE);
168176
};
169177

170178
const handleCreatePassword = async (event) => {
@@ -231,7 +239,11 @@ export default function CreatePassword({
231239
size={ButtonIconSize.Md}
232240
data-testid="create-password-back-button"
233241
type="button"
234-
onClick={() => history.goBack()}
242+
onClick={() =>
243+
firstTimeFlowType === FirstTimeFlowType.import
244+
? history.replace(ONBOARDING_IMPORT_WITH_SRP_ROUTE)
245+
: history.replace(ONBOARDING_WELCOME_ROUTE)
246+
}
235247
ariaLabel={t('back')}
236248
/>
237249
</Box>

ui/pages/onboarding-flow/create-password/create-password.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import {
1010
import { FirstTimeFlowType } from '../../../../shared/constants/onboarding';
1111
import CreatePassword from './create-password';
1212

13-
const mockHistoryPush = jest.fn();
1413
const mockHistoryReplace = jest.fn();
1514

1615
jest.mock('react-router-dom', () => ({
1716
...jest.requireActual('react-router-dom'),
1817
useHistory: () => ({
19-
push: mockHistoryPush,
2018
replace: mockHistoryReplace,
2119
}),
2220
}));
@@ -333,7 +331,7 @@ describe('Onboarding Create Password', () => {
333331
expect(mockCreateNewAccount).toHaveBeenCalledWith(password);
334332

335333
await waitFor(() => {
336-
expect(mockHistoryPush).toHaveBeenCalledWith(
334+
expect(mockHistoryReplace).toHaveBeenCalledWith(
337335
ONBOARDING_SECURE_YOUR_WALLET_ROUTE,
338336
);
339337
});
@@ -395,7 +393,7 @@ describe('Onboarding Create Password', () => {
395393
);
396394

397395
await waitFor(() => {
398-
expect(mockHistoryPush).toHaveBeenCalledWith(ONBOARDING_METAMETRICS);
396+
expect(mockHistoryReplace).toHaveBeenCalledWith(ONBOARDING_METAMETRICS);
399397
});
400398
});
401399
});

ui/pages/onboarding-flow/import-srp/import-srp.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ export default function ImportSRP({ submitSecretRecoveryPhrase }) {
125125
color={IconColor.iconDefault}
126126
size={ButtonIconSize.Md}
127127
data-testid="import-srp-back-button"
128-
onClick={() => history.push(ONBOARDING_WELCOME_ROUTE)}
128+
onClick={() => {
129+
history.replace(ONBOARDING_WELCOME_ROUTE);
130+
}}
129131
ariaLabel={t('back')}
130132
/>
131133
</Box>

ui/pages/onboarding-flow/onboarding-flow.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import {
2121
ONBOARDING_METAMETRICS,
2222
ONBOARDING_ACCOUNT_EXIST,
2323
ONBOARDING_ACCOUNT_NOT_FOUND,
24+
SECURITY_ROUTE,
2425
} from '../../helpers/constants/routes';
2526
import {
2627
getCompletedOnboarding,
28+
getIsPrimarySeedPhraseBackedUp,
2729
getIsUnlocked,
2830
} from '../../ducks/metamask/metamask';
2931
import {
@@ -91,9 +93,15 @@ export default function OnboardingFlow() {
9193
const completedOnboarding = useSelector(getCompletedOnboarding);
9294
const nextRoute = useSelector(getFirstTimeFlowTypeRouteAfterUnlock);
9395
const isFromReminder = new URLSearchParams(search).get('isFromReminder');
96+
const isFromSettingsSecurity = new URLSearchParams(search).get(
97+
'isFromSettingsSecurity',
98+
);
9499
const trackEvent = useContext(MetaMetricsContext);
95100
const isUnlocked = useSelector(getIsUnlocked);
96101
const showTermsOfUse = useSelector(getShowTermsOfUse);
102+
const isPrimarySeedPhraseBackedUp = useSelector(
103+
getIsPrimarySeedPhraseBackedUp,
104+
);
97105

98106
const envType = getEnvironmentType();
99107
const isPopup = envType === ENVIRONMENT_TYPE_POPUP;
@@ -115,17 +123,26 @@ export default function OnboardingFlow() {
115123
}, [history, completedOnboarding, isFromReminder]);
116124

117125
useEffect(() => {
118-
if (isUnlocked && !completedOnboarding && !secretRecoveryPhrase) {
119-
const needsSRP = [
120-
ONBOARDING_SECURE_YOUR_WALLET_ROUTE,
121-
ONBOARDING_REVIEW_SRP_ROUTE,
122-
ONBOARDING_CONFIRM_SRP_ROUTE,
123-
].some((route) => pathname.startsWith(route));
126+
const isSRPBackupRoute = [
127+
ONBOARDING_SECURE_YOUR_WALLET_ROUTE,
128+
ONBOARDING_REVIEW_SRP_ROUTE,
129+
ONBOARDING_CONFIRM_SRP_ROUTE,
130+
].some((route) => pathname?.startsWith(route));
124131

125-
if (needsSRP) {
132+
if (isUnlocked && !completedOnboarding && !secretRecoveryPhrase) {
133+
if (isSRPBackupRoute) {
126134
history.push(ONBOARDING_UNLOCK_ROUTE);
127135
}
128136
}
137+
138+
if (
139+
isPrimarySeedPhraseBackedUp &&
140+
isSRPBackupRoute &&
141+
completedOnboarding
142+
) {
143+
history.replace(isFromSettingsSecurity ? SECURITY_ROUTE : DEFAULT_ROUTE);
144+
}
145+
129146
if (pathname === ONBOARDING_WELCOME_ROUTE) {
130147
setWelcomePageState(
131148
showTermsOfUse ? WelcomePageState.Banner : WelcomePageState.Login,
@@ -140,6 +157,8 @@ export default function OnboardingFlow() {
140157
pathname,
141158
history,
142159
showTermsOfUse,
160+
isPrimarySeedPhraseBackedUp,
161+
isFromSettingsSecurity,
143162
]);
144163

145164
const handleCreateNewAccount = async (password) => {

ui/pages/onboarding-flow/recovery-phrase/confirm-recovery-phrase.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default function ConfirmRecoveryPhrase({ secretRecoveryPhrase = '' }) {
9595

9696
useEffect(() => {
9797
if (!secretRecoveryPhrase) {
98-
history.push(`${ONBOARDING_REVIEW_SRP_ROUTE}${isFromReminderParam}`);
98+
history.replace(`${ONBOARDING_REVIEW_SRP_ROUTE}${isFromReminderParam}`);
9999
}
100100
}, [history, secretRecoveryPhrase, isFromReminderParam]);
101101

@@ -141,7 +141,7 @@ export default function ConfirmRecoveryPhrase({ secretRecoveryPhrase = '' }) {
141141
? ONBOARDING_COMPLETION_ROUTE
142142
: ONBOARDING_METAMETRICS;
143143

144-
history.push(`${nextRoute}${isFromReminderParam}`);
144+
history.replace(`${nextRoute}${isFromReminderParam}`);
145145
}, [dispatch, hdEntropyIndex, history, trackEvent, isFromReminderParam]);
146146

147147
return (

ui/pages/onboarding-flow/recovery-phrase/confirm-recovery-phrase.test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ jest.mock('../../../store/actions.ts', () => ({
1717
setSeedPhraseBackedUp: jest.fn().mockReturnValue(jest.fn()),
1818
}));
1919

20-
const mockHistoryPush = jest.fn();
20+
const mockHistoryReplace = jest.fn();
21+
2122
jest.mock('react-router-dom', () => ({
2223
...jest.requireActual('react-router-dom'),
2324
useHistory: () => ({
24-
push: mockHistoryPush,
25+
replace: mockHistoryReplace,
2526
}),
2627
}));
2728

@@ -192,7 +193,7 @@ describe('Confirm Recovery Phrase Component', () => {
192193
fireEvent.click(gotItButton);
193194

194195
expect(setSeedPhraseBackedUp).toHaveBeenCalledWith(true);
195-
expect(mockHistoryPush).toHaveBeenCalledWith(ONBOARDING_METAMETRICS);
196+
expect(mockHistoryReplace).toHaveBeenCalledWith(ONBOARDING_METAMETRICS);
196197
});
197198

198199
it('should go to Onboarding Completion page as a next step in firefox', async () => {
@@ -212,6 +213,8 @@ describe('Confirm Recovery Phrase Component', () => {
212213
// click and answer the srp quiz
213214
clickAndAnswerSrpQuiz(quizUnansweredChips);
214215

216+
console.log('quizUnansweredChips', quizUnansweredChips);
217+
215218
const quizAnsweredChips = queryAllByTestId(
216219
/recovery-phrase-quiz-answered-/u,
217220
);
@@ -225,6 +228,8 @@ describe('Confirm Recovery Phrase Component', () => {
225228
fireEvent.click(getByText('Got it'));
226229

227230
expect(setSeedPhraseBackedUp).toHaveBeenCalledWith(true);
228-
expect(mockHistoryPush).toHaveBeenCalledWith(ONBOARDING_COMPLETION_ROUTE);
231+
expect(mockHistoryReplace).toHaveBeenCalledWith(
232+
ONBOARDING_COMPLETION_ROUTE,
233+
);
229234
});
230235
});

ui/pages/onboarding-flow/recovery-phrase/recovery-phrase-chips.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default function RecoveryPhraseChips({
9595
};
9696

9797
setQuizAnswers(newQuizAnswers);
98-
setIndexToFocus(setNextTargetIndex(newQuizAnswers));
98+
setIndexToFocus(newQuizAnswers[targetIndex].index);
9999
},
100100
[quizAnswers],
101101
);

ui/pages/onboarding-flow/welcome/welcome.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default function OnboardingWelcome({
6363
const onCreateClick = useCallback(async () => {
6464
setIsLoggingIn(true);
6565
setNewAccountCreationInProgress(true);
66-
dispatch(setFirstTimeFlowType(FirstTimeFlowType.create));
66+
await dispatch(setFirstTimeFlowType(FirstTimeFlowType.create));
6767
trackEvent({
6868
category: MetaMetricsEventCategory.Onboarding,
6969
event: MetaMetricsEventName.WalletSetupStarted,

0 commit comments

Comments
 (0)