diff --git a/dapp/src/components/StakingModal/index.tsx b/dapp/src/components/StakingModal/index.tsx index 9e2324f9a..a404f3623 100644 --- a/dapp/src/components/StakingModal/index.tsx +++ b/dapp/src/components/StakingModal/index.tsx @@ -8,9 +8,9 @@ function StakingModalSteps() { const { activeStep, goNext } = useModalFlowContext() switch (activeStep) { - case "overview": + case 1: return - case "stake": + case 2: return default: return null @@ -25,7 +25,7 @@ export default function StakingModal({ onClose: () => void }) { return ( - + ) diff --git a/dapp/src/components/shared/ModalBase/index.tsx b/dapp/src/components/shared/ModalBase/index.tsx index 6ad40c6d9..0931986b5 100644 --- a/dapp/src/components/shared/ModalBase/index.tsx +++ b/dapp/src/components/shared/ModalBase/index.tsx @@ -7,24 +7,23 @@ import { useSidebar } from "../../../hooks" export default function ModalBase({ isOpen, onClose, - steps, - defaultIndex = 0, + numberOfSteps, + defaultStep = 1, children, }: { isOpen: boolean onClose: () => void - steps: string[] + numberOfSteps: number // eslint-disable-next-line react/require-default-props - defaultIndex?: number + defaultStep?: number children: React.ReactNode }) { const { onOpen: openSideBar, onClose: closeSidebar } = useSidebar() - const [activeStep, setActiveStep] = useState(steps[defaultIndex]) - const [index, setIndex] = useState(defaultIndex) + const [activeStep, setActiveStep] = useState(defaultStep) const handleGoNext = useCallback(() => { - setIndex((prevIndex) => prevIndex + 1) + setActiveStep((prevStep) => prevStep + 1) }, []) const handleClose = useCallback(() => { @@ -32,17 +31,14 @@ export default function ModalBase({ }, [onClose]) const resetState = useCallback(() => { - setActiveStep(steps[defaultIndex]) - setIndex(defaultIndex) - }, [defaultIndex, steps]) + setActiveStep(defaultStep) + }, [defaultStep]) useEffect(() => { - if (index >= steps.length) { + if (activeStep > numberOfSteps) { handleClose() - } else { - setActiveStep(steps[index]) } - }, [steps, index, handleClose]) + }, [activeStep, numberOfSteps, handleClose]) useEffect(() => { let timeout: NodeJS.Timeout @@ -58,12 +54,11 @@ export default function ModalBase({ const contextValue: ModalFlowContextValue = useMemo( () => ({ - steps, activeStep, onClose: handleClose, goNext: handleGoNext, }), - [activeStep, steps, handleGoNext, handleClose], + [activeStep, handleGoNext, handleClose], ) return ( diff --git a/dapp/src/contexts/ModalFlowContext.tsx b/dapp/src/contexts/ModalFlowContext.tsx index dac5e8253..287d134e1 100644 --- a/dapp/src/contexts/ModalFlowContext.tsx +++ b/dapp/src/contexts/ModalFlowContext.tsx @@ -5,15 +5,13 @@ export type ModalStep = { } export type ModalFlowContextValue = { - activeStep?: string - steps: string[] + activeStep?: number onClose: () => void goNext: () => void } export const ModalFlowContext = createContext({ activeStep: undefined, - steps: [], goNext: () => {}, onClose: () => {}, })