From ce7f7b8321c89f9bdd62e9b148181865f8834871 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 24 May 2016 02:05:19 +0200 Subject: show progress --- lib/wallet/wallet.ts | 21 +++++++++++++++++++++ lib/wallet/wxMessaging.ts | 8 ++++++++ 2 files changed, 29 insertions(+) (limited to 'lib') diff --git a/lib/wallet/wallet.ts b/lib/wallet/wallet.ts index d9b529b26..39e3aba90 100644 --- a/lib/wallet/wallet.ts +++ b/lib/wallet/wallet.ts @@ -239,6 +239,8 @@ interface Transaction { export interface Badge { setText(s: string): void; setColor(c: string): void; + startBusy(); + stopBusy(); } @@ -348,6 +350,10 @@ export class Wallet { private notifier: Notifier; public cryptoApi: CryptoApi; + /** + * Set of identifiers for running operations. + */ + private runningOperations: Set = new Set(); constructor(db: IDBDatabase, http: HttpRequestLibrary, @@ -363,6 +369,18 @@ export class Wallet { } + private startOperation(operationId: string) { + this.runningOperations.add(operationId); + this.badge.startBusy(); + } + + private stopOperation(operationId: string) { + this.runningOperations.delete(operationId); + if (this.runningOperations.size == 0) { + this.badge.stopBusy(); + } + } + /** * Resume various pending operations that are pending * by looking at the database. @@ -643,12 +661,15 @@ export class Wallet { */ private processReserve(reserveRecord): void { let retryDelayMs = 100; + const opId = "reserve-" + reserveRecord.reserve_pub; + this.startOperation(opId); this.updateExchangeFromUrl(reserveRecord.exchange_base_url) .then((exchange) => this.updateReserve(reserveRecord.reserve_pub, exchange) .then((reserve) => this.depleteReserve(reserve, exchange))) .then(() => { + this.stopOperation(opId); let depleted = { type: "depleted-reserve", timestamp: (new Date).getTime(), diff --git a/lib/wallet/wxMessaging.ts b/lib/wallet/wxMessaging.ts index 164342f4e..522a87285 100644 --- a/lib/wallet/wxMessaging.ts +++ b/lib/wallet/wxMessaging.ts @@ -153,6 +153,14 @@ class ChromeBadge implements Badge { setColor(c: string) { chrome.browserAction.setBadgeBackgroundColor({color: c}); } + + startBusy() { + this.setText("..."); + } + + stopBusy() { + this.setText(""); + } } -- cgit v1.2.3