Skip to content

Commit

Permalink
Merge pull request #10036 from Gamboster/fix/walletExportAdvancedOpts
Browse files Browse the repository at this point in the history
Fix: show advanced opts in wallet export for all wallets
  • Loading branch information
cmgustavo authored Jul 25, 2019
2 parents 26c7b81 + 3e455ac commit 165d278
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/pages/add/import-wallet/import-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class ImportWalletPage {
.importFile(str2, opts)
.then((wallet: any[]) => {
this.onGoingProcessProvider.clear();
this.finish([].concat(wallet));
if (wallet) this.finish([].concat(wallet));
})
.catch(err => {
this.onGoingProcessProvider.clear();
Expand Down Expand Up @@ -283,7 +283,7 @@ export class ImportWalletPage {
.importWithDerivationPath(opts)
.then(wallet => {
this.onGoingProcessProvider.clear();
this.finish([].concat(wallet));
if (wallet) this.finish([].concat(wallet));
})
.catch(err => {
if (err == 'WALLET_DOES_NOT_EXIST') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ export class WalletGroupSettingsPage {

if (derivationStrategy == 'BIP45') {
this.navCtrl.push(WalletExportPage, {
walletId: this.wallets[0].credentials.walletId,
showNoPrivKeyOpt: true
walletId: this.wallets[0].credentials.walletId
});
} else {
this.navCtrl.push(BackupKeyPage, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,15 @@
The private key of this wallet is not available. The export allows to check the wallet balance, transaction history, and create spend proposals from the export. However, does not allow to approve (sign) proposals, so funds will not be accessible from the export.
</div>
</label-tip>
<label-tip class="no-arrowhead" *ngIf="canSign && !showNoPrivKeyOpt" type="warn">
<span label-tip-title translate>No Private Key</span>
<div label-tip-body translate>
The private key of this wallet will not be included in the generated file. The export allows to check the wallet balance, transaction history, and create spend proposals. However, does not allow to approve (sign) proposals, so funds will not be accessible from the export.
</div>
</label-tip>
<div *ngIf="canSign && showNoPrivKeyOpt">
<div *ngIf="canSign">
<button ion-button class="button-standard button-secondary" (click)="showAdv = !showAdv">
<span *ngIf="!showAdv">{{'Show advanced options' | translate}}</span>
<span *ngIf="showAdv">{{'Hide advanced options' | translate}}</span>
</button>
</div>
<ion-item [ngClass]="{'with-label': exportWalletForm.value.noSignEnabled }" *ngIf="showAdv">
<ion-label stacked>{{'Do not include private key' | translate}}</ion-label>
<ion-checkbox formControlName="noSignEnabled" (ionChange)="noSignEnabledChange()"></ion-checkbox>
<ion-checkbox formControlName="noSignEnabled"></ion-checkbox>
</ion-item>

<label-tip *ngIf="exportWalletForm.value.noSignEnabled" type="warn">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ export class WalletExportPage {
public isCordova: boolean;
public isSafari: boolean;
public isIOS: boolean;
public exportWalletInfo;
public supported: boolean;
public showNoPrivKeyOpt: boolean;

constructor(
private profileProvider: ProfileProvider,
Expand Down Expand Up @@ -69,7 +66,6 @@ export class WalletExportPage {
},
{ validator: this.matchingPasswords('password', 'confirmPassword') }
);
this.showNoPrivKeyOpt = this.navParams.data.showNoPrivKeyOpt;
}

ionViewDidLoad() {
Expand Down Expand Up @@ -114,22 +110,6 @@ export class WalletExportPage {
});
}

public noSignEnabledChange(): void {
if (!this.supported) return;

this.walletProvider
.getEncodedWalletInfo(this.wallet)
.then((code: string) => {
this.supported = true;
this.exportWalletInfo = code;
})
.catch(err => {
this.logger.error(err);
this.supported = false;
this.exportWalletInfo = null;
});
}

public downloadWalletBackup(): void {
this.getPassword()
.then((password: string) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/settings/wallet-settings/wallet-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<button ion-item (click)="openWalletAddresses()">
<span translate>Addresses</span>
</button>
<button ion-item *ngIf="derivationStrategy != 'BIP45'" (click)="openExportWallet()">
<span translate>Export Wallet Metadata</span>
<button ion-item (click)="openExportWallet()">
<span translate>Export Wallet</span>
</button>
<button ion-item (click)="openWalletServiceUrl()">
<span>Wallet Service URL</span>
Expand Down
9 changes: 1 addition & 8 deletions src/pages/settings/wallet-settings/wallet-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Logger } from '../../../providers/logger/logger';
// providers
import { ActionSheetProvider } from '../../../providers/action-sheet/action-sheet';
import { ConfigProvider } from '../../../providers/config/config';
import { DerivationPathHelperProvider } from '../../../providers/derivation-path-helper/derivation-path-helper';
import { ExternalLinkProvider } from '../../../providers/external-link/external-link';
import { KeyProvider } from '../../../providers/key/key';
import { PersistenceProvider } from '../../../providers/persistence/persistence';
Expand Down Expand Up @@ -37,7 +36,6 @@ export class WalletSettingsPage {
public touchIdEnabled: boolean;
public touchIdPrevValue: boolean;
public touchIdAvailable: boolean;
public derivationStrategy: string;
public deleted: boolean = false;
private config;

Expand All @@ -53,7 +51,6 @@ export class WalletSettingsPage {
private translate: TranslateService,
private actionSheetProvider: ActionSheetProvider,
private keyProvider: KeyProvider,
private derivationPathHelperProvider: DerivationPathHelperProvider,
private persistenceProvider: PersistenceProvider,
private events: Events
) {
Expand All @@ -62,9 +59,6 @@ export class WalletSettingsPage {
}

ionViewWillEnter() {
this.derivationStrategy = this.derivationPathHelperProvider.getDerivationStrategy(
this.wallet.credentials.rootPath
);
this.canSign = this.wallet.canSign;
this.needsBackup = this.wallet.needsBackup;
this.hiddenBalance = this.wallet.balanceHidden;
Expand Down Expand Up @@ -195,8 +189,7 @@ export class WalletSettingsPage {
}
public openExportWallet(): void {
this.navCtrl.push(WalletExportPage, {
walletId: this.wallet.credentials.walletId,
showNoPrivKeyOpt: false
walletId: this.wallet.credentials.walletId
});
}
public openWalletServiceUrl(): void {
Expand Down
19 changes: 17 additions & 2 deletions src/providers/backup/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,23 @@ export class BackupProvider {
let b: any = {};

b.credentials = JSON.parse(wallet.toString(opts));
if (wallet.canSign)
b.key = this.keyProvider.getKey(wallet.credentials.keyId);
if (b.credentials.keyId && opts.noSign) {
delete b.credentials.keyId;
}
if (wallet.canSign && !opts.noSign) {
const k = this.keyProvider.getKey(wallet.credentials.keyId);
if (opts.password) {
const k1 = this.keyProvider.get(
wallet.credentials.keyId,
opts.password
);
k.mnemonic = k1.mnemonic;
k.xPrivKey = k1.xPrivKey;
delete k.xPrivKeyEncrypted;
delete k.mnemonicEncrypted;
}
b.key = k;
}
if (opts.addressBook) b.addressBook = opts.addressBook;
b = JSON.stringify(b);

Expand Down
9 changes: 8 additions & 1 deletion src/providers/profile/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class ProfileProvider {
timestamp?: string,
migrating?: boolean
): void {
if (!keyId) return;
this.persistenceProvider.setBackupGroupFlag(keyId, timestamp);
this.logger.debug('Backup flag stored');
if (!migrating) this.walletsGroups[keyId].needsBackup = false;
Expand Down Expand Up @@ -765,6 +766,10 @@ export class ProfileProvider {
this.onGoingProcessProvider.resume();
return this.addAndBindWalletClient(data.walletClient, data.key, {
bwsurl: opts.bwsurl
}).then(walletClient => {
return this.checkIfAlreadyExist([].concat(walletClient)).then(() => {
return Promise.resolve(walletClient);
});
});
});
});
Expand Down Expand Up @@ -1049,7 +1054,9 @@ export class ProfileProvider {
bwsurl: opts.bwsurl
})
.then(walletClient => {
return resolve(walletClient);
this.checkIfAlreadyExist([].concat(walletClient)).then(() => {
return resolve(walletClient);
});
})
.catch(err => {
return reject(err);
Expand Down

0 comments on commit 165d278

Please sign in to comment.