From 356a2eb01a792e4e5ef1887ef02ad2d7c1613ca3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 6 Sep 2016 14:39:45 +0200 Subject: refactor shop api event handling --- lib/wallet/wxMessaging.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'lib/wallet') diff --git a/lib/wallet/wxMessaging.ts b/lib/wallet/wxMessaging.ts index 68c744901..faff0d220 100644 --- a/lib/wallet/wxMessaging.ts +++ b/lib/wallet/wxMessaging.ts @@ -15,7 +15,13 @@ */ -import {Wallet, Offer, Badge, ConfirmReserveRequest, CreateReserveRequest} from "./wallet"; +import { + Wallet, + Offer, + Badge, + ConfirmReserveRequest, + CreateReserveRequest +} from "./wallet"; import {deleteDb, exportDb, openTalerDb} from "./db"; import {BrowserHttpLib} from "./http"; import {Checkable} from "./checkable"; @@ -230,16 +236,9 @@ class ChromeNotifier implements Notifier { } } -function executePayment(contractHash: string, payUrl: string, offerUrl: string) { -} - -function offerContractFromUrl(contractUrl: string) { - -} - - -function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url) { +function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], + url): any { const headers = {}; for (let kv of headerList) { headers[kv.name.toLowerCase()] = kv.value; @@ -249,8 +248,10 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url) { if (contractUrl !== undefined) { // The web shop is proposing a contract, we need to fetch it // and show it to the user - offerContractFromUrl(contractUrl); - return; + const walletUrl = URI(chrome.extension.getURL( + "pages/offer-contract-from.html")); + walletUrl.query({contractUrl}); + return {redirectUrl: walletUrl.href()}; } const contractHash = headers["x-taler-contract-hash"]; @@ -264,14 +265,15 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url) { // Offer URL is optional const offerUrl = headers["x-taler-offer-url"]; - executePayment(contractHash, payUrl, offerUrl); - return; + const walletUrl = URI(chrome.extension.getURL( + "pages/execute-payment.html")); + walletUrl.query({contractHash, offerUrl, payUrl}); + return {redirectUrl: walletUrl.href()}; } // looks like it's not a taler request, it might be // for a different payment system (or the shop is buggy) console.log("ignoring non-taler 402 response"); - } @@ -330,8 +332,7 @@ export function wxMain() { return; } return handleHttpPayment(details.responseHeaders, details.url); - details.responseHeaders - }, {urls: [""]}, ["responseHeaders"]); + }, {urls: [""]}, ["responseHeaders", "blocking"]); }) -- cgit v1.2.3