Add iframe component
This commit is contained in:
parent
4a9f517d85
commit
dfb11c0912
@ -24,6 +24,7 @@ import EnvironmentVariablesForm from 'pages/org-slug/projects/id/settings/Enviro
|
||||
import { EnvironmentVariablesFormValues } from 'types/types';
|
||||
import ConnectWallet from './ConnectWallet';
|
||||
import { useWalletConnectClient } from 'context/WalletConnectContext';
|
||||
import IframeComponent from './IFrame';
|
||||
|
||||
type ConfigureDeploymentFormValues = {
|
||||
option: string;
|
||||
@ -534,10 +535,8 @@ const Configure = () => {
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Heading as="h4" className="md:text-lg font-medium mb-3">
|
||||
Connect to your wallet
|
||||
</Heading>
|
||||
<ConnectWallet onAccountChange={onAccountChange} />
|
||||
<IframeComponent />
|
||||
{accounts.length > 0 && (
|
||||
<div>
|
||||
<Button
|
||||
|
61
packages/frontend/src/components/projects/create/IFrame.tsx
Normal file
61
packages/frontend/src/components/projects/create/IFrame.tsx
Normal file
@ -0,0 +1,61 @@
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
|
||||
const IframeComponent: React.FC = () => {
|
||||
const [localStorageData, setLocalStorageData] = useState<string | null>(null);
|
||||
const iframeRef = useRef<HTMLIFrameElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// Listen for messages from the iframe
|
||||
const handleMessage = (event: MessageEvent) => {
|
||||
if (event.origin !== 'https://wallet.laconic.com') return; // Ensure it's from the iframe
|
||||
|
||||
const { action, key, value } = event.data;
|
||||
|
||||
if (action === 'localStorageDataResponse' && key === 'accountIndices/cosmos:laconic-testnet-2') {
|
||||
setLocalStorageData(value); // Update state with the value from localStorage
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleMessage);
|
||||
|
||||
// Cleanup listener on unmount
|
||||
return () => {
|
||||
window.removeEventListener('message', handleMessage);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Send a message to the iframe to get data from localStorage
|
||||
const requestLocalStorageData = (key: string) => {
|
||||
if (iframeRef.current && iframeRef.current.contentWindow) {
|
||||
iframeRef.current.contentWindow.postMessage(
|
||||
{ action: 'getLocalStorageData', key }, // Send key to request data
|
||||
'https://wallet.laconic.com'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Call to request localStorage data when component mounts
|
||||
useEffect(() => {
|
||||
requestLocalStorageData('accountIndices/cosmos:laconic-testnet-2');
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<iframe
|
||||
// ref={iframeRef}
|
||||
id="walletIframe"
|
||||
src="https://wallet.laconic.com"
|
||||
width="500" height="300"
|
||||
sandbox="allow-scripts allow-same-origin"
|
||||
></iframe>
|
||||
|
||||
{localStorageData ? (
|
||||
<p>LocalStorage Data: {localStorageData}</p>
|
||||
) : (
|
||||
<p>Loading localStorage data...</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default IframeComponent;
|
Loading…
Reference in New Issue
Block a user