aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-09-08 17:26:31 +0200
committerFlorian Dold <florian.dold@gmail.com>2016-09-08 17:26:31 +0200
commita164ea91838b0dd2506acbd67e1b3720abaa7e01 (patch)
tree93b698668cffcc93c2ba3294ff8845dd4d42e439 /lib
parent4b67f220e7d9ab4a7d7a190892f028995baa9902 (diff)
rudimentary 402 handling
Diffstat (limited to 'lib')
-rw-r--r--lib/wallet/wallet.ts7
-rw-r--r--lib/wallet/wxMessaging.ts33
2 files changed, 27 insertions, 13 deletions
diff --git a/lib/wallet/wallet.ts b/lib/wallet/wallet.ts
index 718e7a312..7cb30c358 100644
--- a/lib/wallet/wallet.ts
+++ b/lib/wallet/wallet.ts
@@ -242,9 +242,16 @@ function getWithdrawDenomList(amountAvailable: AmountJson,
let remaining = Amounts.copy(amountAvailable);
let ds: Denomination[] = [];
+ console.log("available denoms");
+ console.log(denoms);
+
denoms = denoms.filter(isWithdrawableDenom);
denoms.sort((d1, d2) => Amounts.cmp(d2.value, d1.value));
+ console.log("withdrawable denoms");
+ console.log(denoms);
+
+
// This is an arbitrary number of coins
// we can withdraw in one go. It's not clear if this limit
// is useful ...
diff --git a/lib/wallet/wxMessaging.ts b/lib/wallet/wxMessaging.ts
index faff0d220..95dcb929a 100644
--- a/lib/wallet/wxMessaging.ts
+++ b/lib/wallet/wxMessaging.ts
@@ -54,7 +54,7 @@ function makeHandlers(db: IDBDatabase,
return exportDb(db);
},
["ping"]: function(detail, sender) {
- return Promise.resolve({});
+ return Promise.resolve(paymentRequestCache[sender.tab.id]);
},
["reset"]: function(detail, sender) {
if (db) {
@@ -237,8 +237,13 @@ class ChromeNotifier implements Notifier {
}
+/**
+ * Mapping from tab ID to payment information (if any).
+ */
+let paymentRequestCache = {};
+
function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[],
- url): any {
+ url: string, tabId: number): any {
const headers = {};
for (let kv of headerList) {
headers[kv.name.toLowerCase()] = kv.value;
@@ -246,12 +251,8 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[],
const contractUrl = headers["x-taler-contract-url"];
if (contractUrl !== undefined) {
- // The web shop is proposing a contract, we need to fetch it
- // and show it to the user
- const walletUrl = URI(chrome.extension.getURL(
- "pages/offer-contract-from.html"));
- walletUrl.query({contractUrl});
- return {redirectUrl: walletUrl.href()};
+ paymentRequestCache[tabId] = {type: "fetch", contractUrl};
+ return;
}
const contractHash = headers["x-taler-contract-hash"];
@@ -265,10 +266,13 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[],
// Offer URL is optional
const offerUrl = headers["x-taler-offer-url"];
- const walletUrl = URI(chrome.extension.getURL(
- "pages/execute-payment.html"));
- walletUrl.query({contractHash, offerUrl, payUrl});
- return {redirectUrl: walletUrl.href()};
+ paymentRequestCache[tabId] = {
+ type: "execute",
+ offerUrl,
+ payUrl,
+ contractHash
+ };
+ return;
}
// looks like it's not a taler request, it might be
@@ -331,7 +335,10 @@ export function wxMain() {
if (details.statusCode != 402) {
return;
}
- return handleHttpPayment(details.responseHeaders, details.url);
+ console.log(`got 402 from ${details.url}`);
+ return handleHttpPayment(details.responseHeaders,
+ details.url,
+ details.tabId);
}, {urls: ["<all_urls>"]}, ["responseHeaders", "blocking"]);