From 102432100f86b0b78922bb4b34915942eb810b3f Mon Sep 17 00:00:00 2001 From: RadoslavDimchev Date: Thu, 7 Sep 2023 19:33:12 +0300 Subject: [PATCH] feat: check words after continue --- .../ValidatorOnboarding/ContinueButton.tsx | 11 ++++++++-- .../AutocompleteInput.tsx | 8 +++++--- .../ValidatorOnboarding.tsx | 20 +++++++++++++++---- .../KeyGeneration/slice.ts | 7 ++++++- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/pages/ValidatorOnboarding/ContinueButton.tsx b/src/pages/ValidatorOnboarding/ContinueButton.tsx index a06b4ac3..f870089a 100644 --- a/src/pages/ValidatorOnboarding/ContinueButton.tsx +++ b/src/pages/ValidatorOnboarding/ContinueButton.tsx @@ -1,9 +1,11 @@ import { Stack, XStack } from 'tamagui' import { Button, InformationBox } from '@status-im/components' import { CloseCircleIcon } from '@status-im/icons' -import { useSelector } from 'react-redux' +import { useDispatch, useSelector } from 'react-redux' +import { useEffect } from 'react' import { RootState } from '../../redux/store' +import { setIsRightPhrase } from '../../redux/ValidatorOnboarding/KeyGeneration/slice' type ContinueButton = { continueHandler: () => void @@ -12,9 +14,14 @@ type ContinueButton = { } const ContinueButton = ({ continueHandler, activeStep, isConfirmPhraseStage }: ContinueButton) => { - const { isCopyPastedPhrase, isRightPhrase } = useSelector( + const { isCopyPastedPhrase, isRightPhrase, words } = useSelector( (state: RootState) => state.keyGeneration, ) + const dispatch = useDispatch() + + useEffect(() => { + dispatch(setIsRightPhrase(words.every(word => word !== ''))) + }, [words]) const isDisabled = () => { if (isConfirmPhraseStage && !isRightPhrase) { diff --git a/src/pages/ValidatorOnboarding/KeyGeneration/ConfirmRecoveryPhrase/AutocompleteInput.tsx b/src/pages/ValidatorOnboarding/KeyGeneration/ConfirmRecoveryPhrase/AutocompleteInput.tsx index 39b61f1c..54b199de 100644 --- a/src/pages/ValidatorOnboarding/KeyGeneration/ConfirmRecoveryPhrase/AutocompleteInput.tsx +++ b/src/pages/ValidatorOnboarding/KeyGeneration/ConfirmRecoveryPhrase/AutocompleteInput.tsx @@ -18,6 +18,7 @@ const AutocompleteInput = ({ index }: AutocompleteInputProps) => { const [suggestions, setSuggestions] = useState([]) const [isFocused, setIsFocused] = useState(false) const word = useSelector((state: RootState) => state.keyGeneration.words[index]) + const isValidWord = useSelector((state: RootState) => state.keyGeneration.validWords[index]) const dispatch = useDispatch() useEffect(() => { @@ -71,7 +72,7 @@ const AutocompleteInput = ({ index }: AutocompleteInputProps) => { onChange={handleInputChange} onFocus={handleInputFocus} onBlur={handleInputBlur} - style={inputStyle(index, isFocused)} + style={inputStyle(index, isFocused, isValidWord)} />
@@ -92,16 +93,17 @@ const AutocompleteInput = ({ index }: AutocompleteInputProps) => { export default AutocompleteInput -const inputStyle = (index: number, isFocused: boolean) => { +const inputStyle = (index: number, isFocused: boolean, isValidWord: boolean) => { const style = { outline: 'none', padding: `12px 16px 12px ${index + 1 < 10 ? '35px' : '45px'}`, + border: isValidWord ? 'none' : '2px solid #E53E3E', } if (isFocused) { return { ...style, - border: '2px solid #4360DF', + border: isValidWord ? '2px solid #4360DF' : '2px solid #E53E3E', backgroundColor: '#f1f2f4', } } else { diff --git a/src/pages/ValidatorOnboarding/ValidatorOnboarding.tsx b/src/pages/ValidatorOnboarding/ValidatorOnboarding.tsx index a1d54628..d5ebd34a 100644 --- a/src/pages/ValidatorOnboarding/ValidatorOnboarding.tsx +++ b/src/pages/ValidatorOnboarding/ValidatorOnboarding.tsx @@ -15,18 +15,20 @@ import Advisories from './Advisories/Advisories' import ValidatorSetup from './ValidatorSetup/ValidatorSetup' import ValidatorSetupInstall from './ValidatorSetup/ValidatorInstall' import ContinueButton from './ContinueButton' -import { setIsCopyPastedPhrase } from '../../redux/ValidatorOnboarding/KeyGeneration/slice' +import { + setIsCopyPastedPhrase, + setValidWords, +} from '../../redux/ValidatorOnboarding/KeyGeneration/slice' import { RootState } from '../../redux/store' import './layoutGradient.css' import ActivationValidatorSetup from './ValidatorSetup/ActivationValidatorSetup' +import wordlist from 'web-bip39/wordlists/english' const ValidatorOnboarding = () => { const [activeStep, setActiveStep] = useState(0) const [isConfirmPhraseStage, setIsConfirmPhraseStage] = useState(false) const [subStepValidatorSetup, setSubStepValidatorSetup] = useState(0) - const isCopyPastedPhrase = useSelector( - (state: RootState) => state.keyGeneration.isCopyPastedPhrase, - ) + const { isCopyPastedPhrase, words } = useSelector((state: RootState) => state.keyGeneration) const navigate = useNavigate() const dispatch = useDispatch() @@ -39,6 +41,15 @@ const ValidatorOnboarding = () => { const continueHandler = () => { if (activeStep === 4 && isConfirmPhraseStage === false) { return setIsConfirmPhraseStage(true) + } else if (activeStep === 4 && isConfirmPhraseStage === true) { + const newValidWords = words.map(w => wordlist.includes(w)) + dispatch(setValidWords(newValidWords)) + + if (newValidWords.every(w => w === true)) { + setActiveStep(activeStep + 1) + } else { + return + } } else if (activeStep === 3 && subStepValidatorSetup < 3) { setSubStepValidatorSetup(subStepValidatorSetup + 1) } else if (activeStep < 5) { @@ -49,6 +60,7 @@ const ValidatorOnboarding = () => { } else { navigate('/') } + removeCopyPastePhraseInfoBox() removeConfirmPhraseStage() } diff --git a/src/redux/ValidatorOnboarding/KeyGeneration/slice.ts b/src/redux/ValidatorOnboarding/KeyGeneration/slice.ts index 87be99a3..a4eef6d7 100644 --- a/src/redux/ValidatorOnboarding/KeyGeneration/slice.ts +++ b/src/redux/ValidatorOnboarding/KeyGeneration/slice.ts @@ -4,6 +4,7 @@ type KeyGenerationState = { words: string[] isCopyPastedPhrase: boolean isRightPhrase: boolean + validWords: boolean[] } type wordProps = { @@ -15,6 +16,7 @@ const initialState: KeyGenerationState = { words: Array(24).fill(''), isCopyPastedPhrase: false, isRightPhrase: false, + validWords: Array(24).fill(true), } const keyGenerationSlice = createSlice({ @@ -35,10 +37,13 @@ const keyGenerationSlice = createSlice({ setIsRightPhrase: (state, action: PayloadAction) => { state.isRightPhrase = action.payload }, + setValidWords: (state, action: PayloadAction) => { + state.validWords = action.payload + }, }, }) -export const { setWord, setMnemonic, setIsCopyPastedPhrase, setIsRightPhrase } = +export const { setWord, setMnemonic, setIsCopyPastedPhrase, setIsRightPhrase, setValidWords } = keyGenerationSlice.actions export default keyGenerationSlice.reducer