@wagmi/core 0.0.0-20220909032847
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 +21 -0
- package/README.md +30 -0
- package/chains/dist/wagmi-core-chains.esm.d.ts +11 -0
- package/chains/dist/wagmi-core-chains.esm.js +2 -0
- package/chains/package.json +3 -0
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.d.ts +11 -0
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +246 -0
- package/connectors/coinbaseWallet/package.json +3 -0
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.d.ts +11 -0
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +146 -0
- package/connectors/metaMask/package.json +3 -0
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.d.ts +11 -0
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +257 -0
- package/connectors/mock/package.json +3 -0
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.d.ts +11 -0
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +207 -0
- package/connectors/walletConnect/package.json +3 -0
- package/dist/chains-de91362e.esm.js +493 -0
- package/dist/getProvider-34b63ce9.esm.js +1055 -0
- package/dist/rpcs-f39d022b.esm.js +50 -0
- package/dist/wagmi-core.esm.d.ts +11 -0
- package/dist/wagmi-core.esm.js +1515 -0
- package/package.json +76 -0
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.d.ts +11 -0
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +32 -0
- package/providers/alchemy/package.json +3 -0
- package/providers/infura/dist/wagmi-core-providers-infura.esm.d.ts +11 -0
- package/providers/infura/dist/wagmi-core-providers-infura.esm.js +32 -0
- package/providers/infura/package.json +3 -0
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.d.ts +11 -0
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js +42 -0
- package/providers/jsonRpc/package.json +3 -0
- package/providers/public/dist/wagmi-core-providers-public.esm.d.ts +11 -0
- package/providers/public/dist/wagmi-core-providers-public.esm.js +28 -0
- package/providers/public/package.json +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 awkweb.eth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @wagmi/core
|
|
2
|
+
|
|
3
|
+
## Documentation
|
|
4
|
+
|
|
5
|
+
For full documentation and examples, visit [wagmi.sh](https://wagmi.sh).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Install wagmi and its ethers peer dependency.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @wagmi/core ethers
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Community
|
|
16
|
+
|
|
17
|
+
Check out the following places for more wagmi-related content:
|
|
18
|
+
|
|
19
|
+
- Join the [discussions on GitHub](https://github.com/wagmi-dev/wagmi/discussions)
|
|
20
|
+
- Follow [@wagmi_sh](https://twitter.com/wagmi_sh) on Twitter for project updates
|
|
21
|
+
- Share [your project/organization](https://github.com/wagmi-dev/wagmi/discussions/201) using wagmi
|
|
22
|
+
- Browse the [awesome-wagmi](https://github.com/wagmi-dev/awesome-wagmi) list of awesome projects and resources
|
|
23
|
+
|
|
24
|
+
## Support
|
|
25
|
+
|
|
26
|
+
If you find wagmi useful, please consider supporting development. Thank you 🙏
|
|
27
|
+
|
|
28
|
+
- [GitHub Sponsors](https://github.com/sponsors/wagmi-dev?metadata_campaign=readme_core)
|
|
29
|
+
- [Gitcoin Grant](https://gitcoin.co/grants/4493/wagmi-react-hooks-library-for-ethereum)
|
|
30
|
+
- [wagmi-dev.eth](https://etherscan.io/enslookup-search?search=wagmi-dev.eth)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// are you seeing an error that a default export doesn't exist but your source file has a default export?
|
|
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/chains";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { g as arbitrum, h as arbitrumGoerli, i as arbitrumRinkeby, j as foundry, k as goerli, l as hardhat, n as kovan, o as localhost, m as mainnet, p as optimism, r as optimismGoerli, q as optimismKovan, t as polygon, u as polygonMumbai, v as rinkeby, w as ropsten, s as sepolia } from '../../dist/chains-de91362e.esm.js';
|
|
2
|
+
import '../../dist/rpcs-f39d022b.esm.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// are you seeing an error that a default export doesn't exist but your source file has a default export?
|
|
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/coinbaseWallet";
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { l as Connector, _ as _classPrivateMethodInitSpec, t as _defineProperty, v as _classPrivateFieldInitSpec, n as normalizeChainId, U as UserRejectedRequestError, x as _classPrivateFieldGet, w as _classPrivateFieldSet, m as ChainNotConfiguredError, u as _classPrivateMethodGet, A as AddChainError, q as SwitchChainError } from '../../../dist/getProvider-34b63ce9.esm.js';
|
|
2
|
+
import { providers } from 'ethers';
|
|
3
|
+
import { getAddress, hexValue } from 'ethers/lib/utils';
|
|
4
|
+
import 'zustand/middleware';
|
|
5
|
+
import 'zustand/vanilla';
|
|
6
|
+
import 'eventemitter3';
|
|
7
|
+
import '../../../dist/chains-de91362e.esm.js';
|
|
8
|
+
import '../../../dist/rpcs-f39d022b.esm.js';
|
|
9
|
+
|
|
10
|
+
var _client = /*#__PURE__*/new WeakMap();
|
|
11
|
+
|
|
12
|
+
var _provider = /*#__PURE__*/new WeakMap();
|
|
13
|
+
|
|
14
|
+
var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
|
|
15
|
+
|
|
16
|
+
class CoinbaseWalletConnector extends Connector {
|
|
17
|
+
constructor(_ref) {
|
|
18
|
+
let {
|
|
19
|
+
chains,
|
|
20
|
+
options
|
|
21
|
+
} = _ref;
|
|
22
|
+
super({
|
|
23
|
+
chains,
|
|
24
|
+
options: {
|
|
25
|
+
reloadOnDisconnect: false,
|
|
26
|
+
...options
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
_classPrivateMethodInitSpec(this, _isUserRejectedRequestError);
|
|
31
|
+
|
|
32
|
+
_defineProperty(this, "id", 'coinbaseWallet');
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "name", 'Coinbase Wallet');
|
|
35
|
+
|
|
36
|
+
_defineProperty(this, "ready", true);
|
|
37
|
+
|
|
38
|
+
_classPrivateFieldInitSpec(this, _client, {
|
|
39
|
+
writable: true,
|
|
40
|
+
value: void 0
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
_classPrivateFieldInitSpec(this, _provider, {
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
_defineProperty(this, "onAccountsChanged", accounts => {
|
|
49
|
+
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
50
|
+
account: getAddress(accounts[0])
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
_defineProperty(this, "onChainChanged", chainId => {
|
|
55
|
+
const id = normalizeChainId(chainId);
|
|
56
|
+
const unsupported = this.isChainUnsupported(id);
|
|
57
|
+
this.emit('change', {
|
|
58
|
+
chain: {
|
|
59
|
+
id,
|
|
60
|
+
unsupported
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
_defineProperty(this, "onDisconnect", () => {
|
|
66
|
+
this.emit('disconnect');
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async connect() {
|
|
71
|
+
let {
|
|
72
|
+
chainId
|
|
73
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const provider = await this.getProvider();
|
|
77
|
+
provider.on('accountsChanged', this.onAccountsChanged);
|
|
78
|
+
provider.on('chainChanged', this.onChainChanged);
|
|
79
|
+
provider.on('disconnect', this.onDisconnect);
|
|
80
|
+
this.emit('message', {
|
|
81
|
+
type: 'connecting'
|
|
82
|
+
});
|
|
83
|
+
const accounts = await provider.enable();
|
|
84
|
+
const account = getAddress(accounts[0]); // Switch to chain if provided
|
|
85
|
+
|
|
86
|
+
let id = await this.getChainId();
|
|
87
|
+
let unsupported = this.isChainUnsupported(id);
|
|
88
|
+
|
|
89
|
+
if (chainId && id !== chainId) {
|
|
90
|
+
const chain = await this.switchChain(chainId);
|
|
91
|
+
id = chain.id;
|
|
92
|
+
unsupported = this.isChainUnsupported(id);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
account,
|
|
97
|
+
chain: {
|
|
98
|
+
id,
|
|
99
|
+
unsupported
|
|
100
|
+
},
|
|
101
|
+
provider: new providers.Web3Provider(provider)
|
|
102
|
+
};
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (/(user closed modal|accounts received is empty)/i.test(error.message)) throw new UserRejectedRequestError(error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async disconnect() {
|
|
110
|
+
if (!_classPrivateFieldGet(this, _provider)) return;
|
|
111
|
+
const provider = await this.getProvider();
|
|
112
|
+
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
113
|
+
provider.removeListener('chainChanged', this.onChainChanged);
|
|
114
|
+
provider.removeListener('disconnect', this.onDisconnect);
|
|
115
|
+
provider.disconnect();
|
|
116
|
+
provider.close();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async getAccount() {
|
|
120
|
+
const provider = await this.getProvider();
|
|
121
|
+
const accounts = await provider.request({
|
|
122
|
+
method: 'eth_accounts'
|
|
123
|
+
}); // return checksum address
|
|
124
|
+
|
|
125
|
+
return getAddress(accounts[0]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async getChainId() {
|
|
129
|
+
const provider = await this.getProvider();
|
|
130
|
+
const chainId = normalizeChainId(provider.chainId);
|
|
131
|
+
return chainId;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async getProvider() {
|
|
135
|
+
if (!_classPrivateFieldGet(this, _provider)) {
|
|
136
|
+
const chain = this.chains.find(chain => chain.id === this.options.chainId) || this.chains[0];
|
|
137
|
+
const chainId = this.options.chainId || (chain === null || chain === void 0 ? void 0 : chain.id);
|
|
138
|
+
const jsonRpcUrl = this.options.jsonRpcUrl || (chain === null || chain === void 0 ? void 0 : chain.rpcUrls.default);
|
|
139
|
+
let CoinbaseWalletSDK = (await import('@coinbase/wallet-sdk')).default; // Workaround for Vite dev import errors
|
|
140
|
+
// https://github.com/vitejs/vite/issues/7112
|
|
141
|
+
|
|
142
|
+
if (typeof CoinbaseWalletSDK !== 'function' && // @ts-expect-error This import error is not visible to TypeScript
|
|
143
|
+
typeof CoinbaseWalletSDK.default === 'function') CoinbaseWalletSDK = CoinbaseWalletSDK.default;
|
|
144
|
+
|
|
145
|
+
_classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
|
|
146
|
+
|
|
147
|
+
_classPrivateFieldSet(this, _provider, _classPrivateFieldGet(this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return _classPrivateFieldGet(this, _provider);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async getSigner() {
|
|
154
|
+
const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
|
|
155
|
+
return new providers.Web3Provider(provider).getSigner(account);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async isAuthorized() {
|
|
159
|
+
try {
|
|
160
|
+
const account = await this.getAccount();
|
|
161
|
+
return !!account;
|
|
162
|
+
} catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async switchChain(chainId) {
|
|
168
|
+
const provider = await this.getProvider();
|
|
169
|
+
const id = hexValue(chainId);
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
var _this$chains$find;
|
|
173
|
+
|
|
174
|
+
await provider.request({
|
|
175
|
+
method: 'wallet_switchEthereumChain',
|
|
176
|
+
params: [{
|
|
177
|
+
chainId: id
|
|
178
|
+
}]
|
|
179
|
+
});
|
|
180
|
+
return (_this$chains$find = this.chains.find(x => x.id === chainId)) !== null && _this$chains$find !== void 0 ? _this$chains$find : {
|
|
181
|
+
id: chainId,
|
|
182
|
+
name: "Chain ".concat(id),
|
|
183
|
+
network: "".concat(id),
|
|
184
|
+
rpcUrls: {
|
|
185
|
+
default: ''
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
} catch (error) {
|
|
189
|
+
const chain = this.chains.find(x => x.id === chainId);
|
|
190
|
+
if (!chain) throw new ChainNotConfiguredError(); // Indicates chain is not added to provider
|
|
191
|
+
|
|
192
|
+
if (error.code === 4902) {
|
|
193
|
+
try {
|
|
194
|
+
var _chain$rpcUrls$public;
|
|
195
|
+
|
|
196
|
+
await provider.request({
|
|
197
|
+
method: 'wallet_addEthereumChain',
|
|
198
|
+
params: [{
|
|
199
|
+
chainId: id,
|
|
200
|
+
chainName: chain.name,
|
|
201
|
+
nativeCurrency: chain.nativeCurrency,
|
|
202
|
+
rpcUrls: [(_chain$rpcUrls$public = chain.rpcUrls.public) !== null && _chain$rpcUrls$public !== void 0 ? _chain$rpcUrls$public : chain.rpcUrls.default],
|
|
203
|
+
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
204
|
+
}]
|
|
205
|
+
});
|
|
206
|
+
return chain;
|
|
207
|
+
} catch (addError) {
|
|
208
|
+
if (_classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, addError)) throw new UserRejectedRequestError(addError);
|
|
209
|
+
throw new AddChainError();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (_classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, error)) throw new UserRejectedRequestError(error);
|
|
214
|
+
throw new SwitchChainError(error);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async watchAsset(_ref2) {
|
|
219
|
+
let {
|
|
220
|
+
address,
|
|
221
|
+
decimals = 18,
|
|
222
|
+
image,
|
|
223
|
+
symbol
|
|
224
|
+
} = _ref2;
|
|
225
|
+
const provider = await this.getProvider();
|
|
226
|
+
return await provider.request({
|
|
227
|
+
method: 'wallet_watchAsset',
|
|
228
|
+
params: {
|
|
229
|
+
type: 'ERC20',
|
|
230
|
+
options: {
|
|
231
|
+
address,
|
|
232
|
+
decimals,
|
|
233
|
+
image,
|
|
234
|
+
symbol
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function _isUserRejectedRequestError2(error) {
|
|
243
|
+
return /(user rejected)/i.test(error.message);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export { CoinbaseWalletConnector };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// are you seeing an error that a default export doesn't exist but your source file has a default export?
|
|
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/metaMask";
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { I as InjectedConnector, _ as _classPrivateMethodInitSpec, t as _defineProperty, u as _classPrivateMethodGet, v as _classPrivateFieldInitSpec, w as _classPrivateFieldSet, a as ConnectorNotFoundError, x as _classPrivateFieldGet, g as getClient, U as UserRejectedRequestError, R as ResourceUnavailableError } from '../../../dist/getProvider-34b63ce9.esm.js';
|
|
2
|
+
import 'zustand/middleware';
|
|
3
|
+
import 'zustand/vanilla';
|
|
4
|
+
import 'ethers';
|
|
5
|
+
import 'ethers/lib/utils';
|
|
6
|
+
import 'eventemitter3';
|
|
7
|
+
import '../../../dist/chains-de91362e.esm.js';
|
|
8
|
+
import '../../../dist/rpcs-f39d022b.esm.js';
|
|
9
|
+
|
|
10
|
+
var _provider = /*#__PURE__*/new WeakMap();
|
|
11
|
+
|
|
12
|
+
var _UNSTABLE_shimOnConnectSelectAccount = /*#__PURE__*/new WeakMap();
|
|
13
|
+
|
|
14
|
+
var _getReady = /*#__PURE__*/new WeakSet();
|
|
15
|
+
|
|
16
|
+
var _findProvider = /*#__PURE__*/new WeakSet();
|
|
17
|
+
|
|
18
|
+
class MetaMaskConnector extends InjectedConnector {
|
|
19
|
+
constructor() {
|
|
20
|
+
let {
|
|
21
|
+
chains,
|
|
22
|
+
options: options_
|
|
23
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
|
+
const options = {
|
|
25
|
+
name: 'MetaMask',
|
|
26
|
+
shimDisconnect: true,
|
|
27
|
+
shimChainChangedDisconnect: true,
|
|
28
|
+
...options_
|
|
29
|
+
};
|
|
30
|
+
super({
|
|
31
|
+
chains,
|
|
32
|
+
options
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
_classPrivateMethodInitSpec(this, _findProvider);
|
|
36
|
+
|
|
37
|
+
_classPrivateMethodInitSpec(this, _getReady);
|
|
38
|
+
|
|
39
|
+
_defineProperty(this, "id", 'metaMask');
|
|
40
|
+
|
|
41
|
+
_defineProperty(this, "ready", typeof window != 'undefined' && !!_classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
|
|
42
|
+
|
|
43
|
+
_classPrivateFieldInitSpec(this, _provider, {
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
_classPrivateFieldInitSpec(this, _UNSTABLE_shimOnConnectSelectAccount, {
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
_classPrivateFieldSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async connect() {
|
|
57
|
+
let {
|
|
58
|
+
chainId
|
|
59
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
var _this$options, _getClient$storage, _this$options2, _getClient$storage2;
|
|
63
|
+
|
|
64
|
+
const provider = await this.getProvider();
|
|
65
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
66
|
+
|
|
67
|
+
if (provider.on) {
|
|
68
|
+
provider.on('accountsChanged', this.onAccountsChanged);
|
|
69
|
+
provider.on('chainChanged', this.onChainChanged);
|
|
70
|
+
provider.on('disconnect', this.onDisconnect);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.emit('message', {
|
|
74
|
+
type: 'connecting'
|
|
75
|
+
}); // Attempt to show wallet select prompt with `wallet_requestPermissions` when
|
|
76
|
+
// `shimDisconnect` is active and account is in disconnected state (flag in storage)
|
|
77
|
+
|
|
78
|
+
if (_classPrivateFieldGet(this, _UNSTABLE_shimOnConnectSelectAccount) && (_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect && !((_getClient$storage = getClient().storage) !== null && _getClient$storage !== void 0 && _getClient$storage.getItem(this.shimDisconnectKey))) {
|
|
79
|
+
const accounts = await provider.request({
|
|
80
|
+
method: 'eth_accounts'
|
|
81
|
+
}).catch(() => []);
|
|
82
|
+
const isConnected = !!accounts[0];
|
|
83
|
+
if (isConnected) await provider.request({
|
|
84
|
+
method: 'wallet_requestPermissions',
|
|
85
|
+
params: [{
|
|
86
|
+
eth_accounts: {}
|
|
87
|
+
}]
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const account = await this.getAccount(); // Switch to chain if provided
|
|
92
|
+
|
|
93
|
+
let id = await this.getChainId();
|
|
94
|
+
let unsupported = this.isChainUnsupported(id);
|
|
95
|
+
|
|
96
|
+
if (chainId && id !== chainId) {
|
|
97
|
+
const chain = await this.switchChain(chainId);
|
|
98
|
+
id = chain.id;
|
|
99
|
+
unsupported = this.isChainUnsupported(id);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(this.shimDisconnectKey, true);
|
|
103
|
+
return {
|
|
104
|
+
account,
|
|
105
|
+
chain: {
|
|
106
|
+
id,
|
|
107
|
+
unsupported
|
|
108
|
+
},
|
|
109
|
+
provider
|
|
110
|
+
};
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (this.isUserRejectedRequestError(error)) throw new UserRejectedRequestError(error);
|
|
113
|
+
if (error.code === -32002) throw new ResourceUnavailableError(error);
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async getProvider() {
|
|
119
|
+
if (typeof window !== 'undefined') {
|
|
120
|
+
// TODO: Fallback to `ethereum#initialized` event for async injection
|
|
121
|
+
// https://github.com/MetaMask/detect-provider#synchronous-and-asynchronous-injection=
|
|
122
|
+
_classPrivateFieldSet(this, _provider, _classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return _classPrivateFieldGet(this, _provider);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function _getReady2(ethereum) {
|
|
131
|
+
const isMetaMask = !!(ethereum !== null && ethereum !== void 0 && ethereum.isMetaMask);
|
|
132
|
+
if (!isMetaMask) return; // Brave tries to make itself look like MetaMask
|
|
133
|
+
// Could also try RPC `web3_clientVersion` if following is unreliable
|
|
134
|
+
|
|
135
|
+
if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state) return;
|
|
136
|
+
if (ethereum.isTokenPocket) return;
|
|
137
|
+
if (ethereum.isTokenary) return;
|
|
138
|
+
return ethereum;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function _findProvider2(ethereum) {
|
|
142
|
+
if (ethereum !== null && ethereum !== void 0 && ethereum.providers) return ethereum.providers.find(_classPrivateMethodGet(this, _getReady, _getReady2));
|
|
143
|
+
return _classPrivateMethodGet(this, _getReady, _getReady2).call(this, ethereum);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { MetaMaskConnector };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// are you seeing an error that a default export doesn't exist but your source file has a default export?
|
|
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";
|