@wagmi/core 0.2.0-next.5 → 0.2.0-next.8

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.
Files changed (41) hide show
  1. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +135 -149
  2. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +135 -149
  3. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +136 -150
  4. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +96 -153
  5. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +96 -153
  6. package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +96 -153
  7. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +91 -122
  8. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +91 -122
  9. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +91 -122
  10. package/dist/base-7ffc0425.cjs.prod.js +541 -0
  11. package/dist/base-82f423a9.esm.js +515 -0
  12. package/dist/base-b3073ce2.cjs.dev.js +541 -0
  13. package/dist/{classPrivateMethodGet-38b54c7a.cjs.dev.js → classPrivateMethodGet-0dc9fedc.cjs.dev.js} +1 -1
  14. package/dist/{classPrivateMethodGet-c9db96d6.esm.js → classPrivateMethodGet-1c660f09.esm.js} +1 -1
  15. package/dist/{classPrivateMethodGet-0e9a7925.cjs.prod.js → classPrivateMethodGet-c084b176.cjs.prod.js} +1 -1
  16. package/dist/declarations/src/actions/accounts/connect.d.ts +12 -3
  17. package/dist/declarations/src/actions/accounts/index.d.ts +1 -1
  18. package/dist/declarations/src/actions/accounts/switchNetwork.d.ts +1 -1
  19. package/dist/declarations/src/actions/index.d.ts +1 -1
  20. package/dist/declarations/src/client.d.ts +1 -1
  21. package/dist/declarations/src/connectors/base.d.ts +7 -1
  22. package/dist/declarations/src/connectors/coinbaseWallet.d.ts +9 -0
  23. package/dist/declarations/src/constants/abis.d.ts +2 -0
  24. package/dist/declarations/src/constants/blockExplorers.d.ts +9 -0
  25. package/dist/declarations/src/constants/chains.d.ts +16 -6
  26. package/dist/declarations/src/constants/index.d.ts +6 -2
  27. package/dist/declarations/src/constants/keys.d.ts +2 -0
  28. package/dist/declarations/src/constants/rpcs.d.ts +7 -0
  29. package/dist/declarations/src/index.d.ts +8 -5
  30. package/dist/declarations/src/types/index.d.ts +10 -5
  31. package/dist/wagmi-core.cjs.dev.js +518 -1020
  32. package/dist/wagmi-core.cjs.prod.js +518 -1020
  33. package/dist/wagmi-core.esm.js +516 -1021
  34. package/package.json +2 -2
  35. package/dist/base-09a653f3.cjs.dev.js +0 -453
  36. package/dist/base-824c3b6d.esm.js +0 -430
  37. package/dist/base-d8123d5f.cjs.prod.js +0 -453
  38. package/dist/declarations/src/constants/abis/erc1155.d.ts +0 -17
  39. package/dist/declarations/src/constants/abis/erc20.d.ts +0 -38
  40. package/dist/declarations/src/constants/abis/erc721.d.ts +0 -15
  41. package/dist/declarations/src/constants/abis/index.d.ts +0 -3
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var base = require('../../../dist/base-09a653f3.cjs.dev.js');
5
+ var base = require('../../../dist/base-b3073ce2.cjs.dev.js');
6
6
  var ethers = require('ethers');
7
7
  var utils = require('ethers/lib/utils');
8
8
  require('eventemitter3');
@@ -58,8 +58,8 @@ class CoinbaseWalletConnector extends base.Connector {
58
58
  });
59
59
 
