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

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 (97) hide show
  1. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.d.ts +11 -1
  2. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.js +15 -6
  3. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.d.ts +11 -1
  4. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.js +15 -6
  5. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.d.ts +11 -1
  6. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.js +15 -6
  7. package/dist/wagmi-core.cjs.d.ts +11 -1
  8. package/dist/wagmi-core.cjs.js +15 -6
  9. package/package.json +1 -2
  10. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +0 -236
  11. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +0 -236
  12. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +0 -214
  13. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +0 -247
  14. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +0 -247
  15. package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +0 -238
  16. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +0 -183
  17. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +0 -183
  18. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +0 -161
  19. package/dist/base-7ffc0425.cjs.prod.js +0 -541
  20. package/dist/base-82f423a9.esm.js +0 -515
  21. package/dist/base-b3073ce2.cjs.dev.js +0 -541
  22. package/dist/classPrivateMethodGet-0dc9fedc.cjs.dev.js +0 -19
  23. package/dist/classPrivateMethodGet-1c660f09.esm.js +0 -16
  24. package/dist/classPrivateMethodGet-c084b176.cjs.prod.js +0 -19
  25. package/dist/declarations/src/actions/accounts/connect.d.ts +0 -16
  26. package/dist/declarations/src/actions/accounts/disconnect.d.ts +0 -1
  27. package/dist/declarations/src/actions/accounts/fetchBalance.d.ts +0 -18
  28. package/dist/declarations/src/actions/accounts/fetchSigner.d.ts +0 -3
  29. package/dist/declarations/src/actions/accounts/getAccount.d.ts +0 -6
  30. package/dist/declarations/src/actions/accounts/getNetwork.d.ts +0 -9
  31. package/dist/declarations/src/actions/accounts/index.d.ts +0 -13
  32. package/dist/declarations/src/actions/accounts/signMessage.d.ts +0 -9
  33. package/dist/declarations/src/actions/accounts/signTypedData.d.ts +0 -13
  34. package/dist/declarations/src/actions/accounts/switchNetwork.d.ts +0 -6
  35. package/dist/declarations/src/actions/accounts/watchAccount.d.ts +0 -3
  36. package/dist/declarations/src/actions/accounts/watchBalance.d.ts +0 -3
  37. package/dist/declarations/src/actions/accounts/watchNetwork.d.ts +0 -3
  38. package/dist/declarations/src/actions/accounts/watchSigner.d.ts +0 -3
  39. package/dist/declarations/src/actions/contracts/getContract.d.ts +0 -11
  40. package/dist/declarations/src/actions/contracts/index.d.ts +0 -5
  41. package/dist/declarations/src/actions/contracts/readContract.d.ts +0 -11
  42. package/dist/declarations/src/actions/contracts/watchContractEvent.d.ts +0 -12
  43. package/dist/declarations/src/actions/contracts/watchReadContract.d.ts +0 -7
  44. package/dist/declarations/src/actions/contracts/writeContract.d.ts +0 -11
  45. package/dist/declarations/src/actions/ens/fetchEnsAddress.d.ts +0 -6
  46. package/dist/declarations/src/actions/ens/fetchEnsAvatar.d.ts +0 -6
  47. package/dist/declarations/src/actions/ens/fetchEnsName.d.ts +0 -6
  48. package/dist/declarations/src/actions/ens/fetchEnsResolver.d.ts +0 -7
  49. package/dist/declarations/src/actions/ens/index.d.ts +0 -8
  50. package/dist/declarations/src/actions/ens/watchEnsAddress.d.ts +0 -3
  51. package/dist/declarations/src/actions/ens/watchEnsAvatar.d.ts +0 -3
  52. package/dist/declarations/src/actions/ens/watchEnsName.d.ts +0 -3
  53. package/dist/declarations/src/actions/ens/watchEnsResolver.d.ts +0 -3
  54. package/dist/declarations/src/actions/index.d.ts +0 -7
  55. package/dist/declarations/src/actions/network-status/fetchBlockNumber.d.ts +0 -2
  56. package/dist/declarations/src/actions/network-status/fetchFeeData.d.ts +0 -14
  57. package/dist/declarations/src/actions/network-status/index.d.ts +0 -4
  58. package/dist/declarations/src/actions/network-status/watchBlockNumber.d.ts +0 -6
  59. package/dist/declarations/src/actions/network-status/watchFeeData.d.ts +0 -7
  60. package/dist/declarations/src/actions/providers/getProvider.d.ts +0 -3
  61. package/dist/declarations/src/actions/providers/getWebSocketProvider.d.ts +0 -3
  62. package/dist/declarations/src/actions/providers/index.d.ts +0 -4
  63. package/dist/declarations/src/actions/providers/watchProvider.d.ts +0 -3
  64. package/dist/declarations/src/actions/providers/watchWebSocketProvider.d.ts +0 -3
  65. package/dist/declarations/src/actions/tokens/fetchToken.d.ts +0 -24
  66. package/dist/declarations/src/actions/tokens/index.d.ts +0 -2
  67. package/dist/declarations/src/actions/tokens/watchToken.d.ts +0 -3
  68. package/dist/declarations/src/actions/transactions/index.d.ts +0 -2
  69. package/dist/declarations/src/actions/transactions/sendTransaction.d.ts +0 -7
  70. package/dist/declarations/src/actions/transactions/waitForTransaction.d.ts +0 -15
  71. package/dist/declarations/src/client.d.ts +0 -80
  72. package/dist/declarations/src/connectors/base.d.ts +0 -56
  73. package/dist/declarations/src/connectors/coinbaseWallet.d.ts +0 -52
  74. package/dist/declarations/src/connectors/index.d.ts +0 -2
  75. package/dist/declarations/src/connectors/injected.d.ts +0 -55
  76. package/dist/declarations/src/connectors/mock/connector.d.ts +0 -37
  77. package/dist/declarations/src/connectors/mock/index.d.ts +0 -2
  78. package/dist/declarations/src/connectors/mock/provider.d.ts +0 -40
  79. package/dist/declarations/src/connectors/walletConnect.d.ts +0 -32
  80. package/dist/declarations/src/constants/abis.d.ts +0 -2
  81. package/dist/declarations/src/constants/blockExplorers.d.ts +0 -9
  82. package/dist/declarations/src/constants/chains.d.ts +0 -20
  83. package/dist/declarations/src/constants/index.d.ts +0 -7
  84. package/dist/declarations/src/constants/keys.d.ts +0 -2
  85. package/dist/declarations/src/constants/rpcs.d.ts +0 -7
  86. package/dist/declarations/src/constants/units.d.ts +0 -1
  87. package/dist/declarations/src/errors.d.ts +0 -28
  88. package/dist/declarations/src/index.d.ts +0 -12
  89. package/dist/declarations/src/storage.d.ts +0 -12
  90. package/dist/declarations/src/types/declarations.d.ts +0 -52
  91. package/dist/declarations/src/types/index.d.ts +0 -19
  92. package/dist/declarations/src/utils/getInjectedName.d.ts +0 -1
  93. package/dist/declarations/src/utils/index.d.ts +0 -2
  94. package/dist/declarations/src/utils/normalizeChainId.d.ts +0 -1
  95. package/dist/wagmi-core.cjs.dev.js +0 -1193
  96. package/dist/wagmi-core.cjs.prod.js +0 -1193
  97. package/dist/wagmi-core.esm.js +0 -1124
