aboutsummaryrefslogtreecommitdiff
path: root/extension/popup
diff options
context:
space:
mode:
Diffstat (limited to 'extension/popup')
-rw-r--r--extension/popup/balance-overview.html34
-rw-r--r--extension/popup/balance-overview.js44
-rw-r--r--extension/popup/balance-overview.tsx46
-rw-r--r--extension/popup/history.html31
-rw-r--r--extension/popup/history.tsx22
-rw-r--r--extension/popup/popup.css1
-rw-r--r--extension/popup/popup.html17
-rw-r--r--extension/popup/popup.tsx182
-rw-r--r--extension/popup/reserve-create-sepa.html28
-rw-r--r--extension/popup/reserve-create.html41
-rw-r--r--extension/popup/reserves.html28
11 files changed, 200 insertions, 274 deletions
diff --git a/extension/popup/balance-overview.html b/extension/popup/balance-overview.html
deleted file mode 100644
index b27a9353a..000000000
--- a/extension/popup/balance-overview.html
+++ /dev/null
@@ -1,34 +0,0 @@
-<!DOCTYPE html>
-
-<html>
-<head>
- <meta charset="utf-8">
- <link rel="stylesheet" href="popup.css" type="text/css">
- <script src="../lib/vendor/handlebars-v4.0.5.js" type="text/javascript"></script>
- <script src="../lib/commonHelpers.js" type="text/javascript"></script>
- <script src="balance-overview.js" type="text/javascript"></script>
-
- <script id="balance-template" type="text/x-handlebars-template">
- {{#each this}}
- <p>{{prettyAmountNoCurrency this}} <a>{{@key}}</a></p>
- {{else}}
- <p>Looks like your wallet is empty. Want to get some
- <a id="link-kudos" href="http://bank.demo.taler.net">KUDOS?</a>
- {{/each}}
- </script>
-
-</head>
-<body>
-<div id="header" class="nav">
- <a href="balance-overview.html" class="active">Wallet</a>
- <a href="history.html">History</a>
- <a href="reserves.html">Reserves</a>
- <button id="debug">Debug!</button>
- <button id="reset">Reset!</button>
-</div>
-
-<div id="content">
-</div>
-
-</body>
-</html>
diff --git a/extension/popup/balance-overview.js b/extension/popup/balance-overview.js
deleted file mode 100644
index 600c4c45d..000000000
--- a/extension/popup/balance-overview.js
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- 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, If not, see <http://www.gnu.org/licenses/>
- */
-"use strict";
-document.addEventListener("DOMContentLoaded", function (e) {
- console.log("content loaded");
- chrome.runtime.sendMessage({ type: "balances" }, function (wallet) {
- var context = document.getElementById("balance-template").innerHTML;
- var template = Handlebars.compile(context);
- document.getElementById("content").innerHTML = template(wallet);
- console.log("got wallet", JSON.stringify(wallet));
- var el = document.getElementById("link-kudos");
- if (el) {
- el.onclick = function (e) {
- var target = e.target;
- chrome.tabs.create({
- "url": target.href
- });
- };
- }
- });
- document.getElementById("debug").addEventListener("click", function (e) {
- chrome.tabs.create({
- "url": chrome.extension.getURL("pages/debug.html")
- });
- });
- document.getElementById("reset").addEventListener("click", function (e) {
- chrome.runtime.sendMessage({ type: "reset" });
- window.close();
- });
-});
-//# sourceMappingURL=balance-overview.js.map \ No newline at end of file
diff --git a/extension/popup/balance-overview.tsx b/extension/popup/balance-overview.tsx
deleted file mode 100644
index 8a278d6a1..000000000
--- a/extension/popup/balance-overview.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- 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, If not, see <http://www.gnu.org/licenses/>
- */
-
-"use strict";
-
-document.addEventListener("DOMContentLoaded", (e) => {
- console.log("content loaded");
- chrome.runtime.sendMessage({type: "balances"}, function(wallet) {
- let context = document.getElementById("balance-template").innerHTML;
- let template = Handlebars.compile(context);
- document.getElementById("content").innerHTML = template(wallet);
- console.log("got wallet", JSON.stringify(wallet));
- let el = document.getElementById("link-kudos");
- if (el) {
- el.onclick = (e) => {
- let target: any = e.target;
- chrome.tabs.create({
- "url": target.href
- });
- };
- }
- });
-
- document.getElementById("debug").addEventListener("click", (e) => {
- chrome.tabs.create({
- "url": chrome.extension.getURL("pages/debug.html")
- });
- });
- document.getElementById("reset").addEventListener("click", (e) => {
- chrome.runtime.sendMessage({type: "reset"});
- window.close();
- });
-});
diff --git a/extension/popup/history.html b/extension/popup/history.html
deleted file mode 100644
index 0b211d8af..000000000
--- a/extension/popup/history.html
+++ /dev/null
@@ -1,31 +0,0 @@
-<!DOCTYPE html>
-
-<html>
-<head>
- <meta charset="utf-8">
- <link rel="stylesheet" href="popup.css" type="text/css">
- <script src="history.js" type="text/javascript"></script>
-
- <script id="balance-template" type="text/x-handlebars-template">
- {{#each transactions}}
- <p>bla</p>
- {{else}}
- There's nothing here. Go to
- our <a href="http://demo.taler.net">demo site</a> to try GNU Taler.
- {{/each}}
- </script>
-</head>
-
-<body>
-<div id="header" class="nav">
- <a href="balance-overview.html">Wallet</a>
- <a href="history.html" class="active">Transactions</a>
- <a href="reserves.html">Reserves</a>
-</div>
-
-<div id="content">
- (Loading...)
-</div>
-
-</body>
-</html>
diff --git a/extension/popup/history.tsx b/extension/popup/history.tsx
deleted file mode 100644
index 387f19c80..000000000
--- a/extension/popup/history.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- 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, If not, see <http://www.gnu.org/licenses/>
- */
-
-
-"use strict";
-
-document.addEventListener("DOMContentLoaded", (e) => {
-
-});
diff --git a/extension/popup/popup.css b/extension/popup/popup.css
index 80a0829e5..20385106e 100644
--- a/extension/popup/popup.css
+++ b/extension/popup/popup.css
@@ -1,4 +1,5 @@
body {
+ min-height: 20em;
width: 30em;
margin: 0;
padding: 0
diff --git a/extension/popup/popup.html b/extension/popup/popup.html
new file mode 100644
index 000000000..88fcf2ac8
--- /dev/null
+++ b/extension/popup/popup.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <link rel="stylesheet" href="popup.css" type="text/css">
+ <script src="../lib/vendor/mithril.js"></script>
+ <script src="../lib/i18n.js"></script>
+ <script src="../lib/vendor/lodash.core.min.js"></script>
+ <script src="popup.js"></script>
+</head>
+<body>
+<div id="nav"></div>
+<div id="content"></div>
+</body>
+
+
+</html>
diff --git a/extension/popup/popup.tsx b/extension/popup/popup.tsx
new file mode 100644
index 000000000..8bfb691ca
--- /dev/null
+++ b/extension/popup/popup.tsx
@@ -0,0 +1,182 @@
+/*
+ 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, If not, see <http://www.gnu.org/licenses/>
+ */
+
+
+/// <reference path="../lib/mithril.d.ts" />
+/// <reference path="../lib/decl/lodash.d.ts" />
+
+"use strict";
+
+
+declare var m: any;
+declare var i18n: any;
+
+document.addEventListener("DOMContentLoaded", function(event) {
+ m.route.mode = "hash";
+ m.route(document.getElementById("content"), "/balance", {
+ "/balance": WalletBalance,
+ "/history": WalletHistory,
+ "/debug": WalletDebug,
+ });
+ m.mount(document.getElementById("nav"), WalletNavBar);
+});
+
+
+function makeTab(target, name) {
+ let cssClass = "";
+ if (target == m.route()) {
+ cssClass = "active";
+ }
+ return m("a", {config: m.route, href: target, "class": cssClass}, name);
+}
+
+var WalletNavBar = {
+ view() {
+ return m("div#header.nav", [
+ makeTab("/balance", i18n`Balance`),
+ makeTab("/history", i18n`History`),
+ makeTab("/debug", i18n`Debug`),
+ ]);
+ }
+};
+
+
+function openInExtension(element, isInitialized) {
+ element.addEventListener("click", (e) => {
+ chrome.tabs.create({
+ "url": element.href
+ });
+ e.preventDefault();
+ });
+}
+
+var WalletBalance = {
+ controller() {
+ var myWallet;
+ m.startComputation();
+ chrome.runtime.sendMessage({type: "balances"}, (wallet) => {
+ console.log("got wallet", wallet);
+ myWallet = wallet;
+ m.endComputation();
+ });
+ return () => myWallet;
+ },
+
+ view(getWallet) {
+ let wallet = getWallet();
+ if (!wallet) {
+ throw Error("Could not retrieve wallet");
+ }
+ let listing = _.map(wallet, x => m("p", formatAmount(x)));
+ if (listing.length > 0) {
+ return listing;
+ }
+ let link = m("a[href=https://demo.taler.net]", {config: openInExtension}, i18n`free KUDOS`);
+ return i18n.parts`You have no balance to show. Want to get some ${link}?`;
+ }
+};
+
+
+function formatTimestamp(t) {
+ let x = new Date(t);
+ return x.toLocaleString();
+}
+
+
+function formatAmount(amount) {
+ let v = amount.value + amount.fraction / 1e6;
+ return `${v.toFixed(2)} ${amount.currency}`;
+}
+
+function formatHistoryItem(historyItem) {
+ const d = historyItem.detail;
+ const t = historyItem.timestamp;
+ switch (historyItem.type) {
+ case "create-reserve":
+ return m("p",
+ i18n`Created reserve of ${formatAmount(d.requestedAmount)} at ${formatTimestamp(
+ t)}`);
+ case "withdraw":
+ return m("p",
+ i18n`Withdraw at ${formatTimestamp(t)}`);
+ case "pay":
+ return m("p",
+ [
+ i18n`Payment for ${formatAmount(d.amount)} to merchant ${d.merchantName}. `,
+ m("a[href=javascript:;]", "Retry")
+ ]);
+ default:
+ return m("p", i18n`Unknown event (${historyItem.type})`);
+ }
+}
+
+
+var WalletHistory = {
+ controller() {
+ var myHistory;
+ m.startComputation();
+ chrome.runtime.sendMessage({type: "get-history"}, (wallet) => {
+ console.log("got history", history);
+ myHistory = wallet;
+ m.endComputation();
+ });
+ return () => myHistory;
+ },
+
+ view(getHistory) {
+ let history = getHistory();
+ if (!history) {
+ throw Error("Could not retrieve history");
+ }
+ let listing = _.map(history, formatHistoryItem);
+ if (listing.length > 0) {
+ return listing;
+ }
+ return i18n`Your wallet has no events recorded.`;
+ }
+};
+
+
+function confirmReset() {
+ if (confirm("Do you want to IRREVOCABLY DESTROY everything inside your" +
+ " wallet and LOSE ALL YOUR COINS?")) {
+ chrome.runtime.sendMessage({type: "reset"});
+ window.close();
+ try {
+ chrome.runtime.reload();
+ } catch (e) {
+ // Functionality missing in firefox, ignore!
+ }
+
+ }
+}
+
+
+var WalletDebug = {
+ view() {
+ return [
+ m("button", {onclick: openWalletAsTab}, "wallet tab"),
+ m("button", {onclick: confirmReset}, "reset")
+ ]
+ }
+};
+
+
+function openWalletAsTab() {
+ chrome.tabs.create({
+ "url": chrome.extension.getURL("popup/popup.html")
+ });
+}
diff --git a/extension/popup/reserve-create-sepa.html b/extension/popup/reserve-create-sepa.html
deleted file mode 100644
index 12d02b832..000000000
--- a/extension/popup/reserve-create-sepa.html
+++ /dev/null
@@ -1,28 +0,0 @@
-<!DOCTYPE html>
-
-<html>
- <head>
- <meta charset="utf-8">
- <link rel="stylesheet" href="popup.css" type="text/css">
- </head>
-
- <body>
- <div id="header" class="nav">
- <a href="balance-overview.html">Wallet</a>
- <a href="history.html">Transactions</a>
- <a href="reserves.html" class="active">Reserves</a>
- </div>
-
- <div id="content">
- <div id="reserve-create-sepa">
- SEPA info here.
- </div>
- </div>
-
- <div id="footer" class="nav">
- <a href="reserves.html">List reserves</a>
- <a href="reserve-create.html">Create reserve</a>
- </div>
-
- </body>
-</html>
diff --git a/extension/popup/reserve-create.html b/extension/popup/reserve-create.html
deleted file mode 100644
index 165496ab6..000000000
--- a/extension/popup/reserve-create.html
+++ /dev/null
@@ -1,41 +0,0 @@
-<!DOCTYPE html>
-
-<html>
- <head>
- <meta charset="utf-8">
- <link rel="stylesheet" href="popup.css" type="text/css">
- </head>
-
- <body>
- <div id="header" class="nav">
- <a href="balance-overview.html">Wallet</a>
- <a href="history.html">Transactions</a>
- <a href="reserves.html" class="active">Reserves</a>
- </div>
-
- <div id="content">
- <form id="reserve-create" action="reserve-create-sepa.html">
- <table>
- <tr>
- <td class="label"><label for="mint">Mint URL:</label></td>
- <td class="input"><input name="mint" type="text" /></td>
- </tr>
- <tr>
- <td class="label"><label for="amount">Amount:</label></td>
- <td class="input"><input name="amount" type="text" /></td>
- </tr>
- <tr>
- <td class="label"></td>
- <td class="input"><input type="submit" value="Create reserve " /></td>
- </tr>
- </table>
- </form>
- </div>
-
- <div id="footer" class="nav">
- <a href="reserves.html">List reserves</a>
- <a href="reserve-create.html" class="active">Create reserve</a>
- </div>
-
- </body>
-</html>
diff --git a/extension/popup/reserves.html b/extension/popup/reserves.html
deleted file mode 100644
index 424f59d3c..000000000
--- a/extension/popup/reserves.html
+++ /dev/null
@@ -1,28 +0,0 @@
-<!DOCTYPE html>
-
-<html>
- <head>
- <meta charset="utf-8">
- <link rel="stylesheet" href="popup.css" type="text/css">
- </head>
-
- <body>
- <div id="header" class="nav">
- <a href="balance-overview.html">Wallet</a>
- <a href="history.html">Transactions</a>
- <a href="reserves.html" class="active">Reserves</a>
- </div>
-
- <div id="content">
- <div id="reserves">
- There are no reserves available.
- </div>
- </div>
-
- <div id="footer" class="nav">
- <a href="reserves.html" class="active">List reserves</a>
- <a href="reserve-create.html">Create reserve</a>
- </div>
-
- </body>
-</html>