import { createConfig, http } from 'wagmi'
import { metaMask, walletConnect, coinbaseWallet } from 'wagmi/connectors'
import {
  allNetworks,
  chainRpcUrls,
} from './networks'

const projectId = import.meta.env.VITE_WALLETCONNECT_PROJECT_ID || ''

const transports = Object.fromEntries(
  allNetworks.map((chain) => {
    const rpcUrl = chainRpcUrls[chain.id]
    return [chain.id, rpcUrl ? http(rpcUrl) : http()]
  })
)

export const config = createConfig({
  chains: allNetworks,
  connectors: [
    metaMask(),
    walletConnect({ projectId }),
    coinbaseWallet({ appName: 'Bridge DApp' }),
  ],
  transports: transports as Record<number, ReturnType<typeof http>>,
})
