diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-02-09 21:56:06 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-02-09 21:56:06 +0100 |
commit | 5e85cd8b8fa25ed3fbfc260b48bcad098978407a (patch) | |
tree | 3c875261e2c3fa2176911caefc4dcf225a04df74 /extension/pages/confirm-create-reserve.js | |
parent | 42a0076f5951d303635b2e544aa66112cdb9abfe (diff) | |
download | wallet-core-5e85cd8b8fa25ed3fbfc260b48bcad098978407a.tar.xz |
new reserve creation protocol
Diffstat (limited to 'extension/pages/confirm-create-reserve.js')
-rw-r--r-- | extension/pages/confirm-create-reserve.js | 56 |
1 files changed, 42 insertions, 14 deletions
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"; } } }); |