diff --git a/packages/frontend/src/components/projects/create/ConnectWallet.tsx b/packages/frontend/src/components/projects/create/ConnectWallet.tsx index 9dbc6e6a..09bd87bb 100644 --- a/packages/frontend/src/components/projects/create/ConnectWallet.tsx +++ b/packages/frontend/src/components/projects/create/ConnectWallet.tsx @@ -1,29 +1,100 @@ import { Button } from '../../shared/Button'; import { useWalletConnectClient } from 'context/WalletConnectContext'; -// import { useGQLClient } from '../../../context/GQLClientContext'; import { Select, Option } from '@snowballtools/material-tailwind-react-fork'; +import { useGQLClient } from 'context/GQLClientContext'; +import { useCallback, useEffect, useState } from 'react'; + +const TEST_AMOUNT = "10000" const ConnectWallet = () => { - const { onConnect, accounts } = useWalletConnectClient(); - // const client = useGQLClient(); + const { onConnect, accounts, signClient, session } = useWalletConnectClient(); + const client = useGQLClient(); + + const [selectedAccount, setSelectedAccount] = useState<{ + address: string; + balance?: string; + }>(); + const [txHash, setTxHash] = useState(); + const [snowballAddress, setSnowballAddress] = useState(); const handleConnect = async () => { await onConnect(); - // const snowballaddress = await client.getAddress(); }; + const cosmosSendTokensHandler = useCallback( + async (senderAddress: string, amount: string) => { + if (!signClient || !session || !selectedAccount) { + console.log({signClient, session, selectedAccount}) + return; + } + + const chainId = selectedAccount.address.split(':')[1]; + + try { + const result: { + signature: string; + } = await signClient.request({ + topic: session.topic, + chainId: `cosmos:${chainId}`, + request: { + method: 'cosmos_sendTokens', + params: [ + { + from: senderAddress, + to: snowballAddress, + value: amount, + }, + ], + }, + }); + if (!result) { + throw new Error('Error completing transaction'); + } + + setTxHash(result.signature); + console.log(txHash) + } catch (error: any) { + throw error; + } + }, + [session, signClient, selectedAccount], + ); + + const fetchSnowballAddress = useCallback(async() => { + + const address = await client.getAddress(); + setSnowballAddress(address); + + console.log(address) + }, [client]) + + useEffect(() => { + fetchSnowballAddress() + }, []) + return ( <> {!accounts ? ( ) : ( - +
+ + +
)} ); diff --git a/packages/frontend/src/context/WalletConnectContext.tsx b/packages/frontend/src/context/WalletConnectContext.tsx index e4b2e173..3639e161 100644 --- a/packages/frontend/src/context/WalletConnectContext.tsx +++ b/packages/frontend/src/context/WalletConnectContext.tsx @@ -69,7 +69,7 @@ export const WalletConnectClientProvider = ({ const onConnect = async () => { const proposalNamespace = { cosmos: { - methods: ['cosmos_sendTransaction'], + methods: ['cosmos_sendTokens'], chains: [`cosmos:${VITE_LACONICD_CHAIN_ID}`], events: [], }, diff --git a/packages/gql-client/src/client.ts b/packages/gql-client/src/client.ts index 558ccc2c..5bf769d9 100644 --- a/packages/gql-client/src/client.ts +++ b/packages/gql-client/src/client.ts @@ -438,6 +438,6 @@ export class GQLClient { query: queries.getAddress, }); - return data; + return data.address; } }