From 857500dc9f38b8e5836336f780b86683d5e3d804 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Thu, 25 Apr 2024 14:32:47 -0500 Subject: [PATCH] move window event listener to be registered sooner --- frontend/src/Widget.jsx | 7 ------- frontend/src/main.jsx | 8 ++++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/frontend/src/Widget.jsx b/frontend/src/Widget.jsx index 85427ba..c4a26a2 100644 --- a/frontend/src/Widget.jsx +++ b/frontend/src/Widget.jsx @@ -253,13 +253,6 @@ function Widget() { useEffect(() => { console.log('window.location', window.location); - window.addEventListener( - 'message', - (event) => { - if (event.data?.target?.startsWith('metamask')) return; - console.log('window message', event); - }, - ); window.widgetApiPromise.then((api) => { console.log('widgetApi promise resolved', api); diff --git a/frontend/src/main.jsx b/frontend/src/main.jsx index 3ddfdd2..faafc0b 100644 --- a/frontend/src/main.jsx +++ b/frontend/src/main.jsx @@ -14,6 +14,14 @@ import Widget from './Widget'; window.widgetApiPromise = WidgetApiImpl.create({}); +window.addEventListener( + 'message', + (event) => { + if (event.data?.target?.startsWith('metamask')) return; + console.log('window message', event); + }, +); + const router = createBrowserRouter([ { path: '/',