diff --git a/packages/wagmi-v2/src/client.ts b/packages/wagmi-v2/src/client.ts index 4a77b233ba..e7d5f04b80 100644 --- a/packages/wagmi-v2/src/client.ts +++ b/packages/wagmi-v2/src/client.ts @@ -1,4 +1,5 @@ -import { type Hex, type Chain } from 'viem' // TODO: THIS DOES NOT COVER 6963 +import { type Hex, type Chain } from 'viem' +import { EthereumProvider } from '@walletconnect/ethereum-provider' import { mainnet } from 'viem/chains' import { connect, @@ -26,7 +27,6 @@ import type { } from '@web3modal/scaffold' import { Web3ModalScaffold } from '@web3modal/scaffold' import type { Web3ModalSIWEClient } from '@web3modal/siwe' -// import type { EIP6963Connector } from './connectors/EIP6963Connector.js' import { ConstantsUtil, PresetsUtil, HelpersUtil } from '@web3modal/scaffold-utils' import { getCaipDefaultChain } from './utils/helpers.js' import { WALLET_CHOICE_KEY } from './utils/constants.js' @@ -57,18 +57,6 @@ interface Web3ModalState extends PublicStateControllerState { selectedNetworkId: number | undefined } -// interface Info { -// uuid: string -// name: string -// icon: string -// rdns: string -// } - -// interface Wallet { -// info: Info -// provider: EIP1193Provider -// } - // -- Client -------------------------------------------------------------------- export class Web3Modal extends Web3ModalScaffold { private hasSyncedConnectedAccount = false @@ -115,13 +103,15 @@ export class Web3Modal extends Web3ModalScaffold { 'networkControllerClient:getApprovedCaipNetworks - connector is undefined' ) } - const provider: any = await connector.getProvider() + const provider = (await connector.getProvider()) as Awaited< + ReturnType<(typeof EthereumProvider)['init']> + > const ns = provider?.signer?.session?.namespaces const nsMethods = ns?.[ConstantsUtil.EIP155]?.methods - const nsChains = ns?.[ConstantsUtil.EIP155]?.chains + const nsChains = ns?.[ConstantsUtil.EIP155]?.chains as CaipNetworkId[] return { - supportsAllNetworks: nsMethods?.includes(ConstantsUtil.ADD_CHAIN_METHOD), + supportsAllNetworks: Boolean(nsMethods?.includes(ConstantsUtil.ADD_CHAIN_METHOD)), approvedCaipNetworkIds: nsChains } } @@ -142,8 +132,7 @@ export class Web3Modal extends Web3ModalScaffold { connector.onMessage = event => { if (event.type === 'display_uri') { onUri(event.data as string) - // TODO: How to do this? - // connector.removeAllListeners() + // TOD0: How to do this? connector.removeAllListeners() } } @@ -219,7 +208,6 @@ export class Web3Modal extends Web3ModalScaffold { this.syncConnectors(wagmiConfig) this.syncEmailConnector(wagmiConfig) - // this.listenEIP6963Connector(wagmiConfig) this.listenEmailConnector(wagmiConfig) watchAccount(this.wagmiConfig, { onChange: this.syncAccount }) @@ -262,10 +250,11 @@ export class Web3Modal extends Web3ModalScaffold { } private async syncAccount({ address, isConnected, chainId }: GetAccountReturnType) { - const chain = this.wagmiConfig.chains.find((chain: Chain) => chain.id === chainId) + const chain = this.wagmiConfig.chains.find((c: Chain) => c.id === chainId) this.resetAccount() - this.syncNetwork() // TODO: Check with Sven. Now network is synced when acc is synced. + // TOD0: Check with Sven. Now network is synced when acc is synced. + this.syncNetwork() if (isConnected && address && chain) { const caipAddress: CaipAddress = `${ConstantsUtil.EIP155}:${chain.id}:${address}` this.setIsConnected(isConnected) @@ -284,10 +273,9 @@ export class Web3Modal extends Web3ModalScaffold { private async syncNetwork() { const { address, isConnected, chainId } = getAccount(this.wagmiConfig) - const chain = this.wagmiConfig.chains.find((chain: Chain) => chain.id === chainId) + const chain = this.wagmiConfig.chains.find((c: Chain) => c.id === chainId) if (chain) { - const chainId = String(chain.id) const caipChainId: CaipNetworkId = `${ConstantsUtil.EIP155}:${chainId}` this.setCaipNetwork({ id: caipChainId, @@ -381,38 +369,6 @@ export class Web3Modal extends Web3ModalScaffold { } } - // private eip6963EventHandler(connector: EIP6963Connector, event: CustomEventInit) { - // if (event.detail) { - // const { info, provider } = event.detail - // const connectors = this.getConnectors() - // const existingConnector = connectors.find(c => c.name === info.name) - // if (!existingConnector) { - // this.addConnector({ - // id: ConstantsUtil.EIP6963_CONNECTOR_ID, - // type: 'ANNOUNCED', - // imageUrl: - // info.icon ?? this.options?.connectorImages?.[ConstantsUtil.EIP6963_CONNECTOR_ID], - // name: info.name, - // provider, - // info - // }) - // connector.isAuthorized({ info, provider }) - // } - // } - // } - - // private listenEIP6963Connector(wagmiConfig: Web3ModalClientOptions['wagmiConfig']) { - // const connector = wagmiConfig.connectors.find( - // c => c.id === ConstantsUtil.EIP6963_CONNECTOR_ID - // ) as EIP6963Connector | undefined - - // if (typeof window !== 'undefined' && connector) { - // const handler = this.eip6963EventHandler.bind(this, connector) - // window.addEventListener(ConstantsUtil.EIP6963_ANNOUNCE_EVENT, handler) - // window.dispatchEvent(new Event(ConstantsUtil.EIP6963_REQUEST_EVENT)) - // } - // } - private async listenEmailConnector(wagmiConfig: Web3ModalClientOptions['wagmiConfig']) { const connector = wagmiConfig.connectors.find(c => c.id === ConstantsUtil.EMAIL_CONNECTOR_ID) diff --git a/packages/wagmi-v2/src/connectors/EIP6963Connector.ts b/packages/wagmi-v2/src/connectors/EIP6963Connector.ts deleted file mode 100644 index 0981db0916..0000000000 --- a/packages/wagmi-v2/src/connectors/EIP6963Connector.ts +++ /dev/null @@ -1,91 +0,0 @@ -// import { type Chain } from 'wagmi/chains' -// import { InjectedConnector } from '@wagmi/core/connectors/injected' -// import { getAddress, type EIP1193Provider } from 'viem' - -// // -- Helpers ---------------------------------------------------------- -// const connectedRdnsKey = 'connectedRdns' - -// // -- Types ------------------------------------------------------------ -// interface Info { -// uuid: string -// name: string -// icon: string -// rdns: string -// } - -// interface EIP6963Wallet { -// info: Info -// provider: EIP1193Provider -// } - -// interface ConnectOptions { -// chainId?: number -// } - -// interface Config { -// chains?: Chain[] -// } - -// // -- Connector -------------------------------------------------------- -// export class EIP6963Connector extends InjectedConnector { -// override readonly id = 'eip6963' - -// override readonly name = 'EIP6963' - -// #defaultProvider?: WindowProvider = undefined - -// #eip6963Wallet?: EIP6963Wallet = undefined - -// public constructor(config: Config) { -// super({ chains: config.chains, options: { shimDisconnect: true } }) -// this.#defaultProvider = this.options.getProvider() -// } - -// // -- Wagmi Methods --------------------------------------------------- -// public override async connect(options: ConnectOptions) { -// const data = await super.connect(options) -// if (this.#eip6963Wallet) { -// this.storage?.setItem(connectedRdnsKey, this.#eip6963Wallet.info.rdns) -// } - -// return data -// } - -// protected override onAccountsChanged = (accounts: string[]) => { -// if (accounts.length === 0) { -// this.storage?.removeItem(connectedRdnsKey) -// this.emit('disconnect') -// } else if (accounts[0]) { -// this.emit('change', { -// account: getAddress(accounts[0]) -// }) -// } -// } - -// public override async disconnect() { -// await super.disconnect() -// this.storage?.removeItem(connectedRdnsKey) -// this.#eip6963Wallet = undefined -// } - -// public override async isAuthorized(eip6963Wallet?: EIP6963Wallet) { -// const connectedEIP6963Rdns = this.storage?.getItem(connectedRdnsKey) -// if (connectedEIP6963Rdns) { -// if (!eip6963Wallet || connectedEIP6963Rdns !== eip6963Wallet.info.rdns) { -// return true -// } -// this.#eip6963Wallet = eip6963Wallet -// } - -// return super.isAuthorized() -// } - -// public override async getProvider() { -// return Promise.resolve(this.#eip6963Wallet?.provider ?? this.#defaultProvider) -// } - -// // -- Extended Methods ------------------------------------------------ -// public setEip6963Wallet(eip6963Wallet: EIP6963Wallet) { -// this.#eip6963Wallet = eip6963Wallet -// } -// } diff --git a/packages/wagmi-v2/src/utils/defaultWagmiCoreConfig.ts b/packages/wagmi-v2/src/utils/defaultWagmiCoreConfig.ts index 0ca393b9f8..582b978db2 100644 --- a/packages/wagmi-v2/src/utils/defaultWagmiCoreConfig.ts +++ b/packages/wagmi-v2/src/utils/defaultWagmiCoreConfig.ts @@ -4,11 +4,9 @@ import type { Config, CreateConnectorFn } from '@wagmi/core' import { type Chain } from 'viem/chains' import { createConfig } from '@wagmi/core' -// import { EIP6963Connector } from '../connectors/EIP6963Connector.js' - import { createClient, http } from 'viem' import { coinbaseWallet, walletConnect, injected } from '@wagmi/connectors' -import { emailConnector } from '../connectors/EmailConnectorv2' +import { emailConnector } from '../connectors/EmailConnectorv2.js' export interface ConfigOptions { projectId: string @@ -33,7 +31,6 @@ export function defaultWagmiConfig({ metadata, enableInjected, enableCoinbase, - // enableEIP6963, enableEmail, enableWalletConnect }: ConfigOptions): Config { @@ -48,10 +45,6 @@ export function defaultWagmiConfig({ connectors.push(injected({ shimDisconnect: true })) } - // if (enableEIP6963 !== false) { - // connectors.push(new EIP6963Connector({ chains })) - // } - if (enableCoinbase !== false) { connectors.push(coinbaseWallet({ appName: metadata?.name ?? 'Unknown' })) } @@ -66,7 +59,8 @@ export function defaultWagmiConfig({ client: ({ chain }) => createClient({ chain, - transport: http() // TODO: How do we add WC transport? + // TOD0: How to use WC transport? Do we need it for analytics? + transport: http() }), connectors, multiInjectedProviderDiscovery: true