aboutsummaryrefslogtreecommitdiff
path: root/extension/pages
diff options
context:
space:
mode:
Diffstat (limited to 'extension/pages')
-rw-r--r--extension/pages/confirm-create-reserve.js101
-rw-r--r--extension/pages/confirm-create-reserve.tsx118
2 files changed, 169 insertions, 50 deletions
diff --git a/extension/pages/confirm-create-reserve.js b/extension/pages/confirm-create-reserve.js
index 4cb8c03fb..6241fcab0 100644
--- a/extension/pages/confirm-create-reserve.js
+++ b/extension/pages/confirm-create-reserve.js
@@ -45,9 +45,49 @@ System.register(["../lib/wallet/helpers", "../lib/wallet/types", "mithril"], fun
else {
mx("p", "Checking URL, please wait ...");
}
+ if (ctrl.reserveCreationInfo) {
+ var withdrawFeeStr = helpers_1.amountToPretty(ctrl.reserveCreationInfo.withdrawFee);
+ mx("p", "Fee for withdrawal: " + withdrawFeeStr);
+ if (ctrl.detailCollapsed()) {
+ mx("button.linky", {
+ onclick: function () {
+ ctrl.detailCollapsed(false);
+ }
+ }, "show more");
+ }
+ else {
+ mx("button.linky", {
+ onclick: function () {
+ ctrl.detailCollapsed(true);
+ }
+ }, "show less");
+ mx("div", {}, renderCoinTable(ctrl.reserveCreationInfo.selectedDenoms));
+ }
+ }
return mithril_1.default("div", controls);
var _a;
}
+ function renderCoinTable(denoms) {
+ function row(denom) {
+ return mithril_1.default("tr", [
+ mithril_1.default("td", denom.pub_hash.substr(0, 5) + "..."),
+ mithril_1.default("td", helpers_1.amountToPretty(denom.value)),
+ mithril_1.default("td", helpers_1.amountToPretty(denom.fee_withdraw)),
+ mithril_1.default("td", helpers_1.amountToPretty(denom.fee_refresh)),
+ mithril_1.default("td", helpers_1.amountToPretty(denom.fee_deposit)),
+ ]);
+ }
+ return mithril_1.default("table", [
+ mithril_1.default("tr", [
+ mithril_1.default("th", "Key Hash"),
+ mithril_1.default("th", "Value"),
+ mithril_1.default("th", "Withdraw Fee"),
+ mithril_1.default("th", "Refresh Fee"),
+ mithril_1.default("th", "Deposit Fee"),
+ ]),
+ denoms.map(row)
+ ]);
+ }
function probeMint(mintBaseUrl) {
throw Error("not implemented");
}
@@ -64,6 +104,21 @@ System.register(["../lib/wallet/helpers", "../lib/wallet/types", "mithril"], fun
}
return Promise.resolve(mint);
}
+ function getReserveCreationInfo(baseUrl, amount) {
+ var m = { type: "reserve-creation-info", detail: { baseUrl: baseUrl, amount: amount } };
+ return new Promise(function (resolve, reject) {
+ chrome.runtime.sendMessage(m, function (resp) {
+ if (resp.error) {
+ console.error("error response", resp);
+ var e = Error("call to reserve-creation-info failed");
+ e.errorResponse = resp;
+ reject(e);
+ return;
+ }
+ resolve(resp);
+ });
+ });
+ }
function main() {
var url = URI(document.location.href);
var query = URI.parseQuery(url.query());
@@ -128,6 +183,9 @@ System.register(["../lib/wallet/helpers", "../lib/wallet/types", "mithril"], fun
this.url = mithril_1.default.prop();
this.statusString = null;
this.isValidMint = false;
+ this.reserveCreationInfo = null;
+ this.detailCollapsed = mithril_1.default.prop(true);
+ console.log("creating main controller");
this.amount = amount;
this.callbackUrl = callbackUrl;
this.timer = new DelayTimer(800, function () { return _this.update(); });
@@ -140,47 +198,44 @@ System.register(["../lib/wallet/helpers", "../lib/wallet/types", "mithril"], fun
var doUpdate = function () {
if (!_this.url()) {
_this.statusString = (_a = ["Please enter a URL"], _a.raw = ["Please enter a URL"], i18n(_a));
- mithril_1.default.endComputation();
return;
}
_this.statusString = null;
var parsedUrl = URI(_this.url());
if (parsedUrl.is("relative")) {
_this.statusString = (_b = ["The URL you've entered is not valid (must be absolute)"], _b.raw = ["The URL you've entered is not valid (must be absolute)"], i18n(_b));
- mithril_1.default.endComputation();
return;
}
- var keysUrl = URI("/keys").absoluteTo(helpers_1.canonicalizeBaseUrl(_this.url()));
- console.log("requesting keys from '" + keysUrl + "'");
- _this.request = new XMLHttpRequest();
- _this.request.onreadystatechange = function () {
- if (_this.request.readyState == XMLHttpRequest.DONE) {
- switch (_this.request.status) {
- case 200:
- _this.isValidMint = true;
- _this.statusString = "The mint base URL is valid!";
- break;
- case 0:
- _this.statusString = "unknown request error";
- break;
- default:
- _this.statusString = "request failed with status " + _this.request.status;
- break;
- }
+ mithril_1.default.redraw(true);
+ console.log("doing get mint info");
+ getReserveCreationInfo(_this.url(), _this.amount)
+ .then(function (r) {
+ console.log("get mint info resolved");
+ _this.isValidMint = true;
+ _this.reserveCreationInfo = r;
+ console.dir(r);
+ _this.statusString = "The mint base URL is valid!";
+ mithril_1.default.endComputation();
+ })
+ .catch(function (e) {
+ console.log("get mint info rejected");
+ if (e.hasOwnProperty("httpStatus")) {
+ _this.statusString = "request failed with status " + _this.request.status;
+ }
+ else {
+ _this.statusString = "unknown request error";
}
mithril_1.default.endComputation();
- };
- _this.request.open("get", keysUrl.href());
- _this.request.send();
+ });
var _a, _b;
};
- mithril_1.default.startComputation();
doUpdate();
console.log("got update");
};
Controller.prototype.reset = function () {
this.isValidMint = false;
this.statusString = null;
+ this.reserveCreationInfo = null;
if (this.request) {
this.request.abort();
this.request = null;
diff --git a/extension/pages/confirm-create-reserve.tsx b/extension/pages/confirm-create-reserve.tsx
index 4be934d37..386fa24e3 100644
--- a/extension/pages/confirm-create-reserve.tsx
+++ b/extension/pages/confirm-create-reserve.tsx
@@ -19,6 +19,10 @@
import {amountToPretty, canonicalizeBaseUrl} from "../lib/wallet/helpers";
import {AmountJson, CreateReserveResponse} from "../lib/wallet/types";
import m from "mithril";
+import {IMintInfo} from "../lib/wallet/types";
+import {ReserveCreationInfo} from "../lib/wallet/types";
+import MithrilComponent = _mithril.MithrilComponent;
+import {Denomination} from "../lib/wallet/types";
"use strict";
@@ -56,12 +60,15 @@ class Controller {
url = m.prop<string>();
statusString = null;
isValidMint = false;
+ reserveCreationInfo: ReserveCreationInfo = null;
private timer: DelayTimer;
private request: XMLHttpRequest;
amount: AmountJson;
callbackUrl: string;
+ detailCollapsed = m.prop<boolean>(true);
constructor(initialMintUrl: string, amount: AmountJson, callbackUrl: string) {
+ console.log("creating main controller");
this.amount = amount;
this.callbackUrl = callbackUrl;
this.timer = new DelayTimer(800, () => this.update());
@@ -74,44 +81,39 @@ class Controller {
const doUpdate = () => {
if (!this.url()) {
this.statusString = i18n`Please enter a URL`;
- m.endComputation();
return;
}
this.statusString = null;
let parsedUrl = URI(this.url());
if (parsedUrl.is("relative")) {
this.statusString = i18n`The URL you've entered is not valid (must be absolute)`;
- m.endComputation();
return;
}
- const keysUrl = URI("/keys").absoluteTo(canonicalizeBaseUrl(this.url()));
-
- console.log(`requesting keys from '${keysUrl}'`);
-
- this.request = new XMLHttpRequest();
- this.request.onreadystatechange = () => {
- if (this.request.readyState == XMLHttpRequest.DONE) {
- switch (this.request.status) {
- case 200:
- this.isValidMint = true;
- this.statusString = "The mint base URL is valid!";
- break;
- case 0:
- this.statusString = `unknown request error`;
- break;
- default:
- this.statusString = `request failed with status ${this.request.status}`;
- break;
+ m.redraw(true);
+
+ console.log("doing get mint info");
+
+ getReserveCreationInfo(this.url(), this.amount)
+ .then((r: ReserveCreationInfo) => {
+ console.log("get mint info resolved");
+ this.isValidMint = true;
+ this.reserveCreationInfo = r;
+ console.dir(r);
+ this.statusString = "The mint base URL is valid!";
+ m.endComputation();
+ })
+ .catch((e) => {
+ console.log("get mint info rejected");
+ if (e.hasOwnProperty("httpStatus")) {
+ this.statusString = `request failed with status ${this.request.status}`;
+ } else {
+ this.statusString = `unknown request error`;
}
- }
- m.endComputation();
- };
- this.request.open("get", keysUrl.href());
- this.request.send();
+ m.endComputation();
+ });
};
- m.startComputation();
doUpdate();
@@ -121,6 +123,7 @@ class Controller {
reset() {
this.isValidMint = false;
this.statusString = null;
+ this.reserveCreationInfo = null;
if (this.request) {
this.request.abort();
this.request = null;
@@ -168,7 +171,7 @@ class Controller {
function view(ctrl: Controller) {
let controls = [];
- let mx = (x: string, ...args) => controls.push(m(x, ...args));
+ let mx = (x, ...args) => controls.push(m(x, ...args));
mx("p",
i18n`The bank wants to create a reserve over ${amountToPretty(
@@ -196,10 +199,53 @@ function view(ctrl: Controller) {
mx("p", "Checking URL, please wait ...");
}
+ if (ctrl.reserveCreationInfo) {
+ let withdrawFeeStr = amountToPretty(ctrl.reserveCreationInfo.withdrawFee);
+ mx("p", `Fee for withdrawal: ${withdrawFeeStr}`);
+
+ if (ctrl.detailCollapsed()) {
+ mx("button.linky", {
+ onclick: () => {
+ ctrl.detailCollapsed(false);
+ }
+ }, "show more");
+ } else {
+ mx("button.linky", {
+ onclick: () => {
+ ctrl.detailCollapsed(true);
+ }
+ }, "show less");
+ mx("div", {}, renderCoinTable(ctrl.reserveCreationInfo.selectedDenoms))
+ }
+ }
+
return m("div", controls);
}
+function renderCoinTable(denoms: Denomination[]) {
+ function row(denom: Denomination) {
+ return m("tr", [
+ m("td", denom.pub_hash.substr(0, 5) + "..."),
+ m("td", amountToPretty(denom.value)),
+ m("td", amountToPretty(denom.fee_withdraw)),
+ m("td", amountToPretty(denom.fee_refresh)),
+ m("td", amountToPretty(denom.fee_deposit)),
+ ]);
+ }
+ return m("table", [
+ m("tr", [
+ m("th", "Key Hash"),
+ m("th", "Value"),
+ m("th", "Withdraw Fee"),
+ m("th", "Refresh Fee"),
+ m("th", "Deposit Fee"),
+ ]),
+ denoms.map(row)
+ ]);
+}
+
+
interface MintProbeResult {
keyInfo?: any;
}
@@ -227,6 +273,24 @@ function getSuggestedMint(currency: string): Promise<string> {
}
+function getReserveCreationInfo(baseUrl: string,
+ amount: AmountJson): Promise<ReserveCreationInfo> {
+ let m = {type: "reserve-creation-info", detail: {baseUrl, amount}};
+ return new Promise((resolve, reject) => {
+ chrome.runtime.sendMessage(m, (resp) => {
+ if (resp.error) {
+ console.error("error response", resp);
+ let e = Error("call to reserve-creation-info failed");
+ (e as any).errorResponse = resp;
+ reject(e);
+ return;
+ }
+ resolve(resp);
+ });
+ });
+}
+
+
export function main() {
const url = URI(document.location.href);
const query: any = URI.parseQuery(url.query());