aboutsummaryrefslogtreecommitdiff
path: root/pages
diff options
context:
space:
mode:
Diffstat (limited to 'pages')
-rw-r--r--pages/confirm-contract.html2
-rw-r--r--pages/confirm-contract.tsx12
-rw-r--r--pages/confirm-create-reserve.html2
-rw-r--r--pages/confirm-create-reserve.tsx220
-rw-r--r--pages/show-db.ts33
5 files changed, 133 insertions, 136 deletions
diff --git a/pages/confirm-contract.html b/pages/confirm-contract.html
index ec7eab8c1..c2d75ef5a 100644
--- a/pages/confirm-contract.html
+++ b/pages/confirm-contract.html
@@ -11,8 +11,8 @@
<script src="../lib/vendor/lodash.core.min.js"></script>
<script src="../lib/vendor/system-csp-production.src.js"></script>
<script src="../lib/vendor/jed.js"></script>
- <script src="../i18n/strings.js"></script>
<script src="../lib/i18n.js"></script>
+ <script src="../i18n/strings.js"></script>
<script src="../lib/module-trampoline.js"></script>
<style>
diff --git a/pages/confirm-contract.tsx b/pages/confirm-contract.tsx
index fadbc3233..19b049eb5 100644
--- a/pages/confirm-contract.tsx
+++ b/pages/confirm-contract.tsx
@@ -26,11 +26,11 @@
import MithrilComponent = _mithril.MithrilComponent;
import {substituteFulfillmentUrl} from "../lib/wallet/helpers";
import m from "mithril";
-import {Contract} from "../lib/wallet/types";
+import {Contract, AmountJson} from "../lib/wallet/types";
"use strict";
-function prettyAmount(amount) {
+function prettyAmount(amount: AmountJson) {
let v = amount.value + amount.fraction / 1e6;
return `${v.toFixed(2)} ${amount.currency}`;
}
@@ -40,7 +40,7 @@ const Details = {
controller() {
return {collapsed: m.prop(true)};
},
- view(ctrl, contract: Contract) {
+ view(ctrl: any, contract: Contract) {
if (ctrl.collapsed()) {
return m("div", [
m("button.linky", {
@@ -71,11 +71,11 @@ export function main() {
let offer = JSON.parse(query.offer);
console.dir(offer);
let contract = offer.contract;
- let error = null;
+ let error: string|null = null;
let payDisabled = true;
var Contract = {
- view(ctrl) {
+ view(ctrl: any) {
return [
m("p",
i18n.parts`${m("strong", contract.merchant.name)}
@@ -95,7 +95,7 @@ export function main() {
}
};
- m.mount(document.getElementById("contract"), Contract);
+ m.mount(document.getElementById("contract")!, Contract);
function checkPayment() {
chrome.runtime.sendMessage({type: 'check-pay', detail: {offer}}, (resp) => {
diff --git a/pages/confirm-create-reserve.html b/pages/confirm-create-reserve.html
index 1612340e8..995a85aec 100644
--- a/pages/confirm-create-reserve.html
+++ b/pages/confirm-create-reserve.html
@@ -8,8 +8,8 @@
<script src="../lib/vendor/mithril.js"></script>
<script src="../lib/vendor/system-csp-production.src.js"></script>
<script src="../lib/vendor/jed.js"></script>
- <script src="../i18n/strings.js"></script>
<script src="../lib/i18n.js"></script>
+ <script src="../i18n/strings.js"></script>
<script src="../lib/module-trampoline.js"></script>
<style>
diff --git a/pages/confirm-create-reserve.tsx b/pages/confirm-create-reserve.tsx
index dafd3ef33..0a509118d 100644
--- a/pages/confirm-create-reserve.tsx
+++ b/pages/confirm-create-reserve.tsx
@@ -27,7 +27,6 @@
import {amountToPretty, canonicalizeBaseUrl} from "../lib/wallet/helpers";
import {AmountJson, CreateReserveResponse} from "../lib/wallet/types";
import m from "mithril";
-import {IExchangeInfo} from "../lib/wallet/types";
import {ReserveCreationInfo, Amounts} from "../lib/wallet/types";
import MithrilComponent = _mithril.MithrilComponent;
import {Denomination} from "../lib/wallet/types";
@@ -41,10 +40,10 @@ import {getReserveCreationInfo} from "../lib/wallet/wxApi";
*/
class DelayTimer {
ms: number;
- f;
- timerId: number = null;
+ f: () => void;
+ timerId: number|undefined = undefined;
- constructor(ms: number, f) {
+ constructor(ms: number, f: () => void) {
this.f = f;
this.ms = ms;
}
@@ -58,7 +57,7 @@ class DelayTimer {
}
stop() {
- if (this.timerId !== null) {
+ if (this.timerId != undefined) {
window.clearTimeout(this.timerId);
}
}
@@ -67,11 +66,10 @@ class DelayTimer {
class Controller {
url = m.prop<string>();
- statusString = null;
+ statusString: string | null = null;
isValidExchange = false;
- reserveCreationInfo: ReserveCreationInfo = null;
+ reserveCreationInfo?: ReserveCreationInfo;
private timer: DelayTimer;
- private request: XMLHttpRequest;
amount: AmountJson;
callbackUrl: string;
wtTypes: string[];
@@ -97,7 +95,7 @@ class Controller {
private update() {
this.timer.stop();
const doUpdate = () => {
- this.reserveCreationInfo = null;
+ this.reserveCreationInfo = undefined;
if (!this.url()) {
this.statusString = i18n`Error: URL is empty`;
m.redraw(true);
@@ -126,7 +124,7 @@ class Controller {
.catch((e) => {
console.log("get exchange info rejected");
if (e.hasOwnProperty("httpStatus")) {
- this.statusString = `Error: request failed with status ${this.request.status}`;
+ this.statusString = `Error: request failed with status ${e.httpStatus}`;
} else if (e.hasOwnProperty("errorResponse")) {
let resp = e.errorResponse;
this.statusString = `Error: ${resp.error} (${resp.hint})`;
@@ -143,11 +141,7 @@ class Controller {
reset() {
this.isValidExchange = false;
this.statusString = null;
- this.reserveCreationInfo = null;
- if (this.request) {
- this.request.abort();
- this.request = null;
- }
+ this.reserveCreationInfo = undefined;
}
confirmReserve(rci: ReserveCreationInfo,
@@ -155,7 +149,7 @@ class Controller {
amount: AmountJson,
callback_url: string) {
const d = {exchange, amount};
- const cb = (rawResp) => {
+ const cb = (rawResp: any) => {
if (!rawResp) {
throw Error("empty response");
}
@@ -195,127 +189,122 @@ class Controller {
}
function view(ctrl: Controller): any {
- let controls = [];
- let mx = (x, ...args) => controls.push(m(x, ...args));
-
- mx("p",
- i18n.parts`You are about to withdraw ${m("strong", amountToPretty(
- ctrl.amount))} from your bank account into your wallet.`);
+ function* f(): IterableIterator<any> {
+ yield m("p",
+ i18n.parts`You are about to withdraw ${m("strong", amountToPretty(
+ ctrl.amount))} from your bank account into your wallet.`);
+
+ if (ctrl.complexViewRequested || !ctrl.suggestedExchangeUrl) {
+ yield viewComplex(ctrl);
+ return;
+ }
+ yield viewSimple(ctrl);
+ }
+ return Array.from(f());
+}
- if (ctrl.complexViewRequested || !ctrl.suggestedExchangeUrl) {
- return controls.concat(viewComplex(ctrl));
+function viewSimple(ctrl: Controller) {
+ function *f() {
+ if (ctrl.statusString) {
+ yield m("p", "Error: ", ctrl.statusString);
+ yield m("button.linky", {
+ onclick: () => {
+ ctrl.complexViewRequested = true;
+ }
+ }, "advanced options");
+ }
+ else if (ctrl.reserveCreationInfo != undefined) {
+ yield m("button.accept", {
+ onclick: () => ctrl.confirmReserve(ctrl.reserveCreationInfo!,
+ ctrl.url(),
+ ctrl.amount,
+ ctrl.callbackUrl),
+ disabled: !ctrl.isValidExchange
+ },
+ "Accept fees and withdraw");
+ yield m("span.spacer");
+ yield m("button.linky", {
+ onclick: () => {
+ ctrl.complexViewRequested = true;
+ }
+ }, "advanced options");
+ let totalCost = Amounts.add(ctrl.reserveCreationInfo.overhead,
+ ctrl.reserveCreationInfo.withdrawFee).amount;
+ yield m("p", `Withdraw cost: ${amountToPretty(totalCost)}`);
+ } else {
+ yield m("p", "Please wait ...");
+ }
}
- return controls.concat(viewSimple(ctrl));
+ return Array.from(f());
}
-function viewSimple(ctrl: Controller) {
- let controls = [];
- let mx = (x, ...args) => controls.push(m(x, ...args));
- if (ctrl.statusString) {
- mx("p", "Error: ", ctrl.statusString);
- mx("button.linky", {
- onclick: () => {
- ctrl.complexViewRequested = true;
- }
- }, "advanced options");
- }
- else if (ctrl.reserveCreationInfo) {
- mx("button.accept", {
- onclick: () => ctrl.confirmReserve(ctrl.reserveCreationInfo,
+function viewComplex(ctrl: Controller) {
+ function *f() {
+ yield m("button.accept", {
+ onclick: () => ctrl.confirmReserve(ctrl.reserveCreationInfo!,
ctrl.url(),
ctrl.amount,
ctrl.callbackUrl),
disabled: !ctrl.isValidExchange
},
"Accept fees and withdraw");
- mx("span.spacer");
- mx("button.linky", {
+ yield m("span.spacer");
+ yield m("button.linky", {
onclick: () => {
- ctrl.complexViewRequested = true;
+ ctrl.complexViewRequested = false;
}
- }, "advanced options");
- let totalCost = Amounts.add(ctrl.reserveCreationInfo.overhead,
- ctrl.reserveCreationInfo.withdrawFee).amount;
- mx("p", `Withdraw cost: ${amountToPretty(totalCost)}`);
- } else {
- mx("p", "Please wait ...");
- }
-
+ }, "back to simple view");
- return controls;
-}
-
-
-function viewComplex(ctrl: Controller) {
- let controls = [];
- let mx = (x, ...args) => controls.push(m(x, ...args));
-
- mx("button.accept", {
- onclick: () => ctrl.confirmReserve(ctrl.reserveCreationInfo,
- ctrl.url(),
- ctrl.amount,
- ctrl.callbackUrl),
- disabled: !ctrl.isValidExchange
- },
- "Accept fees and withdraw");
- mx("span.spacer");
- mx("button.linky", {
- onclick: () => {
- ctrl.complexViewRequested = false;
- }
- }, "back to simple view");
+ yield m("br");
- mx("br");
+ yield m("input", {
+ className: "url",
+ type: "text",
+ spellcheck: false,
+ value: ctrl.url(),
+ oninput: m.withAttr("value", ctrl.onUrlChanged.bind(ctrl)),
+ });
- mx("input",
- {
- className: "url",
- type: "text",
- spellcheck: false,
- value: ctrl.url(),
- oninput: m.withAttr("value", ctrl.onUrlChanged.bind(ctrl)),
- });
+ yield m("br");
- mx("br");
-
- if (ctrl.statusString) {
- mx("p", ctrl.statusString);
- } else if (!ctrl.reserveCreationInfo) {
- mx("p", "Checking URL, please wait ...");
- }
+ if (ctrl.statusString) {
+ yield m("p", ctrl.statusString);
+ } else if (!ctrl.reserveCreationInfo) {
+ yield m("p", "Checking URL, please wait ...");
+ }
- if (ctrl.reserveCreationInfo) {
- let totalCost = Amounts.add(ctrl.reserveCreationInfo.overhead,
- ctrl.reserveCreationInfo.withdrawFee).amount;
- mx("p", `Withdraw cost: ${amountToPretty(totalCost)}`);
- if (ctrl.detailCollapsed()) {
- mx("button.linky", {
- onclick: () => {
- ctrl.detailCollapsed(false);
- }
- }, "show more details");
- } else {
- mx("button.linky", {
- onclick: () => {
- ctrl.detailCollapsed(true);
- }
- }, "hide details");
- mx("div", {}, renderReserveCreationDetails(ctrl.reserveCreationInfo))
+ if (ctrl.reserveCreationInfo) {
+ let totalCost = Amounts.add(ctrl.reserveCreationInfo.overhead,
+ ctrl.reserveCreationInfo.withdrawFee).amount;
+ yield m("p", `Withdraw cost: ${amountToPretty(totalCost)}`);
+ if (ctrl.detailCollapsed()) {
+ yield m("button.linky", {
+ onclick: () => {
+ ctrl.detailCollapsed(false);
+ }
+ }, "show more details");
+ } else {
+ yield m("button.linky", {
+ onclick: () => {
+ ctrl.detailCollapsed(true);
+ }
+ }, "hide details");
+ yield m("div", {}, renderReserveCreationDetails(ctrl.reserveCreationInfo))
+ }
}
}
-
- return m("div", controls);
+ return Array.from(f());
}
function renderReserveCreationDetails(rci: ReserveCreationInfo) {
let denoms = rci.selectedDenoms;
- let countByPub = {};
- let uniq = [];
+ let countByPub: {[s: string]: number} = {};
+ let uniq: Denomination[] = [];
denoms.forEach((x: Denomination) => {
let c = countByPub[x.denom_pub] || 0;
@@ -358,7 +347,7 @@ function renderReserveCreationDetails(rci: ReserveCreationInfo) {
function getSuggestedExchange(currency: string): Promise<string> {
// TODO: make this request go to the wallet backend
// Right now, this is a stub.
- const defaultExchange = {
+ const defaultExchange: {[s: string]: string} = {
"KUDOS": "https://exchange.demo.taler.net",
"PUDOS": "https://exchange.test.taler.net",
};
@@ -373,6 +362,7 @@ function getSuggestedExchange(currency: string): Promise<string> {
}
+
export function main() {
const url = URI(document.location.href);
const query: any = URI.parseQuery(url.query());
@@ -383,14 +373,14 @@ export function main() {
getSuggestedExchange(amount.currency)
.then((suggestedExchangeUrl) => {
- const controller = () => new Controller(suggestedExchangeUrl, amount, callback_url, wt_types);
- var ExchangeSelection = {controller, view};
- m.mount(document.getElementById("exchange-selection"), ExchangeSelection);
+ const controller = function () { return new Controller(suggestedExchangeUrl, amount, callback_url, wt_types); };
+ const ExchangeSelection = {controller, view};
+ m.mount(document.getElementById("exchange-selection")!, ExchangeSelection);
})
.catch((e) => {
// TODO: provide more context information, maybe factor it out into a
// TODO:generic error reporting function or component.
document.body.innerText = `Fatal error: "${e.message}".`;
- console.error(`got backend error "${e.message}"`);
+ console.error(`got error "${e.message}"`, e);
});
-}
+} \ No newline at end of file
diff --git a/pages/show-db.ts b/pages/show-db.ts
index 9a7b315cf..71e74388b 100644
--- a/pages/show-db.ts
+++ b/pages/show-db.ts
@@ -21,30 +21,37 @@
* @author Florian Dold
*/
-function replacer(match, pIndent, pKey, pVal, pEnd) {
+function replacer(match: string, pIndent: string, pKey: string, pVal: string,
+ pEnd: string) {
var key = '<span class=json-key>';
var val = '<span class=json-value>';
var str = '<span class=json-string>';
var r = pIndent || '';
- if (pKey)
- r = r + key + pKey.replace(/[": ]/g, '') + '</span>: ';
- if (pVal)
- r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>';
+ if (pKey) {
+ r = r + key + pKey.replace(/[": ]/g, '') + '</span>: ';
+ }
+ if (pVal) {
+ r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>';
+ }
return r + (pEnd || '');
}
-function prettyPrint(obj) {
+function prettyPrint(obj: any) {
var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg;
- return JSON.stringify(obj, null, 3)
- .replace(/&/g, '&amp;').replace(/\\"/g, '&quot;')
- .replace(/</g, '&lt;').replace(/>/g, '&gt;')
- .replace(jsonLine, replacer);
+ return JSON.stringify(obj, null as any, 3)
+ .replace(/&/g, '&amp;').replace(/\\"/g, '&quot;')
+ .replace(/</g, '&lt;').replace(/>/g, '&gt;')
+ .replace(jsonLine, replacer);
}
-document.addEventListener("DOMContentLoaded", (e) => {
- chrome.runtime.sendMessage({type:'dump-db'}, (resp) => {
- document.getElementById('dump').innerHTML = prettyPrint(resp);
+document.addEventListener("DOMContentLoaded", () => {
+ chrome.runtime.sendMessage({type: 'dump-db'}, (resp) => {
+ const el = document.getElementById('dump');
+ if (!el) {
+ throw Error();
+ }
+ el.innerHTML = prettyPrint(resp);
});
});