Skip to content

Commit c1e7190

Browse files
committed
remove wagmi v2 add ethers v5 because of compat issues
1 parent d623f85 commit c1e7190

File tree

7 files changed

+698
-1172
lines changed

7 files changed

+698
-1172
lines changed
Lines changed: 35 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
11
import {PluginClient} from '@remixproject/plugin'
22
import {createClient} from '@remixproject/plugin-webview'
3-
import {defaultWagmiConfig, createWeb3Modal} from '@web3modal/wagmi/react'
4-
import {
5-
arbitrum,
6-
arbitrumGoerli,
7-
mainnet,
8-
polygon,
9-
polygonMumbai,
10-
optimism,
11-
optimismGoerli,
12-
Chain,
13-
goerli,
14-
sepolia,
15-
ronin,
16-
saigon
17-
} from 'viem/chains'
3+
import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5/react'
4+
import { constants } from '../utils/constants'
185
import EventManager from 'events'
196
import {PROJECT_ID as projectId, METADATA as metadata} from './constant'
20-
import { Config, disconnect, getAccount, watchAccount } from '@wagmi/core'
21-
import { EIP1193Provider, RequestArguments } from '../types'
7+
import { Chain, RequestArguments } from '../types'
228

239
export class WalletConnectRemixClient extends PluginClient {
2410
web3modal: ReturnType<typeof createWeb3Modal>
25-
wagmiConfig: Config
11+
ethersConfig: ReturnType<typeof defaultConfig>
2612
chains: Chain[]
2713
currentChain: number
2814
internalEvents: EventManager
29-
currentAcount: string
15+
currentAccount: string
3016

3117
constructor() {
3218
super()
@@ -49,74 +35,57 @@ export class WalletConnectRemixClient extends PluginClient {
4935

5036
initClient() {
5137
try {
52-
const chains = [
53-
mainnet,
54-
arbitrum,
55-
arbitrumGoerli,
56-
polygon,
57-
polygonMumbai,
58-
optimism,
59-
optimismGoerli,
60-
goerli,
61-
sepolia,
62-
ronin,
63-
saigon
64-
] as [Chain, ...Chain[]]
65-
66-
const wagmiConfig = defaultWagmiConfig({
67-
chains,
68-
projectId,
38+
const ethersConfig = defaultConfig({
6939
metadata,
70-
//ssr: true
40+
rpcUrl: 'https://cloudflare-eth.com'
7141
})
72-
73-
this.web3modal = createWeb3Modal({ wagmiConfig, projectId, chains })
74-
this.wagmiConfig = wagmiConfig
75-
this.chains = chains
42+
43+
this.web3modal = createWeb3Modal({ projectId, chains: constants.chains, metadata, ethersConfig })
44+
this.ethersConfig = ethersConfig
45+
this.chains = constants.chains
7646
} catch (e) {
7747
return console.error('Could not get a wallet connection', e)
7848
}
7949
}
8050

8151
subscribeToEvents() {
82-
watchAccount(this.wagmiConfig, {
83-
onChange(account) {
84-
if(account.isConnected){
85-
if (account.address !== this.currentAcount) {
86-
this.currentAcount = account.address
87-
this.emit('accountsChanged', [account.address])
88-
}
89-
if (this.currentChain !== account.chainId) {
90-
this.currentChain = account.chainId
91-
this.emit('chainChanged', account.chainId)
92-
}
93-
}else{
94-
this.emit('accountsChanged', [])
95-
this.currentAcount = ''
96-
this.emit('chainChanged', 0)
97-
this.currentChain = 0
52+
this.web3modal.subscribeProvider(({ address, isConnected, chainId })=>{
53+
if(isConnected){
54+
if (address !== this.currentAccount) {
55+
this.currentAccount = address
56+
this.emit('accountsChanged', [address])
9857
}
99-
},
100-
})
58+
if (this.currentChain !== chainId) {
59+
this.currentChain = chainId
60+
this.emit('chainChanged', chainId)
61+
}
62+
}else{
63+
this.emit('accountsChanged', [])
64+
this.currentAccount = ''
65+
this.emit('chainChanged', 0)
66+
this.currentChain = 0
67+
}
68+
},)
10169
this.on('theme', 'themeChanged', (theme: any) => {
10270
this.web3modal.setThemeMode(theme.quality)
10371
})
10472
}
10573

10674
async sendAsync(data: RequestArguments) {
107-
const account = getAccount(this.wagmiConfig)
108-
if (account.isConnected) {
75+
const address = this.web3modal.getAddress()
76+
const provider = this.web3modal.getWalletProvider()
77+
if (address && provider) {
10978
if (data.method === 'eth_accounts') {
11079
return {
11180
jsonrpc: '2.0',
112-
result: [account.address],
81+
result: [address],
11382
id: data.id
11483
}
11584
} else {
116-
const provider = await account.connector.getProvider() as EIP1193Provider
117-
118-
if (provider) {
85+
//@ts-expect-error this flag does not correspond to EIP-1193 but was introduced by MetaMask
86+
if (provider.isMetamask && provider.sendAsync) {
11987
return new Promise((resolve) => {
88+
//@ts-expect-error sendAsync is a legacy function we know MetaMask supports it
12089
provider.sendAsync(data, (error, response) => {
12190
if (error) {
12291
if (error.data && error.data.originalError && error.data.originalError.data) {
@@ -160,6 +129,6 @@ export class WalletConnectRemixClient extends PluginClient {
160129

161130
async deactivate() {
162131
console.log('deactivating walletconnect plugin...')
163-
await disconnect(this.wagmiConfig)
132+
await this.web3modal.disconnect()
164133
}
165134
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// @ts-ignore
2-
export const PROJECT_ID = "bd4997ce3ede37c95770ba10a3804dad"
2+
export const PROJECT_ID = WALLET_CONNECT_PROJECT_ID
33
export const METADATA = {
44
name: 'Remix IDE',
55
description: 'The Native IDE for Web3 Development.',
66
url: 'https://remix.ethereum.org/',
77
icons: ['https://remix.ethereum.org/favicon.ico'],
8-
verifyUrl: ''
98
}

apps/walletconnect/src/types.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ export interface RequestArguments {
44
readonly id?: string
55
}
66

7-
export interface EIP1193Provider {
8-
request: <T>(args: RequestArguments) => Promise<T>
9-
sendAsync: <T>(args: RequestArguments, callback:(error, response)=>void) => Promise<T>
10-
on: (event: string, listener: (event: unknown) => void) => void
11-
removeListener: (event: string, listener: (event: unknown) => void) => void
7+
export type Chain = {
8+
chainId: number
9+
name: string
10+
currency: string
11+
explorerUrl: string
12+
rpcUrl: string
1213
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
export const mainnet = {
2+
chainId: 1,
3+
name: 'Ethereum',
4+
currency: 'ETH',
5+
explorerUrl: 'https://etherscan.io',
6+
rpcUrl: 'https://cloudflare-eth.com'
7+
}
8+
9+
export const sepolia = {
10+
chainId: 11155111,
11+
name: 'Sepolia',
12+
currency: 'ETH',
13+
explorerUrl: 'https://sepolia.etherscan.io',
14+
rpcUrl: 'https://rpc.sepolia.org'
15+
}
16+
17+
export const goerli = {
18+
chainId: 5,
19+
name: 'Goerli',
20+
currency: 'ETH',
21+
explorerUrl: 'https://goerli.etherscan.io',
22+
rpcUrl: 'https://rpc.ankr.com/eth_goerli'
23+
}
24+
25+
export const arbitrum = {
26+
chainId: 42161,
27+
name: 'Arbitrum',
28+
currency: 'ETH',
29+
explorerUrl: 'https://arbiscan.io',
30+
rpcUrl: 'https://arb1.arbitrum.io/rpc'
31+
}
32+
33+
export const arbitrumGoerli = {
34+
chainId: 421613,
35+
name: 'Arbitrum Goerli',
36+
currency: 'ETH',
37+
explorerUrl: 'https://goerli.arbiscan.io',
38+
rpcUrl: 'https://goerli-rollup.arbitrum.io/rpc'
39+
}
40+
41+
export const avalanche = {
42+
chainId: 43114,
43+
name: 'Avalanche',
44+
currency: 'AVAX',
45+
explorerUrl: 'https://snowtrace.io',
46+
rpcUrl: 'https://api.avax.network/ext/bc/C/rpc'
47+
}
48+
49+
export const bsc = {
50+
chainId: 56,
51+
name: 'Binance Smart Chain',
52+
currency: 'BNB',
53+
explorerUrl: 'https://bscscan.com',
54+
rpcUrl: 'https://rpc.ankr.com/bsc'
55+
}
56+
57+
export const optimism = {
58+
chainId: 10,
59+
name: 'Optimism',
60+
currency: 'ETH',
61+
explorerUrl: 'https://optimistic.etherscan.io',
62+
rpcUrl: 'https://mainnet.optimism.io'
63+
}
64+
65+
export const optimismGoerli = {
66+
chainId: 420,
67+
name: 'Optimism Goerli',
68+
currency: 'ETH',
69+
explorerUrl: 'https://goerli-optimism.etherscan.io',
70+
rpcUrl: 'https://goerli.optimism.io'
71+
}
72+
73+
export const polygon = {
74+
chainId: 137,
75+
name: 'Polygon',
76+
currency: 'MATIC',
77+
explorerUrl: 'https://polygonscan.com',
78+
rpcUrl: 'https://polygon-rpc.com'
79+
}
80+
81+
export const polygonMumbai = {
82+
chainId: 80001,
83+
name: 'Polygon Mumbai',
84+
currency: 'MATIC',
85+
explorerUrl: 'https://mumbai.polygonscan.com',
86+
rpcUrl: 'https://rpc.ankr.com/polygon_mumbai'
87+
}
88+
89+
export const gnosis = {
90+
chainId: 100,
91+
name: 'Gnosis',
92+
currency: 'xDAI',
93+
explorerUrl: 'https://gnosis.blockscout.com',
94+
rpcUrl: 'https://rpc.gnosischain.com'
95+
}
96+
97+
export const zkSync = {
98+
chainId: 324,
99+
name: 'ZkSync',
100+
currency: 'ETH',
101+
explorerUrl: 'https://explorer.zksync.io',
102+
rpcUrl: 'https://mainnet.era.zksync.io'
103+
}
104+
105+
export const zora = {
106+
chainId: 7777777,
107+
name: 'Zora',
108+
currency: 'ETH',
109+
explorerUrl: 'https://explorer.zora.energy',
110+
rpcUrl: 'https://rpc.zora.energy'
111+
}
112+
113+
export const celo = {
114+
chainId: 42220,
115+
name: 'Celo',
116+
currency: 'CELO',
117+
explorerUrl: 'https://explorer.celo.org/mainnet',
118+
rpcUrl: 'https://forno.celo.org'
119+
}
120+
121+
export const base = {
122+
chainId: 8453,
123+
name: 'Base',
124+
currency: 'BASE',
125+
explorerUrl: 'https://basescan.org',
126+
rpcUrl: 'https://mainnet.base.org'
127+
}
128+
129+
export const aurora = {
130+
chainId: 1313161554,
131+
name: 'Aurora',
132+
currency: 'ETH',
133+
explorerUrl: 'https://explorer.aurora.dev',
134+
rpcUrl: 'https://mainnet.aurora.dev'
135+
}
136+
137+
export const ronin = {
138+
chainId: 2020,
139+
name: 'Ronin',
140+
currency: 'RON',
141+
explorerUrl: 'https://app.roninchain.com',
142+
rpcUrl: 'https://api.roninchain.com/rpc'
143+
}
144+
145+
export const saigon = {
146+
chainId: 2021,
147+
name: 'Saigon Testnet',
148+
currency: 'RON',
149+
explorerUrl: 'https://saigon-explorer.roninchain.com',
150+
rpcUrl: 'https://saigon-testnet.roninchain.com/rpc'
151+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {
2+
arbitrum,
3+
arbitrumGoerli,
4+
mainnet,
5+
polygon,
6+
polygonMumbai,
7+
optimism,
8+
optimismGoerli,
9+
goerli,
10+
sepolia,
11+
ronin,
12+
saigon,
13+
aurora,
14+
avalanche,
15+
base,
16+
bsc,
17+
celo,
18+
gnosis,
19+
zkSync,
20+
zora,
21+
} from './chains'
22+
23+
export const constants = {
24+
chains: [
25+
arbitrum,
26+
arbitrumGoerli,
27+
mainnet,
28+
polygon,
29+
polygonMumbai,
30+
optimism,
31+
optimismGoerli,
32+
goerli,
33+
sepolia,
34+
ronin,
35+
saigon,
36+
aurora,
37+
avalanche,
38+
base,
39+
bsc,
40+
celo,
41+
gnosis,
42+
zkSync,
43+
zora,
44+
]
45+
}

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@
152152
"@remixproject/plugin-ws": "0.3.42",
153153
"@ricarso/react-image-magnifiers": "^1.9.0",
154154
"@types/nightwatch": "^2.3.1",
155-
"@wagmi/connectors": "^4.1.4",
156-
"@wagmi/core": "^2.2.1",
157-
"@web3modal/wagmi": "4.0.0-alpha.0",
155+
"@web3modal/ethers5": "^3.5.7",
158156
"@xenova/transformers": "^2.7.0",
159157
"ansi-gray": "^0.1.1",
160158
"assert": "^2.1.0",
@@ -235,7 +233,6 @@
235233
"tree-kill": "^1.2.2",
236234
"ts-loader": "^9.2.6",
237235
"tslib": "^2.3.0",
238-
"viem": "^2.2.0",
239236
"web3": "^4.1.0",
240237
"winston": "^3.3.3",
241238
"ws": "^7.3.0",

0 commit comments

Comments
 (0)