Fix: import wallet when comes from scan - Fix routing

This commit is contained in:
Gabriel Masclef 2018-01-09 15:04:34 -03:00
parent 6334f811a6
commit ba853b7c9e
No known key found for this signature in database
GPG Key ID: DD6D7EAADE12280D
5 changed files with 34 additions and 19 deletions

View File

@ -32,7 +32,8 @@
<form [formGroup]="importForm" (ngSubmit)="import()">
<ion-item *ngIf="selectedTab == 'words'">
<ion-label stacked>Type the recovery phrase (usually 12 words)</ion-label>
<ion-textarea formControlName="words"></ion-textarea>
<ion-textarea formControlName="words" [value]="importForm.value.words"></ion-textarea>
<ion-icon class="scanner-icon" name="qr-scanner" item-right (click)="openScanner()"></ion-icon>
</ion-item>
<div *ngIf="selectedTab == 'file'">
@ -49,7 +50,7 @@
<ion-item *ngIf="selectedTab != 'file'">
<ion-label stacked>{{'Coin' | translate}}</ion-label>
<ion-select formControlName="coin" (ionChange)="importForm.value.testnetEnabled = false">
<ion-select formControlName="coin" (ionChange)="testnetEnabled = false">
<ion-option value="btc">BTC</ion-option>
<ion-option value="bch">BCH</ion-option>
</ion-select>
@ -76,7 +77,7 @@
<ion-item>
<ion-label stacked>Testnet</ion-label>
<ion-toggle color="primary" formControlName="testnet" (ionChange)="setDerivationPath()"></ion-toggle>
<ion-toggle color="primary" formControlName="testnet" [(ngModel)]="testnetEnabled" (ionChange)="setDerivationPath()"></ion-toggle>
</ion-item>
</div>

View File

@ -5,4 +5,7 @@ page-import-wallet {
white-space: inherit;
}
}
.scanner-icon {
z-index: 99;
}
}

View File

@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Validators, FormBuilder, FormGroup } from '@angular/forms';
import { Logger } from '@nsalaun/ng-logger';
@ -20,7 +20,7 @@ import { WalletProvider } from '../../../providers/wallet/wallet';
selector: 'page-import-wallet',
templateUrl: 'import-wallet.html'
})
export class ImportWalletPage implements OnInit {
export class ImportWalletPage {
private derivationPathByDefault: string;
private derivationPathForTestnet: string;
@ -36,6 +36,7 @@ export class ImportWalletPage implements OnInit {
public selectedTab: string;
public isCordova: boolean;
public file: File;
public testnetEnabled: boolean;
constructor(
private navCtrl: NavController,
@ -69,17 +70,17 @@ export class ImportWalletPage implements OnInit {
mnemonicPassword: [null],
file: [null],
filePassword: [null],
derivationPath: [this.derivationPathByDefault],
derivationPath: [this.derivationPathByDefault, Validators.required],
testnet: [false],
bwsURL: [this.defaults.bws.url],
coin: [this.navParams.data.coin ? this.navParams.data.coin : 'btc']
});
if (this.navParams.data.code)
this.processWalletInfo(this.navParams.data.code);
}
ngOnInit() {
ionViewWillEnter() {
if (this.navParams.data.code) {
this.processWalletInfo(this.navParams.data.code);
}
}
selectTab(tab: string) {
@ -139,13 +140,14 @@ export class ImportWalletPage implements OnInit {
if (info.type == '1' && info.hasPassphrase)
this.popupProvider.ionicAlert('Error', 'Password required. Make sure to enter your password in advanced options', 'Ok'); //TODO gettextcatalog
this.importForm.value.derivationPath = info.derivationPath;
this.importForm.value.testnetEnabled = info.network == 'testnet' ? true : false;
this.importForm.value.words = info.data;
this.testnetEnabled = info.network == 'testnet' ? true : false;
this.importForm.controls['derivationPath'].setValue(info.derivationPath);
this.importForm.controls['words'].setValue(info.data);
}
public setDerivationPath(): void {
this.importForm.value.derivationPath = this.importForm.value.testnet ? this.derivationPathForTestnet : this.derivationPathByDefault;
let path = this.testnetEnabled ? this.derivationPathForTestnet : this.derivationPathByDefault;
this.importForm.controls['derivationPath'].setValue(path);
}
private importBlob(str: string, opts: any): void {
@ -328,4 +330,14 @@ export class ImportWalletPage implements OnInit {
}
}
public openScanner(): void {
if (this.navParams.data.fromScan) {
this.navCtrl.popToRoot();
} else {
this.navCtrl.setRoot(HomePage);
this.navCtrl.popToRoot();
this.navCtrl.parent.select(2);
}
}
}

View File

@ -275,8 +275,8 @@ export class AmountPage {
let data: any = {
recipientType: this.recipientType,
toAddress: this.toAddress,
amount: amount_,
amountFiat: amountFiat,
amount: this.useSendMax ? 0 : amount_,
amountFiat: this.useSendMax ? 0 : amountFiat,
name: this.name,
email: this.email,
color: this.color,

View File

@ -11,7 +11,6 @@ import { AppProvider } from '../app/app';
import { AddressProvider } from '../address/address';
//pages
import { SendPage } from '../../pages/send/send';
import { ConfirmPage } from '../../pages/send/confirm/confirm';
import { AmountPage } from '../../pages/send/amount/amount';
import { JoinWalletPage } from '../../pages/add/join-wallet/join-wallet';
@ -222,7 +221,7 @@ export class IncomingDataProvider {
type: 'privateKey'
});
} else if (data && ((data.substring(0, 2) == '1|') || (data.substring(0, 2) == '2|') || (data.substring(0, 2) == '3|'))) {
this.navCtrl.push(ImportWalletPage, { code: data })
this.navCtrl.push(ImportWalletPage, { code: data, fromScan: true })
return true;
} else {
@ -273,7 +272,7 @@ export class IncomingDataProvider {
}
private goSend(addr: string, amount: string, message: string, coin: string): void {
this.navCtrl.push(SendPage, {});
this.navCtrl.parent.select(3);
if (amount) {
this.navCtrl.push(ConfirmPage, {
amount: amount,