Skip to content

Commit

Permalink
Merge remote-tracking branch 'benma/bb02abort'
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Oct 24, 2022
2 parents ff6fada + c2a7e1d commit bd70f6c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions frontends/web/src/api/bitbox02.ts
Expand Up @@ -17,6 +17,9 @@
import { apiGet, apiPost } from '../utils/request';
import { SuccessResponse, FailResponse } from './response';

// BitBox02 error codes.
export const errUserAbort = 104;

export type DeviceInfo = {
initialized: boolean;
mnemonicPassphraseEnabled: boolean;
Expand Down
27 changes: 19 additions & 8 deletions frontends/web/src/routes/device/bitbox02/bitbox02.tsx
Expand Up @@ -17,7 +17,7 @@

import React, { Component, FormEvent } from 'react';
import { Backup } from '../components/backup';
import { checkSDCard, getVersion, setDeviceName, VersionInfo, verifyAttestation } from '../../../api/bitbox02';
import { checkSDCard, errUserAbort, getVersion, setDeviceName, VersionInfo, verifyAttestation } from '../../../api/bitbox02';
import { multilineMarkup } from '../../../utils/markup';
import { convertDateToLocaleString } from '../../../utils/date';
import { route } from '../../../utils/route';
Expand Down Expand Up @@ -222,6 +222,7 @@ class BitBox02 extends Component<Props, State> {
});
this.setState({
appStatus: 'createWallet',
createWalletStatus: 'intro',
deviceName: '',
});
};
Expand Down Expand Up @@ -269,14 +270,24 @@ class BitBox02 extends Component<Props, State> {
settingPassword: true,
createWalletStatus: 'setPassword',
});
apiPost(this.apiPrefix() + '/set-password').then(({ success }) => {
apiPost(this.apiPrefix() + '/set-password').then(({ code, success }) => {
if (!success) {
this.setState({
errorText: this.props.t('bitbox02Wizard.noPasswordMatch'),
settingPassword: false,
}, () => {
this.setPassword();
});
if (code === errUserAbort) {
// On user abort, just go back to the first screen. This is a bit lazy, as we should show
// a screen to ask the user to go back or try again.
this.setState({
appStatus: '',
errorText: undefined,
settingPassword: false,
});
} else {
this.setState({
errorText: this.props.t('bitbox02Wizard.noPasswordMatch'),
settingPassword: false,
}, () => {
this.setPassword();
});
}
// show noPasswordMatch error and do NOT continue to createBackup
return;
}
Expand Down

0 comments on commit bd70f6c

Please sign in to comment.