move to ES6, clean up views

This commit is contained in:
Florian Dold 2016-09-14 15:20:18 +02:00
parent 8852857347
commit fc6db1824e
5 changed files with 2326 additions and 2253 deletions

View File

@ -117,7 +117,7 @@ const paths = {
const tsBaseArgs = { const tsBaseArgs = {
target: "es5", target: "es6",
jsx: "react", jsx: "react",
experimentalDecorators: true, experimentalDecorators: true,
module: "system", module: "system",

4390
lib/vendor/mithril.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,6 @@
import {amountToPretty, canonicalizeBaseUrl} from "../lib/wallet/helpers"; import {amountToPretty, canonicalizeBaseUrl} from "../lib/wallet/helpers";
import {AmountJson, CreateReserveResponse} from "../lib/wallet/types"; import {AmountJson, CreateReserveResponse} from "../lib/wallet/types";
import m from "mithril"; import m from "mithril";
import {IExchangeInfo} from "../lib/wallet/types";
import {ReserveCreationInfo, Amounts} from "../lib/wallet/types"; import {ReserveCreationInfo, Amounts} from "../lib/wallet/types";
import MithrilComponent = _mithril.MithrilComponent; import MithrilComponent = _mithril.MithrilComponent;
import {Denomination} from "../lib/wallet/types"; import {Denomination} from "../lib/wallet/types";
@ -190,34 +189,60 @@ class Controller {
} }
function view(ctrl: Controller): any { function view(ctrl: Controller): any {
let controls: any[] = []; function* f() {
let mx = (x: any, ...args: any[]) => controls.push(m(x, ...args)); yield m("p",
i18n.parts`You are about to withdraw ${m("strong", amountToPretty(
ctrl.amount))} from your bank account into your wallet.`);
mx("p", if (ctrl.complexViewRequested || !ctrl.suggestedExchangeUrl) {
i18n.parts`You are about to withdraw ${m("strong", amountToPretty( yield viewComplex(ctrl);
ctrl.amount))} from your bank account into your wallet.`); return;
}
if (ctrl.complexViewRequested || !ctrl.suggestedExchangeUrl) { yield viewSimple(ctrl);
return controls.concat(viewComplex(ctrl));
} }
return Array.from(f());
return controls.concat(viewSimple(ctrl));
} }
function viewSimple(ctrl: Controller) { function viewSimple(ctrl: Controller) {
let controls: any[] = []; function *f() {
let mx = (x: any, ...args: any[]) => controls.push(m(x, ...args)); if (ctrl.statusString) {
yield m("p", "Error: ", ctrl.statusString);
if (ctrl.statusString) { yield m("button.linky", {
mx("p", "Error: ", ctrl.statusString); onclick: () => {
mx("button.linky", { ctrl.complexViewRequested = true;
onclick: () => { }
ctrl.complexViewRequested = true; }, "advanced options");
} }
}, "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 ...");
}
} }
else if (ctrl.reserveCreationInfo != undefined) {
mx("button.accept", { return Array.from(f());
}
function viewComplex(ctrl: Controller) {
function *f() {
yield m("button.accept", {
onclick: () => ctrl.confirmReserve(ctrl.reserveCreationInfo!, onclick: () => ctrl.confirmReserve(ctrl.reserveCreationInfo!,
ctrl.url(), ctrl.url(),
ctrl.amount, ctrl.amount,
@ -225,84 +250,53 @@ function viewSimple(ctrl: Controller) {
disabled: !ctrl.isValidExchange disabled: !ctrl.isValidExchange
}, },
"Accept fees and withdraw"); "Accept fees and withdraw");
mx("span.spacer"); yield m("span.spacer");
mx("button.linky", { yield m("button.linky", {
onclick: () => { onclick: () => {
ctrl.complexViewRequested = true; ctrl.complexViewRequested = false;
} }
}, "advanced options"); }, "back to simple view");
let totalCost = Amounts.add(ctrl.reserveCreationInfo.overhead,
ctrl.reserveCreationInfo.withdrawFee).amount; yield m("br");
mx("p", `Withdraw cost: ${amountToPretty(totalCost)}`);
} else {
mx("p", "Please wait ...");
}
return controls; yield m("input", {
} className: "url",
type: "text",
spellcheck: false,
value: ctrl.url(),
oninput: m.withAttr("value", ctrl.onUrlChanged.bind(ctrl)),
});
yield m("br");
function viewComplex(ctrl: Controller) { if (ctrl.statusString) {
let controls: any[] = []; yield m("p", ctrl.statusString);
let mx = (x: any, ...args: any[]) => controls.push(m(x, ...args)); } else if (!ctrl.reserveCreationInfo) {
yield m("p", "Checking URL, please wait ...");
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");
mx("br"); if (ctrl.reserveCreationInfo) {
let totalCost = Amounts.add(ctrl.reserveCreationInfo.overhead,
ctrl.reserveCreationInfo.withdrawFee).amount;
mx("input", yield m("p", `Withdraw cost: ${amountToPretty(totalCost)}`);
{ if (ctrl.detailCollapsed()) {
className: "url", yield m("button.linky", {
type: "text", onclick: () => {
spellcheck: false, ctrl.detailCollapsed(false);
value: ctrl.url(), }
oninput: m.withAttr("value", ctrl.onUrlChanged.bind(ctrl)), }, "show more details");
}); } else {
yield m("button.linky", {
mx("br"); onclick: () => {
ctrl.detailCollapsed(true);
if (ctrl.statusString) { }
mx("p", ctrl.statusString); }, "hide details");
} else if (!ctrl.reserveCreationInfo) { yield m("div", {}, renderReserveCreationDetails(ctrl.reserveCreationInfo))
mx("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))
} }
} }
return Array.from(f());
return m("div", controls);
} }
@ -368,6 +362,7 @@ function getSuggestedExchange(currency: string): Promise<string> {
} }
export function main() { export function main() {
const url = URI(document.location.href); const url = URI(document.location.href);
const query: any = URI.parseQuery(url.query()); const query: any = URI.parseQuery(url.query());
@ -378,7 +373,7 @@ export function main() {
getSuggestedExchange(amount.currency) getSuggestedExchange(amount.currency)
.then((suggestedExchangeUrl) => { .then((suggestedExchangeUrl) => {
const controller = () => new Controller(suggestedExchangeUrl, amount, callback_url, wt_types); const controller = function () { return new Controller(suggestedExchangeUrl, amount, callback_url, wt_types); };
var ExchangeSelection = {controller, view}; var ExchangeSelection = {controller, view};
m.mount(document.getElementById("exchange-selection"), ExchangeSelection); m.mount(document.getElementById("exchange-selection"), ExchangeSelection);
}) })
@ -386,6 +381,6 @@ export function main() {
// TODO: provide more context information, maybe factor it out into a // TODO: provide more context information, maybe factor it out into a
// TODO:generic error reporting function or component. // TODO:generic error reporting function or component.
document.body.innerText = `Fatal error: "${e.message}".`; document.body.innerText = `Fatal error: "${e.message}".`;
console.error(`got backend error "${e.message}"`); console.error(`got error "${e.message}"`, e);
}); });
} }

View File

@ -91,6 +91,8 @@ function openInExtension(element: HTMLAnchorElement, isInitialized: boolean) {
}); });
} }
namespace WalletBalance { namespace WalletBalance {
export function controller() { export function controller() {
return new Controller(); return new Controller();

View File

@ -1,6 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es6",
"jsx": "react", "jsx": "react",
"experimentalDecorators": true, "experimentalDecorators": true,
"module": "system", "module": "system",