fix merchant page event handling, remove taler-pay for now

This commit is contained in:
Florian Dold 2018-03-07 21:15:01 +01:00
parent 922f628fed
commit c1b11a6668
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -141,15 +141,19 @@ function registerHandlers() {
*/
function addHandler(type: string, handler: HandlerFn) {
const handlerWrap = (e: Event) => {
if (!(e instanceof CustomEvent)) {
if (!(e instanceof Event)) {
console.log("unexpected event", e);
throw Error(`invariant violated`);
}
if (e.type !== type) {
console.log("unexpected event type", e);
throw Error(`invariant violated`);
}
let callId: number | undefined;
if (e.detail && e.detail.callId !== undefined) {
let detail;
if ((e instanceof CustomEvent) && e.detail && e.detail.callId !== undefined) {
callId = e.detail.callId;
detail = e.detail;
}
const responder = (msg?: any) => {
const fullMsg = Object.assign({}, msg, {callId});
@ -160,13 +164,12 @@ function registerHandlers() {
const evt = new CustomEvent(type + "-result", opts);
document.dispatchEvent(evt);
};
handler(e.detail, responder);
handler(detail, responder);
};
document.addEventListener(type, handlerWrap);
handlers.push({type, listener: handlerWrap});
}
addHandler("taler-query-id", (msg: any, sendResponse: any) => {
// FIXME: maybe include this info in taler-probe?
sendResponse({ id: chrome.runtime.id });
@ -207,11 +210,6 @@ function registerHandlers() {
await wxApi.confirmReserve(msg.reserve_pub);
sendResponse();
});
addHandler("taler-pay", async(msg: any, sendResponse: any) => {
const resp = await wxApi.talerPay(msg);
sendResponse(resp);
});
}
logVerbose && console.log("loading Taler content script");