@wagmi/core 0.2.4 → 0.2.5

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.
@@ -136,9 +136,7 @@ class CoinbaseWalletConnector extends base.Connector {
136
136
 
137
137
  async getProvider() {
138
138
  if (!base._classPrivateFieldGet(this, _provider)) {
139
- const {
140
- CoinbaseWalletSDK
141
- } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); });
139
+ const CoinbaseWalletSDK = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); })).default;
142
140
 
143
141
  base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
144
142
 
@@ -136,9 +136,7 @@ class CoinbaseWalletConnector extends base.Connector {
136
136
 
137
137
  async getProvider() {
138
138
  if (!base._classPrivateFieldGet(this, _provider)) {
139
- const {
140
- CoinbaseWalletSDK
141
- } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); });
139
+ const CoinbaseWalletSDK = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); })).default;
142
140
 
143
141
  base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
144
142
 
@@ -114,9 +114,7 @@ class CoinbaseWalletConnector extends Connector {
114
114
 
115
115
  async getProvider() {
116
116
  if (!_classPrivateFieldGet(this, _provider)) {
117
- const {
118
- CoinbaseWalletSDK
119
- } = await import('@coinbase/wallet-sdk');
117
+ const CoinbaseWalletSDK = (await import('@coinbase/wallet-sdk')).default;
120
118
 
121
119
  _classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
122
120
 
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var classPrivateMethodGet = require('../../../dist/classPrivateMethodGet-976c8120.cjs.dev.js');
6
6
  var base = require('../../../dist/base-5812b724.cjs.dev.js');
7
- var client = require('../../../dist/client-65157905.cjs.dev.js');
7
+ var client = require('../../../dist/client-72d69b8e.cjs.dev.js');
8
8
  require('eventemitter3');
9
9
  require('ethers');
10
10
  require('zustand/vanilla');
@@ -42,17 +42,25 @@ class MetaMaskConnector extends client.InjectedConnector {
42
42
  }
43
43
 
44
44
  async getProvider() {
45
- if (typeof window !== 'undefined') base._classPrivateFieldSet(this, _provider, classPrivateMethodGet._classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
45
+ if (typeof window !== 'undefined') {
46
+ // TODO: Fallback to `ethereum#initialized` event for async injection
47
+ // https://github.com/MetaMask/detect-provider#synchronous-and-asynchronous-injection=
48
+ base._classPrivateFieldSet(this, _provider, classPrivateMethodGet._classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
49
+ }
50
+
46
51
  return base._classPrivateFieldGet(this, _provider);
47
52
  }
48
53
 
49
54
  }
50
55
 
51
56
  function _getReady2(ethereum) {
52
- const isMetaMask = !!(ethereum !== null && ethereum !== void 0 && ethereum.isMetaMask); // Some wallets (e.g. Brave Wallet) try to make themselves look like MetaMask
57
+ const isMetaMask = !!(ethereum !== null && ethereum !== void 0 && ethereum.isMetaMask);
58
+ if (!isMetaMask) return; // Brave tries to make itself look like MetaMask
59
+ // Could also try RPC `web3_clientVersion` if following is unreliable
53
60
 
54
- const notOtherWallet = !(ethereum !== null && ethereum !== void 0 && ethereum.isBraveWallet) && !(ethereum !== null && ethereum !== void 0 && ethereum.isTokenary);
55
- if (isMetaMask && notOtherWallet) return ethereum;
61
+ if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state) return;
62
+ if (ethereum.isTokenary) return;
63
+ return ethereum;
56
64
  }
57
65
 
58
66
  function _findProvider2(ethereum) {
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var classPrivateMethodGet = require('../../../dist/classPrivateMethodGet-d7330ed7.cjs.prod.js');
6
6
  var base = require('../../../dist/base-59f3457e.cjs.prod.js');
7
- var client = require('../../../dist/client-a06853e2.cjs.prod.js');
7
+ var client = require('../../../dist/client-1f6fd5b6.cjs.prod.js');
8
8
  require('eventemitter3');
9
9
  require('ethers');
10
10
  require('zustand/vanilla');
@@ -42,17 +42,25 @@ class MetaMaskConnector extends client.InjectedConnector {
42
42
  }
43
43
 
44
44
  async getProvider() {
45
- if (typeof window !== 'undefined') base._classPrivateFieldSet(this, _provider, classPrivateMethodGet._classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
45
+ if (typeof window !== 'undefined') {
46
+ // TODO: Fallback to `ethereum#initialized` event for async injection
47
+ // https://github.com/MetaMask/detect-provider#synchronous-and-asynchronous-injection=
48
+ base._classPrivateFieldSet(this, _provider, classPrivateMethodGet._classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
49
+ }
50
+
46
51
  return base._classPrivateFieldGet(this, _provider);
47
52
  }
48
53
 
49
54
  }
50
55
 
51
56
  function _getReady2(ethereum) {
52
- const isMetaMask = !!(ethereum !== null && ethereum !== void 0 && ethereum.isMetaMask); // Some wallets (e.g. Brave Wallet) try to make themselves look like MetaMask
57
+ const isMetaMask = !!(ethereum !== null && ethereum !== void 0 && ethereum.isMetaMask);
58
+ if (!isMetaMask) return; // Brave tries to make itself look like MetaMask
59
+ // Could also try RPC `web3_clientVersion` if following is unreliable
53
60
 
54
- const notOtherWallet = !(ethereum !== null && ethereum !== void 0 && ethereum.isBraveWallet) && !(ethereum !== null && ethereum !== void 0 && ethereum.isTokenary);
55
- if (isMetaMask && notOtherWallet) return ethereum;
61
+ if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state) return;
62
+ if (ethereum.isTokenary) return;
63
+ return ethereum;
56
64
  }
57
65
 
58
66
  function _findProvider2(ethereum) {
@@ -1,6 +1,6 @@
1
1
  import { _ as _classPrivateMethodInitSpec, a as _classPrivateMethodGet } from '../../../dist/classPrivateMethodGet-55c9909f.esm.js';
2
2
  import { _ as _defineProperty, m as _classPrivateFieldInitSpec, o as _classPrivateFieldSet, p as _classPrivateFieldGet } from '../../../dist/base-159de546.esm.js';
3
- import { I as InjectedConnector } from '../../../dist/client-7fcff803.esm.js';
3
+ import { I as InjectedConnector } from '../../../dist/client-3a56f061.esm.js';
4
4
  import 'eventemitter3';
5
5
  import 'ethers';
6
6
  import 'zustand/vanilla';
@@ -38,17 +38,25 @@ class MetaMaskConnector extends InjectedConnector {
38
38
  }
39
39
 
40
40
  async getProvider() {
41
- if (typeof window !== 'undefined') _classPrivateFieldSet(this, _provider, _classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
41
+ if (typeof window !== 'undefined') {
42
+ // TODO: Fallback to `ethereum#initialized` event for async injection
43
+ // https://github.com/MetaMask/detect-provider#synchronous-and-asynchronous-injection=
44
+ _classPrivateFieldSet(this, _provider, _classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
45
+ }
46
+
42
47
  return _classPrivateFieldGet(this, _provider);
43
48
  }
44
49
 
45
50
  }
46
51
 
47
52
  function _getReady2(ethereum) {
48
- const isMetaMask = !!(ethereum !== null && ethereum !== void 0 && ethereum.isMetaMask); // Some wallets (e.g. Brave Wallet) try to make themselves look like MetaMask
53
+ const isMetaMask = !!(ethereum !== null && ethereum !== void 0 && ethereum.isMetaMask);
54
+ if (!isMetaMask) return; // Brave tries to make itself look like MetaMask
55
+ // Could also try RPC `web3_clientVersion` if following is unreliable
49
56
 
50
- const notOtherWallet = !(ethereum !== null && ethereum !== void 0 && ethereum.isBraveWallet) && !(ethereum !== null && ethereum !== void 0 && ethereum.isTokenary);
51
- if (isMetaMask && notOtherWallet) return ethereum;
57
+ if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state) return;
58
+ if (ethereum.isTokenary) return;
59
+ return ethereum;
52
60
  }
53
61
 
54
62
  function _findProvider2(ethereum) {
@@ -26,7 +26,14 @@ function _interopNamespace(e) {
26
26
  return Object.freeze(n);
27
27
  }
28
28
 
29
- const switchChainAllowedRegex = /(metamask|rainbow)/i;
29
+ /**
30
+ * Wallets that support chain switching through WalletConnect
31
+ * - imToken (token.im)
32
+ * - MetaMask (metamask.io)
33
+ * - Rainbow (rainbow.me)
34
+ */
35
+
36
+ const switchChainAllowedRegex = /(imtoken|metamask|rainbow)/i;
30
37
 
31
38
  var _provider = /*#__PURE__*/new WeakMap();
32
39
 
@@ -26,7 +26,14 @@ function _interopNamespace(e) {
26
26
  return Object.freeze(n);
27
27
  }
28
28
 
29
- const switchChainAllowedRegex = /(metamask|rainbow)/i;
29
+ /**
30
+ * Wallets that support chain switching through WalletConnect
31
+ * - imToken (token.im)
32
+ * - MetaMask (metamask.io)
33
+ * - Rainbow (rainbow.me)
34
+ */
35
+
36
+ const switchChainAllowedRegex = /(imtoken|metamask|rainbow)/i;
30
37
 
31
38
  var _provider = /*#__PURE__*/new WeakMap();
32
39
 
@@ -4,7 +4,14 @@ import { providers } from 'ethers';
4
4
  import { getAddress, hexValue } from 'ethers/lib/utils';
5
5
  import 'eventemitter3';
6
6
 
7
- const switchChainAllowedRegex = /(metamask|rainbow)/i;
7
+ /**
8
+ * Wallets that support chain switching through WalletConnect
9
+ * - imToken (token.im)
10
+ * - MetaMask (metamask.io)
11
+ * - Rainbow (rainbow.me)
12
+ */
13
+
14
+ const switchChainAllowedRegex = /(imtoken|metamask|rainbow)/i;
8
15
 
9
16
  var _provider = /*#__PURE__*/new WeakMap();
10
17
 
@@ -20,11 +20,13 @@ function getInjectedName(ethereum) {
20
20
  if (provider.isBraveWallet) return 'Brave Wallet';
21
21
  if (provider.isCoinbaseWallet) return 'Coinbase Wallet';
22
22
  if (provider.isFrame) return 'Frame';
23
+ if (provider.isOpera) return 'Opera';
23
24
  if (provider.isTally) return 'Tally';
24
25
  if (provider.isTokenary) return 'Tokenary';
25
26
  if (provider.isTrust) return 'Trust Wallet';
26
27
  if (provider.isMetaMask) return 'MetaMask';
27
- };
28
+ }; // Some injected providers detect multiple other providers and create a list at `ethers.providers`
29
+
28
30
 
29
31
  if ((_ethereum$providers = ethereum.providers) !== null && _ethereum$providers !== void 0 && _ethereum$providers.length) {
30
32
  // Deduplicate names using Set
@@ -14,11 +14,13 @@ function getInjectedName(ethereum) {
14
14
  if (provider.isBraveWallet) return 'Brave Wallet';
15
15
  if (provider.isCoinbaseWallet) return 'Coinbase Wallet';
16
16
  if (provider.isFrame) return 'Frame';
17
+ if (provider.isOpera) return 'Opera';
17
18
  if (provider.isTally) return 'Tally';
18
19
  if (provider.isTokenary) return 'Tokenary';
19
20
  if (provider.isTrust) return 'Trust Wallet';
20
21
  if (provider.isMetaMask) return 'MetaMask';
21
- };
22
+ }; // Some injected providers detect multiple other providers and create a list at `ethers.providers`
23
+
22
24
 
23
25
  if ((_ethereum$providers = ethereum.providers) !== null && _ethereum$providers !== void 0 && _ethereum$providers.length) {
24
26
  // Deduplicate names using Set
@@ -20,11 +20,13 @@ function getInjectedName(ethereum) {
20
20
  if (provider.isBraveWallet) return 'Brave Wallet';
21
21
  if (provider.isCoinbaseWallet) return 'Coinbase Wallet';
22
22
  if (provider.isFrame) return 'Frame';
23
+ if (provider.isOpera) return 'Opera';
23
24
  if (provider.isTally) return 'Tally';
24
25
  if (provider.isTokenary) return 'Tokenary';
25
26
  if (provider.isTrust) return 'Trust Wallet';
26
27
  if (provider.isMetaMask) return 'MetaMask';
27
- };
28
+ }; // Some injected providers detect multiple other providers and create a list at `ethers.providers`
29
+
28
30
 
29
31
  if ((_ethereum$providers = ethereum.providers) !== null && _ethereum$providers !== void 0 && _ethereum$providers.length) {
30
32
  // Deduplicate names using Set
@@ -41,7 +41,7 @@ export declare class InjectedConnector extends Connector<Window['ethereum'], Inj
41
41
  decimals?: number;
42
42
  image?: string;
43
43
  symbol: string;
44
- }): Promise<any>;
44
+ }): Promise<boolean>;
45
45
  protected onAccountsChanged: (accounts: string[]) => void;
46
46
  protected onChainChanged: (chainId: number | string) => void;
47
47
  protected onDisconnect: () => void;
@@ -40,32 +40,12 @@ declare global {
40
40
  symbol: string;
41
41
  };
42
42
  };
43
- type RequestArguments = {
44
- method: 'eth_accounts';
45
- } | {
46
- method: 'eth_chainId';
47
- } | {
48
- method: 'eth_requestAccounts';
49
- } | {
50
- method: 'personal_sign';
51
- params: [string, string];
52
- } | {
53
- method: 'wallet_addEthereumChain';
54
- params: AddEthereumChainParameter[];
55
- } | {
56
- method: 'wallet_switchEthereumChain';
57
- params: [{
58
- chainId: string;
59
- }];
60
- } | {
61
- method: 'wallet_watchAsset';
62
- params: WatchAssetParams;
63
- };
64
43
  type InjectedProviderFlags = {
65
44
  isBraveWallet?: true;
66
45
  isCoinbaseWallet?: true;
67
46
  isFrame?: true;
68
47
  isMetaMask?: true;
48
+ isOpera?: true;
69
49
  isTally?: true;
70
50
  isTokenary?: true;
71
51
  isTrust?: true;
@@ -88,8 +68,37 @@ declare global {
88
68
  interface Ethereum extends InjectedProviders {
89
69
  on?: (...args: any[]) => void;
90
70
  removeListener?: (...args: any[]) => void;
91
- request<T = any>(args: RequestArguments): Promise<T>;
92
71
  providers?: Ethereum[];
72
+ request(args: {
73
+ method: 'eth_accounts';
74
+ }): Promise<string[]>;
75
+ request(args: {
76
+ method: 'eth_chainId';
77
+ }): Promise<string>;
78
+ request(args: {
79
+ method: 'eth_requestAccounts';
80
+ }): Promise<string[]>;
81
+ request(args: {
82
+ method: 'personal_sign';
83
+ params: [string, string];
84
+ }): Promise<string>;
85
+ request(args: {
86
+ method: 'wallet_addEthereumChain';
87
+ params: AddEthereumChainParameter[];
88
+ }): Promise<null>;
89
+ request(args: {
90
+ method: 'wallet_switchEthereumChain';
91
+ params: [{
92
+ chainId: string;
93
+ }];
94
+ }): Promise<null>;
95
+ request(args: {
96
+ method: 'wallet_watchAsset';
97
+ params: WatchAssetParams;
98
+ }): Promise<boolean>;
99
+ request(args: {
100
+ method: 'web3_clientVersion';
101
+ }): Promise<string>;
93
102
  }
94
103
  interface Window {
95
104
  ethereum?: Ethereum;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var client = require('./client-65157905.cjs.dev.js');
5
+ var client = require('./client-72d69b8e.cjs.dev.js');
6
6
  var base = require('./base-5812b724.cjs.dev.js');
7
7
  var ethers = require('ethers/lib/ethers');
8
8
  var utils = require('ethers/lib/utils');
@@ -453,7 +453,7 @@ async function writeContract(contractConfig, functionName) {
453
453
  const contract = getContract(contractConfig);
454
454
  const contractWithSigner = contract.connect(signer);
455
455
  const contractFunction = contractWithSigner[functionName];
456
- if (!contractFunction) console.warn("\"".concat(functionName, "\" does not in interface for contract \"").concat(contractConfig.addressOrName, "\""));
456
+ if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(contractConfig.addressOrName, "\""));
457
457
  const response = await contractFunction(...params);
458
458
  return response;
459
459
  } catch (error_) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var client = require('./client-a06853e2.cjs.prod.js');
5
+ var client = require('./client-1f6fd5b6.cjs.prod.js');
6
6
  var base = require('./base-59f3457e.cjs.prod.js');
7
7
  var ethers = require('ethers/lib/ethers');
8
8
  var utils = require('ethers/lib/utils');
@@ -453,7 +453,7 @@ async function writeContract(contractConfig, functionName) {
453
453
  const contract = getContract(contractConfig);
454
454
  const contractWithSigner = contract.connect(signer);
455
455
  const contractFunction = contractWithSigner[functionName];
456
- if (!contractFunction) console.warn("\"".concat(functionName, "\" does not in interface for contract \"").concat(contractConfig.addressOrName, "\""));
456
+ if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(contractConfig.addressOrName, "\""));
457
457
  const response = await contractFunction(...params);
458
458
  return response;
459
459
  } catch (error_) {
@@ -1,5 +1,5 @@
1
- import { c as client, g as getClient } from './client-7fcff803.esm.js';
2
- export { C as Client, I as InjectedConnector, C as WagmiClient, a as createClient, b as createStorage, a as createWagmiClient, b as createWagmiStorage, n as noopStorage } from './client-7fcff803.esm.js';
1
+ import { c as client, g as getClient } from './client-3a56f061.esm.js';
2
+ export { C as Client, I as InjectedConnector, C as WagmiClient, a as createClient, b as createStorage, a as createWagmiClient, b as createWagmiStorage, n as noopStorage } from './client-3a56f061.esm.js';
3
3
  import { C as ConnectorAlreadyConnectedError, a as allChains, b as ConnectorNotFoundError, U as UserRejectedRequestError, S as SwitchChainNotSupportedError } from './base-159de546.esm.js';
4
4
  export { A as AddChainError, k as ChainNotConfiguredError, c as Connector, C as ConnectorAlreadyConnectedError, b as ConnectorNotFoundError, l as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, d as alchemyRpcUrls, a as allChains, e as chain, f as chainId, g as defaultChains, h as defaultL2Chains, i as etherscanBlockExplorers, j as infuraRpcUrls, n as normalizeChainId } from './base-159de546.esm.js';
5
5
  import { Contract } from 'ethers/lib/ethers';
@@ -451,7 +451,7 @@ async function writeContract(contractConfig, functionName) {
451
451
  const contract = getContract(contractConfig);
452
452
  const contractWithSigner = contract.connect(signer);
453
453
  const contractFunction = contractWithSigner[functionName];
454
- if (!contractFunction) console.warn("\"".concat(functionName, "\" does not in interface for contract \"").concat(contractConfig.addressOrName, "\""));
454
+ if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(contractConfig.addressOrName, "\""));
455
455
  const response = await contractFunction(...params);
456
456
  return response;
457
457
  } catch (error_) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wagmi/core",
3
3
  "description": "Vanilla JS library for Ethereum",
4
4
  "license": "WAGMIT",
5
- "version": "0.2.4",
5
+ "version": "0.2.5",
6
6
  "author": "awkweb.eth",
7
7
  "ethereum": "awkweb.eth",
8
8
  "repository": "tmm/wagmi",
@@ -64,8 +64,8 @@
64
64
  },
65
65
  "devDependencies": {
66
66
  "@coinbase/wallet-sdk": "^3.0.11",
67
- "@walletconnect/ethereum-provider": "^1.7.5",
68
- "ethers": "^5.6.4"
67
+ "@walletconnect/ethereum-provider": "^1.7.8",
68
+ "ethers": "^5.6.5"
69
69
  },
70
70
  "keywords": [
71
71
  "eth",