Skip to content

Commit

Permalink
Merge pull request #371 from G7DAO/3rd-web
Browse files Browse the repository at this point in the history
switch chain
  • Loading branch information
elclandestin0 authored Feb 7, 2025
2 parents 3191cfc + 9d680a9 commit 39b52a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -90,7 +90,6 @@ const ActionButton: React.FC<ActionButtonProps> = ({
const client = createThirdwebClient({
clientId: '6410e98bc50f9521823ca83e255e279d'
})
const chain = useActiveWalletChain()

const allowances = useAllowances({
bridger,
Expand Down Expand Up @@ -196,7 +195,7 @@ const ActionButton: React.FC<ActionButtonProps> = ({
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]
Expand Down
24 changes: 18 additions & 6 deletions webapps/world-builder-dashboard/src/hooks/useBridgeTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
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
}

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
Expand Down Expand Up @@ -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 }) => {
Expand All @@ -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({
Expand All @@ -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 }) => {
Expand Down

0 comments on commit 39b52a4

Please sign in to comment.