Skip to content

Commit

Permalink
refactor(setup-wallet): mnemonic input
Browse files Browse the repository at this point in the history
  • Loading branch information
banklesss committed May 3, 2024
1 parent 5cc0716 commit fe36431
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const MnemonicInput = ({
mnenonicRefs,
mnemonic,
onError,
onClearError,
}: {
length: number
isValidPhrase: boolean
Expand All @@ -37,7 +38,8 @@ export const MnemonicInput = ({
onFocus: (index: number) => void
mnenonicRefs: React.RefObject<MnemonicWordInputRef>[]
mnemonic: string
onError: (error: string, index: number) => void
onError: (index: number) => void
onClearError: (index: number) => void
}) => {
const strings = useStrings()
const {styles} = useStyles()
Expand All @@ -56,6 +58,7 @@ export const MnemonicInput = ({
setSuggestedWords={setSuggestedWords}
onFocus={onFocus}
onError={onError}
onClearError={onClearError}
/>

<Space height="l" />
Expand Down Expand Up @@ -109,7 +112,8 @@ type MnemonicWordsInputProps = {
suggestedWords: Array<string>
setSuggestedWords: (suggestedWord: Array<string>) => void
onFocus: (index: number) => void
onError: (error: string, index: number) => void
onError: (index: number) => void
onClearError: (index: number) => void
}
const MnemonicWordsInput = ({
onSelect,
Expand All @@ -120,6 +124,7 @@ const MnemonicWordsInput = ({
setSuggestedWords,
onFocus,
onError,
onClearError,
}: MnemonicWordsInputProps) => {
const {styles} = useStyles()
const scrollView = useScrollView()
Expand Down Expand Up @@ -161,9 +166,8 @@ const MnemonicWordsInput = ({
mnenonicRefs[index - 1]?.current?.focus()
}
}}
onError={(error: string) => {
onError(error, index)
}}
onError={() => onError(index)}
onClearError={() => onClearError(index)}
/>
</View>
))}
Expand All @@ -183,6 +187,7 @@ type MnemonicWordInputProps = {
suggestedWords: Array<string>
setSuggestedWords: (suggestedWord: Array<string>) => void
onError: (error: string) => void
onClearError: () => void
}

const MnemonicWordInput = React.forwardRef<MnemonicWordInputRef, MnemonicWordInputProps>(
Expand All @@ -197,6 +202,7 @@ const MnemonicWordInput = React.forwardRef<MnemonicWordInputRef, MnemonicWordInp
suggestedWords,
setSuggestedWords,
onError,
onClearError,
},
ref,
) => {
Expand Down Expand Up @@ -239,15 +245,15 @@ const MnemonicWordInput = React.forwardRef<MnemonicWordInputRef, MnemonicWordInp
onError('error')
} else {
setError(false)
onError('')
onClearError()
}
} else {
setSuggestedWords([])
setError(false)
onError('')
onClearError()
}
},
[onError, onSubmitEditing, setSuggestedWords],
[onClearError, onError, onSubmitEditing, setSuggestedWords],
)

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ export const RestoreWalletScreen = () => {
setInputErrorsIndexes(newInputErrors)
}

const onError = (error: string, index: number) => {
if (!isEmptyString(error)) addInputErrorIndex(index)
else removeInputErrorIndex(index)
const onError = (index: number) => {
addInputErrorIndex(index)
}

const onClearError = (index: number) => {
removeInputErrorIndex(index)
}

const mnenonicRefs = React.useRef(mnemonicSelectedWords.map(() => React.createRef<MnemonicWordInputRef>())).current
Expand Down Expand Up @@ -201,6 +204,7 @@ export const RestoreWalletScreen = () => {
mnemonic={mnemonic}
mnenonicRefs={mnenonicRefs}
onError={onError}
onClearError={onClearError}
/>
</ScrollView>

Expand Down

0 comments on commit fe36431

Please sign in to comment.