import { Chain, getDefaultConfig, WalletList } from "@rainbow-me/rainbowkit" import { Config, createConfig, CreateConfigParameters, http, webSocket, } from "wagmi" import { walletConnectWallet } from "@rainbow-me/rainbowkit/wallets" import { CHAIN_ID, mezoMainnet, mezoTestnet, RPC_BY_NETWORK } from "./constants" import { getOKXWallet, getUnisatWallet, getXverseWallet } from "./wallet" type WagmiConfigParameters = Omit< CreateConfigParameters, "client" | "connectors" | "chains" | "transports" > type GetDefaultConfigParameters = WagmiConfigParameters & { appName: string mezoNetwork?: "mainnet" | "testnet" appDescription?: string appUrl?: string appIcon?: string wallets?: WalletList walletConnectProjectId: string chains?: [Chain, ...Chain[]] transports?: Pick } const bitcoinWalletTestnetConfig = { rpcUrl: RPC_BY_NETWORK.testnet.http, chainId: CHAIN_ID.testnet, } const bitcoinWalletMainnetConfig = { rpcUrl: RPC_BY_NETWORK.mainnet.http, chainId: CHAIN_ID.mainnet, } export const unisatWalletMezoTestnet = getUnisatWallet( bitcoinWalletTestnetConfig, ) export const okxWalletMezoTestnet = getOKXWallet(bitcoinWalletTestnetConfig) export const xverseWalletMezoTestnet = getXverseWallet( bitcoinWalletTestnetConfig, ) export const unisatWalletMezoMainnet = getUnisatWallet( bitcoinWalletMainnetConfig, ) export const okxWalletMezoMainnet = getOKXWallet(bitcoinWalletMainnetConfig) export const xverseWalletMezoMainnet = getXverseWallet( bitcoinWalletMainnetConfig, ) export const preconfiguredWalletConnectWallet = (projectId: string) => walletConnectWallet({ projectId, options: { qrModalOptions: { enableExplorer: false, }, }, }) export function getDefaultWallets( network: "mainnet" | "testnet" = "mainnet", ): WalletList { return [ { groupName: "Bitcoin", wallets: network === "mainnet" ? [ unisatWalletMezoMainnet, okxWalletMezoMainnet, xverseWalletMezoMainnet, ] : [ unisatWalletMezoTestnet, okxWalletMezoTestnet, xverseWalletMezoTestnet, ], }, { groupName: "Ethereum", wallets: [({ projectId }) => preconfiguredWalletConnectWallet(projectId)], }, ] } export function getConfig(config: GetDefaultConfigParameters): Config { const { appName, mezoNetwork = "mainnet", walletConnectProjectId, ...restParameters } = config const chains: [Chain, ...Chain[]] = mezoNetwork === "mainnet" ? [mezoMainnet] : [mezoTestnet] const transports = mezoNetwork === "mainnet" ? { [mezoMainnet.id]: http(RPC_BY_NETWORK.mainnet.http) } : { [mezoTestnet.id]: http(RPC_BY_NETWORK.testnet.http) } const wallets = config.wallets ?? [...getDefaultWallets(mezoNetwork)] return getDefaultConfig({ appName, chains, transports, wallets, projectId: walletConnectProjectId, multiInjectedProviderDiscovery: true, ...restParameters, }) } /** * This config is only used to listen for Transfer events on mezo chain. * Should not be exported in index for public use. */ export const simpleWssMezoConfig = createConfig({ chains: [mezoMainnet, mezoTestnet], transports: { [mezoMainnet.id]: webSocket(RPC_BY_NETWORK.mainnet.webSocket), [mezoTestnet.id]: webSocket(RPC_BY_NETWORK.testnet.webSocket), }, })