Merge pull request #7954 from gabrielbazan7/fix/sweep

[V4] FIX: Sweep paper wallet
This commit is contained in:
Gustavo Maximiliano Cortez 2018-01-30 11:08:13 -03:00 committed by GitHub
commit 304dcfcac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 50 deletions

View File

@ -7,24 +7,30 @@
</ion-header>
<ion-content padding>
<div *ngIf="noMatchingWallet">
<span translate>No wallets available to receive funds</span>
</div>
<div *ngIf="!noMatchingWallet">
<h4 translate>Funds found:</h4>
<div *ngIf="balance">{{balanceSat | satToUnit: wallet.coin}}</div>
<div *ngIf="!balance">...</div>
<h4 class="header" translate>
<span translate>Funds found: </span>
<span *ngIf="balanceSat">{{balanceSat | satToUnit: wallet.coin}}</span>
<span *ngIf="!balanceSat">...</span>
</h4>
<ion-item-divider color="light">{{'Funds will be transferred to' | translate}}</ion-item-divider>
<button ion-item *ngIf="wallet" (click)="showWallets()">
<ion-icon item-start>
<img *ngIf="wallet.network == 'testnet'" src="assets/img/icon-wallet-testnet.svg" class="icon-wallet" />
<img *ngIf="wallet.network != 'testnet'" src="assets/img/icon-wallet.svg" class="icon-wallet" />
<img src="assets/img/icon-wallet.svg" class="icon-wallet" />
</ion-icon>
<h2>{{wallet.name}} <span *ngIf="wallet.credentials.m > 1">{{wallet.credentials.m}}-{{wallet.credentials.n}}</span></h2>
<h2>{{wallet.name}}
<span *ngIf="wallet.credentials.m > 1">{{wallet.credentials.m}}-{{wallet.credentials.n}}</span>
</h2>
<span *ngIf="!wallet.balanceHidden"> {{wallet.status.totalBalanceStr}} </span>
<span *ngIf="wallet.balanceHidden" translate>[Balance Hidden]</span>
<span class="assertive" *ngIf="error">{{error}}</span>
</button>
<button [disabled]="sending || balanceSat <= 0 || noMatchingWallet" ion-button (click)="sweepWallet()" block translate>Sweep</button>
</div>
<div *ngIf="noMatchingWallet">
<span translate>No wallets available to receive funds</span>
</div>
</ion-content>
<ion-footer>
<button ion-button block class="button-footer" (click)="sweepWallet()" [disabled]="sending || balanceSat <= 0 || noMatchingWallet"
translate>Sweep</button>
</ion-footer>

View File

@ -1,32 +1,5 @@
page-paper-wallet {
@mixin wallets-list {
height: 3.5rem;
width: 3.5rem;
content: " ";
position: absolute;
border-radius: 3px;
box-shadow: 0px 6px 12px 0px rgba(0, 0, 0, 0.3);
}
.wallet-livenet::before {
@include wallets-list;
background: color($colors, primary) url('../assets/img/icon-wallet.svg') no-repeat 0px 0px;
}
.wallet-testnet::before {
@include wallets-list;
background: color($colors, primary) url('../assets/img/icon-wallet-testnet.svg') no-repeat 0px 0px;
}
.action-sheet-container {
.action-sheet-button {
display: flex;
justify-content: baseline;
align-items: center;
padding: 2.5rem;
.button-inner {
padding-left: 5rem;
}
}
.header {
padding: 10px;
}
}

View File

@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { NavController, NavParams, Events } from 'ionic-angular';
import { NavController, NavParams, Events, ModalController } from 'ionic-angular';
import { Logger } from '../../providers/logger/logger';
import * as _ from 'lodash';
@ -10,6 +10,7 @@ import { PopupProvider } from '../../providers/popup/popup';
import { WalletProvider } from '../../providers/wallet/wallet';
import { FeeProvider } from '../../providers/fee/fee';
import { ProfileProvider } from '../../providers/profile/profile';
import { SuccessModalPage } from '../success/success';
@Component({
selector: 'page-paper-wallet',
@ -45,7 +46,8 @@ export class PaperWalletPage {
private walletProvider: WalletProvider,
private feeProvider: FeeProvider,
private profileProvider: ProfileProvider,
private events: Events
private events: Events,
private modalCtrl: ModalController
) {
this.bitcore = this.bwcProvider.getBitcore();
}
@ -115,7 +117,10 @@ export class PaperWalletPage {
this.onGoingProcessProvider.set('scanning', false);
this.privateKey = data.privateKey;
this.balanceSat = data.balance;
if (this.balanceSat <= 0) this.popupProvider.ionicAlert('Error', 'Not funds found'); //TODO gettextcatalog
if (this.balanceSat <= 0) {
this.popupProvider.ionicAlert('Error', 'Not funds found'); //TODO gettextcatalog
this.navCtrl.pop();
}
}).catch((err: any) => {
this.onGoingProcessProvider.set('scanning', false);
this.logger.error(err);
@ -155,6 +160,8 @@ export class PaperWalletPage {
this.onGoingProcessProvider.set('sweepingWallet', true);
this._sweepWallet().then((data: any) => {
this.onGoingProcessProvider.set('sweepingWallet', false);
this.logger.debug('Success sweep. Destination address:' + data.destinationAddress + ' - transaction id: ' + data.txid);
this.openSuccessModal();
}).catch((err: any) => {
this.logger.error(err);
this.popupProvider.ionicAlert('Error sweeping wallet:', err || err.toString());//TODO gettextcatalog
@ -173,4 +180,14 @@ export class PaperWalletPage {
this.events.unsubscribe('selectWalletEvent');
});
}
public openSuccessModal(): void {
let successComment = "Check the transaction on your wallet details"; //TODO gettextcatalog
let successText = 'Sweep Completed'; //TODO gettextcatalog
let modal = this.modalCtrl.create(SuccessModalPage, { successText: successText, successComment: successComment }, { showBackdrop: true, enableBackdropDismiss: false });
modal.present();
modal.onDidDismiss(() => {
this.navCtrl.pop();
});
}
}