diff --git a/webapps/world-builder-dashboard/src/components/bridge/bridge/ActionButton.tsx b/webapps/world-builder-dashboard/src/components/bridge/bridge/ActionButton.tsx index dcfbf937..ab68b8b8 100644 --- a/webapps/world-builder-dashboard/src/components/bridge/bridge/ActionButton.tsx +++ b/webapps/world-builder-dashboard/src/components/bridge/bridge/ActionButton.tsx @@ -15,7 +15,7 @@ import { getTokensForNetwork, Token } from '@/utils/tokens' import { returnSymbol, ZERO_ADDRESS } from '@/utils/web3utils' import { MultiTokenApproval } from './MultiTokenApproval' import { useBridger } from '@/hooks/useBridger' -import { useConnectModal, useActiveAccount, useActiveWalletChain, darkTheme, ConnectButton } from 'thirdweb/react' +import { useConnectModal, useActiveAccount, darkTheme, ConnectButton } from 'thirdweb/react' import { ethers5Adapter } from "thirdweb/adapters/ethers5"; import { createThirdwebClient, } from 'thirdweb' import { createWallet } from 'thirdweb/wallets' @@ -90,7 +90,6 @@ const ActionButton: React.FC = ({ const client = createThirdwebClient({ clientId: '6410e98bc50f9521823ca83e255e279d' }) - const chain = useActiveWalletChain() const allowances = useAllowances({ bridger, @@ -196,7 +195,7 @@ const ActionButton: React.FC = ({ return } - if (!account || !chain) return + if (!account) return const signer = await ethers5Adapter.signer.toEthers({ client, chain: network, account }) const destinationChain = direction === 'DEPOSIT' ? selectedHighNetwork : selectedLowNetwork const destinationRPC = destinationChain.rpcs[0] diff --git a/webapps/world-builder-dashboard/src/hooks/useBridgeTransfer.ts b/webapps/world-builder-dashboard/src/hooks/useBridgeTransfer.ts index 038a703f..92c65163 100644 --- a/webapps/world-builder-dashboard/src/hooks/useBridgeTransfer.ts +++ b/webapps/world-builder-dashboard/src/hooks/useBridgeTransfer.ts @@ -1,13 +1,16 @@ import { useMutation, useQueryClient } from '@tanstack/react-query' import { useQuery } from '@tanstack/react-query' import { useNavigate } from 'react-router-dom' -import { getNetworks } from '../../constants' +import { getNetworks, getNetworksThirdWeb } from '../../constants' import { BridgeTransfer, BridgeTransferStatus, getBridgeTransfer } from 'game7-bridge-sdk' import { useBlockchainContext } from '@/contexts/BlockchainContext' import { useBridgeNotificationsContext } from '@/contexts/BridgeNotificationsContext' import { TransactionRecord } from '@/utils/bridge/depositERC20ArbitrumSDK' import { fetchTransactionTimestamp, getCachedTransactions, saveCachedTransactions } from '@/utils/web3utils' import { useRequestQueue } from './useQueueRequests' +import { useActiveAccount } from 'thirdweb/react' +import { createThirdwebClient } from 'thirdweb' +import { ethers5Adapter } from 'thirdweb/adapters/ethers5' interface UseTransferDataProps { txRecord: TransactionRecord @@ -15,7 +18,7 @@ interface UseTransferDataProps { export const useBridgeTransfer = () => { const { queueRequest } = useRequestQueue() - const { connectedAccount, selectedNetworkType, getProvider } = useBlockchainContext() + const { connectedAccount, selectedNetworkType, wallet } = useBlockchainContext() const LOCK_TIMEOUT = 5000; // 5 seconds timeout for lock // Helper functions to manage locks @@ -200,6 +203,12 @@ export const useBridgeTransfer = () => { const navigate = useNavigate() const { refetchNewNotifications } = useBridgeNotificationsContext() const queryClient = useQueryClient() + const account = useActiveAccount() + const client = createThirdwebClient({ + clientId: '6410e98bc50f9521823ca83e255e279d' + }) + + const claim = useMutation({ mutationFn: async ({ txRecord }: { txRecord: TransactionRecord }) => { @@ -212,12 +221,13 @@ export const useBridgeTransfer = () => { if (!txRecord) { throw new Error('transaction hash is undefined') } - const targetChain = getNetworks(selectedNetworkType)?.find((network) => network.chainId === destinationChainId); - if (!targetChain) { + const targetChain = getNetworksThirdWeb(selectedNetworkType)?.find((network) => network.id === destinationChainId); + if (!targetChain || !account) { throw new Error('Target chain is undefined'); } - const provider = await getProvider(targetChain); - const signer = provider.getSigner() + const signer = await ethers5Adapter.signer.toEthers({ client, chain: targetChain, account }) + + await wallet?.switchChain(targetChain) // Bridge Transfer execute const _bridgeTransfer: BridgeTransfer = await getBridgeTransfer({ @@ -229,7 +239,9 @@ export const useBridgeTransfer = () => { }, txRecord.isCCTP) _bridgeTransfer.isCctp() && await _bridgeTransfer.getStatus() + console.log('making tx') const res: any = await _bridgeTransfer?.execute(signer) + console.log(res) return { res, txRecord } }, onSuccess: ({ res, txRecord }) => {