diff options
Diffstat (limited to 'extension/background/wallet.ts')
-rw-r--r-- | extension/background/wallet.ts | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/extension/background/wallet.ts b/extension/background/wallet.ts index 6479b961a..87e41e854 100644 --- a/extension/background/wallet.ts +++ b/extension/background/wallet.ts @@ -23,7 +23,6 @@ /// <reference path="../decl/urijs/URIjs.d.ts" /> -/// <reference path="../decl/chrome/chrome.d.ts" /> "use strict"; @Checkable.Class @@ -196,12 +195,22 @@ function canonicalizeBaseUrl(url) { return x.href() } + interface HttpRequestLibrary { + req(method: string, + url: string|uri.URI, + options?: any): Promise<HttpResponse>; + + get(url: string|uri.URI): Promise<HttpResponse>; + postJson(url: string|uri.URI, body): Promise<HttpResponse>; + + postForm(url: string|uri.URI, form): Promise<HttpResponse>; } interface Badge { - + setText(s: string): void; + setColor(c: string): void; } @@ -435,7 +444,7 @@ class Wallet { // TODO: set bank-specified fields. let mintBaseUrl = canonicalizeBaseUrl(req.mint); - return httpPostForm(req.post_url, form) + return this.http.postForm(req.post_url, form) .then((hresp) => { let resp: ConfirmReserveResponse = { status: hresp.status, @@ -537,7 +546,7 @@ class Wallet { wd.reserve_sig = pc.withdrawSig; wd.coin_ev = pc.coinEv; let reqUrl = URI("reserve/withdraw").absoluteTo(r.mint_base_url); - return httpPostJson(reqUrl, wd); + return this.http.postJson(reqUrl, wd); }) .then(resp => { if (resp.status != 200) { @@ -572,8 +581,8 @@ class Wallet { } function doBadge(n) { - chrome.browserAction.setBadgeText({text: "" + n}); - chrome.browserAction.setBadgeBackgroundColor({color: "#0F0"}); + this.badge.setText(n.toString()); + this.badge.setColor("#0F0"); } Query(this.db) @@ -647,7 +656,7 @@ class Wallet { .then((reserve) => { let reqUrl = URI("reserve/status").absoluteTo(mint.baseUrl); reqUrl.query({'reserve_pub': reservePubStr}); - return httpGet(reqUrl).then(resp => { + return this.http.get(reqUrl).then(resp => { if (resp.status != 200) { throw Error(); } @@ -671,7 +680,7 @@ class Wallet { */ updateMintFromUrl(baseUrl) { let reqUrl = URI("keys").absoluteTo(baseUrl); - return httpGet(reqUrl).then((resp) => { + return this.http.get(reqUrl).then((resp) => { if (resp.status != 200) { throw Error("/keys request failed"); } |