mirror of https://github.com/BTCPrivate/copay.git
Fix getAddress. Ref events from home view
This commit is contained in:
parent
491d49b31d
commit
f85080753f
|
@ -60,10 +60,6 @@ export class CopayersPage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ionViewWillLeave() {
|
|
||||||
this.events.unsubscribe('bwsEvent');
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateWallet(): void {
|
private updateWallet(): void {
|
||||||
this.logger.debug('Updating wallet:' + this.wallet.name)
|
this.logger.debug('Updating wallet:' + this.wallet.name)
|
||||||
this.walletProvider.getStatus(this.wallet, {}).then((status: any) => {
|
this.walletProvider.getStatus(this.wallet, {}).then((status: any) => {
|
||||||
|
|
|
@ -198,7 +198,7 @@ export class CreateWalletPage implements OnInit {
|
||||||
|
|
||||||
this.profileProvider.createWallet(opts).then((wallet: any) => {
|
this.profileProvider.createWallet(opts).then((wallet: any) => {
|
||||||
this.onGoingProcessProvider.set('creatingWallet', false);
|
this.onGoingProcessProvider.set('creatingWallet', false);
|
||||||
this.events.publish('Local/WalletAction', wallet.credentials.walletId);
|
this.events.publish('status:updated');
|
||||||
this.walletProvider.updateRemotePreferences(wallet);
|
this.walletProvider.updateRemotePreferences(wallet);
|
||||||
this.pushNotificationsProvider.updateSubscription(wallet);
|
this.pushNotificationsProvider.updateSubscription(wallet);
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,7 @@ export class ImportWalletPage {
|
||||||
private finish(wallet: any): void {
|
private finish(wallet: any): void {
|
||||||
this.walletProvider.updateRemotePreferences(wallet).then(() => {
|
this.walletProvider.updateRemotePreferences(wallet).then(() => {
|
||||||
this.profileProvider.setBackupFlag(wallet.credentials.walletId);
|
this.profileProvider.setBackupFlag(wallet.credentials.walletId);
|
||||||
this.events.publish('Local/WalletAction', wallet.credentials.walletId);
|
this.events.publish('status:updated');
|
||||||
if (this.fromOnboarding) {
|
if (this.fromOnboarding) {
|
||||||
this.profileProvider.setDisclaimerAccepted().catch((err: any) => {
|
this.profileProvider.setDisclaimerAccepted().catch((err: any) => {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
|
|
|
@ -148,7 +148,7 @@ export class JoinWalletPage {
|
||||||
|
|
||||||
this.profileProvider.joinWallet(opts).then((wallet: any) => {
|
this.profileProvider.joinWallet(opts).then((wallet: any) => {
|
||||||
this.onGoingProcessProvider.set('joiningWallet', false);
|
this.onGoingProcessProvider.set('joiningWallet', false);
|
||||||
this.events.publish('Local/WalletAction', wallet.credentials.walletId);
|
this.events.publish('status:updated');
|
||||||
this.walletProvider.updateRemotePreferences(wallet);
|
this.walletProvider.updateRemotePreferences(wallet);
|
||||||
|
|
||||||
if (!wallet.isComplete()) {
|
if (!wallet.isComplete()) {
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
<div item-start>
|
<div item-start>
|
||||||
<span translate>Payment Proposals</span>
|
<span translate>Payment Proposals</span>
|
||||||
</div>
|
</div>
|
||||||
<ion-badge item-end (click)="openProposalsPage()" *ngIf="txpsN>3">{{txpsN}}</ion-badge>
|
<ion-badge item-end (click)="openProposalsPage()">{{txpsN}}</ion-badge>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
<page-txp *ngFor="let txp of txps" [tx]="txp" [addressbook]="addressbook"></page-txp>
|
<page-txp *ngFor="let txp of txps" [tx]="txp" [addressbook]="addressbook"></page-txp>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
|
|
|
@ -70,6 +70,7 @@ export class HomePage {
|
||||||
|
|
||||||
private isNW: boolean;
|
private isNW: boolean;
|
||||||
private isWindowsPhoneApp: boolean;
|
private isWindowsPhoneApp: boolean;
|
||||||
|
private updatingWalletId: object;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private navCtrl: NavController,
|
private navCtrl: NavController,
|
||||||
|
@ -94,19 +95,17 @@ export class HomePage {
|
||||||
private bitPayCardProvider: BitPayCardProvider,
|
private bitPayCardProvider: BitPayCardProvider,
|
||||||
private translate: TranslateService
|
private translate: TranslateService
|
||||||
) {
|
) {
|
||||||
|
this.updatingWalletId = {};
|
||||||
this.cachedBalanceUpdateOn = '';
|
this.cachedBalanceUpdateOn = '';
|
||||||
this.isNW = this.platformProvider.isNW;
|
this.isNW = this.platformProvider.isNW;
|
||||||
this.isWindowsPhoneApp = this.platformProvider.isWP;
|
this.isWindowsPhoneApp = this.platformProvider.isWP;
|
||||||
this.showReorderBtc = false;
|
this.showReorderBtc = false;
|
||||||
this.showReorderBch = false;
|
this.showReorderBch = false;
|
||||||
this.setWallets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ionViewWillEnter() {
|
ionViewWillEnter() {
|
||||||
this.config = this.configProvider.get();
|
this.config = this.configProvider.get();
|
||||||
|
|
||||||
this.setWallets();
|
|
||||||
|
|
||||||
this.recentTransactionsEnabled = this.config.recentTransactions.enabled;
|
this.recentTransactionsEnabled = this.config.recentTransactions.enabled;
|
||||||
if (this.recentTransactionsEnabled) this.getNotifications();
|
if (this.recentTransactionsEnabled) this.getNotifications();
|
||||||
|
|
||||||
|
@ -120,15 +119,19 @@ export class HomePage {
|
||||||
return homeIntegrations.show == true;
|
return homeIntegrations.show == true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// BWS Events: Update Status per Wallet
|
||||||
|
// NewBlock, NewCopayer, NewAddress, NewTxProposal, TxProposalAcceptedBy, TxProposalRejectedBy, txProposalFinallyRejected,
|
||||||
|
// txProposalFinallyAccepted, TxProposalRemoved, NewIncomingTx, NewOutgoingTx
|
||||||
this.events.subscribe('bwsEvent', (walletId: string) => {
|
this.events.subscribe('bwsEvent', (walletId: string) => {
|
||||||
this.update(walletId);
|
this.update(walletId);
|
||||||
});
|
});
|
||||||
this.events.subscribe('Local/TxAction', (walletId: string) => {
|
|
||||||
this.update(walletId);
|
// Create, Join, Import and Delete -> Get Wallets -> Update Status for All Wallets
|
||||||
});
|
this.events.subscribe('status:updated', () => {
|
||||||
this.events.subscribe('Local/WalletAction', (walletId: string) => {
|
this.setWallets();
|
||||||
this.update(walletId);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Hide stars to rate
|
||||||
this.events.subscribe('feedback:hide', () => {
|
this.events.subscribe('feedback:hide', () => {
|
||||||
this.showRateCard = false;
|
this.showRateCard = false;
|
||||||
});
|
});
|
||||||
|
@ -156,21 +159,32 @@ export class HomePage {
|
||||||
|
|
||||||
ionViewDidLoad() {
|
ionViewDidLoad() {
|
||||||
this.logger.info('ionViewDidLoad HomePage');
|
this.logger.info('ionViewDidLoad HomePage');
|
||||||
this.updateAllWallets();
|
this.setWallets();
|
||||||
}
|
}
|
||||||
|
|
||||||
private update(walletId: string): void {
|
private startUpdatingWalletId(walletId: string) {
|
||||||
this.logger.debug('Got action for wallet ' + walletId);
|
this.updatingWalletId[walletId] = true;
|
||||||
let wallet = this.profileProvider.getWallet(walletId);
|
}
|
||||||
this.updateWallet(wallet);
|
|
||||||
|
private stopUpdatingWalletId(walletId: string) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.updatingWalletId[walletId] = false;
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private update(walletId: string) {
|
||||||
if (this.recentTransactionsEnabled) this.getNotifications();
|
if (this.recentTransactionsEnabled) this.getNotifications();
|
||||||
|
this.updateWallet(walletId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private setWallets(): void {
|
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' });
|
||||||
this.walletsBch = this.profileProvider.getWallets({ coin: 'bch' });
|
this.walletsBch = this.profileProvider.getWallets({ coin: 'bch' });
|
||||||
}
|
this.updateAllWallets();
|
||||||
|
}, 10000, {
|
||||||
|
'leading': true
|
||||||
|
});
|
||||||
|
|
||||||
public checkHomeTip(): void {
|
public checkHomeTip(): void {
|
||||||
this.persistenceProvider.getHomeTipAccepted().then((value: string) => {
|
this.persistenceProvider.getHomeTipAccepted().then((value: string) => {
|
||||||
|
@ -217,24 +231,34 @@ export class HomePage {
|
||||||
this.persistenceProvider.setFeedbackInfo(feedbackInfo);
|
this.persistenceProvider.setFeedbackInfo(feedbackInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateWallet(wallet: any): void {
|
private updateWallet(walletId: string): void {
|
||||||
this.logger.debug('Updating wallet:' + wallet.name)
|
if (this.updatingWalletId[walletId]) return;
|
||||||
|
this.startUpdatingWalletId(walletId);
|
||||||
|
let wallet = this.profileProvider.getWallet(walletId);
|
||||||
this.walletProvider.getStatus(wallet, {}).then((status: any) => {
|
this.walletProvider.getStatus(wallet, {}).then((status: any) => {
|
||||||
wallet.status = status;
|
wallet.status = status;
|
||||||
|
wallet.error = null;
|
||||||
|
this.profileProvider.setLastKnownBalance(wallet.id, wallet.status.availableBalanceStr);
|
||||||
|
|
||||||
|
//this.setWallets();
|
||||||
this.updateTxps();
|
this.updateTxps();
|
||||||
|
this.stopUpdatingWalletId(walletId);
|
||||||
}).catch((err: any) => {
|
}).catch((err: any) => {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
|
this.stopUpdatingWalletId(walletId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateTxps(): void {
|
private updateTxps = _.debounce(() => {
|
||||||
this.profileProvider.getTxps({ limit: 3 }).then((data: any) => {
|
this.profileProvider.getTxps({ limit: 3 }).then((data: any) => {
|
||||||
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);
|
||||||
});
|
});
|
||||||
}
|
}, 5000, {
|
||||||
|
'leading': true
|
||||||
|
});
|
||||||
|
|
||||||
private getNotifications = _.debounce(() => {
|
private getNotifications = _.debounce(() => {
|
||||||
this.profileProvider.getNotifications({ limit: 3 }).then((data: any) => {
|
this.profileProvider.getNotifications({ limit: 3 }).then((data: any) => {
|
||||||
|
@ -243,9 +267,9 @@ export class HomePage {
|
||||||
}).catch((err: any) => {
|
}).catch((err: any) => {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
});
|
});
|
||||||
}, 2000, {
|
}, 5000, {
|
||||||
'leading': true
|
'leading': true
|
||||||
});
|
});
|
||||||
|
|
||||||
private updateAllWallets(): void {
|
private updateAllWallets(): void {
|
||||||
let wallets: Array<any> = [];
|
let wallets: Array<any> = [];
|
||||||
|
|
|
@ -43,10 +43,6 @@ export class ShapeshiftPage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ionViewWillLeave() {
|
|
||||||
this.events.unsubscribe('bwsEvent');
|
|
||||||
}
|
|
||||||
|
|
||||||
public openExternalLink(url: string): void {
|
public openExternalLink(url: string): void {
|
||||||
this.externalLinkProvider.open(url);
|
this.externalLinkProvider.open(url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { NavController, NavParams } from 'ionic-angular';
|
import { NavController, NavParams, Events } from 'ionic-angular';
|
||||||
import { Logger } from '../../../../../providers/logger/logger';
|
import { Logger } from '../../../../../providers/logger/logger';
|
||||||
|
|
||||||
//providers
|
//providers
|
||||||
|
@ -26,6 +26,7 @@ export class WalletDeletePage {
|
||||||
private onGoingProcessProvider: OnGoingProcessProvider,
|
private onGoingProcessProvider: OnGoingProcessProvider,
|
||||||
private pushNotificationsProvider: PushNotificationsProvider,
|
private pushNotificationsProvider: PushNotificationsProvider,
|
||||||
private logger: Logger,
|
private logger: Logger,
|
||||||
|
private events: Events,
|
||||||
private translate: TranslateService
|
private translate: TranslateService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ export class WalletDeletePage {
|
||||||
public deleteWallet(): void {
|
public deleteWallet(): void {
|
||||||
this.onGoingProcessProvider.set('deletingWallet', true);
|
this.onGoingProcessProvider.set('deletingWallet', true);
|
||||||
this.profileProvider.deleteWalletClient(this.wallet).then(() => {
|
this.profileProvider.deleteWalletClient(this.wallet).then(() => {
|
||||||
|
this.events.publish('status:updated');
|
||||||
this.onGoingProcessProvider.set('deletingWallet', false);
|
this.onGoingProcessProvider.set('deletingWallet', false);
|
||||||
this.pushNotificationsProvider.unsubscribe(this.wallet);
|
this.pushNotificationsProvider.unsubscribe(this.wallet);
|
||||||
this.navCtrl.popToRoot({ animate: false });
|
this.navCtrl.popToRoot({ animate: false });
|
||||||
|
@ -59,4 +61,4 @@ export class WalletDeletePage {
|
||||||
this.popupProvider.ionicAlert(this.translate.instant('Error'), err.message || err);
|
this.popupProvider.ionicAlert(this.translate.instant('Error'), err.message || err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,10 +86,6 @@ export class TxDetailsPage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ionViewWillLeave() {
|
|
||||||
this.events.unsubscribe('bwsEvent');
|
|
||||||
}
|
|
||||||
|
|
||||||
public readMore(): void {
|
public readMore(): void {
|
||||||
let url = 'https://github.com/bitpay/copay/wiki/COPAY---FAQ#amount-too-low-to-spend';
|
let url = 'https://github.com/bitpay/copay/wiki/COPAY---FAQ#amount-too-low-to-spend';
|
||||||
let optIn = true;
|
let optIn = true;
|
||||||
|
|
|
@ -91,9 +91,6 @@ export class TxpDetailsPage {
|
||||||
this.tx.canBeRemoved = (Date.now() / 1000 - (this.tx.ts || this.tx.createdOn)) > this.GLIDERA_LOCK_TIME;
|
this.tx.canBeRemoved = (Date.now() / 1000 - (this.tx.ts || this.tx.createdOn)) > this.GLIDERA_LOCK_TIME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.events.subscribe('accepted', () => {
|
|
||||||
this.sign();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.events.subscribe('bwsEvent', (walletId: string, type: string, n: number) => {
|
this.events.subscribe('bwsEvent', (walletId: string, type: string, n: number) => {
|
||||||
_.each([
|
_.each([
|
||||||
|
@ -215,7 +212,6 @@ export class TxpDetailsPage {
|
||||||
public sign(): void {
|
public sign(): void {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.walletProvider.publishAndSign(this.wallet, this.tx).then((txp: any) => {
|
this.walletProvider.publishAndSign(this.wallet, this.tx).then((txp: any) => {
|
||||||
this.events.publish('UpdateTx');
|
|
||||||
this.openSuccessModal();
|
this.openSuccessModal();
|
||||||
}).catch((err: any) => {
|
}).catch((err: any) => {
|
||||||
this.setError(err, ('Could not send payment'));
|
this.setError(err, ('Could not send payment'));
|
||||||
|
@ -248,7 +244,6 @@ export class TxpDetailsPage {
|
||||||
}).catch((err: any) => {
|
}).catch((err: any) => {
|
||||||
this.onGoingProcessProvider.set('removeTx', false);
|
this.onGoingProcessProvider.set('removeTx', false);
|
||||||
if (err && !(err.message && err.message.match(/Unexpected/))) {
|
if (err && !(err.message && err.message.match(/Unexpected/))) {
|
||||||
this.events.publish('UpdateTx');
|
|
||||||
this.setError(err, this.translate.instant('Could not delete payment proposal'));
|
this.setError(err, this.translate.instant('Could not delete payment proposal'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -308,7 +303,6 @@ export class TxpDetailsPage {
|
||||||
};
|
};
|
||||||
|
|
||||||
public close(): void {
|
public close(): void {
|
||||||
this.events.unsubscribe('bwsEvent');
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.viewCtrl.dismiss();
|
this.viewCtrl.dismiss();
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,6 @@ export class WalletDetailsPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
ionViewWillLeave() {
|
ionViewWillLeave() {
|
||||||
this.events.unsubscribe('bwsEvent');
|
|
||||||
this.events.unsubscribe('Local/TxAction');
|
this.events.unsubscribe('Local/TxAction');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,8 +162,7 @@ export class ProfileProvider {
|
||||||
wallet.on('walletCompleted', () => {
|
wallet.on('walletCompleted', () => {
|
||||||
this.logger.debug('Wallet completed');
|
this.logger.debug('Wallet completed');
|
||||||
this.updateCredentials(JSON.parse(wallet.export()))
|
this.updateCredentials(JSON.parse(wallet.export()))
|
||||||
// TODO: never used
|
this.events.publish('status:updated');
|
||||||
//this.events.publish('wallet:completed', walletId);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
wallet.initialize({
|
wallet.initialize({
|
||||||
|
@ -707,7 +706,6 @@ export class ProfileProvider {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
});
|
});
|
||||||
}).catch((err: any) => {
|
}).catch((err: any) => {
|
||||||
this.events.publish('Local/DeviceError', err);
|
|
||||||
return reject(err);
|
return reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -376,8 +376,10 @@ export class WalletProvider {
|
||||||
return setTimeout(() => {
|
return setTimeout(() => {
|
||||||
this.createAddress(wallet);
|
this.createAddress(wallet);
|
||||||
}, 5000);
|
}, 5000);
|
||||||
} else if (err instanceof this.errors.MAIN_ADDRESS_GAP_REACHED || (err.message && err.message == 'MAIN_ADDRESS_GAP_REACHED')) {
|
} else if (
|
||||||
this.logger.warn(err);
|
err instanceof this.errors.MAIN_ADDRESS_GAP_REACHED || (err.message && err.message == 'MAIN_ADDRESS_GAP_REACHED')
|
||||||
|
) {
|
||||||
|
this.logger.warn(this.bwcErrorProvider.msg(err, 'Server Error'));
|
||||||
prefix = null;
|
prefix = null;
|
||||||
wallet.getMainAddresses({
|
wallet.getMainAddresses({
|
||||||
reverse: true,
|
reverse: true,
|
||||||
|
@ -386,10 +388,11 @@ export class WalletProvider {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
return resolve(addr[0].address);
|
return resolve(addr[0].address);
|
||||||
});
|
});
|
||||||
};
|
} else {
|
||||||
this.bwcErrorProvider.cb(err, prefix).then((msg) => {
|
this.bwcErrorProvider.cb(err, prefix).then((msg) => {
|
||||||
return reject(msg);
|
return reject(msg);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
return resolve(addr.address);
|
return resolve(addr.address);
|
||||||
});
|
});
|
||||||
|
@ -534,7 +537,6 @@ export class WalletProvider {
|
||||||
|
|
||||||
});
|
});
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
this.logger.warn(this.bwcErrorProvider.msg(err, 'Server Error')); //TODO
|
|
||||||
if (err instanceof this.errors.CONNECTION_ERROR || (err.message && err.message.match(/5../))) {
|
if (err instanceof this.errors.CONNECTION_ERROR || (err.message && err.message.match(/5../))) {
|
||||||
this.logger.info('Retrying history download in 5 secs...');
|
this.logger.info('Retrying history download in 5 secs...');
|
||||||
return reject(setTimeout(() => {
|
return reject(setTimeout(() => {
|
||||||
|
|
Loading…
Reference in New Issue