Merge pull request #8077 from cmgustavo/bug/notifications-02

Fix notifications when send/reject/remove a tx/txp
This commit is contained in:
Gabriel Masclef 2018-02-20 12:30:34 -03:00 committed by GitHub
commit 5de66e7032
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 23 deletions

View File

@ -1,4 +1,4 @@
import { Component } from '@angular/core'; import { Component, NgZone } from '@angular/core';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { Events, ModalController, NavController } from 'ionic-angular'; import { Events, ModalController, NavController } from 'ionic-angular';
import { Logger } from '../../providers/logger/logger'; import { Logger } from '../../providers/logger/logger';
@ -71,6 +71,7 @@ export class HomePage {
private isNW: boolean; private isNW: boolean;
private isWindowsPhoneApp: boolean; private isWindowsPhoneApp: boolean;
private updatingWalletId: object; private updatingWalletId: object;
private zone: any;
constructor( constructor(
private navCtrl: NavController, private navCtrl: NavController,
@ -101,14 +102,11 @@ export class HomePage {
this.isWindowsPhoneApp = this.platformProvider.isWP; this.isWindowsPhoneApp = this.platformProvider.isWP;
this.showReorderBtc = false; this.showReorderBtc = false;
this.showReorderBch = false; this.showReorderBch = false;
this.zone = new NgZone({ enableLongStackTrace: false });
} }
ionViewWillEnter() { ionViewWillEnter() {
this.config = this.configProvider.get(); this.config = this.configProvider.get();
this.recentTransactionsEnabled = this.config.recentTransactions.enabled;
if (this.recentTransactionsEnabled) this.getNotifications();
this.pushNotificationsProvider.init(); this.pushNotificationsProvider.init();
this.homeIntegrations = this.homeIntegrationsProvider.get(); this.homeIntegrations = this.homeIntegrationsProvider.get();
this.showIntegration = this.config.showIntegration; this.showIntegration = this.config.showIntegration;
@ -119,11 +117,16 @@ export class HomePage {
return homeIntegrations.show == true; return homeIntegrations.show == true;
}); });
// Update Tx Notifications
this.recentTransactionsEnabled = this.config.recentTransactions.enabled;
if (this.recentTransactionsEnabled) this.getNotifications();
// BWS Events: Update Status per Wallet // BWS Events: Update Status per Wallet
// NewBlock, NewCopayer, NewAddress, NewTxProposal, TxProposalAcceptedBy, TxProposalRejectedBy, txProposalFinallyRejected, // NewBlock, NewCopayer, NewAddress, NewTxProposal, TxProposalAcceptedBy, TxProposalRejectedBy, txProposalFinallyRejected,
// txProposalFinallyAccepted, TxProposalRemoved, NewIncomingTx, NewOutgoingTx // txProposalFinallyAccepted, TxProposalRemoved, NewIncomingTx, NewOutgoingTx
this.events.subscribe('bwsEvent', (walletId: string) => { this.events.subscribe('bwsEvent', (walletId: string) => {
this.update(walletId); if (this.recentTransactionsEnabled) this.getNotifications();
this.updateWallet(walletId);
}); });
// Create, Join, Import and Delete -> Get Wallets -> Update Status for All Wallets // Create, Join, Import and Delete -> Get Wallets -> Update Status for All Wallets
@ -172,11 +175,6 @@ export class HomePage {
}, 10000); }, 10000);
} }
private update(walletId: string) {
if (this.recentTransactionsEnabled) this.getNotifications();
this.updateWallet(walletId);
}
private setWallets = _.debounce(() => { private setWallets = _.debounce(() => {
this.wallets = this.profileProvider.getWallets(); this.wallets = this.profileProvider.getWallets();
this.walletsBtc = this.profileProvider.getWallets({ coin: 'btc' }); this.walletsBtc = this.profileProvider.getWallets({ coin: 'btc' });
@ -239,8 +237,6 @@ export class HomePage {
wallet.status = status; wallet.status = status;
wallet.error = null; wallet.error = null;
this.profileProvider.setLastKnownBalance(wallet.id, wallet.status.availableBalanceStr); this.profileProvider.setLastKnownBalance(wallet.id, wallet.status.availableBalanceStr);
//this.setWallets();
this.updateTxps(); this.updateTxps();
this.stopUpdatingWalletId(walletId); this.stopUpdatingWalletId(walletId);
}).catch((err: any) => { }).catch((err: any) => {
@ -251,8 +247,10 @@ export class HomePage {
private updateTxps = _.debounce(() => { private updateTxps = _.debounce(() => {
this.profileProvider.getTxps({ limit: 3 }).then((data: any) => { this.profileProvider.getTxps({ limit: 3 }).then((data: any) => {
this.zone.run(() => {
this.txps = data.txps; this.txps = data.txps;
this.txpsN = data.n; this.txpsN = data.n;
});
}).catch((err: any) => { }).catch((err: any) => {
this.logger.error(err); this.logger.error(err);
}); });
@ -262,8 +260,10 @@ export class HomePage {
private getNotifications = _.debounce(() => { private getNotifications = _.debounce(() => {
this.profileProvider.getNotifications({ limit: 3 }).then((data: any) => { this.profileProvider.getNotifications({ limit: 3 }).then((data: any) => {
this.zone.run(() => {
this.notifications = data.notifications; this.notifications = data.notifications;
this.notificationsN = data.total; this.notificationsN = data.total;
});
}).catch((err: any) => { }).catch((err: any) => {
this.logger.error(err); this.logger.error(err);
}); });

View File

@ -433,8 +433,7 @@ export class BuyAmazonPage {
let modal = this.modalCtrl.create(SuccessModalPage, { successText: successText, successComment: successComment, cssClass: cssClass }, { showBackdrop: true, enableBackdropDismiss: false }); let modal = this.modalCtrl.create(SuccessModalPage, { successText: successText, successComment: successComment, cssClass: cssClass }, { showBackdrop: true, enableBackdropDismiss: false });
modal.present(); modal.present();
modal.onDidDismiss(() => { modal.onDidDismiss(() => {
this.navCtrl.remove(2, 2); this.navCtrl.popToRoot({ animate: false });
this.navCtrl.pop();
this.navCtrl.push(AmazonPage, { invoiceId: this.invoiceId }); this.navCtrl.push(AmazonPage, { invoiceId: this.invoiceId });
}); });
} }

View File

@ -418,8 +418,7 @@ export class BuyMercadoLibrePage {
let modal = this.modalCtrl.create(SuccessModalPage, { successText: successText, successComment: successComment, cssClass: cssClass }, { showBackdrop: true, enableBackdropDismiss: false }); let modal = this.modalCtrl.create(SuccessModalPage, { successText: successText, successComment: successComment, cssClass: cssClass }, { showBackdrop: true, enableBackdropDismiss: false });
modal.present(); modal.present();
modal.onDidDismiss(() => { modal.onDidDismiss(() => {
this.navCtrl.remove(2, 2); this.navCtrl.popToRoot({ animate: false });
this.navCtrl.pop();
this.navCtrl.push(MercadoLibrePage, { invoiceId: this.invoiceId }); this.navCtrl.push(MercadoLibrePage, { invoiceId: this.invoiceId });
}); });
} }