From fb96ea7b3a7df4c0edaec391c568b2a4288de620 Mon Sep 17 00:00:00 2001 From: Arnaud Brousseau Date: Thu, 16 Nov 2023 17:52:45 -0600 Subject: [PATCH] Send ERROR event when something goes wrong in event processing logic --- export/index.html | 22 +++++++++++++++++----- recovery/index.html | 20 ++++++++++++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/export/index.html b/export/index.html index 005f41d..1846ca6 100644 --- a/export/index.html +++ b/export/index.html @@ -340,18 +340,30 @@

Message log

// TODO: find a way to filter messages and ensure they're coming from the parent window? // We do not want to arbitrarily receive messages from all origins. - window.addEventListener("message", event => { + window.addEventListener("message", async function(event) { if (event.data && event.data["type"] == "INJECT_KEY_EXPORT_BUNDLE") { TKHQ.logMessage(`⬇️ Received message ${event.data["type"]}: ${event.data["value"]}`); - onInjectKeyBundle(event.data["value"]) + try { + await onInjectKeyBundle(event.data["value"]) + } catch (e) { + TKHQ.sendMessageUp("ERROR", e.toString()); + } } if (event.data && event.data["type"] == "INJECT_WALLET_EXPORT_BUNDLE") { TKHQ.logMessage(`⬇️ Received message ${event.data["type"]}: ${event.data["value"]}`); - onInjectWalletBundle(event.data["value"]) + try { + await onInjectWalletBundle(event.data["value"]) + } catch (e) { + TKHQ.sendMessageUp("ERROR", e.toString()); + } } if (event.data && event.data["type"] == "RESET_EMBEDDED_KEY") { TKHQ.logMessage(`⬇️ Received message ${event.data["type"]}`); - TKHQ.onResetEmbeddedKey(); + try { + TKHQ.onResetEmbeddedKey(); + } catch (e) { + TKHQ.sendMessageUp("ERROR", e.toString()); + } } }, false); @@ -522,7 +534,7 @@

Message log

} /** - * Function triggered when INJECT_KEY_EXPORT_BUNDLE event is received. + * Function triggered when INJECT_WALLET_EXPORT_BUNDLE event is received. * @param {string} bundle */ const onInjectWalletBundle = async bundle => { diff --git a/recovery/index.html b/recovery/index.html index caf260b..46e82b9 100644 --- a/recovery/index.html +++ b/recovery/index.html @@ -795,18 +795,30 @@

Message log

// TODO: find a way to filter messages and ensure they're coming from the parent window? // We do not want to arbitrarily receive messages from all origins. - window.addEventListener("message", function(event) { + window.addEventListener("message", async function(event) { if (event.data && event.data["type"] == "INJECT_RECOVERY_BUNDLE") { TKHQ.logMessage(`⬇️ Received message ${event.data["type"]}: ${event.data["value"]}`); - onInjectBundle(event.data["value"]) + try { + await onInjectBundle(event.data["value"]) + } catch (e) { + TKHQ.sendMessageUp("ERROR", e.toString()); + } } if (event.data && event.data["type"] == "STAMP_REQUEST") { TKHQ.logMessage(`⬇️ Received message ${event.data["type"]}: ${event.data["value"]}`); - onStampRequest(event.data["value"]); + try { + await onStampRequest(event.data["value"]); + } catch (e) { + TKHQ.sendMessageUp("ERROR", e.toString()); + } } if (event.data && event.data["type"] == "RESET_EMBEDDED_KEY") { TKHQ.logMessage(`⬇️ Received message ${event.data["type"]}`); - TKHQ.onResetEmbeddedKey(); + try { + TKHQ.onResetEmbeddedKey(); + } catch (e) { + TKHQ.sendMessageUp("ERROR", e.toString()); + } } }, false);