How to use the @ledgerhq/errors.PasswordIncorrectError function in @ledgerhq/errors

To help you get started, weā€™ve selected a few @ledgerhq/errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LedgerHQ / ledger-live-mobile / src / context / AuthPass / AuthScreen.js View on Github external
submit = async () => {
    const id = ++this.submitId;
    const { password } = this.state;
    const { unlock } = this.props;
    if (!password) return;
    try {
      const credentials = await Keychain.getGenericPassword();
      if (id !== this.submitId) return;
      if (credentials && credentials.password === password) {
        unlock();
      } else if (credentials) {
        Vibration.vibrate(VIBRATION_PATTERN_ERROR);
        this.setState({
          passwordError: new PasswordIncorrectError(),
          password: "",
        });
      } else {
        console.log("no credentials stored"); // eslint-disable-line
      }
    } catch (err) {
      if (id !== this.submitId) return;
      console.log("could not load credentials"); // eslint-disable-line
      this.setState({ passwordError: err, password: "" });
    }
  };
github LedgerHQ / ledger-live-desktop / src / components / SettingsPage / DisablePasswordModal.js View on Github external
disablePassword = (e: SyntheticEvent) => {
    if (e) {
      e.preventDefault()
    }

    const { currentPassword } = this.state
    const { onChangePassword } = this.props

    if (!db.isEncryptionKeyCorrect('app', 'accounts', currentPassword)) {
      this.setState({ incorrectPassword: new PasswordIncorrectError() })
      return
    }

    onChangePassword('')
  }
github LedgerHQ / ledger-live-desktop / src / components / IsUnlocked.js View on Github external
const { unlock, fetchAccounts } = this.props
    const { inputValue } = this.state

    const isAccountsDecrypted = await db.hasBeenDecrypted('app', 'accounts')
    try {
      if (!isAccountsDecrypted) {
        await db.setEncryptionKey('app', 'accounts', inputValue.password)
        await fetchAccounts()
      } else if (!db.isEncryptionKeyCorrect('app', 'accounts', inputValue.password)) {
        throw new PasswordIncorrectError()
      }
      unlock()
      this.setState(defaultState)
    } catch (err) {
      this.setState({ incorrectPassword: new PasswordIncorrectError() })
    }
  }
github LedgerHQ / ledger-live-desktop / src / components / SettingsPage / PasswordModal.js View on Github external
handleSave = (e: SyntheticEvent) => {
    const { currentPassword, newPassword } = this.state

    if (e) {
      e.preventDefault()
    }
    if (!this.isValid()) {
      return
    }

    const { hasPassword, onChangePassword } = this.props
    if (hasPassword) {
      if (!db.isEncryptionKeyCorrect('app', 'accounts', currentPassword)) {
        this.setState({ incorrectPassword: new PasswordIncorrectError() })
        return
      }
      onChangePassword(newPassword)
    } else {
      onChangePassword(newPassword)
    }
  }