diff options
Diffstat (limited to 'lib/wallet')
-rw-r--r-- | lib/wallet/chromeBadge.ts | 5 | ||||
-rw-r--r-- | lib/wallet/wallet.ts | 12 |
2 files changed, 9 insertions, 8 deletions
diff --git a/lib/wallet/chromeBadge.ts b/lib/wallet/chromeBadge.ts index 6586f7e6e..df12fba83 100644 --- a/lib/wallet/chromeBadge.ts +++ b/lib/wallet/chromeBadge.ts @@ -86,6 +86,9 @@ export class ChromeBadge implements Badge { constructor(window?: Window) { // Allow injecting another window for testing let bg = window || chrome.extension.getBackgroundPage(); + if (!bg) { + throw Error("no window available"); + } this.canvas = bg.document.createElement("canvas"); // Note: changing the width here means changing the font // size in draw() as well! @@ -221,4 +224,4 @@ export class ChromeBadge implements Badge { stopBusy() { this.isBusy = false; } -}
\ No newline at end of file +} diff --git a/lib/wallet/wallet.ts b/lib/wallet/wallet.ts index 32b85e7b0..ffd57e201 100644 --- a/lib/wallet/wallet.ts +++ b/lib/wallet/wallet.ts @@ -612,8 +612,7 @@ export class Wallet { * First fetch information requred to withdraw from the reserve, * then deplete the reserve, withdrawing coins until it is empty. */ - private processReserve(reserveRecord: any): void { - let retryDelayMs = 100; + private processReserve(reserveRecord: any, retryDelayMs: number = 250): void { const opId = "reserve-" + reserveRecord.reserve_pub; this.startOperation(opId); this.updateExchangeFromUrl(reserveRecord.exchange_base_url) @@ -633,11 +632,10 @@ export class Wallet { return Query(this.db).put("history", depleted).finish(); }) .catch((e) => { - console.error("Failed to deplete reserve"); - console.error(e); - setTimeout(() => this.processReserve(reserveRecord), retryDelayMs); - // exponential backoff truncated at one minute - retryDelayMs = Math.min(retryDelayMs * 2, 1000 * 60); + // random, exponential backoff truncated at 3 minutes + let nextDelay = Math.min(2 * retryDelayMs + retryDelayMs * Math.random(), 3000 * 60); + console.warn(`Failed to deplete reserve, trying again in ${retryDelayMs} ms`); + setTimeout(() => this.processReserve(reserveRecord, nextDelay), retryDelayMs); }); } |