@@ -1 +1,11 @@
1
- export * from "../../../dist/declarations/src/connectors/coinbaseWallet";
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";
@@ -1,7 +1,16 @@
1
- 'use strict';
1
+ "use strict";
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
2
9
 
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
- }
10
+ // this bit of code imports the require hook and registers it
11
+ let unregister = require("../../../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../../..", "../../..");
12
+
13
+ // this re-exports the source file
14
+ module.exports = require("../../../src/connectors/coinbaseWallet.ts");
15
+
16
+ unregister();
@@ -1 +1,11 @@
1
- export * from "../../../dist/declarations/src/connectors/mock/index";
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";
@@ -1,7 +1,16 @@
1
- 'use strict';
1
+ "use strict";
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
2
9
 
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./wagmi-core-connectors-mock.cjs.prod.js");
5
- } else {
6
- module.exports = require("./wagmi-core-connectors-mock.cjs.dev.js");
7
- }
10
+ // this bit of code imports the require hook and registers it
11
+ let unregister = require("../../../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../../..", "../../..");
12
+
13
+ // this re-exports the source file
14
+ module.exports = require("../../../src/connectors/mock/index.ts");
15
+
16
+ unregister();
@@ -1 +1,11 @@
1
- export * from "../../../dist/declarations/src/connectors/walletConnect";
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/walletConnect";
@@ -1,7 +1,16 @@
1
- 'use strict';
1
+ "use strict";
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
2
9
 
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./wagmi-core-connectors-walletConnect.cjs.prod.js");
5
- } else {
6
- module.exports = require("./wagmi-core-connectors-walletConnect.cjs.dev.js");
7
- }
10
+ // this bit of code imports the require hook and registers it
11
+ let unregister = require("../../../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../../..", "../../..");
12
+
13
+ // this re-exports the source file
14
+ module.exports = require("../../../src/connectors/walletConnect.ts");
15
+
16
+ unregister();
@@ -1 +1,11 @@
1
- export * from "./declarations/src/index";
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/index";
@@ -1,7 +1,16 @@
1
- 'use strict';
1
+ "use strict";
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
2
9
 
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./wagmi-core.cjs.prod.js");
5
- } else {
6
- module.exports = require("./wagmi-core.cjs.dev.js");
7
- }
10
+ // this bit of code imports the require hook and registers it
11
+ let unregister = require("../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../..", "..");
12
+
13
+ // this re-exports the source file
14
+ module.exports = require("../src/index.ts");
15
+
16
+ unregister();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wagmi/core",
3
3
  "description": "Vanilla JS Client for Ethereum",
