Skip to content

Commit

Permalink
fix message passing in Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
yushih committed Oct 21, 2024
1 parent 450bd41 commit c1bb4c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/yoroi-extension/app/api/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,19 @@ const callbacks = Object.freeze({
serverStatusUpdate: [],
coinPriceUpdate: [],
});
chrome.runtime.onMessage.addListener(async (message, _sender, _sendResponse) => {
chrome.runtime.onMessage.addListener(async (serializedMessage, _sender, _sendResponse) => {
//fixme: verify sender.id/origin
Logger.debug('get message from background:', JSON.stringify(message, null, 2));
Logger.debug('get message from background:', serializedMessage);

let message;
try {
message = JSON.parse(serializedMessage);
} catch {
return;
}
if (typeof message !== 'object') {
return;
}

if (message.type === 'wallet-state-update') {
if (message.params.newTxs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ declare var chrome;
*/
export function emitUpdateToSubscriptions(data: Object): void {
for (const { tabId } of getSubscriptions()) {
chrome.tabs.sendMessage(tabId, data);
chrome.tabs.sendMessage(tabId, JSON.stringify(data));
}
}

0 comments on commit c1bb4c5

Please sign in to comment.