diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/wxBackend.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/wxBackend.ts | 115 |
1 files changed, 58 insertions, 57 deletions
diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts index f5483e807..532b28622 100644 --- a/packages/taler-wallet-webextension/src/wxBackend.ts +++ b/packages/taler-wallet-webextension/src/wxBackend.ts @@ -121,69 +121,70 @@ async function dispatch( }; }; - switch (req.operation) { - case "wxGetDiagnostics": { - r = wrapResponse(await getDiagnostics()); - break; - } - case "reset-db": { - await deleteTalerDatabase(indexedDB as any); - r = wrapResponse(await reinitWallet()); - break; - } - case "run-gc": { - logger.info("gc") - const dump = await exportDb(currentDatabase!.idbHandle()); - await deleteTalerDatabase(indexedDB as any); - logger.info("cleaned") - await reinitWallet(); - logger.info("init") - await importDb(currentDatabase!.idbHandle(), dump) - logger.info("imported") - r = wrapResponse({ result: true }); - break; - } - case "containsHeaderListener": { - const res = await platform.containsTalerHeaderListener(); - r = wrapResponse({ newValue: res }); - break; - } - case "toggleHeaderListener": { - const newVal = req.payload.value; - logger.trace("new extended permissions value", newVal); - if (newVal) { - platform.registerTalerHeaderListener(parseTalerUriAndRedirect); - r = wrapResponse({ newValue: true }); - } else { - const rem = await platform.getPermissionsApi().removeHostPermissions(); - logger.trace("permissions removed:", rem); - r = wrapResponse({ newVal: false }); + try { + switch (req.operation) { + case "wxGetDiagnostics": { + r = wrapResponse(await getDiagnostics()); + break; } - break; - } - default: { - const w = currentWallet; - if (!w) { - r = { - type: "error", - id: req.id, - operation: req.operation, - error: makeErrorDetail( - TalerErrorCode.WALLET_CORE_NOT_AVAILABLE, - {}, - "wallet core not available", - ), - }; + case "reset-db": { + await deleteTalerDatabase(indexedDB as any); + r = wrapResponse(await reinitWallet()); + break; + } + case "run-gc": { + logger.info("gc") + const dump = await exportDb(currentDatabase!.idbHandle()); + await deleteTalerDatabase(indexedDB as any); + logger.info("cleaned") + await reinitWallet(); + logger.info("init") + await importDb(currentDatabase!.idbHandle(), dump) + logger.info("imported") + r = wrapResponse({ result: true }); + break; + } + case "containsHeaderListener": { + const res = await platform.containsTalerHeaderListener(); + r = wrapResponse({ newValue: res }); + break; + } + case "toggleHeaderListener": { + const newVal = req.payload.value; + logger.trace("new extended permissions value", newVal); + if (newVal) { + platform.registerTalerHeaderListener(parseTalerUriAndRedirect); + r = wrapResponse({ newValue: true }); + } else { + const rem = await platform.getPermissionsApi().removeHostPermissions(); + logger.trace("permissions removed:", rem); + r = wrapResponse({ newVal: false }); + } + break; + } + default: { + const w = currentWallet; + if (!w) { + r = { + type: "error", + id: req.id, + operation: req.operation, + error: makeErrorDetail( + TalerErrorCode.WALLET_CORE_NOT_AVAILABLE, + {}, + "wallet core not available", + ), + }; + break; + } + r = await w.handleCoreApiRequest(req.operation, req.id, req.payload); break; } - r = await w.handleCoreApiRequest(req.operation, req.id, req.payload); - break; } - } - try { sendResponse(r); } catch (e) { + logger.error(`Error sending operation: ${req.operation}`, e) // might fail if tab disconnected } } @@ -231,7 +232,7 @@ async function reinitWallet(): Promise<void> { }); platform.keepAlive(() => { - wallet.runTaskLoop().catch((e) => { + return wallet.runTaskLoop().catch((e) => { logger.error("error during wallet task loop", e); }); }) |