diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-02-23 14:07:53 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-02-23 14:07:59 +0100 |
commit | 5591077fe9241def5fa33fc90a24681c8b7b0976 (patch) | |
tree | e4020c487d20fd7bfd7b2256ee8f2d88861dcc6a /extension/content_scripts/notify.ts | |
parent | 718f81bcd858bd50373066845727b0cf520ccd06 (diff) | |
download | wallet-core-5591077fe9241def5fa33fc90a24681c8b7b0976.tar.xz |
repurchase detection
Diffstat (limited to 'extension/content_scripts/notify.ts')
-rw-r--r-- | extension/content_scripts/notify.ts | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/extension/content_scripts/notify.ts b/extension/content_scripts/notify.ts index 9a64bcf0c..d300dbc03 100644 --- a/extension/content_scripts/notify.ts +++ b/extension/content_scripts/notify.ts @@ -77,12 +77,40 @@ namespace TalerNotify { document.addEventListener("taler-contract", function(e: CustomEvent) { // XXX: the merchant should just give us the parsed data ... let offer = JSON.parse(e.detail); - let uri = URI(chrome.extension.getURL("pages/confirm-contract.html")); - let params = { - offer: JSON.stringify(offer), - merchantPageUrl: document.location.href, + + if (!offer.contract) { + console.error("contract field missing"); + return; + } + + let msg = { + type: "check-repurchase", + detail: { + contract: offer.contract + }, }; - document.location.href = uri.query(params).href(); + + chrome.runtime.sendMessage(msg, (resp) => { + if (resp.error) { + console.error("wallet backend error", resp); + return; + } + if (resp.isRepurchase) { + console.log("doing repurchase"); + console.assert(resp.existingFulfillmentUrl); + console.assert(resp.existingContractHash); + window.location.href = subst(resp.existingFulfillmentUrl, + resp.existingContractHash); + + } else { + let uri = URI(chrome.extension.getURL("pages/confirm-contract.html")); + let params = { + offer: JSON.stringify(offer), + merchantPageUrl: document.location.href, + }; + document.location.href = uri.query(params).href(); + } + }); }); |