diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-09-09 14:07:54 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-09-09 14:11:55 +0200 |
commit | 7352b62aab893a55e761ad2d8ea3cbc3834f760e (patch) | |
tree | 36c9402a46242ab93ad69456f833db63198b8411 /content_scripts/notify.ts | |
parent | a164ea91838b0dd2506acbd67e1b3720abaa7e01 (diff) | |
download | wallet-core-7352b62aab893a55e761ad2d8ea3cbc3834f760e.tar.xz |
Make JSless payments work.
Diffstat (limited to 'content_scripts/notify.ts')
-rw-r--r-- | content_scripts/notify.ts | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/content_scripts/notify.ts b/content_scripts/notify.ts index ad77a1e37..1d31c929a 100644 --- a/content_scripts/notify.ts +++ b/content_scripts/notify.ts @@ -46,7 +46,7 @@ namespace TalerNotify { } var contract_request = new XMLHttpRequest(); - console.log("downloading contract from '" + url + "'") + console.log("downloading contract from '" + url + "'"); contract_request.open("GET", url, true); contract_request.onload = function (e) { if (contract_request.readyState == 4) { @@ -76,6 +76,9 @@ namespace TalerNotify { /** * Wallet-internal version of executeContract, used for 402 payments. + * + * Even though we're inside a content script, we send events to the dom + * to avoid code duplication. */ function internalExecuteContract(contractHash: string, payUrl: string, offerUrl: string) { @@ -86,25 +89,13 @@ namespace TalerNotify { * synchronous error message (such as an alert) or leave the page. */ function handleFailedPayment(status) { - let timeoutHandle = null; - function err() { - alert("Payment failed: Unexpected status code for $pay_url: " + status); - } - function onResp() { - if (timeoutHandle != null) { - clearTimeout(timeoutHandle); - timeoutHandle = null; - } - err(); - } - function onTimeout() { - timeoutHandle = null; - err(); - } - let eve = new CustomEvent('taler-payment-failed', {detail: {}}); - document.dispatchEvent(eve); - document.addEventListener("taler-payment-failed-ok", onResp, false); - timeoutHandle = setTimeout(onTimeout, 200); + const msg = { + type: "payment-failed", + detail: {}, + }; + chrome.runtime.sendMessage(msg, (resp) => { + alert("payment failed"); + }); } @@ -157,7 +148,7 @@ namespace TalerNotify { }; document.addEventListener("taler-notify-payment", handleResponse, false); - let eve = new CustomEvent('taler-fetch-payment', {detail: detail}); + let eve = new CustomEvent('taler-execute-contract', {detail: detail}); document.dispatchEvent(eve); } @@ -187,14 +178,14 @@ namespace TalerNotify { } }); - console.log(resp); - if (resp.type === "fetch") { + + if (resp && resp.type === "fetch") { console.log("it's fetch"); internalOfferContractFrom(resp.contractUrl); document.documentElement.style.visibility = "hidden"; - } else if (resp.type === "execute") { + } else if (resp && resp.type === "execute") { console.log("it's execute"); document.documentElement.style.visibility = "hidden"; internalExecuteContract(resp.contractHash, resp.payUrl, resp.offerUrl); @@ -333,7 +324,7 @@ namespace TalerNotify { console.log("got resp"); console.dir(resp); if (!resp.success) { - console.log("got event detial:"); + console.log("got event detail:"); console.dir(e.detail); if (e.detail.offering_url) { console.log("offering url", e.detail.offering_url); |