From cf09fa412f93cdc0ef9b64e1794813ba8411aa9a Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Mon, 28 Oct 2024 14:48:38 +0530 Subject: [PATCH] Display wallet connect only when payment is required --- .../components/projects/create/Configure.tsx | 72 ++++++++++++++----- .../projects/create/ConnectWallet.tsx | 1 + .../src/context/WalletConnectContext.tsx | 4 +- packages/frontend/src/utils/web3modal.ts | 5 +- 4 files changed, 59 insertions(+), 23 deletions(-) diff --git a/packages/frontend/src/components/projects/create/Configure.tsx b/packages/frontend/src/components/projects/create/Configure.tsx index 9a5e1501..711b448b 100644 --- a/packages/frontend/src/components/projects/create/Configure.tsx +++ b/packages/frontend/src/components/projects/create/Configure.tsx @@ -35,12 +35,15 @@ type ConfigureDeploymentFormValues = { type ConfigureFormValues = ConfigureDeploymentFormValues & EnvironmentVariablesFormValues; +const DEFAULT_MAX_PRICE = '10000'; + const Configure = () => { const { signClient, session, accounts } = useWalletConnectClient(); const [isLoading, setIsLoading] = useState(false); const [deployers, setDeployers] = useState([]); const [selectedAccount, setSelectedAccount] = useState(); + const [selectedDeployer, setSelectedDeployer] = useState(); const [isPaymentLoading, setIsPaymentLoading] = useState(false); const [isPaymentDone, setIsPaymentDone] = useState(false); @@ -64,9 +67,9 @@ const Configure = () => { const methods = useForm({ defaultValues: { option: 'Auction', - maxPrice: '0', + maxPrice: DEFAULT_MAX_PRICE, lrn: '', - numProviders: 0, + numProviders: 1, }, }); @@ -214,12 +217,12 @@ const Configure = () => { txHash = txHashResponse; - const isTxHashValid = verifyTx( + const isTxHashValid = await verifyTx( senderAddress, txHash, amount.toString(), ); - if (!isTxHashValid) { + if (isTxHashValid === false) { console.error('Invalid Tx hash', txHash); return; } @@ -276,6 +279,11 @@ const Configure = () => { setSelectedAccount(account); }, []); + const onDeployerChange = useCallback((selectedLrn: string) => { + const deployer = deployers.find((d) => d.deployerLrn === selectedLrn); + setSelectedDeployer(deployer); + }, [deployers]); + const cosmosSendTokensHandler = useCallback( async (selectedAccount: string, amount: string) => { if (!signClient || !session || !selectedAccount) { @@ -410,7 +418,10 @@ const Configure = () => {