@wagmi/core 0.2.0-next.0 → 0.2.0-next.11
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/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +135 -151
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +135 -151
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +136 -152
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +96 -153
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +96 -153
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +96 -153
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +91 -124
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +91 -124
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +91 -124
- package/dist/base-83fd83c6.cjs.dev.js +543 -0
- package/dist/base-9b2942ee.cjs.prod.js +543 -0
- package/dist/base-b052e615.esm.js +516 -0
- package/dist/{classPrivateMethodGet-38b54c7a.cjs.dev.js → classPrivateMethodGet-45a38143.cjs.dev.js} +1 -1
- package/dist/{classPrivateMethodGet-c9db96d6.esm.js → classPrivateMethodGet-7c370e43.esm.js} +1 -1
- package/dist/{classPrivateMethodGet-0e9a7925.cjs.prod.js → classPrivateMethodGet-a1e1a4aa.cjs.prod.js} +1 -1
- package/dist/declarations/src/actions/accounts/connect.d.ts +14 -5
- package/dist/declarations/src/actions/accounts/getAccount.d.ts +5 -4
- package/dist/declarations/src/actions/accounts/index.d.ts +1 -1
- package/dist/declarations/src/actions/accounts/switchNetwork.d.ts +1 -1
- package/dist/declarations/src/actions/accounts/watchAccount.d.ts +3 -2
- package/dist/declarations/src/actions/index.d.ts +1 -1
- package/dist/declarations/src/actions/providers/getProvider.d.ts +2 -2
- package/dist/declarations/src/actions/providers/getWebSocketProvider.d.ts +2 -2
- package/dist/declarations/src/actions/providers/watchProvider.d.ts +3 -2
- package/dist/declarations/src/actions/providers/watchWebSocketProvider.d.ts +3 -2
- package/dist/declarations/src/client.d.ts +27 -24
- package/dist/declarations/src/connectors/base.d.ts +7 -1
- package/dist/declarations/src/connectors/coinbaseWallet.d.ts +9 -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 +17 -6
- package/dist/declarations/src/constants/index.d.ts +6 -2
- package/dist/declarations/src/constants/keys.d.ts +2 -0
- package/dist/declarations/src/constants/rpcs.d.ts +7 -0
- package/dist/declarations/src/index.d.ts +8 -5
- package/dist/declarations/src/types/index.d.ts +73 -6
- package/dist/declarations/src/utils/getInjectedName.d.ts +1 -1
- package/dist/wagmi-core.cjs.dev.js +578 -1067
- package/dist/wagmi-core.cjs.prod.js +578 -1067
- package/dist/wagmi-core.esm.js +575 -1068
- package/package.json +2 -3
- package/dist/base-09a653f3.cjs.dev.js +0 -453
- package/dist/base-824c3b6d.esm.js +0 -430
- package/dist/base-d8123d5f.cjs.prod.js +0 -453
- package/dist/declarations/src/constants/abis/erc1155.d.ts +0 -17
- package/dist/declarations/src/constants/abis/erc20.d.ts +0 -38
- package/dist/declarations/src/constants/abis/erc721.d.ts +0 -15
- package/dist/declarations/src/constants/abis/index.d.ts +0 -3
- package/dist/declarations/src/types/declarations.d.ts +0 -52
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var base = require('../../../dist/base-
|
|
5
|
+
var base = require('../../../dist/base-83fd83c6.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
|
-
|
|
62
|
-
|
|
61
|
+
const id = base.normalizeChainId(chainId);
|
|
62
|
+
const unsupported = this.isChainUnsupported(id);
|
|
63
63
|
this.emit('change', {
|
|
64
64
|
chain: {
|
|
65
65
|
id,
|
|
@@ -73,178 +73,162 @@ class CoinbaseWalletConnector extends base.Connector {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
connect() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
return
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
var {
|
|
160
|
-
CoinbaseWalletSDK
|
|
161
|
-
} = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); });
|
|
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')); });
|
|
162
144
|
|
|
163
|
-
|
|
145
|
+
base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
|
|
164
146
|
|
|
165
|
-
|
|
166
|
-
|
|
147
|
+
base._classPrivateFieldSet(this, _provider, base._classPrivateFieldGet(this, _client).makeWeb3Provider(this.options.jsonRpcUrl, this.options.chainId));
|
|
148
|
+
}
|
|
167
149
|
|
|
168
|
-
|
|
169
|
-
})();
|
|
150
|
+
return base._classPrivateFieldGet(this, _provider);
|
|
170
151
|
}
|
|
171
152
|
|
|
172
|
-
getSigner() {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return base._asyncToGenerator(function* () {
|
|
176
|
-
var provider = _this6.getProvider();
|
|
177
|
-
|
|
178
|
-
var account = yield _this6.getAccount();
|
|
179
|
-
return new ethers.providers.Web3Provider(provider).getSigner(account);
|
|
180
|
-
})();
|
|
153
|
+
async getSigner() {
|
|
154
|
+
const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
|
|
155
|
+
return new ethers.providers.Web3Provider(provider).getSigner(account);
|
|
181
156
|
}
|
|
182
157
|
|
|
183
|
-
isAuthorized() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
} catch (_unused) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
})();
|
|
158
|
+
async isAuthorized() {
|
|
159
|
+
try {
|
|
160
|
+
const account = await this.getAccount();
|
|
161
|
+
return !!account;
|
|
162
|
+
} catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
194
165
|
}
|
|
195
166
|
|
|
196
|
-
switchChain(chainId) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return base._asyncToGenerator(function* () {
|
|
200
|
-
var provider = yield _this8.getProvider();
|
|
201
|
-
var id = utils.hexValue(chainId);
|
|
167
|
+
async switchChain(chainId) {
|
|
168
|
+
const provider = await this.getProvider();
|
|
169
|
+
const id = utils.hexValue(chainId);
|
|
202
170
|
|
|
203
|
-
|
|
204
|
-
|
|
171
|
+
try {
|
|
172
|
+
var _chains$find;
|
|
205
173
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
}
|
|
222
210
|
}
|
|
223
211
|
|
|
224
|
-
watchAsset(_ref) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
decimals,
|
|
242
|
-
image,
|
|
243
|
-
symbol
|
|
244
|
-
}
|
|
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
|
|
245
229
|
}
|
|
246
|
-
}
|
|
247
|
-
})
|
|
230
|
+
}
|
|
231
|
+
});
|
|
248
232
|
}
|
|
249
233
|
|
|
250
234
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var base = require('../../../dist/base-
|
|
5
|
+
var base = require('../../../dist/base-9b2942ee.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
|
-
|
|
62
|
-
|
|
61
|
+
const id = base.normalizeChainId(chainId);
|
|
62
|
+
const unsupported = this.isChainUnsupported(id);
|
|
63
63
|
this.emit('change', {
|
|
64
64
|
chain: {
|
|
65
65
|
id,
|
|
@@ -73,178 +73,162 @@ class CoinbaseWalletConnector extends base.Connector {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
connect() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
return
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
var {
|
|
160
|
-
CoinbaseWalletSDK
|
|
161
|
-
} = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); });
|
|
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')); });
|
|
162
144
|
|
|
163
|
-
|
|
145
|
+
base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
|
|
164
146
|
|
|
165
|
-
|
|
166
|
-
|
|
147
|
+
base._classPrivateFieldSet(this, _provider, base._classPrivateFieldGet(this, _client).makeWeb3Provider(this.options.jsonRpcUrl, this.options.chainId));
|
|
148
|
+
}
|
|
167
149
|
|
|
168
|
-
|
|
169
|
-
})();
|
|
150
|
+
return base._classPrivateFieldGet(this, _provider);
|
|
170
151
|
}
|
|
171
152
|
|
|
172
|
-
getSigner() {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return base._asyncToGenerator(function* () {
|
|
176
|
-
var provider = _this6.getProvider();
|
|
177
|
-
|
|
178
|
-
var account = yield _this6.getAccount();
|
|
179
|
-
return new ethers.providers.Web3Provider(provider).getSigner(account);
|
|
180
|
-
})();
|
|
153
|
+
async getSigner() {
|
|
154
|
+
const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
|
|
155
|
+
return new ethers.providers.Web3Provider(provider).getSigner(account);
|
|
181
156
|
}
|
|
182
157
|
|
|
183
|
-
isAuthorized() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
} catch (_unused) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
})();
|
|
158
|
+
async isAuthorized() {
|
|
159
|
+
try {
|
|
160
|
+
const account = await this.getAccount();
|
|
161
|
+
return !!account;
|
|
162
|
+
} catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
194
165
|
}
|
|
195
166
|
|
|
196
|
-
switchChain(chainId) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return base._asyncToGenerator(function* () {
|
|
200
|
-
var provider = yield _this8.getProvider();
|
|
201
|
-
var id = utils.hexValue(chainId);
|
|
167
|
+
async switchChain(chainId) {
|
|
168
|
+
const provider = await this.getProvider();
|
|
169
|
+
const id = utils.hexValue(chainId);
|
|
202
170
|
|
|
203
|
-
|
|
204
|
-
|
|
171
|
+
try {
|
|
172
|
+
var _chains$find;
|
|
205
173
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
}
|
|
222
210
|
}
|
|
223
211
|
|
|
224
|
-
watchAsset(_ref) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
decimals,
|
|
242
|
-
image,
|
|
243
|
-
symbol
|
|
244
|
-
}
|
|
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
|
|
245
229
|
}
|
|
246
|
-
}
|
|
247
|
-
})
|
|
230
|
+
}
|
|
231
|
+
});
|
|
248
232
|
}
|
|
249
233
|
|
|
250
234
|
}
|