From ffa23fc8749d2dab3a41afafb20c804fe664c7c2 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Tue, 11 Feb 2025 12:06:26 +0530 Subject: [PATCH] Update check for displaying deploy button --- .../components/projects/create/Configure.tsx | 50 +++++++++---------- .../frontend/src/hooks/useFetchBalance.tsx | 9 ++-- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/packages/frontend/src/components/projects/create/Configure.tsx b/packages/frontend/src/components/projects/create/Configure.tsx index a8bc348b..edd3edc4 100644 --- a/packages/frontend/src/components/projects/create/Configure.tsx +++ b/packages/frontend/src/components/projects/create/Configure.tsx @@ -422,7 +422,7 @@ const Configure = () => { }, []); useEffect(() => { - if(isAccountsDataReceived) { + if (isAccountsDataReceived) { checkBalance(); } }, [amountToBePaid, selectedAccount, selectedDeployer, isAccountsDataReceived]); @@ -589,31 +589,29 @@ const Configure = () => { ) : (
- {selectedAccount && ( - - )} + {isAccountsDataReceived && isBalanceSufficient !== undefined ? ( (!selectedAccount || !isBalanceSufficient) ? ( diff --git a/packages/frontend/src/hooks/useFetchBalance.tsx b/packages/frontend/src/hooks/useFetchBalance.tsx index f1a3418a..be5ee33c 100644 --- a/packages/frontend/src/hooks/useFetchBalance.tsx +++ b/packages/frontend/src/hooks/useFetchBalance.tsx @@ -3,9 +3,7 @@ import { useState, useEffect, useCallback } from 'react'; import { VITE_LACONICD_CHAIN_ID } from 'utils/constants'; const useCheckBalance = (amount: string, iframeId: string) => { - const [isBalanceSufficient, setIsBalanceSufficient] = useState(undefined); - - const chainId = VITE_LACONICD_CHAIN_ID; + const [isBalanceSufficient, setIsBalanceSufficient] = useState(); const checkBalance = useCallback(() => { const iframe = document.getElementById(iframeId) as HTMLIFrameElement; @@ -18,16 +16,17 @@ const useCheckBalance = (amount: string, iframeId: string) => { iframe.contentWindow.postMessage( { type: 'CHECK_BALANCE', - chainId, + chainId: VITE_LACONICD_CHAIN_ID, amount, }, import.meta.env.VITE_WALLET_IFRAME_URL ); - }, [iframeId, chainId, amount]); + }, [iframeId, amount]); useEffect(() => { const handleMessage = (event: MessageEvent) => { if (event.origin !== import.meta.env.VITE_WALLET_IFRAME_URL) return; + if (event.data.type !== 'IS_SUFFICIENT') return; setIsBalanceSufficient(event.data.data);