Skip to content

Commit eebf498

Browse files
authored
Merge pull request #3906 from ethereum/fix-wallet-connect
Update walletconnect dependencies and implementation
2 parents 4dd6a56 + bccd233 commit eebf498

File tree

6 files changed

+368
-576
lines changed

6 files changed

+368
-576
lines changed

apps/walletconnect/src/app/app.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import React, { useEffect, useState } from 'react'
22
import '../css/app.css'
33
import '@fortawesome/fontawesome-free/css/all.css'
44
import type { EthereumClient } from '@web3modal/ethereum'
5-
import { RemixClient } from '../services/RemixClient'
5+
import { WalletConnectRemixClient } from '../services/WalletConnectRemixClient'
66
import { WalletConnectUI } from './walletConnectUI'
77

8-
const remix = new RemixClient()
8+
const remix = new WalletConnectRemixClient()
99

1010
function App() {
1111
const [ethereumClient, setEthereumClient] = useState<EthereumClient>(null)
12-
const [wagmiClient, setWagmiClient] = useState(null)
12+
const [wagmiConfig, setWagmiConfig] = useState(null)
1313
const [theme, setTheme] = useState<string>('dark')
1414

1515
useEffect(() => {
@@ -19,15 +19,15 @@ function App() {
1919
setTheme(theme)
2020
})
2121

22-
setWagmiClient(remix.wagmiClient)
22+
setWagmiConfig(remix.wagmiConfig)
2323
setEthereumClient(remix.ethereumClient)
2424
})()
2525
}, [])
2626

2727
return (
2828
<div className="App">
2929
<h4 className='mt-1'>WalletConnect</h4>
30-
{ ethereumClient && wagmiClient && <WalletConnectUI wagmiClient={wagmiClient} ethereumClient={ethereumClient} theme={theme} /> }
30+
{ ethereumClient && wagmiConfig && <WalletConnectUI wagmiConfig={wagmiConfig} ethereumClient={ethereumClient} theme={theme} /> }
3131
</div>
3232
)
3333
}

apps/walletconnect/src/app/walletConnectUI.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Web3Button, Web3Modal } from "@web3modal/react"
22
import { WagmiConfig } from "wagmi"
33
import { PROJECT_ID } from "../services/constant"
44

