fix: make useRecoveryProgressEffect use a switch for better readability

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

@ -38,7 +38,8 @@ export const useRecoveryProgressEffect = (props: UseRecoveryProgressEffectProps)
}, [displayName, ourPubkey]); }, [displayName, ourPubkey]);
useEffect(() => { useEffect(() => {
if (step === AccountRestoration.Loading) { switch (step) {
case AccountRestoration.Loading:
interval = setInterval(() => { interval = setInterval(() => {
if (progress < totalProgress) { if (progress < totalProgress) {
dispatch(setProgress(progress + 1)); dispatch(setProgress(progress + 1));
@ -50,9 +51,8 @@ export const useRecoveryProgressEffect = (props: UseRecoveryProgressEffectProps)
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName)); dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
} }
}, ONBOARDING_TIMES.RECOVERY_TIMEOUT / totalProgress); }, ONBOARDING_TIMES.RECOVERY_TIMEOUT / totalProgress);
} break;
case AccountRestoration.Finishing:
if (step === AccountRestoration.Finishing) {
interval = setInterval(() => { interval = setInterval(() => {
if (progress < totalProgress) { if (progress < totalProgress) {
dispatch(setProgress(progress + 1)); dispatch(setProgress(progress + 1));
@ -63,9 +63,8 @@ export const useRecoveryProgressEffect = (props: UseRecoveryProgressEffectProps)
dispatch(setAccountRestorationStep(AccountRestoration.Finished)); dispatch(setAccountRestorationStep(AccountRestoration.Finished));
} }
}, ONBOARDING_TIMES.RECOVERY_FINISHING / totalProgress); }, ONBOARDING_TIMES.RECOVERY_FINISHING / totalProgress);
} break;
case AccountRestoration.Finished:
if (step === AccountRestoration.Finished) {
interval = setInterval(() => { interval = setInterval(() => {
clearInterval(interval); clearInterval(interval);
if (!isEmpty(displayName)) { if (!isEmpty(displayName)) {
@ -75,9 +74,8 @@ export const useRecoveryProgressEffect = (props: UseRecoveryProgressEffectProps)
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName)); dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
} }
}, ONBOARDING_TIMES.RECOVERY_FINISHED); }, ONBOARDING_TIMES.RECOVERY_FINISHED);
} break;
case AccountRestoration.Complete:
if (step === AccountRestoration.Complete) {
clearInterval(interval); clearInterval(interval);
if (!isEmpty(ourPubkey) && !isEmpty(displayName)) { if (!isEmpty(ourPubkey) && !isEmpty(displayName)) {
void recoveryComplete(); void recoveryComplete();
@ -85,6 +83,8 @@ export const useRecoveryProgressEffect = (props: UseRecoveryProgressEffectProps)
window.log.debug(`[onboarding] restore account: We don't have a pubkey or display name`); window.log.debug(`[onboarding] restore account: We don't have a pubkey or display name`);
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName)); dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
} }
break;
default:
} }
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