Skip to content

Commit

Permalink
Send ERROR event when something goes wrong in event processing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
r-n-o committed Nov 16, 2023
1 parent 9caa023 commit fb96ea7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
22 changes: 17 additions & 5 deletions export/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,30 @@ <h2>Message log</h2>

// 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);

Expand Down Expand Up @@ -522,7 +534,7 @@ <h2>Message log</h2>
}

/**
* 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 => {
Expand Down
20 changes: 16 additions & 4 deletions recovery/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -795,18 +795,30 @@ <h2>Message log</h2>

// 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);

Expand Down

0 comments on commit fb96ea7

Please sign in to comment.