Skip to content

Commit 1284e7b

Browse files
committed
Fix and upgrade walletconnect plugin
1 parent ead79fd commit 1284e7b

File tree

9 files changed

+1060
-1047
lines changed

9 files changed

+1060
-1047
lines changed

Diff for: apps/remix-dapp/src/actions/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { toBytes, addHexPrefix } from '@ethereumjs/util';
77
import { toast } from 'react-toastify';
88
import txRunner from '../utils/txRunner';
99
import metamask from '../utils/metamask';
10-
import walletConnect from '../utils/walletConnect';
10+
// import walletConnect from '../utils/walletConnect';
1111
import buildData from '../utils/buildData';
1212

1313
const { txFormat, txHelper: { makeFullTypeDefinition } } = execution;
@@ -61,8 +61,8 @@ export const setProvider = async (payload: any) => {
6161
}
6262

6363
if (provider === 'walletconnect') {
64-
txRunner.setProvider(walletConnect as any);
65-
walletConnect.subscribeToEvents();
64+
// txRunner.setProvider(walletConnect as any);
65+
// walletConnect.subscribeToEvents();
6666
}
6767
};
6868

Diff for: apps/remix-dapp/src/components/SettingsUI/network.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function NetworkUI() {
3939
</div>
4040
{provider === 'walletconnect' && (
4141
<div className="mt-2">
42-
<w3m-button />
42+
{/* <w3m-button /> */}
4343
</div>
4444
)}
4545
</div>

Diff for: apps/remix-dapp/src/utils/walletConnect.ts

+122-122
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,129 @@
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';
1111

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;
1919

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+
// });
2626

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+
// }
3636

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+
// }
5454

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+
// }
122122

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+
// }
128128

129-
export default new WalletConnect();
129+
// export default new WalletConnect();

0 commit comments

Comments
 (0)