Skip to content
Permalink
Browse files

Merge branch 'feature/ddw-893-implement-wallet-mnemonics-checker' of h…

…ttps://github.com/input-output-hk/daedalus into feature/ddw-893-implement-wallet-mnemonics-checker
  • Loading branch information...
daniloprates committed Sep 12, 2019
2 parents 0b01e03 + ed63254 commit a36f2cb0bcfb113e35130af0266f889848929c6a
@@ -5,7 +5,9 @@ import Action from './lib/Action';

export default class WalletBackupActions {
startWalletBackup: Action<any> = new Action();
initiateWalletBackup: Action<{ recoveryPhrase: string[] }> = new Action();
initiateWalletBackup: Action<{
recoveryPhrase: Array<string>,
}> = new Action();
acceptPrivacyNoticeForWalletBackup: Action<any> = new Action();
continueToRecoveryPhraseForWalletBackup: Action<any> = new Action();
addWordToWalletBackupVerification: Action<{
@@ -18,4 +20,7 @@ export default class WalletBackupActions {
restartWalletBackup: Action<any> = new Action();
cancelWalletBackup: Action<any> = new Action();
finishWalletBackup: Action<any> = new Action();
// Recovery phrase confirmation dialog actions
checkRecoveryPhrase: Action<{ recoveryPhrase: Array<string> }> = new Action();
resetRecoveryPhraseCheck: Action<any> = new Action();
}
@@ -1,12 +1,14 @@
// @flow
import { observable, action, computed } from 'mobx';
import Store from './lib/Store';
import Request from './lib/LocalizedRequest';
import WalletBackupDialog from '../components/wallet/WalletBackupDialog';
import { WALLET_BACKUP_STEPS } from '../types/walletBackupTypes';
import type {
RecoveryPhraseWord,
walletBackupStep,
} from '../types/walletBackupTypes';
import type { WalletIdAndBalance } from '../api/wallets/types';

export default class WalletBackupStore extends Store {
@observable inProgress = false;
@@ -22,6 +24,13 @@ export default class WalletBackupStore extends Store {
@observable isTermRecoveryAccepted = false;
@observable countdownRemaining = 0;

// Recovery phrase confirmation dialog observables ---
@observable isRecoveryPhraseMatching = null;
@observable
getWalletIdAndBalanceRequest: Request<WalletIdAndBalance> = new Request(
this.api.ada.getWalletIdAndBalance
);

countdownTimerInterval: ?IntervalID = null;

setup() {
@@ -46,6 +55,9 @@ export default class WalletBackupStore extends Store {
a.cancelWalletBackup.listen(this._cancelWalletBackup);
a.finishWalletBackup.listen(this._finishWalletBackup);
this.actions.app.initAppEnvironment.listen(() => {});
// Recovery phrase confirmation dialog actions
a.checkRecoveryPhrase.listen(this._checkRecoveryPhrase);
a.resetRecoveryPhraseCheck.listen(this._resetRecoveryPhraseCheck);
}

@action _initiateWalletBackup = (params: {
@@ -109,6 +121,27 @@ export default class WalletBackupStore extends Store {
);
};

@action _checkRecoveryPhrase = async (params: {
recoveryPhrase: Array<string>,
}) => {
const activeWallet = this.stores.wallets.active;
if (!activeWallet)
throw new Error(
'Active wallet required before checking recovery phrase.'
);
const {
walletId,
}: WalletIdAndBalance = await this.getWalletIdAndBalanceRequest.execute(
params
).promise;
this.isRecoveryPhraseMatching = walletId === activeWallet.id;
};

@action _resetRecoveryPhraseCheck = () => {
this.getWalletIdAndBalanceRequest.reset();
this.isRecoveryPhraseMatching = null;
};

@computed get isRecoveryPhraseValid(): boolean {
return (
this.recoveryPhraseWords.reduce((words, { word }) => words + word, '') ===

0 comments on commit a36f2cb

Please sign in to comment.
You can’t perform that action at this time.