diff options
Diffstat (limited to 'extension/pages')
-rw-r--r-- | extension/pages/confirm-create-reserve.html | 85 | ||||
-rw-r--r-- | extension/pages/confirm-create-reserve.js | 56 | ||||
-rw-r--r-- | extension/pages/confirm-create-reserve.tsx | 48 | ||||
-rw-r--r-- | extension/pages/show-db.js | 43 | ||||
-rw-r--r-- | extension/pages/show-db.ts | 44 |
5 files changed, 187 insertions, 89 deletions
diff --git a/extension/pages/confirm-create-reserve.html b/extension/pages/confirm-create-reserve.html index b78f96712..7af54a828 100644 --- a/extension/pages/confirm-create-reserve.html +++ b/extension/pages/confirm-create-reserve.html @@ -1,43 +1,50 @@ <!doctype html> <html> - <head> - <title>Taler Wallet: Select Taler Provider</title> - <script src="../lib/vendor/URI.js"></script> - <script src="../lib/vendor/system-csp-production.src.js"></script> - <script src="../lib/module-trampoline.js"></script> - <link rel="stylesheet" type="text/css" href="../style/wallet.css"> - </head> - - <body> - - <header> - <div id="logo"></div> - <h1>Select Taler Provider</h1> - </header> - - <aside class="sidebar" id="left"> - </aside> - - <section id="main"> - - <article> - <p> - You asked to withdraw <span id="show-amount">(loading...)</span> from your bank account. - </p> - <p> - Please specify the base URL of the Taler mint you want to use. The Taler mint will process the payments, possibly for a fee. The mint underwrites electronic coins and will hold matching funds in reserve in its bank account. Mints are expected to be regularly audited by a trusted party to ensure that they have sufficient reserves to cover all outstanding obligations. - </p> - - <div class="formish"> - <div class="form-row"> - <label for="mint-url">Mint URL</label> - <input class="url" id="mint-url" type="text" value="http://mint.demo.taler.net/"></input> - </div> - <button id="confirm">Confirm Mint Selection</button> - </div> - </article> - - </section> - </body> +<head> + <title>Taler Wallet: Select Taler Provider</title> + <script src="../lib/vendor/URI.js"></script> + <script src="../lib/vendor/system-csp-production.src.js"></script> + <script src="../lib/module-trampoline.js"></script> + <link rel="stylesheet" type="text/css" href="../style/wallet.css"> +</head> + +<body> + +<header> + <div id="logo"></div> + <h1>Select Taler Provider</h1> +</header> + +<aside class="sidebar" id="left"> +</aside> + +<section id="main"> + + <article> + <p> + You asked to withdraw <span id="show-amount">(loading...)</span> from your + bank account. + </p> + <p> + Please specify the base URL of the Taler mint you want to use. The Taler + mint will process the payments, possibly for a fee. The mint underwrites + electronic coins and will hold matching funds in reserve in its bank + account. Mints are expected to be regularly audited by a trusted party to + ensure that they have sufficient reserves to cover all outstanding + obligations. + </p> + + <div class="formish"> + <div class="form-row"> + <label for="mint-url">Mint URL</label> + <input class="url" id="mint-url" type="text" + value="http://mint.demo.taler.net/"/> + </div> + <button id="confirm">Confirm Mint Selection</button> + </div> + </article> + +</section> +</body> </html> diff --git a/extension/pages/confirm-create-reserve.js b/extension/pages/confirm-create-reserve.js index ca9ef4099..a53833f04 100644 --- a/extension/pages/confirm-create-reserve.js +++ b/extension/pages/confirm-create-reserve.js @@ -13,41 +13,69 @@ 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/> */ -System.register([], function(exports_1) { +System.register(["../lib/wallet/types", "../lib/web-common"], function(exports_1) { "use strict"; + var types_1, web_common_1, types_2; function main() { function updateAmount() { var showAmount = document.getElementById("show-amount"); console.log("Query is " + JSON.stringify(query)); - var s = query.amount_str; - if (!s) { - document.body.innerHTML = "Oops, something went wrong."; - return; - } - showAmount.textContent = s; + var amount = types_1.AmountJson.checked(JSON.parse(query.amount)); + showAmount.textContent = web_common_1.amountToPretty(amount); } var url = URI(document.location.href); var query = URI.parseQuery(url.query()); updateAmount(); document.getElementById("confirm").addEventListener("click", function (e) { - var d = Object.assign({}, query); - d.mint = document.getElementById('mint-url').value; - var cb = function (resp) { - if (resp.success === true) { - document.location.href = resp.backlink; + var d = { + mint: document.getElementById('mint-url').value, + amount: JSON.parse(query.amount) + }; + if (!d.mint) { + // FIXME: indicate error instead! + throw Error("mint missing"); + } + if (!d.amount) { + // FIXME: indicate error instead! + throw Error("amount missing"); + } + var cb = function (rawResp) { + if (!rawResp) { + throw Error("empty response"); + } + if (!rawResp.error) { + var resp = types_2.CreateReserveResponse.checked(rawResp); + var q = { + mint: resp.mint, + reserve_pub: resp.reservePub, + amount: query.amount, + }; + var url_1 = URI(query.callback_url).addQuery(q); + if (!url_1.is("absolute")) { + throw Error("callback url is not absolute"); + } + document.location.href = url_1.href(); } else { document.body.innerHTML = "Oops, something went wrong. It looks like the bank could not\n transfer funds to the mint. Please go back to your bank's website\n to check what happened."; } }; - chrome.runtime.sendMessage({ type: 'confirm-reserve', detail: d }, cb); + chrome.runtime.sendMessage({ type: 'create-reserve', detail: d }, cb); }); } exports_1("main", main); return { - setters:[], + setters:[ + function (types_1_1) { + types_1 = types_1_1; + types_2 = types_1_1; + }, + function (web_common_1_1) { + web_common_1 = web_common_1_1; + }], execute: function() { + "use strict"; } } }); diff --git a/extension/pages/confirm-create-reserve.tsx b/extension/pages/confirm-create-reserve.tsx index 88af96466..e4d2d27e6 100644 --- a/extension/pages/confirm-create-reserve.tsx +++ b/extension/pages/confirm-create-reserve.tsx @@ -14,6 +14,9 @@ TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> */ +import {AmountJson} from "../lib/wallet/types"; +import {amountToPretty} from "../lib/web-common"; +import {CreateReserveResponse} from "../lib/wallet/types"; "use strict"; @@ -21,12 +24,8 @@ export function main() { function updateAmount() { let showAmount = document.getElementById("show-amount"); console.log("Query is " + JSON.stringify(query)); - let s = query.amount_str; - if (!s) { - document.body.innerHTML = "Oops, something went wrong."; - return; - } - showAmount.textContent = s; + let amount = AmountJson.checked(JSON.parse(query.amount)); + showAmount.textContent = amountToPretty(amount); } let url = URI(document.location.href); @@ -35,12 +34,37 @@ export function main() { updateAmount(); document.getElementById("confirm").addEventListener("click", (e) => { - let d = Object.assign({}, query); - d.mint = (document.getElementById('mint-url') as HTMLInputElement).value; + const d = { + mint: (document.getElementById('mint-url') as HTMLInputElement).value, + amount: JSON.parse(query.amount) + }; + + if (!d.mint) { + // FIXME: indicate error instead! + throw Error("mint missing"); + } - const cb = (resp) => { - if (resp.success === true) { - document.location.href = resp.backlink; + if (!d.amount) { + // FIXME: indicate error instead! + throw Error("amount missing"); + } + + const cb = (rawResp) => { + if (!rawResp) { + throw Error("empty response"); + } + if (!rawResp.error) { + const resp = CreateReserveResponse.checked(rawResp); + let q = { + mint: resp.mint, + reserve_pub: resp.reservePub, + amount: query.amount, + }; + let url = URI(query.callback_url).addQuery(q); + if (!url.is("absolute")) { + throw Error("callback url is not absolute"); + } + document.location.href = url.href(); } else { document.body.innerHTML = `Oops, something went wrong. It looks like the bank could not @@ -48,6 +72,6 @@ export function main() { to check what happened.`; } }; - chrome.runtime.sendMessage({type: 'confirm-reserve', detail: d}, cb); + chrome.runtime.sendMessage({type: 'create-reserve', detail: d}, cb); }); }
\ No newline at end of file diff --git a/extension/pages/show-db.js b/extension/pages/show-db.js index 1c414dde7..bcd8485cb 100644 --- a/extension/pages/show-db.js +++ b/extension/pages/show-db.js @@ -13,32 +13,27 @@ 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/> */ - - function replacer(match, pIndent, pKey, pVal, pEnd) { - var key = '<span class=json-key>'; - var val = '<span class=json-value>'; - var str = '<span class=json-string>'; - var r = pIndent || ''; - if (pKey) - r = r + key + pKey.replace(/[": ]/g, '') + '</span>: '; - if (pVal) - r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>'; - return r + (pEnd || ''); + var key = '<span class=json-key>'; + var val = '<span class=json-value>'; + var str = '<span class=json-string>'; + var r = pIndent || ''; + if (pKey) + r = r + key + pKey.replace(/[": ]/g, '') + '</span>: '; + if (pVal) + r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>'; + return r + (pEnd || ''); } - - function prettyPrint(obj) { - var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg; - return JSON.stringify(obj, null, 3) - .replace(/&/g, '&').replace(/\\"/g, '"') - .replace(/</g, '<').replace(/>/g, '>') - .replace(jsonLine, replacer); + var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg; + return JSON.stringify(obj, null, 3) + .replace(/&/g, '&').replace(/\\"/g, '"') + .replace(/</g, '<').replace(/>/g, '>') + .replace(jsonLine, replacer); } - - -document.addEventListener("DOMContentLoaded", (e) => { - chrome.runtime.sendMessage({type:'dump-db'}, (resp) => { - document.getElementById('dump').innerHTML = prettyPrint(resp); - }); +document.addEventListener("DOMContentLoaded", function (e) { + chrome.runtime.sendMessage({ type: 'dump-db' }, function (resp) { + document.getElementById('dump').innerHTML = prettyPrint(resp); + }); }); +//# sourceMappingURL=show-db.js.map
\ No newline at end of file diff --git a/extension/pages/show-db.ts b/extension/pages/show-db.ts new file mode 100644 index 000000000..1c414dde7 --- /dev/null +++ b/extension/pages/show-db.ts @@ -0,0 +1,44 @@ +/* + This file is part of TALER + (C) 2015 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/> + */ + + +function replacer(match, pIndent, pKey, pVal, pEnd) { + var key = '<span class=json-key>'; + var val = '<span class=json-value>'; + var str = '<span class=json-string>'; + var r = pIndent || ''; + if (pKey) + r = r + key + pKey.replace(/[": ]/g, '') + '</span>: '; + if (pVal) + r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>'; + return r + (pEnd || ''); +} + + +function prettyPrint(obj) { + var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg; + return JSON.stringify(obj, null, 3) + .replace(/&/g, '&').replace(/\\"/g, '"') + .replace(/</g, '<').replace(/>/g, '>') + .replace(jsonLine, replacer); +} + + +document.addEventListener("DOMContentLoaded", (e) => { + chrome.runtime.sendMessage({type:'dump-db'}, (resp) => { + document.getElementById('dump').innerHTML = prettyPrint(resp); + }); +}); |