@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,214 @@
|
|
|
1
|
+
import { C as Connector, _ as _defineProperty, a as _classPrivateFieldInitSpec, n as normalizeChainId, U as UserRejectedRequestError, d as _classPrivateFieldGet, c as _classPrivateFieldSet, e as allChains, f as ChainNotConfiguredError, A as AddChainError, S as SwitchChainError } from '../../../dist/base-f0102d32.esm.js';
|
|
2
|
+
import { providers } from 'ethers';
|
|
3
|
+
import { getAddress, hexValue } from 'ethers/lib/utils';
|
|
4
|
+
import 'eventemitter3';
|
|
5
|
+
|
|
6
|
+
var _client = /*#__PURE__*/new WeakMap();
|
|
7
|
+
|
|
8
|
+
var _provider = /*#__PURE__*/new WeakMap();
|
|
9
|
+
|
|
10
|
+
class CoinbaseWalletConnector extends Connector {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
var _window$ethereum;
|
|
13
|
+
|
|
14
|
+
super(config);
|
|
15
|
+
|
|
16
|
+
_defineProperty(this, "id", 'coinbaseWallet');
|
|
17
|
+
|
|
18
|
+
_defineProperty(this, "name", 'Coinbase Wallet');
|
|
19
|
+
|
|
20
|
+
_defineProperty(this, "ready", typeof window !== 'undefined' && !((_window$ethereum = window.ethereum) !== null && _window$ethereum !== void 0 && _window$ethereum.isCoinbaseWallet));
|
|
21
|
+
|
|
22
|
+
_classPrivateFieldInitSpec(this, _client, {
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
_classPrivateFieldInitSpec(this, _provider, {
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
_defineProperty(this, "onAccountsChanged", accounts => {
|
|
33
|
+
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
34
|
+
account: getAddress(accounts[0])
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
_defineProperty(this, "onChainChanged", chainId => {
|
|
39
|
+
const id = normalizeChainId(chainId);
|
|
40
|
+
const unsupported = this.isChainUnsupported(id);
|
|
41
|
+
this.emit('change', {
|
|
42
|
+
chain: {
|
|
43
|
+
id,
|
|
44
|
+
unsupported
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
_defineProperty(this, "onDisconnect", () => {
|
|
50
|
+
this.emit('disconnect');
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async connect() {
|
|
55
|
+
try {
|
|
56
|
+
const provider = await this.getProvider();
|
|
57
|
+
provider.on('accountsChanged', this.onAccountsChanged);
|
|
58
|
+
provider.on('chainChanged', this.onChainChanged);
|
|
59
|
+
provider.on('disconnect', this.onDisconnect);
|
|
60
|
+
this.emit('message', {
|
|
61
|
+
type: 'connecting'
|
|
62
|
+
});
|
|
63
|
+
const accounts = await provider.enable();
|
|
64
|
+
const account = getAddress(accounts[0]);
|
|
65
|
+
const id = await this.getChainId();
|
|
66
|
+
const unsupported = this.isChainUnsupported(id);
|
|
67
|
+
return {
|
|
68
|
+
account,
|
|
69
|
+
chain: {
|
|
70
|
+
id,
|
|
71
|
+
unsupported
|
|
72
|
+
},
|
|
73
|
+
provider: new providers.Web3Provider(provider)
|
|
74
|
+
};
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (/user closed modal/i.test(error.message)) throw new UserRejectedRequestError();
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async disconnect() {
|
|
82
|
+
if (!_classPrivateFieldGet(this, _provider)) return;
|
|
83
|
+
const provider = await this.getProvider();
|
|
84
|
+
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
85
|
+
provider.removeListener('chainChanged', this.onChainChanged);
|
|
86
|
+
provider.removeListener('disconnect', this.onDisconnect);
|
|
87
|
+
provider.disconnect();
|
|
88
|
+
provider.close();
|
|
89
|
+
|
|
90
|
+
if (typeof localStorage !== 'undefined') {
|
|
91
|
+
let n = localStorage.length;
|
|
92
|
+
|
|
93
|
+
while (n--) {
|
|
94
|
+
const key = localStorage.key(n);
|
|
95
|
+
if (!key) continue;
|
|
96
|
+
if (!/-walletlink/.test(key)) continue;
|
|
97
|
+
localStorage.removeItem(key);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async getAccount() {
|
|
103
|
+
const provider = await this.getProvider();
|
|
104
|
+
const accounts = await provider.request({
|
|
105
|
+
method: 'eth_accounts'
|
|
106
|
+
}); // return checksum address
|
|
107
|
+
|
|
108
|
+
return getAddress(accounts[0]);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async getChainId() {
|
|
112
|
+
const provider = await this.getProvider();
|
|
113
|
+
const chainId = normalizeChainId(provider.chainId);
|
|
114
|
+
return chainId;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async getProvider() {
|
|
118
|
+
if (!_classPrivateFieldGet(this, _provider)) {
|
|
119
|
+
const {
|
|
120
|
+
CoinbaseWalletSDK
|
|
121
|
+
} = await import('@coinbase/wallet-sdk');
|
|
122
|
+
|
|
123
|
+
_classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
|
|
124
|
+
|
|
125
|
+
_classPrivateFieldSet(this, _provider, _classPrivateFieldGet(this, _client).makeWeb3Provider(this.options.jsonRpcUrl, this.options.chainId));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return _classPrivateFieldGet(this, _provider);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async getSigner() {
|
|
132
|
+
const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
|
|
133
|
+
return new providers.Web3Provider(provider).getSigner(account);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async isAuthorized() {
|
|
137
|
+
try {
|
|
138
|
+
const account = await this.getAccount();
|
|
139
|
+
return !!account;
|
|
140
|
+
} catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async switchChain(chainId) {
|
|
146
|
+
const provider = await this.getProvider();
|
|
147
|
+
const id = hexValue(chainId);
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
var _chains$find;
|
|
151
|
+
|
|
152
|
+
await provider.request({
|
|
153
|
+
method: 'wallet_switchEthereumChain',
|
|
154
|
+
params: [{
|
|
155
|
+
chainId: id
|
|
156
|
+
}]
|
|
157
|
+
});
|
|
158
|
+
const chains = [...this.chains, ...allChains];
|
|
159
|
+
return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
|
|
160
|
+
id: chainId,
|
|
161
|
+
name: "Chain ".concat(id),
|
|
162
|
+
rpcUrls: {
|
|
163
|
+
default: ''
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
} catch (error) {
|
|
167
|
+
// Indicates chain is not added to provider
|
|
168
|
+
if (error.code === 4902) {
|
|
169
|
+
try {
|
|
170
|
+
const chain = this.chains.find(x => x.id === chainId);
|
|
171
|
+
if (!chain) throw new ChainNotConfiguredError();
|
|
172
|
+
await provider.request({
|
|
173
|
+
method: 'wallet_addEthereumChain',
|
|
174
|
+
params: [{
|
|
175
|
+
chainId: id,
|
|
176
|
+
chainName: chain.name,
|
|
177
|
+
nativeCurrency: chain.nativeCurrency,
|
|
178
|
+
rpcUrls: this.getRpcUrls(chain),
|
|
179
|
+
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
180
|
+
}]
|
|
181
|
+
});
|
|
182
|
+
return chain;
|
|
183
|
+
} catch (addError) {
|
|
184
|
+
throw new AddChainError();
|
|
185
|
+
}
|
|
186
|
+
} else if (error.code === 4001) throw new UserRejectedRequestError();else throw new SwitchChainError();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async watchAsset(_ref) {
|
|
191
|
+
let {
|
|
192
|
+
address,
|
|
193
|
+
decimals = 18,
|
|
194
|
+
image,
|
|
195
|
+
symbol
|
|
196
|
+
} = _ref;
|
|
197
|
+
const provider = await this.getProvider();
|
|
198
|
+
return await provider.request({
|
|
199
|
+
method: 'wallet_watchAsset',
|
|
200
|
+
params: {
|
|
201
|
+
type: 'ERC20',
|
|
202
|
+
options: {
|
|
203
|
+
address,
|
|
204
|
+
decimals,
|
|
205
|
+
image,
|
|
206
|
+
symbol
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export { CoinbaseWalletConnector };
|
|
@@ -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/mock/index";
|
|
1
|
+
export * from "../../../dist/declarations/src/connectors/mock/index";
|
|
@@ -0,0 +1,250 @@
|
|
|
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 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;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
// this file might look strange and you might be wondering what it's for
|
|
3
|
-
// it's lets you import your source files by importing this entrypoint
|
|
4
|
-
// as you would import it if it was built with preconstruct build
|
|
5
|
-
// this file is slightly different to some others though
|
|
6
|
-
// it has a require hook which compiles your code with Babel
|
|
7
|
-
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
-
// but you can still require this module and it'll be compiled
|
|
1
|
+
'use strict';
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
unregister();
|
|
3
|
+
if (process.env.NODE_ENV === "production") {
|
|
4
|
+
module.exports = require("./wagmi-core-connectors-mock.cjs.prod.js");
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require("./wagmi-core-connectors-mock.cjs.dev.js");
|
|
7
|
+
}
|