diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-02-11 11:29:57 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-02-11 11:30:41 +0100 |
commit | 164d5f20c3dbb60c8898fb4aa7d729ec8d9b7537 (patch) | |
tree | 20f6461bb48a89a455fff82ac3cc4f2cde020ac1 /extension/lib/wallet/wallet.ts | |
parent | 47f2084706aaa79c2f2bc4851f487b7badf9d60a (diff) |
refactoring; make wallet follow new bank protocol
Diffstat (limited to 'extension/lib/wallet/wallet.ts')
-rw-r--r-- | extension/lib/wallet/wallet.ts | 63 |
1 files changed, 3 insertions, 60 deletions
diff --git a/extension/lib/wallet/wallet.ts b/extension/lib/wallet/wallet.ts index 0a9fbe191..f94e9c87e 100644 --- a/extension/lib/wallet/wallet.ts +++ b/extension/lib/wallet/wallet.ts @@ -22,9 +22,11 @@ */ import * as native from "./emscriptif"; +import {AmountJson, CreateReserveResponse} from "./types"; import {HttpResponse, RequestException} from "./http"; import {Query} from "./query"; import {Checkable} from "./checkable"; +import {canonicalizeBaseUrl} from "./helpers"; "use strict"; @@ -74,21 +76,6 @@ export interface Coin { @Checkable.Class -export class AmountJson { - @Checkable.Number - value: number; - - @Checkable.Number - fraction: number; - - @Checkable.String - currency: string; - - static checked: (obj: any) => AmountJson; -} - - -@Checkable.Class export class CreateReserveRequest { /** * The initial amount for the reserve. @@ -107,22 +94,6 @@ export class CreateReserveRequest { @Checkable.Class -export class CreateReserveResponse { - /** - * Mint URL where the bank should create the reserve. - * The URL is canonicalized in the response. - */ - @Checkable.String - mint: string; - - @Checkable.String - reservePub: string; - - static checked: (obj: any) => CreateReserveResponse; -} - - -@Checkable.Class export class ConfirmReserveRequest { /** * Public key of then reserve that should be marked @@ -270,34 +241,6 @@ function isWithdrawableDenom(d: Denomination) { } -/** - * See http://api.taler.net/wallet.html#general - */ -function canonicalizeBaseUrl(url) { - let x = new URI(url); - if (!x.protocol()) { - x.protocol("https"); - } - x.path(x.path() + "/").normalizePath(); - x.fragment(); - x.query(); - return x.href() -} - - -function parsePrettyAmount(pretty: string): AmountJson { - const res = /([0-9]+)(.[0-9]+)?\s*(\w+)/.exec(pretty); - if (!res) { - return null; - } - return { - value: parseInt(res[1], 10), - fraction: res[2] ? (parseFloat(`0.${res[2]}`) * 1e-6) : 0, - currency: res[3] - } -} - - interface HttpRequestLibrary { req(method: string, url: string|uri.URI, @@ -619,7 +562,7 @@ export class Wallet { reservePub: reserveRecord.reserve_pub, } }; - + return Query(this.db) .put("reserves", reserveRecord) .put("history", historyEntry) |