aboutsummaryrefslogtreecommitdiff
path: root/extension/lib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-02-11 11:29:57 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-02-11 11:30:41 +0100
commit164d5f20c3dbb60c8898fb4aa7d729ec8d9b7537 (patch)
tree20f6461bb48a89a455fff82ac3cc4f2cde020ac1 /extension/lib
parent47f2084706aaa79c2f2bc4851f487b7badf9d60a (diff)
downloadwallet-core-164d5f20c3dbb60c8898fb4aa7d729ec8d9b7537.tar.xz
refactoring; make wallet follow new bank protocol
Diffstat (limited to 'extension/lib')
-rw-r--r--extension/lib/wallet/emscriptif.ts2
-rw-r--r--extension/lib/wallet/helpers.ts (renamed from extension/lib/web-common.ts)39
-rw-r--r--extension/lib/wallet/types.ts56
-rw-r--r--extension/lib/wallet/wallet.ts63
4 files changed, 98 insertions, 62 deletions
diff --git a/extension/lib/wallet/emscriptif.ts b/extension/lib/wallet/emscriptif.ts
index 16c883451..b11d845f0 100644
--- a/extension/lib/wallet/emscriptif.ts
+++ b/extension/lib/wallet/emscriptif.ts
@@ -14,7 +14,7 @@
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
-import {AmountJson} from "./wallet";
+import {AmountJson} from "./types";
import * as EmscWrapper from "../emscripten/emsc";
/**
diff --git a/extension/lib/web-common.ts b/extension/lib/wallet/helpers.ts
index 79ff4b13e..99913e558 100644
--- a/extension/lib/web-common.ts
+++ b/extension/lib/wallet/helpers.ts
@@ -14,7 +14,13 @@
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
-import {AmountJson} from "./wallet/wallet";
+
+/**
+ * Smaller helper functions that do not depend
+ * on the emscripten machinery.
+ */
+
+import {AmountJson} from "./types";
export function substituteFulfillmentUrl(url: string, vars) {
url = url.replace("${H_contract}", vars.H_contract);
@@ -22,7 +28,38 @@ export function substituteFulfillmentUrl(url: string, vars) {
return url;
}
+
export function amountToPretty(amount: AmountJson): string {
let x = amount.value + amount.fraction / 1e6;
return `${x} ${amount.currency}`;
+}
+
+
+/**
+ * Canonicalize a base url, typically for the mint.
+ *
+ * See http://api.taler.net/wallet.html#general
+ */
+export 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()
+}
+
+
+export 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]
+ }
} \ No newline at end of file
diff --git a/extension/lib/wallet/types.ts b/extension/lib/wallet/types.ts
new file mode 100644
index 000000000..197aed938
--- /dev/null
+++ b/extension/lib/wallet/types.ts
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ (C) 2015 GNUnet e.V.
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+ */
+
+/**
+ * Common types that are used by Taler.
+ *
+ * Note most types are defined in wallet.ts, types that
+ * are defined in types.ts are intended to be used by components
+ * that do not depend on the whole wallet implementation (which depends on
+ * emscripten).
+ */
+
+import {Checkable} from "./checkable";
+
+@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 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;
+} \ No newline at end of file
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)