5-
export function WalletConnectUI ({ ethereumClient, wagmiClient, theme }) {
5+
export function WalletConnectUI ({ ethereumClient, wagmiConfig, theme }) {
66

77
return (
88
<div>
99
<div style={{ display: 'inline-block' }}>
10-
<WagmiConfig client={wagmiClient}>
10+
<WagmiConfig config={wagmiConfig}>
1111
<Web3Button label='Connect to a wallet' />
1212
</WagmiConfig>
1313
</div>

apps/walletconnect/src/services/RemixClient.ts renamed to apps/walletconnect/src/services/WalletConnectRemixClient.ts

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { PluginClient } from '@remixproject/plugin'
22
import { createClient } from '@remixproject/plugin-webview'
33
import { w3mConnectors, w3mProvider } from '@web3modal/ethereum'
4-
import { configureChains, createClient as wagmiCreateClient } from 'wagmi'
5-
import { arbitrum, arbitrumGoerli, mainnet, polygon, polygonMumbai, optimism, optimismGoerli, Chain, goerli, sepolia } from 'wagmi/chains'
4+
import { createConfig, configureChains } from 'wagmi'
5+
import { arbitrum, arbitrumGoerli, mainnet, polygon, polygonMumbai, optimism, optimismGoerli, Chain, goerli, sepolia } from 'viem/chains'
66
import { EthereumClient } from '@web3modal/ethereum'
77
import EventManager from "events"
88
import { PROJECT_ID } from './constant'
99

10-
export class RemixClient extends PluginClient {
11-
wagmiClient
10+
export class WalletConnectRemixClient extends PluginClient {
11+
wagmiConfig
1212
ethereumClient: EthereumClient
1313
chains: Chain[]
1414
currentChain: number
@@ -36,21 +36,21 @@ export class RemixClient extends PluginClient {
3636
async initClient () {
3737
try {
3838
this.chains = [arbitrum, arbitrumGoerli, mainnet, polygon, polygonMumbai, optimism, optimismGoerli, goerli, sepolia]
39-
const { provider } = configureChains(this.chains, [w3mProvider({ projectId: PROJECT_ID })])
40-
41-
this.wagmiClient = wagmiCreateClient({
42-
autoConnect: false,
43-
connectors: w3mConnectors({ projectId: PROJECT_ID, version: 2, chains: this.chains }),
44-
provider
39+
const { publicClient } = configureChains(this.chains, [w3mProvider({ projectId: PROJECT_ID })])
40+
41+
this.wagmiConfig = createConfig({
42+
autoConnect: false,
43+
connectors: w3mConnectors({ projectId: PROJECT_ID, chains: this.chains }),
44+
publicClient
4545
})
46-
this.ethereumClient = new EthereumClient(this.wagmiClient, this.chains)
46+
this.ethereumClient = new EthereumClient(this.wagmiConfig, this.chains)
4747
} catch (e) {
4848
return console.error("Could not get a wallet connection", e)
4949
}
5050
}
5151

5252
subscribeToEvents () {
53-
this.wagmiClient.subscribe((event) => {
53+
this.wagmiConfig.subscribe((event) => {
5454
if (event.status === 'connected') {
5555
this.emit('accountsChanged', [event.data.account])
5656
if (this.currentChain !== event.data.chain.id) {
@@ -70,29 +70,12 @@ export class RemixClient extends PluginClient {
7070

7171
sendAsync (data: { method: string, params: string, id: string }) {
7272
return new Promise((resolve, reject) => {
73-
if (this.wagmiClient) {
74-
if (this.wagmiClient.data && this.wagmiClient.data.provider && this.wagmiClient.data.provider.sendAsync) {
75-
this.wagmiClient.data.provider.sendAsync(data, (error, message) => {
76-
if (error) return reject(error)
77-
resolve(message)
78-
})
79-
} else if (this.wagmiClient.data && this.wagmiClient.data.provider && this.wagmiClient.data.provider.jsonRpcFetchFunc) {
80-
if (data.method === 'net_version' || data.method === 'eth_chainId') {
81-
resolve({"jsonrpc": "2.0", "result": this.currentChain, "id": data.id})
82-
} else {
83-
this.wagmiClient.data.provider.jsonRpcFetchFunc(data.method, data.params).then((message) => {
84-
resolve({"jsonrpc": "2.0", "result": message, "id": data.id})
85-
}).catch((error) => {
86-
reject(error)
87-
})
88-
}
89-
} else {
90-
this.wagmiClient.provider.send(data.method, data.params).then((message) => {
91-
resolve({"jsonrpc": "2.0", "result": message, "id": data.id})
92-
}).catch((error) => {
93-
reject(error)
94-
})
95-
}
73+
if (this.wagmiConfig) {
74+
this.wagmiConfig.publicClient.request(data).then((message) => {
75+
resolve({"jsonrpc": "2.0", "result": message, "id": data.id})
76+
}).catch((error) => {
77+
reject(error)
78+
})
9679
} else {
9780
console.error(`Cannot make ${data.method} request. Remix client is not connect to walletconnect client`)
9881
resolve({"jsonrpc": "2.0", "result": [], "id": data.id})

apps/walletconnect/src/services/provider.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,8 @@
138138
"@remixproject/plugin-webview": "0.3.33",
139139
"@remixproject/plugin-ws": "0.3.33",
140140
"@types/nightwatch": "^2.3.1",
141-
"@walletconnect/ethereum-provider": "^2.6.2",
142-
"@walletconnect/sign-client": "^2.6.0",
143-
"@web3modal/ethereum": "^2.2.2",
144-
"@web3modal/react": "^2.2.2",
145-
"@web3modal/standalone": "^2.2.2",
141+
"@web3modal/ethereum": "^2.6.2",
142+
"@web3modal/react": "^2.6.2",
146143
"ansi-gray": "^0.1.1",
147144
"async": "^2.6.2",
148145
"axios": "1.1.2",
@@ -208,7 +205,8 @@
208205
"tree-kill": "^1.2.2",
209206
"ts-loader": "^9.2.6",
210207
"tslib": "^2.3.0",
211-
"wagmi": "^0.12.7",
208+
"viem": "^1.2.12",
209+
"wagmi": "^1.3.8",
212210
"web3": "^1.8.0",
213211
"winston": "^3.3.3",
214212
"ws": "^7.3.0"

0 commit comments

Comments
 (0)