60
60
  base._defineProperty(this, "onChainChanged", chainId => {
61
- var id = base.normalizeChainId(chainId);
62
- var unsupported = this.isChainUnsupported(id);
61
+ const id = base.normalizeChainId(chainId);
62
+ const unsupported = this.isChainUnsupported(id);
63
63
  this.emit('change', {
64
64
  chain: {
65
65
  id,
@@ -73,176 +73,162 @@ class CoinbaseWalletConnector extends base.Connector {
73
73
  });
74
74
  }
75
75
 
76
- connect() {
77
- var _this = this;
78
-
79
- return base._asyncToGenerator(function* () {
80
- try {
81
- var provider = yield _this.getProvider();
82
- provider.on('accountsChanged', _this.onAccountsChanged);
83
- provider.on('chainChanged', _this.onChainChanged);
84
- provider.on('disconnect', _this.onDisconnect);
85
- var accounts = yield provider.enable();
86
- var account = utils.getAddress(accounts[0]);
87
- var id = yield _this.getChainId();
88
-
89
- var unsupported = _this.isChainUnsupported(id);
90
-
91
- return {
92
- account,
93
- chain: {
94
- id,
95
- unsupported
96
- },
97
- provider: new ethers.providers.Web3Provider(provider)
98
- };
99
- } catch (error) {
100
- if (/user closed modal/i.test(error.message)) throw new base.UserRejectedRequestError();
101
- throw error;
102
- }
103
- })();
76
+ async connect() {
77
+ try {
78
+ const provider = await this.getProvider();
79
+ provider.on('accountsChanged', this.onAccountsChanged);
80
+ provider.on('chainChanged', this.onChainChanged);
81
+ provider.on('disconnect', this.onDisconnect);
82
+ this.emit('message', {
83
+ type: 'connecting'
84
+ });
85
+ const accounts = await provider.enable();
86
+ const account = utils.getAddress(accounts[0]);
87
+ const id = await this.getChainId();
88
+ const unsupported = this.isChainUnsupported(id);
89
+ return {
90
+ account,
91
+ chain: {
92
+ id,
93
+ unsupported
94
+ },
95
+ provider: new ethers.providers.Web3Provider(provider)
96
+ };
97
+ } catch (error) {
98
+ if (/user closed modal/i.test(error.message)) throw new base.UserRejectedRequestError();
99
+ throw error;
100
+ }
104
101
  }
105
102
 
106
- disconnect() {
107
- var _this2 = this;
108
-
109
- return base._asyncToGenerator(function* () {
110
- if (!base._classPrivateFieldGet(_this2, _provider)) return;
111
- var provider = yield _this2.getProvider();
112
- provider.removeListener('accountsChanged', _this2.onAccountsChanged);
113
- provider.removeListener('chainChanged', _this2.onChainChanged);
114
- provider.removeListener('disconnect', _this2.onDisconnect);
115
- provider.disconnect();
116
- provider.close();
117
-
118
- if (typeof localStorage !== 'undefined') {
119
- var n = localStorage.length;
120
-
121
- while (n--) {
122
- var key = localStorage.key(n);
123
- if (!key) continue;
124
- if (!/-walletlink/.test(key)) continue;
125
- localStorage.removeItem(key);
126
- }
103
+ async disconnect() {
104
+ if (!base._classPrivateFieldGet(this, _provider)) return;
105
+ const provider = await this.getProvider();
106
+ provider.removeListener('accountsChanged', this.onAccountsChanged);
107
+ provider.removeListener('chainChanged', this.onChainChanged);
108
+ provider.removeListener('disconnect', this.onDisconnect);
109
+ provider.disconnect();
110
+ provider.close();
111
+
112
+ if (typeof localStorage !== 'undefined') {
113
+ let n = localStorage.length;
114
+
115
+ while (n--) {
116
+ const key = localStorage.key(n);
117
+ if (!key) continue;
118
+ if (!/-walletlink/.test(key)) continue;
119
+ localStorage.removeItem(key);
127
120
  }
128
- })();
121
+ }
129
122
  }
130
123
 
131
- getAccount() {
132
- var _this3 = this;
124
+ async getAccount() {
125
+ const provider = await this.getProvider();
126
+ const accounts = await provider.request({
127
+ method: 'eth_accounts'
128
+ }); // return checksum address
133
129
 
134
- return base._asyncToGenerator(function* () {
135
- var provider = yield _this3.getProvider();
136
- var accounts = yield provider.request({
137
- method: 'eth_accounts'
138
- }); // return checksum address
139
-
140
- return utils.getAddress(accounts[0]);
141
- })();
130
+ return utils.getAddress(accounts[0]);
142
131
  }
143
132
 
144
- getChainId() {
145
- var _this4 = this;
146
-
147
- return base._asyncToGenerator(function* () {
148
- var provider = yield _this4.getProvider();
149
- var chainId = base.normalizeChainId(provider.chainId);
150
- return chainId;
151
- })();
133
+ async getChainId() {
134
+ const provider = await this.getProvider();
135
+ const chainId = base.normalizeChainId(provider.chainId);
136
+ return chainId;
152
137
  }
153
138
 
154
- getProvider() {
155
- var _this5 = this;
139
+ async getProvider() {
140
+ if (!base._classPrivateFieldGet(this, _provider)) {
141
+ const {
142
+ CoinbaseWalletSDK
143
+ } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); });
156
144
 
157
- return base._asyncToGenerator(function* () {
158
- if (!base._classPrivateFieldGet(_this5, _provider)) {
159
- var {
160
- CoinbaseWalletSDK
161
- } = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); });
145
+ base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
162
146
 
163
- base._classPrivateFieldSet(_this5, _client, new CoinbaseWalletSDK(_this5.options));
147
+ base._classPrivateFieldSet(this, _provider, base._classPrivateFieldGet(this, _client).makeWeb3Provider(this.options.jsonRpcUrl, this.options.chainId));
148
+ }
164
149
 
165
- base._classPrivateFieldSet(_this5, _provider, base._classPrivateFieldGet(_this5, _client).makeWeb3Provider(_this5.options.jsonRpcUrl));
166
- }
167
-
168
- return base._classPrivateFieldGet(_this5, _provider);
169
- })();
150
+ return base._classPrivateFieldGet(this, _provider);
170
151
  }
171
152
 
172
- getSigner() {
173
- var _this6 = this;
174
-
175
- return base._asyncToGenerator(function* () {
176
- var [provider, account] = yield Promise.all([_this6.getProvider(), _this6.getAccount()]);
177
- return new ethers.providers.Web3Provider(provider).getSigner(account);
178
- })();
153
+ async getSigner() {
154
+ const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
155
+ return new ethers.providers.Web3Provider(provider).getSigner(account);
179
156
  }
180
157
 
181
- isAuthorized() {
182
- var _this7 = this;
183
-
184
- return base._asyncToGenerator(function* () {
185
- try {
186
- var account = yield _this7.getAccount();
187
- return !!account;
188
- } catch (_unused) {
189
- return false;
190
- }
191
- })();
158
+ async isAuthorized() {
159
+ try {
160
+ const account = await this.getAccount();
161
+ return !!account;
162
+ } catch {
163
+ return false;
164
+ }
192
165
  }
193
166
 
194
- switchChain(chainId) {
195
- var _this8 = this;
196
-
197
- return base._asyncToGenerator(function* () {
198
- var provider = yield _this8.getProvider();
199
- var id = utils.hexValue(chainId);
167
+ async switchChain(chainId) {
168
+ const provider = await this.getProvider();
169
+ const id = utils.hexValue(chainId);
200
170
 
201
- try {
202
- var _chains$find;
171
+ try {
172
+ var _chains$find;
203
173
 
204
- yield provider.request({
205
- method: 'wallet_switchEthereumChain',
206
- params: [{
207
- chainId: id
208
- }]
209
- });
210
- var chains = [..._this8.chains, ...base.allChains];
211
- return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
212
- id: chainId,
213
- name: "Chain ".concat(id),
214
- rpcUrls: []
215
- };
216
- } catch (error) {
217
- if (/user rejected signature request/i.test(error.message)) throw new base.UserRejectedRequestError();else throw new base.SwitchChainError();
218
- }
219
- })();
174
+ await provider.request({
175
+ method: 'wallet_switchEthereumChain',
176
+ params: [{
177
+ chainId: id
178
+ }]
179
+ });
180
+ const chains = [...this.chains, ...base.allChains];
181
+ return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
182
+ id: chainId,
183
+ name: "Chain ".concat(id),
184
+ rpcUrls: {
185
+ default: []
186
+ }
187
+ };
188
+ } catch (error) {
189
+ // Indicates chain is not added to provider
190
+ if (error.code === 4902) {
191
+ try {
192
+ const chain = this.chains.find(x => x.id === chainId);
193
+ if (!chain) throw new base.ChainNotConfiguredError();
194
+ await provider.request({
195
+ method: 'wallet_addEthereumChain',
196
+ params: [{
197
+ chainId: id,
198
+ chainName: chain.name,
199
+ nativeCurrency: chain.nativeCurrency,
200
+ rpcUrls: this.getRpcUrls(chain),
201
+ blockExplorerUrls: this.getBlockExplorerUrls(chain)
202
+ }]
203
+ });
204
+ return chain;
205
+ } catch (addError) {
206
+ throw new base.AddChainError();
207
+ }
208
+ } else if (error.code === 4001) throw new base.UserRejectedRequestError();else throw new base.SwitchChainError();
209
+ }
220
210
  }
221
211
 
222
- watchAsset(_ref) {
223
- var _this9 = this;
224
-
225
- return base._asyncToGenerator(function* () {
226
- var {
227
- address,
228
- decimals = 18,
229
- image,
230
- symbol
231
- } = _ref;
232
- var provider = yield _this9.getProvider();
233
- return yield provider.request({
234
- method: 'wallet_watchAsset',
235
- params: {
236
- type: 'ERC20',
237
- options: {
238
- address,
239
- decimals,
240
- image,
241
- symbol
242
- }
212
+ async watchAsset(_ref) {
213
+ let {
214
+ address,
215
+ decimals = 18,
216
+ image,
217
+ symbol
218
+ } = _ref;
219
+ const provider = await this.getProvider();
220
+ return await provider.request({
221
+ method: 'wallet_watchAsset',
222
+ params: {
223
+ type: 'ERC20',
224
+ options: {
225
+ address,
226
+ decimals,
227
+ image,
228
+ symbol
243
229
  }
244
- });
245
- })();
230
+ }
231
+ });
246
232
  }
247
233
 
248
234
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var base = require('../../../dist/base-d8123d5f.cjs.prod.js');
5
+ var base = require('../../../dist/base-7ffc0425.cjs.prod.js');
6
6
  var ethers = require('ethers');
7
7
  var utils = require('ethers/lib/utils');
8
8
  require('eventemitter3');
@@ -58,8 +58,8 @@ class CoinbaseWalletConnector extends base.Connector {
58
58
  });
59
59
 
60
60
  base._defineProperty(this, "onChainChanged", chainId => {
61
- var id = base.normalizeChainId(chainId);
62
- var unsupported = this.isChainUnsupported(id);
61
+ const id = base.normalizeChainId(chainId);
62
+ const unsupported = this.isChainUnsupported(id);
63
63
  this.emit('change', {
64
64
  chain: {
65
65
  id,
@@ -73,176 +73,162 @@ class CoinbaseWalletConnector extends base.Connector {
73
73
  });
74
74
  }
75
75
 
76
- connect() {
77
- var _this = this;
78
-
79
- return base._asyncToGenerator(function* () {
80
- try {
81
- var provider = yield _this.getProvider();
82
- provider.on('accountsChanged', _this.onAccountsChanged);
83
- provider.on('chainChanged', _this.onChainChanged);
84
- provider.on('disconnect', _this.onDisconnect);
85
- var accounts = yield provider.enable();
86
- var account = utils.getAddress(accounts[0]);
87
- var id = yield _this.getChainId();
88
-
89
- var unsupported = _this.isChainUnsupported(id);
90
-
91
- return {
92
- account,
93
- chain: {
94
- id,
95
- unsupported
96
- },
97
- provider: new ethers.providers.Web3Provider(provider)
98
- };
99
- } catch (error) {
100
- if (/user closed modal/i.test(error.message)) throw new base.UserRejectedRequestError();
101
- throw error;
102
- }
103
- })();
76
+ async connect() {
77
+ try {
78
+ const provider = await this.getProvider();
79
+ provider.on('accountsChanged', this.onAccountsChanged);
80
+ provider.on('chainChanged', this.onChainChanged);
81
+ provider.on('disconnect', this.onDisconnect);
82
+ this.emit('message', {
83
+ type: 'connecting'
84
+ });
85
+ const accounts = await provider.enable();
86
+ const account = utils.getAddress(accounts[0]);
87
+ const id = await this.getChainId();
88
+ const unsupported = this.isChainUnsupported(id);
89
+ return {
90
+ account,
91
+ chain: {
92
+ id,
93
+ unsupported
94
+ },
95
+ provider: new ethers.providers.Web3Provider(provider)
96
+ };
97
+ } catch (error) {
98
+ if (/user closed modal/i.test(error.message)) throw new base.UserRejectedRequestError();
99
+ throw error;
100
+ }
104
101
  }
105
102
 
106
- disconnect() {
107
- var _this2 = this;
108
-
109
- return base._asyncToGenerator(function* () {
110
- if (!base._classPrivateFieldGet(_this2, _provider)) return;
111
- var provider = yield _this2.getProvider();
112
- provider.removeListener('accountsChanged', _this2.onAccountsChanged);
113
- provider.removeListener('chainChanged', _this2.onChainChanged);
114
- provider.removeListener('disconnect', _this2.onDisconnect);
115
- provider.disconnect();
116
- provider.close();
117
-
118
- if (typeof localStorage !== 'undefined') {
119
- var n = localStorage.length;
120
-
121
- while (n--) {
122
- var key = localStorage.key(n);
123
- if (!key) continue;
124
- if (!/-walletlink/.test(key)) continue;
125
- localStorage.removeItem(key);
126
- }
103
+ async disconnect() {
104
+ if (!base._classPrivateFieldGet(this, _provider)) return;
105
+ const provider = await this.getProvider();
106
+ provider.removeListener('accountsChanged', this.onAccountsChanged);
107
+ provider.removeListener('chainChanged', this.onChainChanged);
108
+ provider.removeListener('disconnect', this.onDisconnect);
109
+ provider.disconnect();
110
+ provider.close();
111
+
112
+ if (typeof localStorage !== 'undefined') {
113
+ let n = localStorage.length;
114
+
115
+ while (n--) {
116
+ const key = localStorage.key(n);
117
+ if (!key) continue;
118
+ if (!/-walletlink/.test(key)) continue;
119
+ localStorage.removeItem(key);
127
120
  }
128
- })();
121
+ }
129
122
  }
130
123
 
131
- getAccount() {
132
- var _this3 = this;
124
+ async getAccount() {
125
+ const provider = await this.getProvider();
126
+ const accounts = await provider.request({
127
+ method: 'eth_accounts'
128
+ }); // return checksum address
133
129
 
134
- return base._asyncToGenerator(function* () {
135
- var provider = yield _this3.getProvider();
136
- var accounts = yield provider.request({
137
- method: 'eth_accounts'
138
- }); // return checksum address
139
-
140
- return utils.getAddress(accounts[0]);
141
- })();
130
+ return utils.getAddress(accounts[0]);
142
131
  }
143
132
 
144
- getChainId() {
145
- var _this4 = this;
146
-
147
- return base._asyncToGenerator(function* () {
148
- var provider = yield _this4.getProvider();
149
- var chainId = base.normalizeChainId(provider.chainId);
150
- return chainId;
151
- })();
133
+ async getChainId() {
134
+ const provider = await this.getProvider();
135
+ const chainId = base.normalizeChainId(provider.chainId);
136
+ return chainId;
152
137
  }
153
138
 
154
- getProvider() {
155
- var _this5 = this;
139
+ async getProvider() {
140
+ if (!base._classPrivateFieldGet(this, _provider)) {
141
+ const {
142
+ CoinbaseWalletSDK
143
+ } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); });
156
144
 
157
- return base._asyncToGenerator(function* () {
158
- if (!base._classPrivateFieldGet(_this5, _provider)) {
159
- var {
160
- CoinbaseWalletSDK
161
- } = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); });
145
+ base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
162
146
 
163
- base._classPrivateFieldSet(_this5, _client, new CoinbaseWalletSDK(_this5.options));
147
+ base._classPrivateFieldSet(this, _provider, base._classPrivateFieldGet(this, _client).makeWeb3Provider(this.options.jsonRpcUrl, this.options.chainId));
148
+ }
164
149
 
165
- base._classPrivateFieldSet(_this5, _provider, base._classPrivateFieldGet(_this5, _client).makeWeb3Provider(_this5.options.jsonRpcUrl));
166
- }
167
-
168
- return base._classPrivateFieldGet(_this5, _provider);
169
- })();
150
+ return base._classPrivateFieldGet(this, _provider);
170
151
  }
171
152
 
172
- getSigner() {
173
- var _this6 = this;
174
-
175
- return base._asyncToGenerator(function* () {
176
- var [provider, account] = yield Promise.all([_this6.getProvider(), _this6.getAccount()]);
177
- return new ethers.providers.Web3Provider(provider).getSigner(account);
178
- })();
153
+ async getSigner() {
154
+ const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
155
+ return new ethers.providers.Web3Provider(provider).getSigner(account);
179
156
  }
180
157
 
181
- isAuthorized() {
182
- var _this7 = this;
183
-
184
- return base._asyncToGenerator(function* () {
185
- try {
186
- var account = yield _this7.getAccount();
187
- return !!account;
188
- } catch (_unused) {
189
- return false;
190
- }
191
- })();
158
+ async isAuthorized() {
159
+ try {
160
+ const account = await this.getAccount();
161
+ return !!account;
162
+ } catch {
163
+ return false;
164
+ }
192
165
  }
193
166
 
194
- switchChain(chainId) {
195
- var _this8 = this;
196
-
197
- return base._asyncToGenerator(function* () {
198
- var provider = yield _this8.getProvider();
199
- var id = utils.hexValue(chainId);
167
+ async switchChain(chainId) {
168
+ const provider = await this.getProvider();
169
+ const id = utils.hexValue(chainId);
200
170
 
201
- try {
202
- var _chains$find;
171
+ try {
172
+ var _chains$find;
203
173
 
204
- yield provider.request({
205
- method: 'wallet_switchEthereumChain',
206
- params: [{
207
- chainId: id
208
- }]
209
- });
210
- var chains = [..._this8.chains, ...base.allChains];
211
- return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
212
- id: chainId,
213
- name: "Chain ".concat(id),
214
- rpcUrls: []
215
- };
216
- } catch (error) {
217
- if (/user rejected signature request/i.test(error.message)) throw new base.UserRejectedRequestError();else throw new base.SwitchChainError();
218
- }
219
- })();
174
+ await provider.request({
175
+ method: 'wallet_switchEthereumChain',
176
+ params: [{
177
+ chainId: id
178
+ }]
179
+ });
180
+ const chains = [...this.chains, ...base.allChains];
181
+ return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
182
+ id: chainId,
183
+ name: "Chain ".concat(id),
184
+ rpcUrls: {
185
+ default: []
186
+ }
187
+ };
188
+ } catch (error) {
189
+ // Indicates chain is not added to provider
190
+ if (error.code === 4902) {
191
+ try {
192
+ const chain = this.chains.find(x => x.id === chainId);
193
+ if (!chain) throw new base.ChainNotConfiguredError();
194
+ await provider.request({
195
+ method: 'wallet_addEthereumChain',
196
+ params: [{
197
+ chainId: id,
198
+ chainName: chain.name,
199
+ nativeCurrency: chain.nativeCurrency,
200
+ rpcUrls: this.getRpcUrls(chain),
201
+ blockExplorerUrls: this.getBlockExplorerUrls(chain)
202
+ }]
203
+ });
204
+ return chain;
205
+ } catch (addError) {
206
+ throw new base.AddChainError();
207
+ }
208
+ } else if (error.code === 4001) throw new base.UserRejectedRequestError();else throw new base.SwitchChainError();
209
+ }
220
210
  }
221
211
 
222
- watchAsset(_ref) {
223
- var _this9 = this;
224
-
225
- return base._asyncToGenerator(function* () {
226
- var {
227
- address,
228
- decimals = 18,
229
- image,
230
- symbol
231
- } = _ref;
232
- var provider = yield _this9.getProvider();
233
- return yield provider.request({
234
- method: 'wallet_watchAsset',
235
- params: {
236
- type: 'ERC20',
237
- options: {
238
- address,
239
- decimals,
240
- image,
241
- symbol
242
- }
212
+ async watchAsset(_ref) {
213
+ let {
214
+ address,
215
+ decimals = 18,
216
+ image,
217
+ symbol
218
+ } = _ref;
219
+ const provider = await this.getProvider();
220
+ return await provider.request({
221
+ method: 'wallet_watchAsset',
222
+ params: {
223
+ type: 'ERC20',
224
+ options: {
225
+ address,
226
+ decimals,
227
+ image,
228
+ symbol
243
229
  }
244
- });
245
- })();
230
+ }
231
+ });
246
232
  }
247
233
 
248
234
  }