Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

mantle-demo - Yup custom validation for mnemonic #45

Open
TdfGomes opened this issue Nov 28, 2018 · 2 comments
Open

mantle-demo - Yup custom validation for mnemonic #45

TdfGomes opened this issue Nov 28, 2018 · 2 comments

Comments

@TdfGomes
Copy link

I saw in a commit that doing a 12 words validation was commented as a TODO. In AuBit I did like this:

const validationSchema = Yup.object().shape({
    mnemonic: Yup.string()
      .test('mnemonic', function(value) {
        let errorMessage
        if (value)) {
          if (value.split(' ').length !== 12) {
            errorMessage = 'Mnemonic should have 12 words'
          }
        } else {
          errorMessage = 'This field is required'
        }
        return this.createError({ path: this.path, message: errorMessage })
      })
  })

Just an idea! you might want to go from here.

@makevoid
Copy link
Contributor

very nice, I think we should pick up this

@ayrbox
Copy link
Contributor

ayrbox commented Dec 3, 2018

regex can also be used. Please consider following mnemonic validation in e2e testing for generated mnemonic

https://github.com/appliedblockchain/base-app/pull/48/files#diff-5fd0af204b6a3027f0e61a448976fc89R16

const wordCount = mnemonic.match(/(\w+)\s{0,1}/g).length
expect(wordCount).toEqual(12)

@makevoid makevoid changed the title Yup custom validation for mnemonic mantle-example - Yup custom validation for mnemonic Dec 7, 2018
@zube zube bot removed the enhancement label Jan 2, 2019
@makevoid makevoid changed the title mantle-example - Yup custom validation for mnemonic mantle-demo - Yup custom validation for mnemonic Jan 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants