From 8ff441a794b966abefaa5a5d016dc278708cdf9c Mon Sep 17 00:00:00 2001 From: Adw8 Date: Wed, 6 Nov 2024 16:18:45 +0530 Subject: [PATCH] Add event listener for iframe message --- src/index.tsx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index 61a4189..20ed759 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,6 +18,35 @@ import { createTheme, ThemeProvider } from "@mui/material"; globalThis.Buffer = Buffer; +window.addEventListener('message', (event: MessageEvent) => { + if (event.origin !== 'http://localhost:3001') return; + + if (event.data.type === 'REQUEST_LOCAL_STORAGE') { + try { + const data = localStorage.getItem('accounts/cosmos:laconic-testnet-2/0'); + + if (!data) { + event.source?.postMessage({ + type: 'ERROR', + message: 'Data not found in local storage' + }); + return; + } + + (event.source as Window)?.postMessage({ + type: 'LOCAL_STORAGE_DATA', + data + }, 'http://localhost:3001'); + + } catch (error) { + (event.source as Window)?.postMessage({ + type: 'ERROR', + message: 'Error accessing local storage' + }, 'http://localhost:3001'); + } + } +}); + const linking = { prefixes: ["https://wallet.laconic.com"], };