Integrate wallet IFrame for payments #42

Merged
nabarun merged 27 commits from iv-integrate-frame into main 2024-11-13 13:32:28 +00:00
2 changed files with 63 additions and 3 deletions
Showing only changes of commit dfb11c0912 - Show all commits

View File

@ -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

View 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;