Skip to content
Permalink
Browse files

refactor cache -> cachedStatus

  • Loading branch information...
matiu committed Apr 8, 2019
1 parent 9293f7e commit f463b71ef8844918dc55d5455ff29505ba8cf899
@@ -0,0 +1,2 @@
platforms
test
@@ -115,9 +115,9 @@ export class CopayersPage {
this.walletProvider
.getStatus(this.wallet, {})
.then(status => {
this.wallet.status = status;
this.copayers = this.wallet.status.wallet.copayers;
this.secret = this.wallet.status.wallet.secret;
this.wallet.cachedStatus = status;
this.copayers = this.wallet.cachedStatus.wallet.copayers;
this.secret = this.wallet.cachedStatus.wallet.secret;
if (status.wallet.status == 'complete') {
this.wallet.openWallet(err => {
if (err) this.logger.error(err);
@@ -118,7 +118,7 @@
</span>
<span *ngIf="wallet.isComplete() && !wallet.needsBackup">
<span *ngIf="!wallet.balanceHidden && !wallet.scanning">
{{wallet.status && wallet.status.totalBalanceStr ? (wallet.status.totalBalanceStr) : (
{{wallet.cachedStatus && wallet.cachedStatus.totalBalanceStr ? (wallet.cachedStatus.totalBalanceStr) : (
wallet.cachedBalance ? wallet.cachedBalance
+ (wallet.cachedBalanceUpdatedOn ? ' &middot; ' + ( wallet.cachedBalanceUpdatedOn * 1000 | amTimeAgo)
:
@@ -128,7 +128,7 @@
<span *ngIf="wallet.balanceHidden && !wallet.scanning">[
<span translate>Balance Hidden</span>]</span>
<span class="text-gray" *ngIf="wallet.credentials.m > 1">{{wallet.credentials.m}}-of-{{wallet.credentials.n}}</span>
<ion-icon *ngIf="!wallet.balanceHidden && wallet.status && (wallet.status.totalBalanceSat != wallet.status.spendableAmount)" ios="ios-timer-outline" md="md-timer"></ion-icon>
<ion-icon *ngIf="!wallet.balanceHidden && wallet.cachedStatus && (wallet.cachedStatus.totalBalanceSat != wallet.cachedStatus.spendableAmount)" ios="ios-timer-outline" md="md-timer"></ion-icon>
<div *ngIf="wallet.error" class="wallet-warning">{{wallet.error}}</div>
</span>
</div>
@@ -170,7 +170,7 @@
</span>
<span *ngIf="wallet.isComplete() && !wallet.needsBackup">
<span *ngIf="!wallet.balanceHidden && !wallet.scanning">
{{wallet.status && wallet.status.totalBalanceStr ? (wallet.status.totalBalanceStr) : (
{{wallet.cachedStatus && wallet.cachedStatus.totalBalanceStr ? (wallet.cachedStatus.totalBalanceStr) : (
wallet.cachedBalance ? wallet.cachedBalance
+ (wallet.cachedBalanceUpdatedOn ? ' &middot; ' + ( wallet.cachedBalanceUpdatedOn * 1000 | amTimeAgo)
:
@@ -180,7 +180,7 @@
<span *ngIf="wallet.balanceHidden && !wallet.scanning">[
<span translate>Balance Hidden</span>]</span>
<span class="text-gray" *ngIf="wallet.credentials.m > 1">{{wallet.credentials.m}}-of-{{wallet.credentials.n}}</span>
<ion-icon *ngIf="!wallet.balanceHidden && wallet.status && (wallet.status.totalBalanceSat != wallet.status.spendableAmount)" ios="ios-timer-outline" md="md-timer"></ion-icon>
<ion-icon *ngIf="!wallet.balanceHidden && wallet.cachedStatus && (wallet.cachedStatus.totalBalanceSat != wallet.cachedStatus.spendableAmount)" ios="ios-timer-outline" md="md-timer"></ion-icon>
<div *ngIf="wallet.error" class="wallet-warning">{{wallet.error}}</div>
</span>
</div>
@@ -222,7 +222,7 @@
</span>
<span *ngIf="wallet.isComplete() && !wallet.needsBackup">
<span *ngIf="!wallet.balanceHidden && !wallet.scanning">
{{wallet.status && wallet.status.totalBalanceStr ? (wallet.status.totalBalanceStr) : (
{{wallet.cachedStatus && wallet.cachedStatus.totalBalanceStr ? (wallet.cachedStatus.totalBalanceStr) : (
wallet.cachedBalance ? wallet.cachedBalance
+ (wallet.cachedBalanceUpdatedOn ? ' &middot; ' + ( wallet.cachedBalanceUpdatedOn * 1000 | amTimeAgo)
:
@@ -232,7 +232,7 @@
<span *ngIf="wallet.balanceHidden && !wallet.scanning">[
<span translate>Balance Hidden</span>]</span>
<span *ngIf="wallet.credentials.m > 1">{{wallet.credentials.m}}-of-{{wallet.credentials.n}}</span>
<ion-icon *ngIf="!wallet.balanceHidden && wallet.status && (wallet.status.totalBalanceSat != wallet.status.spendableAmount)" ios="ios-timer-outline" md="md-timer"></ion-icon>
<ion-icon *ngIf="!wallet.balanceHidden && wallet.cachedStatus && (wallet.cachedStatus.totalBalanceSat != wallet.cachedStatus.spendableAmount)" ios="ios-timer-outline" md="md-timer"></ion-icon>
<div *ngIf="wallet.error" class="wallet-warning">{{wallet.error}}</div>
</span>
</div>
@@ -289,4 +289,4 @@
<ion-icon name="tab-scan"></ion-icon>
</button>
</ion-fab>
</ion-content>
</ion-content>
@@ -473,11 +473,11 @@ console.log('[home.ts.130:ionViewDidEnter:]'); // TODO
this.walletProvider
.getStatus(wallet, opts)
.then(status => {
wallet.status = status;
wallet.cachedStatus = status;
wallet.error = null;
this.profileProvider.setLastKnownBalance(
wallet.id,
wallet.status.availableBalanceStr
wallet.cachedStatus.availableBalanceStr
);

// Update txps
@@ -489,7 +489,7 @@ console.log('[home.ts.130:ionViewDidEnter:]'); // TODO
//
} else {
wallet.error = err;
wallet.status = null;
wallet.cachedStatus = null;
this.logger.error(err);
}

@@ -519,7 +519,7 @@ console.log('[home.ts.130:ionViewDidEnter:]'); // TODO
return this.walletProvider
.getStatus(wallet, {})
.then(async status => {
wallet.status = status;
wallet.cachedStatus = status;
wallet.error = null;

if (!foundMessage && !_.isEmpty(status.serverMessages)) {
@@ -536,7 +536,7 @@ console.log('[home.ts.130:ionViewDidEnter:]'); // TODO

this.profileProvider.setLastKnownBalance(
wallet.id,
wallet.status.availableBalanceStr
wallet.cachedStatus.availableBalanceStr
);
return Promise.resolve();
})
@@ -24,7 +24,7 @@ <h4 class="title">
<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"> {{wallet.cachedStatus.totalBalanceStr}} </span>
<span *ngIf="wallet.balanceHidden" translate>[Balance Hidden]</span>
<span class="assertive" *ngIf="error">{{error}}</span>
<div item-end>
@@ -43,4 +43,4 @@ <h2>{{wallet.name}}
{{'Sweep' | translate}}
</button>
</ion-toolbar>
</ion-footer>
</ion-footer>
@@ -13,9 +13,9 @@
</ion-buttons>
</ion-navbar>
<ion-toolbar [navbar-bg]="wallet.color">
<div *ngIf="!wallet.balanceHidden && !wallet.scanning && wallet.status" class="wallet-details-header__balance">
<span>{{wallet.status && wallet.status.totalBalanceStr}}</span>
<ion-icon *ngIf="wallet.status.totalBalanceSat != wallet.status.spendableAmount" ios="ios-timer-outline" md="md-timer"></ion-icon>
<div *ngIf="!wallet.balanceHidden && !wallet.scanning && wallet.cachedStatus" class="wallet-details-header__balance">
<span>{{wallet.cachedStatus && wallet.cachedStatus.totalBalanceStr}}</span>
<ion-icon *ngIf="wallet.cachedStatus.totalBalanceSat != wallet.cachedStatus.spendableAmount" ios="ios-timer-outline" md="md-timer"></ion-icon>
</div>
<div *ngIf="wallet.balanceHidden && !wallet.scanning" class="wallet-details-header__balance-hidden">
<span class="title" translate>[Balance Hidden]</span>
@@ -53,7 +53,7 @@
<span copy-to-clipboard="{{ address }}" hide-toast="true">{{ address }}</span>
</div>

<button *ngIf="!(wallet.status && wallet.status.wallet && wallet.status.wallet.singleAddress)" class="new-address-btn" detail-none text-center (click)="setAddress(true)">
<button *ngIf="!(wallet.cachedStatus && wallet.cachedStatus.wallet && wallet.cachedStatus.wallet.singleAddress)" class="new-address-btn" detail-none text-center (click)="setAddress(true)">
<span ion-text color="primary" translate>
<img [hidden]="loading" class="spin-icon" [ngClass]="{'spin-backwards': playAnimation}" src="assets/img/right.svg" width="16" />
<div *ngIf="loading" [ngClass]="{'spin-fast': loading}" class="spinner"></div>
@@ -70,4 +70,4 @@
</div>
</div>
</div>
</ion-content>
</ion-content>
@@ -8,9 +8,9 @@
<ion-title>{{wallet && wallet.name || ('Amount' | translate)}}</ion-title>
</ion-navbar>
<ion-toolbar *ngIf="wallet && !requestingAmount" [navbar-bg]="wallet.color">
<div *ngIf="!wallet.balanceHidden && !wallet.scanning && wallet.status" class="wallet-details-header__balance">
<span>{{wallet.status && wallet.status.totalBalanceStr}}</span>
<ion-icon *ngIf="wallet.status.totalBalanceSat != wallet.status.spendableAmount" ios="ios-timer-outline" md="md-timer"></ion-icon>
<div *ngIf="!wallet.balanceHidden && !wallet.scanning && wallet.cachedStatus" class="wallet-details-header__balance">
<span>{{wallet.cachedStatus && wallet.cachedStatus.totalBalanceStr}}</span>
<ion-icon *ngIf="wallet.cachedStatus.totalBalanceSat != wallet.cachedStatus.spendableAmount" ios="ios-timer-outline" md="md-timer"></ion-icon>
</div>
<div *ngIf="wallet.balanceHidden && !wallet.scanning" class="wallet-details-header__balance-hidden">
<span class="title" translate>[Balance Hidden]</span>
@@ -56,4 +56,4 @@

</div>

</ion-content>
</ion-content>
@@ -38,7 +38,7 @@ describe('AmountPage', () => {
instance.ionViewDidLoad();
instance.sendMax();
expect(instance.expression).toBe(
instance.wallet.status.availableBalanceSat / 1e8
instance.wallet.cachedStatus.availableBalanceSat / 1e8
);
});

@@ -326,7 +326,7 @@ export class AmountPage extends WalletTabsChild {
return this.finish();
}
const maxAmount = this.txFormatProvider.satToUnit(
this.wallet.status.availableBalanceSat
this.wallet.cachedStatus.availableBalanceSat
);
this.zone.run(() => {
this.expression = this.availableUnits[this.unitIndex].isFiat
@@ -289,7 +289,7 @@ export class ConfirmPage extends WalletTabsChild {
.getStatus(wallet, {})
.then(status => {
walletsUpdated++;
wallet.status = status;
wallet.cachedStatus = status;

if (!status.availableBalanceSat) {
this.logger.debug('No balance available in: ' + wallet.name);
@@ -3,9 +3,9 @@
<ion-title>{{wallet && wallet.name || ('Amount' | translate)}}</ion-title>
</ion-navbar>
<ion-toolbar *ngIf="wallet" [navbar-bg]="wallet.color">
<div *ngIf="!wallet.balanceHidden && !wallet.scanning && wallet.status" class="wallet-details-header__balance">
<span>{{wallet.status && wallet.status.totalBalanceStr}}</span>
<ion-icon *ngIf="wallet.status.totalBalanceSat != wallet.status.spendableAmount" ios="ios-timer-outline" md="md-timer"></ion-icon>
<div *ngIf="!wallet.balanceHidden && !wallet.scanning && wallet.cachedStatus" class="wallet-details-header__balance">
<span>{{wallet.cachedStatus && wallet.cachedStatus.totalBalanceStr}}</span>
<ion-icon *ngIf="wallet.cachedStatus.totalBalanceSat != wallet.cachedStatus.spendableAmount" ios="ios-timer-outline" md="md-timer"></ion-icon>
</div>
<div *ngIf="wallet.balanceHidden && !wallet.scanning" class="wallet-details-header__balance-hidden">
<span class="title" translate>[Balance Hidden]</span>
@@ -86,4 +86,4 @@
<span translate>To get started, you'll need to enter a valid address, contact or wallet.</span>
</div>
</div>
</ion-content>
</ion-content>
@@ -8,9 +8,9 @@
<ion-title>{{wallet && wallet.name || ('Amount' | translate)}}</ion-title>
</ion-navbar>
<ion-toolbar *ngIf="wallet" [navbar-bg]="wallet.color">
<div *ngIf="!wallet.balanceHidden && !wallet.scanning && wallet.status" class="wallet-details-header__balance">
<span>{{wallet.status && wallet.status.totalBalanceStr}}</span>
<ion-icon *ngIf="wallet.status.totalBalanceSat != wallet.status.spendableAmount" ios="ios-timer-outline" md="md-timer"></ion-icon>
<div *ngIf="!wallet.balanceHidden && !wallet.scanning && wallet.cachedStatus" class="wallet-details-header__balance">
<span>{{wallet.cachedStatus && wallet.cachedStatus.totalBalanceStr}}</span>
<ion-icon *ngIf="wallet.cachedStatus.totalBalanceSat != wallet.cachedStatus.spendableAmount" ios="ios-timer-outline" md="md-timer"></ion-icon>
</div>
<div *ngIf="wallet.balanceHidden && !wallet.scanning" class="wallet-details-header__balance-hidden">
<span class="title" translate>[Balance Hidden]</span>
@@ -71,4 +71,4 @@
<span translate>To get started, you'll need to create a bitcoin wallet and get some bitcoin.</span>
</div>
</div>
</ion-content>
</ion-content>
@@ -83,7 +83,7 @@ export class SendPage extends WalletTabsChild {

public shouldShowZeroState() {
return (
this.wallet && this.wallet.status && !this.wallet.status.totalBalanceSat
this.wallet && this.wallet.cachedStatus && !this.wallet.cachedStatus.totalBalanceSat
);
}

@@ -91,7 +91,7 @@ export class TxpDetailsPage {
this.currentSpendUnconfirmed = config.spendUnconfirmed;
this.loading = false;
this.isCordova = this.platformProvider.isCordova;
this.copayers = this.wallet.status.wallet.copayers;
this.copayers = this.wallet.cachedStatus.wallet.copayers;
this.copayerId = this.wallet.credentials.copayerId;
this.isShared = this.wallet.credentials.n > 1;
this.canSign = this.wallet.canSign() || this.wallet.isPrivKeyExternal();

0 comments on commit f463b71

Please sign in to comment.
You can’t perform that action at this time.