aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/moduleTrampoline.ts80
-rw-r--r--src/pages/error.html27
-rw-r--r--src/pages/error.tsx59
-rw-r--r--src/wxBackend.ts13
-rw-r--r--tsconfig.json7
5 files changed, 182 insertions, 4 deletions
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 <http://www.gnu.org/licenses/>
+ */
+
+
+/**
+ * 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 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <title>Taler Wallet: Error Occured</title>
+
+ <link rel="stylesheet" type="text/css" href="../style/lang.css">
+ <link rel="stylesheet" type="text/css" href="../style/wallet.css">
+
+ <link rel="icon" href="/img/icon.png">
+
+ <script src="/src/vendor/URI.js"></script>
+ <script src="/src/vendor/react.js"></script>
+ <script src="/src/vendor/react-dom.js"></script>
+
+ <!-- i18n -->
+ <script src="/src/vendor/jed.js"></script>
+ <script src="/src/i18n.js"></script>
+ <script src="/src/i18n/strings.js"></script>
+
+ <script src="/src/vendor/system-csp-production.src.js"></script>
+ <script src="/src/moduleTrampoline.js"></script>
+
+ <body>
+ <div id="container"></div>
+ </body>
+</html>
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 <http://www.gnu.org/licenses/>
+ */
+
+
+/**
+ * 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<ErrorProps, void> {
+ render(): JSX.Element {
+ return (
+ <div>
+ An error occurred: {this.props.message}
+ </div>
+ );
+ }
+}
+
+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(<ErrorView message={message} />, 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"