// useThirdwebTrailsAdapters.ts
import { evmAdapter, type Eip1193ProviderLike } from '0xtrails'
import { useMemo } from 'react'
import {
useActiveAccount,
useActiveWallet,
useActiveWalletChain,
} from 'thirdweb/react'
import { EIP1193 } from 'thirdweb/wallets'
import { defaultChain, thirdwebClient } from './thirdwebClient'
export function useThirdwebTrailsAdapters() {
const activeAccount = useActiveAccount()
const activeWallet = useActiveWallet()
const activeChain = useActiveWalletChain()
return useMemo(() => {
if (!activeAccount || !activeWallet) {
return undefined
}
// thirdweb wallet (injected, in-app, smart account, ...) → EIP-1193
const provider = EIP1193.toProvider({
wallet: activeWallet,
chain: activeChain ?? defaultChain,
client: thirdwebClient,
})
return [
evmAdapter({
wallets: [{
id: 'thirdweb-active-wallet',
name: 'thirdweb',
provider: provider as Eip1193ProviderLike,
showDisconnect: false, // thirdweb owns disconnect
}],
supportsWalletSelection: false, // hide Trails's wallet picker
}),
] as const
}, [activeAccount, activeWallet, activeChain])
}