diff options
author | Florian Dold <florian.dold@gmail.com> | 2015-12-07 23:39:25 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2015-12-07 23:39:25 +0100 |
commit | 415570a720a7a74b2d25699a55d03403e6d6231a (patch) | |
tree | 1fb56e2adc5da40bfd7247a42b41e5cf6d9d69b0 /extension/background/wallet.js | |
parent | aeac228df7121dada4827ac248e61ba8b1db7318 (diff) | |
download | wallet-core-415570a720a7a74b2d25699a55d03403e6d6231a.tar.xz |
Towards reserve creation.
Diffstat (limited to 'extension/background/wallet.js')
-rw-r--r-- | extension/background/wallet.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/extension/background/wallet.js b/extension/background/wallet.js index 1e8dd6a7c..2d3687f98 100644 --- a/extension/background/wallet.js +++ b/extension/background/wallet.js @@ -17,6 +17,8 @@ DB.open(function () { console.log ("DB: ready"); }); +let DONE = 4; + chrome.runtime.onMessage.addListener( function (req, sender, onresponse) { console.log("Message: " + req.type + @@ -36,5 +38,38 @@ chrome.runtime.onMessage.addListener( case "db-list-reserves": DB.reserve_list (onresponse); break; + case "confirm-reserve": + console.log('detail: ' + JSON.stringify(req.detail)); + let keypair = createEddsaKeyPair(); + let form = new FormData(); + form.append(req.detail.field_amount, req.detail.amount_str); + form.append(req.detail.field_reserve_pub, keypair.pub); + form.append(req.detail.field_mint, req.detail.mint); + // XXX: set bank-specified fields. + let myRequest = new XMLHttpRequest(); + console.log("making request to " + req.detail.post_url); + myRequest.open('post', req.detail.post_url); + myRequest.send(form); + myRequest.addEventListener('readystatechange', (e) => { + if (myRequest.readyState == DONE) { + let resp = {}; + resp.status = myRequest.status; + resp.text = myRequest.responseText; + switch (myRequest.status) { + case 200: + resp.success = true; + // We can't show the page directly, so + // we show some generic page from the wallet. + resp.backlink = chrome.extension.getURL("pages/reserve-success.html"); + break; + default: + resp.success = false; + } + onresponse(resp); + } + }); + // Allow async response + return true; + break; } }); |