@wagmi/core 0.2.0-next.9 → 0.2.2
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 +1 -1
- 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 +234 -0
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.js +6 -15
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +234 -0
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +212 -0
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.d.ts +1 -0
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +62 -0
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.js +7 -0
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +62 -0
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +58 -0
- package/connectors/metaMask/package.json +4 -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-159de546.esm.js +513 -0
- package/dist/base-5812b724.cjs.dev.js +540 -0
- package/dist/base-59f3457e.cjs.prod.js +540 -0
- package/dist/classPrivateMethodGet-55c9909f.esm.js +16 -0
- package/dist/classPrivateMethodGet-976c8120.cjs.dev.js +19 -0
- package/dist/classPrivateMethodGet-d7330ed7.cjs.prod.js +19 -0
- package/dist/client-4d8337e7.cjs.prod.js +606 -0
- package/dist/client-5d456446.esm.js +595 -0
- package/dist/client-f77a08e4.cjs.dev.js +606 -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 +55 -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 +48 -0
- package/dist/declarations/src/connectors/metaMask.d.ts +13 -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 +101 -0
- package/dist/declarations/src/utils/getInjectedName.d.ts +1 -0
- package/dist/declarations/src/utils/index.d.ts +3 -0
- package/dist/declarations/src/utils/normalizeChainId.d.ts +1 -0
- package/dist/declarations/src/utils/warn.d.ts +1 -0
- package/dist/wagmi-core.cjs.d.ts +1 -11
- package/dist/wagmi-core.cjs.dev.js +653 -0
- package/dist/wagmi-core.cjs.js +6 -15
- package/dist/wagmi-core.cjs.prod.js +653 -0
- package/dist/wagmi-core.esm.js +593 -0
- package/package.json +24 -12
package/LICENSE
CHANGED
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/tmm/wagmi/discussions)
|
|
20
|
+
- Follow [@awkweb](https://twitter.com/awkweb) on Twitter for project updates
|
|
21
|
+
- Sign the [guestbook](https://github.com/tmm/wagmi/discussions/2)
|
|
22
|
+
- Share [your project/organization](https://github.com/tmm/wagmi/discussions/201) using wagmi
|
|
23
|
+
|
|
24
|
+
## Support
|
|
25
|
+
|
|
26
|
+
If you find wagmi useful, please consider supporting development. Thank you 🙏
|
|
27
|
+
|
|
28
|
+
- [awkweb.eth](https://etherscan.io/enslookup-search?search=awkweb.eth)
|
|
29
|
+
- [GitHub Sponsors](https://github.com/sponsors/tmm?metadata_campaign=readme_core)
|
|
30
|
+
- [Gitcoin Grant](https://gitcoin.co/grants/4493/wagmi-react-hooks-library-for-ethereum)
|
|
@@ -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/coinbaseWallet";
|
|
1
|
+
export * from "../../../dist/declarations/src/connectors/coinbaseWallet";
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var base = require('../../../dist/base-5812b724.cjs.dev.js');
|
|
6
|
+
var ethers = require('ethers');
|
|
7
|
+
var utils = require('ethers/lib/utils');
|
|
8
|
+
require('eventemitter3');
|
|
9
|
+
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n["default"] = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var _client = /*#__PURE__*/new WeakMap();
|
|
29
|
+
|
|
30
|
+
var _provider = /*#__PURE__*/new WeakMap();
|
|
31
|
+
|
|
32
|
+
class CoinbaseWalletConnector extends base.Connector {
|
|
33
|
+
constructor(config) {
|
|
34
|
+
super(config);
|
|
35
|
+
|
|
36
|
+
base._defineProperty(this, "id", 'coinbaseWallet');
|
|
37
|
+
|
|
38
|
+
base._defineProperty(this, "name", 'Coinbase Wallet');
|
|
39
|
+
|
|
40
|
+
base._defineProperty(this, "ready", true);
|
|
41
|
+
|
|
42
|
+
base._classPrivateFieldInitSpec(this, _client, {
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
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
|
+
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 = utils.getAddress(accounts[0]);
|
|
85
|
+
const id = await this.getChainId();
|
|
86
|
+
const unsupported = this.isChainUnsupported(id);
|
|
87
|
+
return {
|
|
88
|
+
account,
|
|
89
|
+
chain: {
|
|
90
|
+
id,
|
|
91
|
+
unsupported
|
|
92
|
+
},
|
|
93
|
+
provider: new ethers.providers.Web3Provider(provider)
|
|
94
|
+
};
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (/(user closed modal|accounts received is empty)/i.test(error.message)) throw new base.UserRejectedRequestError();
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async disconnect() {
|
|
102
|
+
if (!base._classPrivateFieldGet(this, _provider)) return;
|
|
103
|
+
const provider = await this.getProvider();
|
|
104
|
+
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
105
|
+
provider.removeListener('chainChanged', this.onChainChanged);
|
|
106
|
+
provider.removeListener('disconnect', this.onDisconnect);
|
|
107
|
+
provider.disconnect();
|
|
108
|
+
provider.close();
|
|
109
|
+
|
|
110
|
+
if (typeof localStorage !== 'undefined') {
|
|
111
|
+
let n = localStorage.length;
|
|
112
|
+
|
|
113
|
+
while (n--) {
|
|
114
|
+
const key = localStorage.key(n);
|
|
115
|
+
if (!key) continue;
|
|
116
|
+
if (!/-walletlink/.test(key)) continue;
|
|
117
|
+
localStorage.removeItem(key);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async getAccount() {
|
|
123
|
+
const provider = await this.getProvider();
|
|
124
|
+
const accounts = await provider.request({
|
|
125
|
+
method: 'eth_accounts'
|
|
126
|
+
}); // return checksum address
|
|
127
|
+
|
|
128
|
+
return utils.getAddress(accounts[0]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async getChainId() {
|
|
132
|
+
const provider = await this.getProvider();
|
|
133
|
+
const chainId = base.normalizeChainId(provider.chainId);
|
|
134
|
+
return chainId;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async getProvider() {
|
|
138
|
+
if (!base._classPrivateFieldGet(this, _provider)) {
|
|
139
|
+
const {
|
|
140
|
+
CoinbaseWalletSDK
|
|
141
|
+
} = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); });
|
|
142
|
+
|
|
143
|
+
base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
|
|
144
|
+
|
|
145
|
+
base._classPrivateFieldSet(this, _provider, base._classPrivateFieldGet(this, _client).makeWeb3Provider(this.options.jsonRpcUrl, this.options.chainId));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return base._classPrivateFieldGet(this, _provider);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async getSigner() {
|
|
152
|
+
const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
|
|
153
|
+
return new ethers.providers.Web3Provider(provider).getSigner(account);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async isAuthorized() {
|
|
157
|
+
try {
|
|
158
|
+
const account = await this.getAccount();
|
|
159
|
+
return !!account;
|
|
160
|
+
} catch {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async switchChain(chainId) {
|
|
166
|
+
const provider = await this.getProvider();
|
|
167
|
+
const id = utils.hexValue(chainId);
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
var _chains$find;
|
|
171
|
+
|
|
172
|
+
await provider.request({
|
|
173
|
+
method: 'wallet_switchEthereumChain',
|
|
174
|
+
params: [{
|
|
175
|
+
chainId: id
|
|
176
|
+
}]
|
|
177
|
+
});
|
|
178
|
+
const chains = [...this.chains, ...base.allChains];
|
|
179
|
+
return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
|
|
180
|
+
id: chainId,
|
|
181
|
+
name: "Chain ".concat(id),
|
|
182
|
+
rpcUrls: {
|
|
183
|
+
default: ''
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
} catch (error) {
|
|
187
|
+
// Indicates chain is not added to provider
|
|
188
|
+
if (error.code === 4902) {
|
|
189
|
+
try {
|
|
190
|
+
const chain = this.chains.find(x => x.id === chainId);
|
|
191
|
+
if (!chain) throw new base.ChainNotConfiguredError();
|
|
192
|
+
await provider.request({
|
|
193
|
+
method: 'wallet_addEthereumChain',
|
|
194
|
+
params: [{
|
|
195
|
+
chainId: id,
|
|
196
|
+
chainName: chain.name,
|
|
197
|
+
nativeCurrency: chain.nativeCurrency,
|
|
198
|
+
rpcUrls: [chain.rpcUrls.default],
|
|
199
|
+
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
200
|
+
}]
|
|
201
|
+
});
|
|
202
|
+
return chain;
|
|
203
|
+
} catch (addError) {
|
|
204
|
+
throw new base.AddChainError();
|
|
205
|
+
}
|
|
206
|
+
} else if (error.code === 4001) throw new base.UserRejectedRequestError();else throw new base.SwitchChainError();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async watchAsset(_ref) {
|
|
211
|
+
let {
|
|
212
|
+
address,
|
|
213
|
+
decimals = 18,
|
|
214
|
+
image,
|
|
215
|
+
symbol
|
|
216
|
+
} = _ref;
|
|
217
|
+
const provider = await this.getProvider();
|
|
218
|
+
return await provider.request({
|
|
219
|
+
method: 'wallet_watchAsset',
|
|
220
|
+
params: {
|
|
221
|
+
type: 'ERC20',
|
|
222
|
+
options: {
|
|
223
|
+
address,
|
|
224
|
+
decimals,
|
|
225
|
+
image,
|
|
226
|
+
symbol
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
exports.CoinbaseWalletConnector = CoinbaseWalletConnector;
|
|
@@ -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-coinbaseWallet.cjs.prod.js");
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require("./wagmi-core-connectors-coinbaseWallet.cjs.dev.js");
|
|
7
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var base = require('../../../dist/base-59f3457e.cjs.prod.js');
|
|
6
|
+
var ethers = require('ethers');
|
|
7
|
+
var utils = require('ethers/lib/utils');
|
|
8
|
+
require('eventemitter3');
|
|
9
|
+
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n["default"] = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var _client = /*#__PURE__*/new WeakMap();
|
|
29
|
+
|
|
30
|
+
var _provider = /*#__PURE__*/new WeakMap();
|
|
31
|
+
|
|
32
|
+
class CoinbaseWalletConnector extends base.Connector {
|
|
33
|
+
constructor(config) {
|
|
34
|
+
super(config);
|
|
35
|
+
|
|
36
|
+
base._defineProperty(this, "id", 'coinbaseWallet');
|
|
37
|
+
|
|
38
|
+
base._defineProperty(this, "name", 'Coinbase Wallet');
|
|
39
|
+
|
|
40
|
+
base._defineProperty(this, "ready", true);
|
|
41
|
+
|
|
42
|
+
base._classPrivateFieldInitSpec(this, _client, {
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
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
|
+
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 = utils.getAddress(accounts[0]);
|
|
85
|
+
const id = await this.getChainId();
|
|
86
|
+
const unsupported = this.isChainUnsupported(id);
|
|
87
|
+
return {
|
|
88
|
+
account,
|
|
89
|
+
chain: {
|
|
90
|
+
id,
|
|
91
|
+
unsupported
|
|
92
|
+
},
|
|
93
|
+
provider: new ethers.providers.Web3Provider(provider)
|
|
94
|
+
};
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (/(user closed modal|accounts received is empty)/i.test(error.message)) throw new base.UserRejectedRequestError();
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async disconnect() {
|
|
102
|
+
if (!base._classPrivateFieldGet(this, _provider)) return;
|
|
103
|
+
const provider = await this.getProvider();
|
|
104
|
+
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
105
|
+
provider.removeListener('chainChanged', this.onChainChanged);
|
|
106
|
+
provider.removeListener('disconnect', this.onDisconnect);
|
|
107
|
+
provider.disconnect();
|
|
108
|
+
provider.close();
|
|
109
|
+
|
|
110
|
+
if (typeof localStorage !== 'undefined') {
|
|
111
|
+
let n = localStorage.length;
|
|
112
|
+
|
|
113
|
+
while (n--) {
|
|
114
|
+
const key = localStorage.key(n);
|
|
115
|
+
if (!key) continue;
|
|
116
|
+
if (!/-walletlink/.test(key)) continue;
|
|
117
|
+
localStorage.removeItem(key);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async getAccount() {
|
|
123
|
+
const provider = await this.getProvider();
|
|
124
|
+
const accounts = await provider.request({
|
|
125
|
+
method: 'eth_accounts'
|
|
126
|
+
}); // return checksum address
|
|
127
|
+
|
|
128
|
+
return utils.getAddress(accounts[0]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async getChainId() {
|
|
132
|
+
const provider = await this.getProvider();
|
|
133
|
+
const chainId = base.normalizeChainId(provider.chainId);
|
|
134
|
+
return chainId;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async getProvider() {
|
|
138
|
+
if (!base._classPrivateFieldGet(this, _provider)) {
|
|
139
|
+
const {
|
|
140
|
+
CoinbaseWalletSDK
|
|
141
|
+
} = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); });
|
|
142
|
+
|
|
143
|
+
base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
|
|
144
|
+
|
|
145
|
+
base._classPrivateFieldSet(this, _provider, base._classPrivateFieldGet(this, _client).makeWeb3Provider(this.options.jsonRpcUrl, this.options.chainId));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return base._classPrivateFieldGet(this, _provider);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async getSigner() {
|
|
152
|
+
const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
|
|
153
|
+
return new ethers.providers.Web3Provider(provider).getSigner(account);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async isAuthorized() {
|
|
157
|
+
try {
|
|
158
|
+
const account = await this.getAccount();
|
|
159
|
+
return !!account;
|
|
160
|
+
} catch {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async switchChain(chainId) {
|
|
166
|
+
const provider = await this.getProvider();
|
|
167
|
+
const id = utils.hexValue(chainId);
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
var _chains$find;
|
|
171
|
+
|
|
172
|
+
await provider.request({
|
|
173
|
+
method: 'wallet_switchEthereumChain',
|
|
174
|
+
params: [{
|
|
175
|
+
chainId: id
|
|
176
|
+
}]
|
|
177
|
+
});
|
|
178
|
+
const chains = [...this.chains, ...base.allChains];
|
|
179
|
+
return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
|
|
180
|
+
id: chainId,
|
|
181
|
+
name: "Chain ".concat(id),
|
|
182
|
+
rpcUrls: {
|
|
183
|
+
default: ''
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
} catch (error) {
|
|
187
|
+
// Indicates chain is not added to provider
|
|
188
|
+
if (error.code === 4902) {
|
|
189
|
+
try {
|
|
190
|
+
const chain = this.chains.find(x => x.id === chainId);
|
|
191
|
+
if (!chain) throw new base.ChainNotConfiguredError();
|
|
192
|
+
await provider.request({
|
|
193
|
+
method: 'wallet_addEthereumChain',
|
|
194
|
+
params: [{
|
|
195
|
+
chainId: id,
|
|
196
|
+
chainName: chain.name,
|
|
197
|
+
nativeCurrency: chain.nativeCurrency,
|
|
198
|
+
rpcUrls: [chain.rpcUrls.default],
|
|
199
|
+
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
200
|
+
}]
|
|
201
|
+
});
|
|
202
|
+
return chain;
|
|
203
|
+
} catch (addError) {
|
|
204
|
+
throw new base.AddChainError();
|
|
205
|
+
}
|
|
206
|
+
} else if (error.code === 4001) throw new base.UserRejectedRequestError();else throw new base.SwitchChainError();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async watchAsset(_ref) {
|
|
211
|
+
let {
|
|
212
|
+
address,
|
|
213
|
+
decimals = 18,
|
|
214
|
+
image,
|
|
215
|
+
symbol
|
|
216
|
+
} = _ref;
|
|
217
|
+
const provider = await this.getProvider();
|
|
218
|
+
return await provider.request({
|
|
219
|
+
method: 'wallet_watchAsset',
|
|
220
|
+
params: {
|
|
221
|
+
type: 'ERC20',
|
|
222
|
+
options: {
|
|
223
|
+
address,
|
|
224
|
+
decimals,
|
|
225
|
+
image,
|
|
226
|
+
symbol
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
exports.CoinbaseWalletConnector = CoinbaseWalletConnector;
|