diff --git a/src/views/Home/components/NewUserForm/CreatePin.tsx b/src/views/Home/components/NewUserForm/CreatePin.tsx new file mode 100644 index 0000000..ed97535 --- /dev/null +++ b/src/views/Home/components/NewUserForm/CreatePin.tsx @@ -0,0 +1,14 @@ +import React, { ChangeEvent } from 'react'; +import { Input } from '@chakra-ui/react'; +interface CreatePinProps { + setPin: React.Dispatch>; +} +function CreatePin({ setPin }: CreatePinProps) { + const handlePinChange = (event: ChangeEvent) => { + setPin(event.target.value); + } + return ( + + ); +} +export default CreatePin; \ No newline at end of file diff --git a/src/views/Home/components/NewUserForm/CreateWallet.tsx b/src/views/Home/components/NewUserForm/CreateWallet.tsx index f0ae9b4..13a3a45 100644 --- a/src/views/Home/components/NewUserForm/CreateWallet.tsx +++ b/src/views/Home/components/NewUserForm/CreateWallet.tsx @@ -10,9 +10,9 @@ import { TransactionActionsEnum } from "@multiversx/sdk-dapp/types"; -export default function CreateWallet({formData, email, handleReset, userGid}: {formData: any, email: string, handleReset: any, userGid: string}) { +export default function CreateWallet({pin, email, handleReset, userGid}: {pin: string, email: string, handleReset: any, userGid: string}) { - const [encryptionKey, setEncryptionKey] = useState(createEncryptionKey(formData.pin, userGid)); + const [encryptionKey, setEncryptionKey] = useState(createEncryptionKey(pin, userGid)); const [walletCreationHash, setWalletCreationHash] = useState(""); const [txDetails, setTxDetails] = useState(''); diff --git a/src/views/Home/components/NewUserForm/NewUserForm.tsx b/src/views/Home/components/NewUserForm/NewUserForm.tsx index 3020290..07e1605 100644 --- a/src/views/Home/components/NewUserForm/NewUserForm.tsx +++ b/src/views/Home/components/NewUserForm/NewUserForm.tsx @@ -13,10 +13,16 @@ import { CSSReset, Box, Flex, + Heading } from '@chakra-ui/react'; import { createUser } from "../../services/calls"; import CreateWallet from "./CreateWallet"; import { createEncryptionKey } from "@/utils/functions/cryptography"; +import { useColorModeValue } from "@chakra-ui/color-mode"; +import { Step, Steps, useSteps } from "chakra-ui-steps"; +import CreatePin from "./CreatePin"; +const steps = [{ label: "Step 1" }, { label: "Step 2" }, { label: "Step 3" }]; + interface Step1Props { pinData: { @@ -26,102 +32,164 @@ interface Step1Props { onNext: (data: { pin: string }) => void; } -function Step1({ pinData, onPrevious, onNext }: Step1Props) { - const [pin, setPin] = useState(pinData.pin || ''); +// function Step1({ pinData, onPrevious, onNext }: Step1Props) { +// const [pin, setPin] = useState(pinData.pin || ''); - const handlePrevious = () => { - onPrevious(); - }; +// const handlePrevious = () => { +// onPrevious(); +// }; - const handleNext = () => { - onNext({ pin }); - }; +// const handleNext = () => { +// onNext({ pin }); +// }; - const handlePinChange = (e: React.ChangeEvent) => { - const value = e.target.value; - if (value.length <= 4 && /^\d*$/.test(value)) { - setPin(value); - } - }; +// const handlePinChange = (e: React.ChangeEvent) => { +// const value = e.target.value; +// if (value.length <= 4 && /^\d*$/.test(value)) { +// setPin(value); +// } +// }; - return ( - - Create PIN - - This is the most important part. - - - Your PIN (alongside your email) will be used to encrypt your 24 secret words in the SC. The encryption key will be created from a combination of your email and your PIN using a hashing algorithm. - - - In order to maintain the security of your wallet, PIN will never be saved anywhere. Thus, if you forget your PIN, you lose access to your wallet. This is irreversible since nobody else can recover the PIN for you. - - - Notice that you will need to enter your PIN every time you want to connect in a dApp using xLogin. - - - - - - *only 4 digits - - - - - - - ); -} +// return ( +// +// Create PIN +// +// This is the most important part. +// +// +// Your PIN (alongside your email) will be used to encrypt your 24 secret words in the SC. The encryption key will be created from a combination of your email and your PIN using a hashing algorithm. +// +// +// In order to maintain the security of your wallet, PIN will never be saved anywhere. Thus, if you forget your PIN, you lose access to your wallet. This is irreversible since nobody else can recover the PIN for you. +// +// +// Notice that you will need to enter your PIN every time you want to connect in a dApp using xLogin. +// +// +// +// +// +// *only 4 digits +// +// +// +// +// +// +// ); +// } -interface FormData { - pin?: string; -} +// interface FormData { +// pin?: string; +// } function NewUserForm({ email, userGid }: { email: string; userGid: string; }) { - const [step, setStep] = useState(1); - const [formData, setFormData] = useState({}); - const handleNext = (data: SetStateAction<{}>) => { - setFormData({ ...formData, ...data }); - setStep(step + 1); - }; + const [pin, setPin] = useState(""); - const handlePrevious = () => { - setStep(step - 1); - }; + const { nextStep, prevStep, reset, activeStep } = useSteps({ + initialStep: 0, + }); + + const isLastStep = activeStep === steps.length - 1; + const hasCompletedAllSteps = activeStep === steps.length; + const bg = useColorModeValue("gray.200", "gray.700"); + // const [step, setStep] = useState(1); + // const [formData, setFormData] = useState({}); + + // const handleNext = (data: SetStateAction<{}>) => { + // setFormData({ ...formData, ...data }); + // setStep(step + 1); + // }; + + // const handlePrevious = () => { + // setStep(step - 1); + // }; const handleReset = () => { - setStep(1); - setFormData({}); + setPin(""); + reset(); } return ( - + // {step === 1 && ( + // + // )} + // {step == 2 && + // + // + // + // } + // + - {step === 1 && ( - - )} - {step == 2 && - - - - } - + + + {steps.map(({ label }, index) => ( + + + + {index === 0 ? ( + + ) : index === 1 ? ( + + ) : "Create your account"} + + + + ))} + + {hasCompletedAllSteps && ( + + + Woohoo! All steps completed! 🎉 + + + )} + + {hasCompletedAllSteps ? ( + + ) : ( + <> + + + + )} + + + ); }