@wagmi/core 0.2.0-next.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +30 -0
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.d.ts +1 -11
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +236 -0
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.js +6 -15
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +236 -0
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +214 -0
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.d.ts +1 -11
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +250 -0
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.js +6 -15
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +250 -0
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +241 -0
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.d.ts +1 -11
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +183 -0
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.js +6 -15
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +183 -0
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +161 -0
- package/dist/base-30d4fad4.cjs.prod.js +544 -0
- package/dist/base-a0d63eb0.cjs.dev.js +544 -0
- package/dist/base-f0102d32.esm.js +517 -0
- package/dist/classPrivateMethodGet-656c08a7.cjs.prod.js +19 -0
- package/dist/classPrivateMethodGet-9b9cd39b.cjs.dev.js +19 -0
- package/dist/classPrivateMethodGet-e0eaacfc.esm.js +16 -0
- package/dist/declarations/src/actions/accounts/connect.d.ts +16 -0
- package/dist/declarations/src/actions/accounts/disconnect.d.ts +1 -0
- package/dist/declarations/src/actions/accounts/fetchBalance.d.ts +20 -0
- package/dist/declarations/src/actions/accounts/fetchSigner.d.ts +3 -0
- package/dist/declarations/src/actions/accounts/getAccount.d.ts +7 -0
- package/dist/declarations/src/actions/accounts/getNetwork.d.ts +9 -0
- package/dist/declarations/src/actions/accounts/index.d.ts +12 -0
- package/dist/declarations/src/actions/accounts/signMessage.d.ts +9 -0
- package/dist/declarations/src/actions/accounts/signTypedData.d.ts +13 -0
- package/dist/declarations/src/actions/accounts/switchNetwork.d.ts +6 -0
- package/dist/declarations/src/actions/accounts/watchAccount.d.ts +4 -0
- package/dist/declarations/src/actions/accounts/watchNetwork.d.ts +3 -0
- package/dist/declarations/src/actions/accounts/watchSigner.d.ts +3 -0
- package/dist/declarations/src/actions/contracts/getContract.d.ts +11 -0
- package/dist/declarations/src/actions/contracts/index.d.ts +5 -0
- package/dist/declarations/src/actions/contracts/readContract.d.ts +14 -0
- package/dist/declarations/src/actions/contracts/watchContractEvent.d.ts +14 -0
- package/dist/declarations/src/actions/contracts/watchReadContract.d.ts +7 -0
- package/dist/declarations/src/actions/contracts/writeContract.d.ts +11 -0
- package/dist/declarations/src/actions/ens/fetchEnsAddress.d.ts +8 -0
- package/dist/declarations/src/actions/ens/fetchEnsAvatar.d.ts +8 -0
- package/dist/declarations/src/actions/ens/fetchEnsName.d.ts +8 -0
- package/dist/declarations/src/actions/ens/fetchEnsResolver.d.ts +9 -0
- package/dist/declarations/src/actions/ens/index.d.ts +4 -0
- package/dist/declarations/src/actions/index.d.ts +7 -0
- package/dist/declarations/src/actions/network-status/fetchBlockNumber.d.ts +5 -0
- package/dist/declarations/src/actions/network-status/fetchFeeData.d.ts +16 -0
- package/dist/declarations/src/actions/network-status/index.d.ts +3 -0
- package/dist/declarations/src/actions/network-status/watchBlockNumber.d.ts +6 -0
- package/dist/declarations/src/actions/providers/getProvider.d.ts +7 -0
- package/dist/declarations/src/actions/providers/getWebSocketProvider.d.ts +7 -0
- package/dist/declarations/src/actions/providers/index.d.ts +4 -0
- package/dist/declarations/src/actions/providers/watchProvider.d.ts +4 -0
- package/dist/declarations/src/actions/providers/watchWebSocketProvider.d.ts +4 -0
- package/dist/declarations/src/actions/tokens/fetchToken.d.ts +20 -0
- package/dist/declarations/src/actions/tokens/index.d.ts +1 -0
- package/dist/declarations/src/actions/transactions/index.d.ts +2 -0
- package/dist/declarations/src/actions/transactions/sendTransaction.d.ts +7 -0
- package/dist/declarations/src/actions/transactions/waitForTransaction.d.ts +17 -0
- package/dist/declarations/src/client.d.ts +81 -0
- package/dist/declarations/src/connectors/base.d.ts +56 -0
- package/dist/declarations/src/connectors/coinbaseWallet.d.ts +52 -0
- package/dist/declarations/src/connectors/index.d.ts +2 -0
- package/dist/declarations/src/connectors/injected.d.ts +47 -0
- package/dist/declarations/src/connectors/mock/connector.d.ts +37 -0
- package/dist/declarations/src/connectors/mock/index.d.ts +2 -0
- package/dist/declarations/src/connectors/mock/provider.d.ts +42 -0
- package/dist/declarations/src/connectors/walletConnect.d.ts +32 -0
- package/dist/declarations/src/constants/abis.d.ts +2 -0
- package/dist/declarations/src/constants/blockExplorers.d.ts +9 -0
- package/dist/declarations/src/constants/chains.d.ts +21 -0
- package/dist/declarations/src/constants/index.d.ts +7 -0
- package/dist/declarations/src/constants/rpcs.d.ts +9 -0
- package/dist/declarations/src/constants/units.d.ts +1 -0
- package/dist/declarations/src/errors.d.ts +28 -0
- package/dist/declarations/src/index.d.ts +12 -0
- package/dist/declarations/src/storage.d.ts +12 -0
- package/dist/declarations/src/types/index.d.ts +85 -0
- package/dist/declarations/src/utils/getInjectedName.d.ts +1 -0
- package/dist/declarations/src/utils/index.d.ts +2 -0
- package/dist/declarations/src/utils/normalizeChainId.d.ts +1 -0
- package/dist/wagmi-core.cjs.d.ts +1 -11
- package/dist/wagmi-core.cjs.dev.js +1204 -0
- package/dist/wagmi-core.cjs.js +6 -15
- package/dist/wagmi-core.cjs.prod.js +1204 -0
- package/dist/wagmi-core.esm.js +1139 -0
- package/package.json +17 -8
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var classPrivateMethodGet = require('../../../dist/classPrivateMethodGet-656c08a7.cjs.prod.js');
|
|
6
|
+
var base = require('../../../dist/base-30d4fad4.cjs.prod.js');
|
|
7
|
+
var utils = require('ethers/lib/utils');
|
|
8
|
+
var EventEmitter = require('eventemitter3');
|
|
9
|
+
var ethers = require('ethers');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var EventEmitter__default = /*#__PURE__*/_interopDefault(EventEmitter);
|
|
14
|
+
|
|
15
|
+
var _options = /*#__PURE__*/new WeakMap();
|
|
16
|
+
|
|
17
|
+
var _signer = /*#__PURE__*/new WeakMap();
|
|
18
|
+
|
|
19
|
+
class MockProvider extends ethers.providers.BaseProvider {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
var _options$network;
|
|
22
|
+
|
|
23
|
+
super((_options$network = options.network) !== null && _options$network !== void 0 ? _options$network : 1);
|
|
24
|
+
|
|
25
|
+
base._defineProperty(this, "events", new EventEmitter__default["default"]());
|
|
26
|
+
|
|
27
|
+
base._classPrivateFieldInitSpec(this, _options, {
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
base._classPrivateFieldInitSpec(this, _signer, {
|
|
33
|
+
writable: true,
|
|
34
|
+
value: void 0
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
base._classPrivateFieldSet(this, _options, options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async enable() {
|
|
41
|
+
var _classPrivateFieldGet2;
|
|
42
|
+
|
|
43
|
+
if ((_classPrivateFieldGet2 = base._classPrivateFieldGet(this, _options).flags) !== null && _classPrivateFieldGet2 !== void 0 && _classPrivateFieldGet2.failConnect) throw new base.UserRejectedRequestError();
|
|
44
|
+
if (!base._classPrivateFieldGet(this, _signer)) base._classPrivateFieldSet(this, _signer, base._classPrivateFieldGet(this, _options).signer);
|
|
45
|
+
const address = await base._classPrivateFieldGet(this, _signer).getAddress();
|
|
46
|
+
this.events.emit('accountsChanged', [address]);
|
|
47
|
+
return [address];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async disconnect() {
|
|
51
|
+
this.events.emit('disconnect');
|
|
52
|
+
|
|
53
|
+
base._classPrivateFieldSet(this, _signer, undefined);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async getAccounts() {
|
|
57
|
+
var _classPrivateFieldGet3;
|
|
58
|
+
|
|
59
|
+
const address = await ((_classPrivateFieldGet3 = base._classPrivateFieldGet(this, _signer)) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.getAddress());
|
|
60
|
+
if (!address) return [];
|
|
61
|
+
return [utils.getAddress(address)];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getSigner() {
|
|
65
|
+
const signer = base._classPrivateFieldGet(this, _signer);
|
|
66
|
+
|
|
67
|
+
if (!signer) throw new Error('Signer not found');
|
|
68
|
+
return signer;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async switchChain(chainId) {
|
|
72
|
+
var _classPrivateFieldGet4;
|
|
73
|
+
|
|
74
|
+
if ((_classPrivateFieldGet4 = base._classPrivateFieldGet(this, _options).flags) !== null && _classPrivateFieldGet4 !== void 0 && _classPrivateFieldGet4.failSwitchChain) throw new base.UserRejectedRequestError();
|
|
75
|
+
base._classPrivateFieldGet(this, _options).network = chainId;
|
|
76
|
+
this.network.chainId = chainId;
|
|
77
|
+
this.events.emit('chainChanged', chainId);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async watchAsset(_asset) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
on(event, listener) {
|
|
85
|
+
this.events.on(event, listener);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
once(event, listener) {
|
|
90
|
+
this.events.once(event, listener);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
removeListener(event, listener) {
|
|
95
|
+
this.events.removeListener(event, listener);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
off(event, listener) {
|
|
100
|
+
this.events.off(event, listener);
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
toJSON() {
|
|
105
|
+
return '<MockProvider>';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
var _provider = /*#__PURE__*/new WeakMap();
|
|
111
|
+
|
|
112
|
+
var _switchChain = /*#__PURE__*/new WeakSet();
|
|
113
|
+
|
|
114
|
+
class MockConnector extends base.Connector {
|
|
115
|
+
constructor(config) {
|
|
116
|
+
super(config);
|
|
117
|
+
|
|
118
|
+
classPrivateMethodGet._classPrivateMethodInitSpec(this, _switchChain);
|
|
119
|
+
|
|
120
|
+
base._defineProperty(this, "id", 'mock');
|
|
121
|
+
|
|
122
|
+
base._defineProperty(this, "name", 'Mock');
|
|
123
|
+
|
|
124
|
+
base._defineProperty(this, "ready", true);
|
|
125
|
+
|
|
126
|
+
base._classPrivateFieldInitSpec(this, _provider, {
|
|
127
|
+
writable: true,
|
|
128
|
+
value: void 0
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
base._defineProperty(this, "onAccountsChanged", accounts => {
|
|
132
|
+
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
133
|
+
account: utils.getAddress(accounts[0])
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
base._defineProperty(this, "onChainChanged", chainId => {
|
|
138
|
+
const id = base.normalizeChainId(chainId);
|
|
139
|
+
const unsupported = this.isChainUnsupported(id);
|
|
140
|
+
this.emit('change', {
|
|
141
|
+
chain: {
|
|
142
|
+
id,
|
|
143
|
+
unsupported
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
base._defineProperty(this, "onDisconnect", () => {
|
|
149
|
+
this.emit('disconnect');
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async connect() {
|
|
154
|
+
var _this$options$flags;
|
|
155
|
+
|
|
156
|
+
const provider = await this.getProvider();
|
|
157
|
+
provider.on('accountsChanged', this.onAccountsChanged);
|
|
158
|
+
provider.on('chainChanged', this.onChainChanged);
|
|
159
|
+
provider.on('disconnect', this.onDisconnect);
|
|
160
|
+
this.emit('message', {
|
|
161
|
+
type: 'connecting'
|
|
162
|
+
});
|
|
163
|
+
const accounts = await provider.enable();
|
|
164
|
+
const account = utils.getAddress(accounts[0]);
|
|
165
|
+
const id = base.normalizeChainId(provider._network.chainId);
|
|
166
|
+
const unsupported = this.isChainUnsupported(id);
|
|
167
|
+
const data = {
|
|
168
|
+
account,
|
|
169
|
+
chain: {
|
|
170
|
+
id,
|
|
171
|
+
unsupported
|
|
172
|
+
},
|
|
173
|
+
provider
|
|
174
|
+
};
|
|
175
|
+
if (!((_this$options$flags = this.options.flags) !== null && _this$options$flags !== void 0 && _this$options$flags.noSwitchChain)) this.switchChain = classPrivateMethodGet._classPrivateMethodGet(this, _switchChain, _switchChain2);
|
|
176
|
+
return data;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async disconnect() {
|
|
180
|
+
const provider = await this.getProvider();
|
|
181
|
+
await provider.disconnect();
|
|
182
|
+
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
183
|
+
provider.removeListener('chainChanged', this.onChainChanged);
|
|
184
|
+
provider.removeListener('disconnect', this.onDisconnect);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async getAccount() {
|
|
188
|
+
const provider = await this.getProvider();
|
|
189
|
+
const accounts = await provider.getAccounts();
|
|
190
|
+
const account = accounts[0];
|
|
191
|
+
if (!account) throw new Error('Failed to get account'); // return checksum address
|
|
192
|
+
|
|
193
|
+
return utils.getAddress(account);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async getChainId() {
|
|
197
|
+
const provider = await this.getProvider();
|
|
198
|
+
return base.normalizeChainId(provider.network.chainId);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async getProvider() {
|
|
202
|
+
if (!base._classPrivateFieldGet(this, _provider)) base._classPrivateFieldSet(this, _provider, new MockProvider(this.options));
|
|
203
|
+
return base._classPrivateFieldGet(this, _provider);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async getSigner() {
|
|
207
|
+
const provider = await this.getProvider();
|
|
208
|
+
return provider.getSigner();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async isAuthorized() {
|
|
212
|
+
try {
|
|
213
|
+
var _this$options$flags$i, _this$options$flags2;
|
|
214
|
+
|
|
215
|
+
const provider = await this.getProvider();
|
|
216
|
+
const account = await provider.getAccounts();
|
|
217
|
+
return (_this$options$flags$i = (_this$options$flags2 = this.options.flags) === null || _this$options$flags2 === void 0 ? void 0 : _this$options$flags2.isAuthorized) !== null && _this$options$flags$i !== void 0 ? _this$options$flags$i : !!account;
|
|
218
|
+
} catch {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async watchAsset(asset) {
|
|
224
|
+
const provider = await this.getProvider();
|
|
225
|
+
return await provider.watchAsset(asset);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
toJSON() {
|
|
229
|
+
return '<MockConnector>';
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function _switchChain2(chainId) {
|
|
235
|
+
var _chains$find;
|
|
236
|
+
|
|
237
|
+
const provider = await this.getProvider();
|
|
238
|
+
await provider.switchChain(chainId);
|
|
239
|
+
const chains = [...this.chains, ...base.allChains];
|
|
240
|
+
return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
|
|
241
|
+
id: chainId,
|
|
242
|
+
name: "Chain ".concat(chainId),
|
|
243
|
+
rpcUrls: {
|
|
244
|
+
default: ''
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
exports.MockConnector = MockConnector;
|
|
250
|
+
exports.MockProvider = MockProvider;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { _ as _classPrivateMethodInitSpec, a as _classPrivateMethodGet } from '../../../dist/classPrivateMethodGet-e0eaacfc.esm.js';
|
|
2
|
+
import { _ as _defineProperty, a as _classPrivateFieldInitSpec, c as _classPrivateFieldSet, d as _classPrivateFieldGet, U as UserRejectedRequestError, C as Connector, n as normalizeChainId, e as allChains } from '../../../dist/base-f0102d32.esm.js';
|
|
3
|
+
import { getAddress } from 'ethers/lib/utils';
|
|
4
|
+
import EventEmitter from 'eventemitter3';
|
|
5
|
+
import { providers } from 'ethers';
|
|
6
|
+
|
|
7
|
+
var _options = /*#__PURE__*/new WeakMap();
|
|
8
|
+
|
|
9
|
+
var _signer = /*#__PURE__*/new WeakMap();
|
|
10
|
+
|
|
11
|
+
class MockProvider extends providers.BaseProvider {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
var _options$network;
|
|
14
|
+
|
|
15
|
+
super((_options$network = options.network) !== null && _options$network !== void 0 ? _options$network : 1);
|
|
16
|
+
|
|
17
|
+
_defineProperty(this, "events", new EventEmitter());
|
|
18
|
+
|
|
19
|
+
_classPrivateFieldInitSpec(this, _options, {
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
_classPrivateFieldInitSpec(this, _signer, {
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
_classPrivateFieldSet(this, _options, options);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async enable() {
|
|
33
|
+
var _classPrivateFieldGet2;
|
|
34
|
+
|
|
35
|
+
if ((_classPrivateFieldGet2 = _classPrivateFieldGet(this, _options).flags) !== null && _classPrivateFieldGet2 !== void 0 && _classPrivateFieldGet2.failConnect) throw new UserRejectedRequestError();
|
|
36
|
+
if (!_classPrivateFieldGet(this, _signer)) _classPrivateFieldSet(this, _signer, _classPrivateFieldGet(this, _options).signer);
|
|
37
|
+
const address = await _classPrivateFieldGet(this, _signer).getAddress();
|
|
38
|
+
this.events.emit('accountsChanged', [address]);
|
|
39
|
+
return [address];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async disconnect() {
|
|
43
|
+
this.events.emit('disconnect');
|
|
44
|
+
|
|
45
|
+
_classPrivateFieldSet(this, _signer, undefined);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async getAccounts() {
|
|
49
|
+
var _classPrivateFieldGet3;
|
|
50
|
+
|
|
51
|
+
const address = await ((_classPrivateFieldGet3 = _classPrivateFieldGet(this, _signer)) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.getAddress());
|
|
52
|
+
if (!address) return [];
|
|
53
|
+
return [getAddress(address)];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getSigner() {
|
|
57
|
+
const signer = _classPrivateFieldGet(this, _signer);
|
|
58
|
+
|
|
59
|
+
if (!signer) throw new Error('Signer not found');
|
|
60
|
+
return signer;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async switchChain(chainId) {
|
|
64
|
+
var _classPrivateFieldGet4;
|
|
65
|
+
|
|
66
|
+
if ((_classPrivateFieldGet4 = _classPrivateFieldGet(this, _options).flags) !== null && _classPrivateFieldGet4 !== void 0 && _classPrivateFieldGet4.failSwitchChain) throw new UserRejectedRequestError();
|
|
67
|
+
_classPrivateFieldGet(this, _options).network = chainId;
|
|
68
|
+
this.network.chainId = chainId;
|
|
69
|
+
this.events.emit('chainChanged', chainId);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async watchAsset(_asset) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
on(event, listener) {
|
|
77
|
+
this.events.on(event, listener);
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
once(event, listener) {
|
|
82
|
+
this.events.once(event, listener);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
removeListener(event, listener) {
|
|
87
|
+
this.events.removeListener(event, listener);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
off(event, listener) {
|
|
92
|
+
this.events.off(event, listener);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
toJSON() {
|
|
97
|
+
return '<MockProvider>';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var _provider = /*#__PURE__*/new WeakMap();
|
|
103
|
+
|
|
104
|
+
var _switchChain = /*#__PURE__*/new WeakSet();
|
|
105
|
+
|
|
106
|
+
class MockConnector extends Connector {
|
|
107
|
+
constructor(config) {
|
|
108
|
+
super(config);
|
|
109
|
+
|
|
110
|
+
_classPrivateMethodInitSpec(this, _switchChain);
|
|
111
|
+
|
|
112
|
+
_defineProperty(this, "id", 'mock');
|
|
113
|
+
|
|
114
|
+
_defineProperty(this, "name", 'Mock');
|
|
115
|
+
|
|
116
|
+
_defineProperty(this, "ready", true);
|
|
117
|
+
|
|
118
|
+
_classPrivateFieldInitSpec(this, _provider, {
|
|
119
|
+
writable: true,
|
|
120
|
+
value: void 0
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
_defineProperty(this, "onAccountsChanged", accounts => {
|
|
124
|
+
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
125
|
+
account: getAddress(accounts[0])
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
_defineProperty(this, "onChainChanged", chainId => {
|
|
130
|
+
const id = normalizeChainId(chainId);
|
|
131
|
+
const unsupported = this.isChainUnsupported(id);
|
|
132
|
+
this.emit('change', {
|
|
133
|
+
chain: {
|
|
134
|
+
id,
|
|
135
|
+
unsupported
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
_defineProperty(this, "onDisconnect", () => {
|
|
141
|
+
this.emit('disconnect');
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async connect() {
|
|
146
|
+
var _this$options$flags;
|
|
147
|
+
|
|
148
|
+
const provider = await this.getProvider();
|
|
149
|
+
provider.on('accountsChanged', this.onAccountsChanged);
|
|
150
|
+
provider.on('chainChanged', this.onChainChanged);
|
|
151
|
+
provider.on('disconnect', this.onDisconnect);
|
|
152
|
+
this.emit('message', {
|
|
153
|
+
type: 'connecting'
|
|
154
|
+
});
|
|
155
|
+
const accounts = await provider.enable();
|
|
156
|
+
const account = getAddress(accounts[0]);
|
|
157
|
+
const id = normalizeChainId(provider._network.chainId);
|
|
158
|
+
const unsupported = this.isChainUnsupported(id);
|
|
159
|
+
const data = {
|
|
160
|
+
account,
|
|
161
|
+
chain: {
|
|
162
|
+
id,
|
|
163
|
+
unsupported
|
|
164
|
+
},
|
|
165
|
+
provider
|
|
166
|
+
};
|
|
167
|
+
if (!((_this$options$flags = this.options.flags) !== null && _this$options$flags !== void 0 && _this$options$flags.noSwitchChain)) this.switchChain = _classPrivateMethodGet(this, _switchChain, _switchChain2);
|
|
168
|
+
return data;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async disconnect() {
|
|
172
|
+
const provider = await this.getProvider();
|
|
173
|
+
await provider.disconnect();
|
|
174
|
+
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
175
|
+
provider.removeListener('chainChanged', this.onChainChanged);
|
|
176
|
+
provider.removeListener('disconnect', this.onDisconnect);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async getAccount() {
|
|
180
|
+
const provider = await this.getProvider();
|
|
181
|
+
const accounts = await provider.getAccounts();
|
|
182
|
+
const account = accounts[0];
|
|
183
|
+
if (!account) throw new Error('Failed to get account'); // return checksum address
|
|
184
|
+
|
|
185
|
+
return getAddress(account);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async getChainId() {
|
|
189
|
+
const provider = await this.getProvider();
|
|
190
|
+
return normalizeChainId(provider.network.chainId);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async getProvider() {
|
|
194
|
+
if (!_classPrivateFieldGet(this, _provider)) _classPrivateFieldSet(this, _provider, new MockProvider(this.options));
|
|
195
|
+
return _classPrivateFieldGet(this, _provider);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async getSigner() {
|
|
199
|
+
const provider = await this.getProvider();
|
|
200
|
+
return provider.getSigner();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async isAuthorized() {
|
|
204
|
+
try {
|
|
205
|
+
var _this$options$flags$i, _this$options$flags2;
|
|
206
|
+
|
|
207
|
+
const provider = await this.getProvider();
|
|
208
|
+
const account = await provider.getAccounts();
|
|
209
|
+
return (_this$options$flags$i = (_this$options$flags2 = this.options.flags) === null || _this$options$flags2 === void 0 ? void 0 : _this$options$flags2.isAuthorized) !== null && _this$options$flags$i !== void 0 ? _this$options$flags$i : !!account;
|
|
210
|
+
} catch {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async watchAsset(asset) {
|
|
216
|
+
const provider = await this.getProvider();
|
|
217
|
+
return await provider.watchAsset(asset);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
toJSON() {
|
|
221
|
+
return '<MockConnector>';
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function _switchChain2(chainId) {
|
|
227
|
+
var _chains$find;
|
|
228
|
+
|
|
229
|
+
const provider = await this.getProvider();
|
|
230
|
+
await provider.switchChain(chainId);
|
|
231
|
+
const chains = [...this.chains, ...allChains];
|
|
232
|
+
return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
|
|
233
|
+
id: chainId,
|
|
234
|
+
name: "Chain ".concat(chainId),
|
|
235
|
+
rpcUrls: {
|
|
236
|
+
default: ''
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export { MockConnector, MockProvider };
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
|
|
3
|
-
|
|
4
|
-
// curious why you need to?
|
|
5
|
-
// this file exists so that you can import from the entrypoint normally
|
|
6
|
-
// except that it points to your source file and you don't need to run build constantly
|
|
7
|
-
// which means we need to re-export all of the modules from your source file
|
|
8
|
-
// and since export * doesn't include default exports, we need to read your source file
|
|
9
|
-
// to check for a default export and re-export it if it exists
|
|
10
|
-
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
|
|
11
|
-
export * from "../../../src/connectors/walletConnect";
|
|
1
|
+
export * from "../../../dist/declarations/src/connectors/walletConnect";
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var classPrivateMethodGet = require('../../../dist/classPrivateMethodGet-9b9cd39b.cjs.dev.js');
|
|
6
|
+
var base = require('../../../dist/base-a0d63eb0.cjs.dev.js');
|
|
7
|
+
var ethers = require('ethers');
|
|
8
|
+
var utils = require('ethers/lib/utils');
|
|
9
|
+
require('eventemitter3');
|
|
10
|
+
|
|
11
|
+
function _interopNamespace(e) {
|
|
12
|
+
if (e && e.__esModule) return e;
|
|
13
|
+
var n = Object.create(null);
|
|
14
|
+
if (e) {
|
|
15
|
+
Object.keys(e).forEach(function (k) {
|
|
16
|
+
if (k !== 'default') {
|
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return e[k]; }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
n["default"] = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const switchChainAllowedRegex = /(rainbow)/i;
|
|
30
|
+
|
|
31
|
+
var _provider = /*#__PURE__*/new WeakMap();
|
|
32
|
+
|
|
33
|
+
var _switchChain = /*#__PURE__*/new WeakSet();
|
|
34
|
+
|
|
35
|
+
class WalletConnectConnector extends base.Connector {
|
|
36
|
+
constructor(config) {
|
|
37
|
+
super(config);
|
|
38
|
+
|
|
39
|
+
classPrivateMethodGet._classPrivateMethodInitSpec(this, _switchChain);
|
|
40
|
+
|
|
41
|
+
base._defineProperty(this, "id", 'walletConnect');
|
|
42
|
+
|
|
43
|
+
base._defineProperty(this, "name", 'WalletConnect');
|
|
44
|
+
|
|
45
|
+
base._defineProperty(this, "ready", true);
|
|
46
|
+
|
|
47
|
+
base._classPrivateFieldInitSpec(this, _provider, {
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
base._defineProperty(this, "onAccountsChanged", accounts => {
|
|
53
|
+
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
54
|
+
account: utils.getAddress(accounts[0])
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
base._defineProperty(this, "onChainChanged", chainId => {
|
|
59
|
+
const id = base.normalizeChainId(chainId);
|
|
60
|
+
const unsupported = this.isChainUnsupported(id);
|
|
61
|
+
this.emit('change', {
|
|
62
|
+
chain: {
|
|
63
|
+
id,
|
|
64
|
+
unsupported
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
base._defineProperty(this, "onDisconnect", () => {
|
|
70
|
+
this.emit('disconnect');
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async connect() {
|
|
75
|
+
try {
|
|
76
|
+
var _provider$connector$p, _provider$connector, _provider$connector$p2;
|
|
77
|
+
|
|
78
|
+
const provider = await this.getProvider(true);
|
|
79
|
+
provider.on('accountsChanged', this.onAccountsChanged);
|
|
80
|
+
provider.on('chainChanged', this.onChainChanged);
|
|
81
|
+
provider.on('disconnect', this.onDisconnect); // Defer message to the next tick to ensure wallet connect data (provided by `.enable()`) is available
|
|
82
|
+
|
|
83
|
+
setTimeout(() => this.emit('message', {
|
|
84
|
+
type: 'connecting'
|
|
85
|
+
}), 0);
|
|
86
|
+
const accounts = await provider.enable();
|
|
87
|
+
const account = utils.getAddress(accounts[0]);
|
|
88
|
+
const id = await this.getChainId();
|
|
89
|
+
const unsupported = this.isChainUnsupported(id); // Not all WalletConnect options support programmatic chain switching
|
|
90
|
+
// Only enable for wallet options that do
|
|
91
|
+
|
|
92
|
+
const walletName = (_provider$connector$p = (_provider$connector = provider.connector) === null || _provider$connector === void 0 ? void 0 : (_provider$connector$p2 = _provider$connector.peerMeta) === null || _provider$connector$p2 === void 0 ? void 0 : _provider$connector$p2.name) !== null && _provider$connector$p !== void 0 ? _provider$connector$p : '';
|
|
93
|
+
if (switchChainAllowedRegex.test(walletName)) this.switchChain = classPrivateMethodGet._classPrivateMethodGet(this, _switchChain, _switchChain2);
|
|
94
|
+
return {
|
|
95
|
+
account,
|
|
96
|
+
chain: {
|
|
97
|
+
id,
|
|
98
|
+
unsupported
|
|
99
|
+
},
|
|
100
|
+
provider: new ethers.providers.Web3Provider(provider)
|
|
101
|
+
};
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (/user closed modal/i.test(error.message)) throw new base.UserRejectedRequestError();
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async disconnect() {
|
|
109
|
+
const provider = await this.getProvider();
|
|
110
|
+
await provider.disconnect();
|
|
111
|
+
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
112
|
+
provider.removeListener('chainChanged', this.onChainChanged);
|
|
113
|
+
provider.removeListener('disconnect', this.onDisconnect);
|
|
114
|
+
typeof localStorage !== 'undefined' && localStorage.removeItem('walletconnect');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async getAccount() {
|
|
118
|
+
const provider = await this.getProvider();
|
|
119
|
+
const accounts = provider.accounts; // return checksum address
|
|
120
|
+
|
|
121
|
+
return utils.getAddress(accounts[0]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async getChainId() {
|
|
125
|
+
const provider = await this.getProvider();
|
|
126
|
+
const chainId = base.normalizeChainId(provider.chainId);
|
|
127
|
+
return chainId;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async getProvider(create) {
|
|
131
|
+
if (!base._classPrivateFieldGet(this, _provider) || create) {
|
|
132
|
+
const WalletConnectProvider = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@walletconnect/ethereum-provider')); })).default;
|
|
133
|
+
|
|
134
|
+
base._classPrivateFieldSet(this, _provider, new WalletConnectProvider(this.options));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return base._classPrivateFieldGet(this, _provider);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async getSigner() {
|
|
141
|
+
const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
|
|
142
|
+
return new ethers.providers.Web3Provider(provider).getSigner(account);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async isAuthorized() {
|
|
146
|
+
try {
|
|
147
|
+
const account = await this.getAccount();
|
|
148
|
+
return !!account;
|
|
149
|
+
} catch {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function _switchChain2(chainId) {
|
|
157
|
+
const provider = await this.getProvider();
|
|
158
|
+
const id = utils.hexValue(chainId);
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
var _chains$find;
|
|
162
|
+
|
|
163
|
+
await provider.request({
|
|
164
|
+
method: 'wallet_switchEthereumChain',
|
|
165
|
+
params: [{
|
|
166
|
+
chainId: id
|
|
167
|
+
}]
|
|
168
|
+
});
|
|
169
|
+
const chains = [...this.chains, ...base.allChains];
|
|
170
|
+
return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
|
|
171
|
+
id: chainId,
|
|
172
|
+
name: "Chain ".concat(id),
|
|
173
|
+
rpcUrls: {
|
|
174
|
+
default: ''
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
} catch (error) {
|
|
178
|
+
const message = typeof error === 'string' ? error : error === null || error === void 0 ? void 0 : error.message;
|
|
179
|
+
if (/user rejected request/i.test(message)) throw new base.UserRejectedRequestError();else throw new base.SwitchChainError();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
exports.WalletConnectConnector = WalletConnectConnector;
|