Set iframe visiblity conditionally
This commit is contained in:
parent
d862a02f92
commit
f3645ab487
@ -38,14 +38,16 @@ type ConfigureFormValues = ConfigureDeploymentFormValues &
|
|||||||
const DEFAULT_MAX_PRICE = '10000';
|
const DEFAULT_MAX_PRICE = '10000';
|
||||||
|
|
||||||
const Configure = () => {
|
const Configure = () => {
|
||||||
const { signClient, session, accounts } = useWalletConnectClient();
|
const { signClient, session } = useWalletConnectClient();
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [deployers, setDeployers] = useState<Deployer[]>([]);
|
const [deployers, setDeployers] = useState<Deployer[]>([]);
|
||||||
const [selectedAccount, setSelectedAccount] = useState<string>();
|
const [selectedAccount, setSelectedAccount] = useState<string>();
|
||||||
|
const [accounts, setAccounts] = useState<string[]>([]);
|
||||||
const [selectedDeployer, setSelectedDeployer] = useState<Deployer>();
|
const [selectedDeployer, setSelectedDeployer] = useState<Deployer>();
|
||||||
const [isPaymentLoading, setIsPaymentLoading] = useState(false);
|
const [isPaymentLoading, setIsPaymentLoading] = useState(false);
|
||||||
const [isPaymentDone, setIsPaymentDone] = useState(false);
|
const [isPaymentDone, setIsPaymentDone] = useState(false);
|
||||||
|
const [isFrameVisible, setIsFrameVisible] = useState(false);
|
||||||
|
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const templateId = searchParams.get('templateId');
|
const templateId = searchParams.get('templateId');
|
||||||
@ -175,6 +177,7 @@ const Configure = () => {
|
|||||||
const handleFormSubmit = useCallback(
|
const handleFormSubmit = useCallback(
|
||||||
async (createFormData: FieldValues) => {
|
async (createFormData: FieldValues) => {
|
||||||
try {
|
try {
|
||||||
|
setIsFrameVisible(true);
|
||||||
const deployerLrn = createFormData.lrn;
|
const deployerLrn = createFormData.lrn;
|
||||||
const deployer = deployers.find(
|
const deployer = deployers.find(
|
||||||
(deployer) => deployer.deployerLrn === deployerLrn,
|
(deployer) => deployer.deployerLrn === deployerLrn,
|
||||||
@ -534,7 +537,7 @@ const Configure = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<IFrame onAccountChange={onAccountChange} />
|
<IFrame accounts={accounts} setAccounts={setAccounts} onAccountChange={onAccountChange} isVisible={isFrameVisible} />
|
||||||
{accounts.length > 0 && (
|
{accounts.length > 0 && (
|
||||||
<div>
|
<div>
|
||||||
<Button
|
<Button
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
import { Select, Option } from '@snowballtools/material-tailwind-react-fork';
|
import { Select, Option } from '@snowballtools/material-tailwind-react-fork';
|
||||||
import { VITE_LACONICD_CHAIN_ID } from 'utils/constants';
|
import { VITE_LACONICD_CHAIN_ID } from 'utils/constants';
|
||||||
|
|
||||||
const IFrame = ({
|
const IFrame = ({
|
||||||
|
accounts,
|
||||||
|
setAccounts,
|
||||||
onAccountChange,
|
onAccountChange,
|
||||||
|
isVisible,
|
||||||
}: {
|
}: {
|
||||||
|
accounts: string[];
|
||||||
|
setAccounts: (accounts: string[]) => void
|
||||||
onAccountChange: (selectedAccount: string) => void;
|
onAccountChange: (selectedAccount: string) => void;
|
||||||
|
isVisible: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const [accounts, setAccounts] = useState<string[]>([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleMessage = (event: MessageEvent) => {
|
const handleMessage = (event: MessageEvent) => {
|
||||||
if (event.origin !== 'http://localhost:3001') return;
|
if (event.origin !== 'http://localhost:3001') return;
|
||||||
@ -22,11 +26,6 @@ const IFrame = ({
|
|||||||
|
|
||||||
window.addEventListener('message', handleMessage);
|
window.addEventListener('message', handleMessage);
|
||||||
|
|
||||||
const iframe = document.getElementById('walletIframe');
|
|
||||||
if (iframe) {
|
|
||||||
iframe.onload = getDataFromWallet;
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('message', handleMessage);
|
window.removeEventListener('message', handleMessage);
|
||||||
};
|
};
|
||||||
@ -84,11 +83,12 @@ const IFrame = ({
|
|||||||
onLoad={getDataFromWallet}
|
onLoad={getDataFromWallet}
|
||||||
id="walletIframe"
|
id="walletIframe"
|
||||||
src="http://localhost:3001"
|
src="http://localhost:3001"
|
||||||
width="510"
|
width={isVisible ? "510": 0}
|
||||||
height="300"
|
height={isVisible ? "300": 0}
|
||||||
sandbox="allow-scripts allow-same-origin"
|
sandbox="allow-scripts allow-same-origin"
|
||||||
className="border rounded-md shadow-sm mt-4"
|
className={`border rounded-md shadow-sm transition-opacity duration-300 ${
|
||||||
title="Wallet Integration"
|
isVisible ? 'opacity-100 visible mt-4 ' : 'opacity-0 invisible'
|
||||||
|
}`}
|
||||||
></iframe>
|
></iframe>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user