Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(seed): only highlight seed after success
Browse files Browse the repository at this point in the history
Ensure that the seed confirmation input fields only turn green when the
user inputs the specific word correctly

Fix #938
  • Loading branch information
mrfelton committed Nov 29, 2018
1 parent 5c5d8ce commit 07cdf0c
Showing 1 changed file with 46 additions and 39 deletions.
85 changes: 46 additions & 39 deletions app/components/Onboarding/Steps/SeedConfirm.js
Expand Up @@ -40,6 +40,19 @@ class SeedConfirm extends React.Component {
this.formApi = formApi
}

handleWordChange = (value, fieldIndex, wordIndex) => {
// If the word has been determined as valid, mark the field touched to trigger field highlighting.
const error = this.validateWord(wordIndex, value)
if (!error) {
this.formApi.setTouched(`word${fieldIndex}`, true)
}
// Otherwise reset the field state to prevent highlightning as valid.
else {
this.formApi.setTouched(`word${fieldIndex}`, false)
this.formApi.setError(`word${fieldIndex}`, null)
}
}

validateWord = (index, word) => {
const { seed } = this.props
return !word || word !== seed[index] ? 'incorrect' : null
Expand All @@ -65,48 +78,42 @@ class SeedConfirm extends React.Component {
onSubmit={onSubmit}
onSubmitFailure={onSubmitFailure}
>
{({ formState }) => {
const shouldValidateInline = formState.submits > 0
return (
<>
<Header
title={<FormattedMessage {...messages.retype_seed_title} />}
subtitle={
<FormattedMessage
{...messages.retype_seed_description}
values={{
word1: seedWordIndexes[0],
word2: seedWordIndexes[1],
word3: seedWordIndexes[2]
}}
/>
}
align="left"
/>
<Header
title={<FormattedMessage {...messages.retype_seed_title} />}
subtitle={
<FormattedMessage
{...messages.retype_seed_description}
values={{
word1: seedWordIndexes[0],
word2: seedWordIndexes[1],
word3: seedWordIndexes[2]
}}
/>
}
align="left"
/>

<Bar my={4} />
<Bar my={4} />

{seedWordIndexes.map((wordIndex, index) => {
return (
<Flex key={`word${index}`} justifyContent="flex-start" mb={3}>
<Label htmlFor="alias" width={25} mt={18}>
{wordIndex}
</Label>
<Input
field={`word${index}`}
name={`word${index}`}
validateOnBlur={shouldValidateInline}
validateOnChange={shouldValidateInline}
validate={value => this.validateWord.call(null, wordIndex - 1, value)}
placeholder={intl.formatMessage({ ...messages.word_placeholder })}
required
/>
</Flex>
)
})}
</>
{seedWordIndexes.map((wordIndex, index) => {
// Only validate if the word has been entered connectly already or the form has been siubmitted.
return (
<Flex key={`word${index}`} justifyContent="flex-start" mb={3}>
<Label htmlFor="alias" width={25} mt={18}>
{wordIndex}
</Label>
<Input
field={`word${index}`}
name={`word${index}`}
validateOnBlur
validateOnChange
validate={value => this.validateWord.call(null, wordIndex - 1, value)}
onChange={e => this.handleWordChange(e.target.value, index, wordIndex - 1)}
placeholder={intl.formatMessage({ ...messages.word_placeholder })}
/>
</Flex>
)
}}
})}
</Form>
)
}
Expand Down

0 comments on commit 07cdf0c

Please sign in to comment.