|
1 |
| -import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5/react'; |
2 |
| -import { |
3 |
| - constants, |
4 |
| - PROJECT_ID as projectId, |
5 |
| - METADATA as metadata, |
6 |
| -} from './constants'; |
7 |
| -import EventManager from 'events'; |
8 |
| -import { Chain, RequestArguments } from '../types'; |
9 |
| -import txRunner from './txRunner'; |
10 |
| -import { saveSettings } from '../actions'; |
| 1 | +// import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5/react'; |
| 2 | +// import { |
| 3 | +// constants, |
| 4 | +// PROJECT_ID as projectId, |
| 5 | +// METADATA as metadata, |
| 6 | +// } from './constants'; |
| 7 | +// import EventManager from 'events'; |
| 8 | +// import { Chain, RequestArguments } from '../types'; |
| 9 | +// import txRunner from './txRunner'; |
| 10 | +// import { saveSettings } from '../actions'; |
11 | 11 |
|
12 |
| -class WalletConnect { |
13 |
| - web3modal: ReturnType<typeof createWeb3Modal>; |
14 |
| - ethersConfig: ReturnType<typeof defaultConfig>; |
15 |
| - chains: Chain[]; |
16 |
| - currentChain?: number; |
17 |
| - internalEvents: EventManager; |
18 |
| - currentAccount?: string; |
| 12 | +// class WalletConnect { |
| 13 | +// web3modal: ReturnType<typeof createWeb3Modal>; |
| 14 | +// ethersConfig: ReturnType<typeof defaultConfig>; |
| 15 | +// chains: Chain[]; |
| 16 | +// currentChain?: number; |
| 17 | +// internalEvents: EventManager; |
| 18 | +// currentAccount?: string; |
19 | 19 |
|
20 |
| - constructor() { |
21 |
| - this.internalEvents = new EventManager(); |
22 |
| - const ethersConfig = defaultConfig({ |
23 |
| - metadata, |
24 |
| - rpcUrl: 'https://cloudflare-eth.com', |
25 |
| - }); |
| 20 | +// constructor() { |
| 21 | +// this.internalEvents = new EventManager(); |
| 22 | +// const ethersConfig = defaultConfig({ |
| 23 | +// metadata, |
| 24 | +// rpcUrl: 'https://cloudflare-eth.com', |
| 25 | +// }); |
26 | 26 |
|
27 |
| - this.web3modal = createWeb3Modal({ |
28 |
| - projectId, |
29 |
| - chains: constants.chains, |
30 |
| - metadata, |
31 |
| - ethersConfig, |
32 |
| - }); |
33 |
| - this.ethersConfig = ethersConfig; |
34 |
| - this.chains = constants.chains; |
35 |
| - } |
| 27 | +// this.web3modal = createWeb3Modal({ |
| 28 | +// projectId, |
| 29 | +// chains: constants.chains, |
| 30 | +// metadata, |
| 31 | +// ethersConfig, |
| 32 | +// }); |
| 33 | +// this.ethersConfig = ethersConfig; |
| 34 | +// this.chains = constants.chains; |
| 35 | +// } |
36 | 36 |
|
37 |
| - subscribeToEvents() { |
38 |
| - this.web3modal.subscribeProvider(({ address, isConnected, chainId }) => { |
39 |
| - if (isConnected) { |
40 |
| - txRunner.getAccounts(); |
41 |
| - if (address !== this.currentAccount) { |
42 |
| - this.currentAccount = address; |
43 |
| - } |
44 |
| - if (this.currentChain !== chainId) { |
45 |
| - this.currentChain = chainId; |
46 |
| - } |
47 |
| - } else { |
48 |
| - saveSettings({ loadedAccounts: {} }); |
49 |
| - this.currentAccount = ''; |
50 |
| - this.currentChain = 0; |
51 |
| - } |
52 |
| - }); |
53 |
| - } |
| 37 | +// subscribeToEvents() { |
| 38 | +// this.web3modal.subscribeProvider(({ address, isConnected, chainId }) => { |
| 39 | +// if (isConnected) { |
| 40 | +// txRunner.getAccounts(); |
| 41 | +// if (address !== this.currentAccount) { |
| 42 | +// this.currentAccount = address; |
| 43 | +// } |
| 44 | +// if (this.currentChain !== chainId) { |
| 45 | +// this.currentChain = chainId; |
| 46 | +// } |
| 47 | +// } else { |
| 48 | +// saveSettings({ loadedAccounts: {} }); |
| 49 | +// this.currentAccount = ''; |
| 50 | +// this.currentChain = 0; |
| 51 | +// } |
| 52 | +// }); |
| 53 | +// } |
54 | 54 |
|
55 |
| - async sendAsync(data: RequestArguments) { |
56 |
| - const address = this.web3modal.getAddress(); |
57 |
| - const provider = this.web3modal.getWalletProvider(); |
58 |
| - if (address && provider) { |
59 |
| - if (data.method === 'eth_accounts') { |
60 |
| - return { |
61 |
| - jsonrpc: '2.0', |
62 |
| - result: [address], |
63 |
| - id: data.id, |
64 |
| - }; |
65 |
| - } else { |
66 |
| - //@ts-expect-error this flag does not correspond to EIP-1193 but was introduced by MetaMask |
67 |
| - if (provider.isMetamask && provider.sendAsync) { |
68 |
| - return new Promise((resolve) => { |
69 |
| - //@ts-expect-error sendAsync is a legacy function we know MetaMask supports it |
70 |
| - provider.sendAsync(data, (error, response) => { |
71 |
| - if (error) { |
72 |
| - if ( |
73 |
| - error.data && |
74 |
| - error.data.originalError && |
75 |
| - error.data.originalError.data |
76 |
| - ) { |
77 |
| - resolve({ |
78 |
| - jsonrpc: '2.0', |
79 |
| - error: error.data.originalError, |
80 |
| - id: data.id, |
81 |
| - }); |
82 |
| - } else if (error.data && error.data.message) { |
83 |
| - resolve({ |
84 |
| - jsonrpc: '2.0', |
85 |
| - error: error.data && error.data, |
86 |
| - id: data.id, |
87 |
| - }); |
88 |
| - } else { |
89 |
| - resolve({ |
90 |
| - jsonrpc: '2.0', |
91 |
| - error, |
92 |
| - id: data.id, |
93 |
| - }); |
94 |
| - } |
95 |
| - } |
96 |
| - return resolve(response); |
97 |
| - }); |
98 |
| - }); |
99 |
| - } else { |
100 |
| - try { |
101 |
| - const message = await provider.request(data); |
102 |
| - return { jsonrpc: '2.0', result: message, id: data.id }; |
103 |
| - } catch (e: any) { |
104 |
| - return { |
105 |
| - jsonrpc: '2.0', |
106 |
| - error: { message: e.message, code: -32603 }, |
107 |
| - id: data.id, |
108 |
| - }; |
109 |
| - } |
110 |
| - } |
111 |
| - } |
112 |
| - } else { |
113 |
| - const err = `Cannot make ${data.method} request. Remix client is not connected to walletconnect client`; |
114 |
| - console.error(err); |
115 |
| - return { |
116 |
| - jsonrpc: '2.0', |
117 |
| - error: { message: err, code: -32603 }, |
118 |
| - id: data.id, |
119 |
| - }; |
120 |
| - } |
121 |
| - } |
| 55 | +// async sendAsync(data: RequestArguments) { |
| 56 | +// const address = this.web3modal.getAddress(); |
| 57 | +// const provider = this.web3modal.getWalletProvider(); |
| 58 | +// if (address && provider) { |
| 59 | +// if (data.method === 'eth_accounts') { |
| 60 | +// return { |
| 61 | +// jsonrpc: '2.0', |
| 62 | +// result: [address], |
| 63 | +// id: data.id, |
| 64 | +// }; |
| 65 | +// } else { |
| 66 | +// //@ts-expect-error this flag does not correspond to EIP-1193 but was introduced by MetaMask |
| 67 | +// if (provider.isMetamask && provider.sendAsync) { |
| 68 | +// return new Promise((resolve) => { |
| 69 | +// //@ts-expect-error sendAsync is a legacy function we know MetaMask supports it |
| 70 | +// provider.sendAsync(data, (error, response) => { |
| 71 | +// if (error) { |
| 72 | +// if ( |
| 73 | +// error.data && |
| 74 | +// error.data.originalError && |
| 75 | +// error.data.originalError.data |
| 76 | +// ) { |
| 77 | +// resolve({ |
| 78 | +// jsonrpc: '2.0', |
| 79 | +// error: error.data.originalError, |
| 80 | +// id: data.id, |
| 81 | +// }); |
| 82 | +// } else if (error.data && error.data.message) { |
| 83 | +// resolve({ |
| 84 | +// jsonrpc: '2.0', |
| 85 | +// error: error.data && error.data, |
| 86 | +// id: data.id, |
| 87 | +// }); |
| 88 | +// } else { |
| 89 | +// resolve({ |
| 90 | +// jsonrpc: '2.0', |
| 91 | +// error, |
| 92 | +// id: data.id, |
| 93 | +// }); |
| 94 | +// } |
| 95 | +// } |
| 96 | +// return resolve(response); |
| 97 | +// }); |
| 98 | +// }); |
| 99 | +// } else { |
| 100 | +// try { |
| 101 | +// const message = await provider.request(data); |
| 102 | +// return { jsonrpc: '2.0', result: message, id: data.id }; |
| 103 | +// } catch (e: any) { |
| 104 | +// return { |
| 105 | +// jsonrpc: '2.0', |
| 106 | +// error: { message: e.message, code: -32603 }, |
| 107 | +// id: data.id, |
| 108 | +// }; |
| 109 | +// } |
| 110 | +// } |
| 111 | +// } |
| 112 | +// } else { |
| 113 | +// const err = `Cannot make ${data.method} request. Remix client is not connected to walletconnect client`; |
| 114 | +// console.error(err); |
| 115 | +// return { |
| 116 | +// jsonrpc: '2.0', |
| 117 | +// error: { message: err, code: -32603 }, |
| 118 | +// id: data.id, |
| 119 | +// }; |
| 120 | +// } |
| 121 | +// } |
122 | 122 |
|
123 |
| - async deactivate() { |
124 |
| - console.log('deactivating walletconnect plugin...'); |
125 |
| - await this.web3modal.disconnect(); |
126 |
| - } |
127 |
| -} |
| 123 | +// async deactivate() { |
| 124 | +// console.log('deactivating walletconnect plugin...'); |
| 125 | +// await this.web3modal.disconnect(); |
| 126 | +// } |
| 127 | +// } |
128 | 128 |
|
129 |
| -export default new WalletConnect(); |
| 129 | +// export default new WalletConnect(); |
0 commit comments