From bad21725d99690f87784ba49f3446e8c29c97273 Mon Sep 17 00:00:00 2001 From: William Grant Date: Wed, 17 Apr 2024 16:17:30 +1000 Subject: [PATCH] fix: dont pass redux args to restoration hook we can use the selectors inside of it --- ts/components/registration/hooks/index.tsx | 34 ++++++++----------- .../registration/stages/RestoreAccount.tsx | 10 +----- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/ts/components/registration/hooks/index.tsx b/ts/components/registration/hooks/index.tsx index 649794d51..cbee953dd 100644 --- a/ts/components/registration/hooks/index.tsx +++ b/ts/components/registration/hooks/index.tsx @@ -1,4 +1,3 @@ -import { AnyAction } from '@reduxjs/toolkit'; import { isEmpty } from 'lodash'; import { useCallback, useEffect } from 'react'; import { useDispatch } from 'react-redux'; @@ -6,31 +5,26 @@ import { ONBOARDING_TIMES } from '../../../session/constants'; import { AccountRestoration, setAccountRestorationStep, + setProgress, } from '../../../state/onboarding/ducks/registration'; +import { + useDisplayName, + useOnboardAccountRestorationStep, + useOnboardHexGeneratedPubKey, + useProgress, +} from '../../../state/onboarding/selectors/registration'; import { finishRestore } from '../stages/RestoreAccount'; let interval: NodeJS.Timeout; -type UseRecoveryProgressEffectProps = { - step: AccountRestoration; - progress: number; - setProgress: (progress: number) => AnyAction; - ourPubkey: string; - displayName: string; -}; - -/** - * Effect to handle the progress rate of the recovery loading animation - * @param step AccountRestoration the onboarding step we are currently on - * @param progress number the progress % of the loading bar - * @param setProgress (progress: number) => AnyAction redux function to set the progress % of the loading bar - * @param ourPubkey: string the public key of the user - * @param displayName: string the display name of the user - */ -export const useRecoveryProgressEffect = (props: UseRecoveryProgressEffectProps) => { - const { step, progress, setProgress, ourPubkey, displayName } = props; +/** Effect to handle the progress rate of the recovery loading animation */ +export const useRecoveryProgressEffect = () => { const totalProgress = 100; + const step = useOnboardAccountRestorationStep(); + const ourPubkey = useOnboardHexGeneratedPubKey(); + const displayName = useDisplayName(); + const progress = useProgress(); const dispatch = useDispatch(); const recoveryComplete = useCallback(async () => { @@ -88,5 +82,5 @@ export const useRecoveryProgressEffect = (props: UseRecoveryProgressEffectProps) } return () => clearInterval(interval); - }, [dispatch, displayName, ourPubkey, progress, recoveryComplete, setProgress, step]); + }, [dispatch, displayName, ourPubkey, progress, recoveryComplete, step]); }; diff --git a/ts/components/registration/stages/RestoreAccount.tsx b/ts/components/registration/stages/RestoreAccount.tsx index e74b585be..b7afc4365 100644 --- a/ts/components/registration/stages/RestoreAccount.tsx +++ b/ts/components/registration/stages/RestoreAccount.tsx @@ -20,7 +20,6 @@ import { useDisplayName, useDisplayNameError, useOnboardAccountRestorationStep, - useOnboardHexGeneratedPubKey, useProgress, useRecoveryPassword, useRecoveryPasswordError, @@ -120,20 +119,13 @@ export const RestoreAccount = () => { const step = useOnboardAccountRestorationStep(); const recoveryPassword = useRecoveryPassword(); const recoveryPasswordError = useRecoveryPasswordError(); - const ourPubkey = useOnboardHexGeneratedPubKey(); const displayName = useDisplayName(); const displayNameError = useDisplayNameError(); const progress = useProgress(); const dispatch = useDispatch(); - useRecoveryProgressEffect({ - step, - progress, - setProgress, - ourPubkey, - displayName, - }); + useRecoveryProgressEffect(); const recoverAndFetchDisplayName = async () => { if (!(!!recoveryPassword && !recoveryPasswordError)) {