From 1357271717109f90ae510e3cc2d1ecaa94e55336 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 19 Nov 2016 17:37:39 +0100 Subject: missing files --- src/moduleTrampoline.ts | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ src/pages/error.html | 27 +++++++++++++++++ src/pages/error.tsx | 59 ++++++++++++++++++++++++++++++++++++ src/wxBackend.ts | 13 +++++++- tsconfig.json | 7 +++-- 5 files changed, 182 insertions(+), 4 deletions(-) create mode 100644 src/moduleTrampoline.ts create mode 100644 src/pages/error.html create mode 100644 src/pages/error.tsx diff --git a/src/moduleTrampoline.ts b/src/moduleTrampoline.ts new file mode 100644 index 000000000..acbf2afcf --- /dev/null +++ b/src/moduleTrampoline.ts @@ -0,0 +1,80 @@ +/* + This file is part of TALER + (C) 2016 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, see + */ + + +/** + * Boilerplate to initialize the module system and call main() + * + * @author Florian Dold + */ + +"use strict"; + +if (typeof System === "undefined") { + throw Error("system loader not present (must be included before the" + + " trampoline"); +} + +System.config({ + defaultJSExtensions: true, + map: { + src: "/src/", + }, +}); + +let me = window.location.protocol + + "//" + window.location.host + + window.location.pathname.replace(/[.]html$/, ".js"); + +let domLoaded = false; + +document.addEventListener("DOMContentLoaded", function(event) { + domLoaded = true; +}); + +function execMain(m: any) { + if (m.main) { + console.log("executing module main"); + let res = m.main(); + } else { + console.warn("module does not export a main() function"); + } +} + +console.log("loading", me); + +System.import("src/logging").then((logging) => { + window.onerror = (m, source, lineno, colno, error) => { + logging.record("error", m + error, source || "(unknown)", undefined, lineno || 0, colno || 0); + }; + window.addEventListener('unhandledrejection', (evt: any) => { + logging.recordException("unhandled promise rejection", evt.reason); + }); + System.import(me).then((m) => { + if (domLoaded) { + execMain(m); + return; + } + document.addEventListener("DOMContentLoaded", function(event) { + execMain(m); + }); + }); +}) +.catch((e) => { + console.log("trampoline failed"); + console.error(e.stack); +}); + diff --git a/src/pages/error.html b/src/pages/error.html new file mode 100644 index 000000000..8d6b3e153 --- /dev/null +++ b/src/pages/error.html @@ -0,0 +1,27 @@ + + + + + Taler Wallet: Error Occured + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/src/pages/error.tsx b/src/pages/error.tsx new file mode 100644 index 000000000..2878dfcf1 --- /dev/null +++ b/src/pages/error.tsx @@ -0,0 +1,59 @@ +/* + This file is part of TALER + (C) 2015-2016 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, see + */ + + +/** + * Page shown to the user to confirm creation + * of a reserve, usually requested by the bank. + * + * @author Florian Dold + */ + +import {ImplicitStateComponent, StateHolder} from "src/components"; + +"use strict"; + +interface ErrorProps { + message: string; +} + +class ErrorView extends React.Component { + render(): JSX.Element { + return ( +
+ An error occurred: {this.props.message} +
+ ); + } +} + +export async function main() { + try { + const url = URI(document.location.href); + const query: any = URI.parseQuery(url.query()); + + const message: string = query.message || "unknown error"; + + ReactDOM.render(, document.getElementById( + "container")!); + + } 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 error "${e.message}"`, e); + } +} diff --git a/src/wxBackend.ts b/src/wxBackend.ts index 7893dd64d..6e637a2a6 100644 --- a/src/wxBackend.ts +++ b/src/wxBackend.ts @@ -392,6 +392,17 @@ function handleBankRequest(wallet: Wallet, headerList: chrome.webRequest.HttpHea console.log("202 not understood (X-Taler-Callback-Url missing)"); return; } + let amountParsed; + try { + amountParsed = JSON.parse(amount); + } catch (e) { + let uri = URI(chrome.extension.getURL("/src/pages/error.html")); + let p = { + message: `Can't parse amount ("${amount}"): ${e.message}`, + }; + let redirectUrl = uri.query(p).href(); + return {redirectUrl}; + } let wtTypes = headers["x-taler-wt-types"]; if (!wtTypes) { console.log("202 not understood (X-Taler-Wt-Types missing)"); @@ -408,7 +419,7 @@ function handleBankRequest(wallet: Wallet, headerList: chrome.webRequest.HttpHea let redirectUrl = uri.query(params).href(); return {redirectUrl}; } - console.log("202 not understood"); + // no known headers found, not a taler request ... } // Useful for debugging ... diff --git a/tsconfig.json b/tsconfig.json index f504e41df..d00d1c2b1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,14 +16,14 @@ "src/checkable.ts", "decl/lib.es6.d.ts", "src/chromeBadge.ts", - "decl/urijs/URIjs.d.ts", "src/cryptoApi-test.ts", + "decl/urijs/URIjs.d.ts", "src/components.ts", - "decl/systemjs/systemjs.d.ts", "src/emscriptif-test.ts", + "decl/systemjs/systemjs.d.ts", "src/cryptoApi.ts", - "decl/react-global.d.ts", "src/helpers-test.ts", + "decl/react-global.d.ts", "src/cryptoLib.ts", "src/types-test.ts", "decl/chrome/chrome.d.ts", @@ -48,6 +48,7 @@ "src/pages/show-db.ts", "src/pages/confirm-contract.tsx", "src/pages/confirm-create-reserve.tsx", + "src/pages/error.tsx", "src/pages/logs.tsx", "src/pages/tree.tsx", "src/popup/popup.tsx" -- cgit v1.2.3