fix: make useRecoveryProgressEffect use a switch for better readability

pull/3056/head
William Grant 2 years ago
parent 6d7ebb7a86
commit 86baed64ba

@ -38,53 +38,53 @@ export const useRecoveryProgressEffect = (props: UseRecoveryProgressEffectProps)
}, [displayName, ourPubkey]); }, [displayName, ourPubkey]);
useEffect(() => { useEffect(() => {
if (step === AccountRestoration.Loading) { switch (step) {
interval = setInterval(() => { case AccountRestoration.Loading:
if (progress < totalProgress) { interval = setInterval(() => {
dispatch(setProgress(progress + 1)); if (progress < totalProgress) {
} dispatch(setProgress(progress + 1));
}
if (progress >= totalProgress) {
clearInterval(interval);
// if we didn't get the display name in time, we need to enter it manually
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
}
}, ONBOARDING_TIMES.RECOVERY_TIMEOUT / totalProgress);
}
if (step === AccountRestoration.Finishing) { if (progress >= totalProgress) {
interval = setInterval(() => { clearInterval(interval);
if (progress < totalProgress) { // if we didn't get the display name in time, we need to enter it manually
dispatch(setProgress(progress + 1)); dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
} }
}, ONBOARDING_TIMES.RECOVERY_TIMEOUT / totalProgress);
break;
case AccountRestoration.Finishing:
interval = setInterval(() => {
if (progress < totalProgress) {
dispatch(setProgress(progress + 1));
}
if (progress >= totalProgress) { if (progress >= totalProgress) {
clearInterval(interval);
dispatch(setAccountRestorationStep(AccountRestoration.Finished));
}
}, ONBOARDING_TIMES.RECOVERY_FINISHING / totalProgress);
break;
case AccountRestoration.Finished:
interval = setInterval(() => {
clearInterval(interval); clearInterval(interval);
dispatch(setAccountRestorationStep(AccountRestoration.Finished)); if (!isEmpty(displayName)) {
} dispatch(setAccountRestorationStep(AccountRestoration.Complete));
}, ONBOARDING_TIMES.RECOVERY_FINISHING / totalProgress); } else {
} // if we didn't get the display name in time, we need to enter it manually
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
if (step === AccountRestoration.Finished) { }
interval = setInterval(() => { }, ONBOARDING_TIMES.RECOVERY_FINISHED);
break;
case AccountRestoration.Complete:
clearInterval(interval); clearInterval(interval);
if (!isEmpty(displayName)) { if (!isEmpty(ourPubkey) && !isEmpty(displayName)) {
dispatch(setAccountRestorationStep(AccountRestoration.Complete)); void recoveryComplete();
} else { } else {
// if we didn't get the display name in time, we need to enter it manually window.log.debug(`[onboarding] restore account: We don't have a pubkey or display name`);
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName)); dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
} }
}, ONBOARDING_TIMES.RECOVERY_FINISHED); break;
} default:
if (step === AccountRestoration.Complete) {
clearInterval(interval);
if (!isEmpty(ourPubkey) && !isEmpty(displayName)) {
void recoveryComplete();
} else {
window.log.debug(`[onboarding] restore account: We don't have a pubkey or display name`);
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
}
} }
return () => clearInterval(interval); return () => clearInterval(interval);

@ -169,7 +169,7 @@ export const RestoreAccount = () => {
dispatch(setRecoveryPasswordError(window.i18n('recoveryPasswordErrorMessageGeneric'))); dispatch(setRecoveryPasswordError(window.i18n('recoveryPasswordErrorMessageGeneric')));
} }
window.log.debug( window.log.debug(
`WIP: [onboarding] restore account: there is a problem with the display nam. Error: ${e.message || e}` `WIP: [onboarding] restore account: there is a problem with the display name. Error: ${e.message || e}`
); );
dispatch(setAccountRestorationStep(AccountRestoration.RecoveryPassword)); dispatch(setAccountRestorationStep(AccountRestoration.RecoveryPassword));
} }

Loading…
Cancel
Save