4
4
  "license": "MIT",
5
- "version": "0.2.0-next.8",
5
+ "version": "0.2.0-next.9",
6
6
  "ethereum": "awkweb.eth",
7
7
  "repository": "tmm/wagmi",
8
8
  "sideEffects": false,
@@ -60,7 +60,6 @@
60
60
  },
61
61
  "devDependencies": {
62
62
  "@coinbase/wallet-sdk": "^3.0.1",
63
- "@ethersproject/providers": "^5.5.1",
64
63
  "@walletconnect/ethereum-provider": "1.7.5",
65
64
  "ethers": "^5.5.1"
66
65
  }
@@ -1,236 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var base = require('../../../dist/base-b3073ce2.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
- var _window$ethereum;
35
-
36
- super(config);
37
-
38
- base._defineProperty(this, "id", 'coinbaseWallet');
39
-
40
- base._defineProperty(this, "name", 'Coinbase Wallet');
41
-
42
- base._defineProperty(this, "ready", typeof window !== 'undefined' && !((_window$ethereum = window.ethereum) !== null && _window$ethereum !== void 0 && _window$ethereum.isCoinbaseWallet));
43
-
44
- base._classPrivateFieldInitSpec(this, _client, {
45
- writable: true,
46
- value: void 0
47
- });
48
-
49
- base._classPrivateFieldInitSpec(this, _provider, {
50
- writable: true,
51
- value: void 0
52
- });
53
-
54
- base._defineProperty(this, "onAccountsChanged", accounts => {
55
- if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
56
- account: utils.getAddress(accounts[0])
57
- });
58
- });
59
-
60
- base._defineProperty(this, "onChainChanged", chainId => {
61
- const id = base.normalizeChainId(chainId);
62
- const unsupported = this.isChainUnsupported(id);
63
- this.emit('change', {
64
- chain: {
65
- id,
66
- unsupported
67
- }
68
- });
69
- });
70
-
71
- base._defineProperty(this, "onDisconnect", () => {
72
- this.emit('disconnect');
73
- });
74
- }
75
-
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
- }
101
- }
102
-
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);
120
- }
121
- }
122
- }
123
-
124
- async getAccount() {
125
- const provider = await this.getProvider();
126
- const accounts = await provider.request({
127
- method: 'eth_accounts'
128
- }); // return checksum address
129
-
130
- return utils.getAddress(accounts[0]);
131
- }
132
-
133
- async getChainId() {
134
- const provider = await this.getProvider();
135
- const chainId = base.normalizeChainId(provider.chainId);
136
- return chainId;
137
- }
138
-
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')); });
144
-
145
- base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
146
-
147
- base._classPrivateFieldSet(this, _provider, base._classPrivateFieldGet(this, _client).makeWeb3Provider(this.options.jsonRpcUrl, this.options.chainId));
148
- }
149
-
150
- return base._classPrivateFieldGet(this, _provider);
151
- }
152
-
153
- async getSigner() {
154
- const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
155
- return new ethers.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 = utils.hexValue(chainId);
170
-
171
- try {
172
- var _chains$find;
173
-
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
- }
210
- }
211
-
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
229
- }
230
- }
231
- });
232
- }
233
-
234
- }
235
-
236
- exports.CoinbaseWalletConnector = CoinbaseWalletConnector;
@@ -1,236 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var base = require('../../../dist/base-7ffc0425.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
- var _window$ethereum;
35
-
36
- super(config);
37
-
38
- base._defineProperty(this, "id", 'coinbaseWallet');
39
-
40
- base._defineProperty(this, "name", 'Coinbase Wallet');
41
-
42
- base._defineProperty(this, "ready", typeof window !== 'undefined' && !((_window$ethereum = window.ethereum) !== null && _window$ethereum !== void 0 && _window$ethereum.isCoinbaseWallet));
43
-
44
- base._classPrivateFieldInitSpec(this, _client, {
45
- writable: true,
46
- value: void 0
47
- });
48
-
49
- base._classPrivateFieldInitSpec(this, _provider, {
50
- writable: true,
51
- value: void 0
52
- });
53
-
54
- base._defineProperty(this, "onAccountsChanged", accounts => {
55
- if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
56
- account: utils.getAddress(accounts[0])
57
- });
58
- });
59
-
60
- base._defineProperty(this, "onChainChanged", chainId => {
61
- const id = base.normalizeChainId(chainId);
62
- const unsupported = this.isChainUnsupported(id);
63
- this.emit('change', {
64
- chain: {
65
- id,
66
- unsupported
67
- }
68
- });
69
- });
70
-
71
- base._defineProperty(this, "onDisconnect", () => {
72
- this.emit('disconnect');
73
- });
74
- }
75
-
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
- }
101
- }
102
-
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);
120
- }
121
- }
122
- }
123
-
124
- async getAccount() {
125
- const provider = await this.getProvider();
126
- const accounts = await provider.request({
127
- method: 'eth_accounts'
128
- }); // return checksum address
129
-
130
- return utils.getAddress(accounts[0]);
131
- }
132
-
133
- async getChainId() {
134
- const provider = await this.getProvider();
135
- const chainId = base.normalizeChainId(provider.chainId);
136
- return chainId;
137
- }
138
-
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')); });
144
-
145
- base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
146
-
147
- base._classPrivateFieldSet(this, _provider, base._classPrivateFieldGet(this, _client).makeWeb3Provider(this.options.jsonRpcUrl, this.options.chainId));
148
- }
149
-
150
- return base._classPrivateFieldGet(this, _provider);
151
- }
152
-
153
- async getSigner() {
154
- const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
155
- return new ethers.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 = utils.hexValue(chainId);
170
-
171
- try {
172
- var _chains$find;
173
-
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
- }
210
- }
211
-
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
229
- }
230
- }
231
- });
232
- }
233
-
234
- }
235
-
236
- exports.CoinbaseWalletConnector = CoinbaseWalletConnector;