@wagmi/core 0.4.6 → 0.4.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 (38) hide show
  1. package/chains/dist/wagmi-core-chains.cjs.dev.js +1 -1
  2. package/chains/dist/wagmi-core-chains.cjs.prod.js +1 -1
  3. package/chains/dist/wagmi-core-chains.esm.js +1 -1
  4. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +4 -3
  5. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +4 -3
  6. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +4 -3
  7. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +5 -5
  8. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +5 -5
  9. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +5 -5
  10. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +2 -2
  11. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +2 -2
  12. package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +2 -2
  13. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +3 -3
  14. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +3 -3
  15. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +3 -3
  16. package/dist/{base-797ad073.cjs.prod.js → base-337e6424.cjs.prod.js} +1 -1
  17. package/dist/{base-90b7f3e4.cjs.dev.js → base-bd337280.cjs.dev.js} +1 -1
  18. package/dist/{base-b565d5d4.esm.js → base-f1bbf263.esm.js} +1 -1
  19. package/dist/{chains-fd2c546c.esm.js → chains-174cf4b4.esm.js} +3 -3
  20. package/dist/{chains-f7bb3211.cjs.prod.js → chains-b8e32454.cjs.prod.js} +3 -3
  21. package/dist/{chains-7e6dc59c.cjs.dev.js → chains-ba6218fb.cjs.dev.js} +3 -3
  22. package/dist/{client-71ece661.cjs.dev.js → client-4983a639.cjs.dev.js} +17 -14
  23. package/dist/{client-a6e61429.cjs.prod.js → client-dfad744f.cjs.prod.js} +17 -14
  24. package/dist/{client-a05fd511.esm.js → client-fbdcbdb2.esm.js} +18 -14
  25. package/dist/declarations/src/actions/tokens/fetchToken.d.ts +1 -0
  26. package/dist/declarations/src/client.d.ts +1 -1
  27. package/dist/declarations/src/connectors/index.d.ts +1 -1
  28. package/dist/declarations/src/connectors/injected.d.ts +3 -3
  29. package/dist/declarations/src/connectors/metaMask.d.ts +1 -1
  30. package/dist/declarations/src/index.d.ts +3 -3
  31. package/dist/declarations/src/types/index.d.ts +129 -128
  32. package/dist/declarations/src/utils/getInjectedName.d.ts +2 -1
  33. package/dist/declarations/src/utils/index.d.ts +1 -0
  34. package/dist/declarations/src/utils/parseContractResult.d.ts +7 -0
  35. package/dist/wagmi-core.cjs.dev.js +53 -11
  36. package/dist/wagmi-core.cjs.prod.js +53 -11
  37. package/dist/wagmi-core.esm.js +58 -17
  38. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { e as Connector, _ as _defineProperty, j as _classPrivateFieldInitSpec, n as normalizeChainId, k as _classPrivateFieldGet, l as _classPrivateFieldSet, c as ConnectorNotFoundError, U as UserRejectedRequestError, R as ResourceUnavailableError, f as ChainNotConfiguredError, A as AddChainError, i as SwitchChainError, m as _classPrivateMethodInitSpec, o as _classPrivateMethodGet } from './base-b565d5d4.esm.js';
1
+ import { e as Connector, _ as _defineProperty, j as _classPrivateFieldInitSpec, n as normalizeChainId, k as _classPrivateFieldGet, l as _classPrivateFieldSet, c as ConnectorNotFoundError, U as UserRejectedRequestError, R as ResourceUnavailableError, f as ChainNotConfiguredError, A as AddChainError, i as SwitchChainError, m as _classPrivateMethodInitSpec, o as _classPrivateMethodGet } from './base-f1bbf263.esm.js';
2
2
  import create from 'zustand/vanilla';
3
3
  import { subscribeWithSelector, persist } from 'zustand/middleware';
4
4
  import { providers } from 'ethers';
@@ -50,8 +50,6 @@ function getInjectedName(ethereum) {
50
50
  return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
51
51
  }
52
52
 
53
- const shimDisconnectKey = 'injected.shimDisconnect';
54
-
55
53
  var _provider = /*#__PURE__*/new WeakMap();
56
54
 
57
55
  var _switchingChains = /*#__PURE__*/new WeakMap();
@@ -85,6 +83,8 @@ class InjectedConnector extends Connector {
85
83
  value: void 0
86
84
  });
87
85
 
86
+ _defineProperty(this, "shimDisconnectKey", 'injected.shimDisconnect');
87
+
88
88
  _defineProperty(this, "onAccountsChanged", accounts => {
89
89
  if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
90
90
  account: getAddress(accounts[0])
@@ -116,17 +116,15 @@ class InjectedConnector extends Connector {
116
116
 
117
117
  this.emit('disconnect'); // Remove shim signalling wallet is disconnected
118
118
 
119
- if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimDisconnectKey);
119
+ if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(this.shimDisconnectKey);
120
120
  });
121
121
 
122
122
  let name = 'Injected';
123
-
124
- if (typeof window !== 'undefined') {
125
- const overrideName = options.name;
123
+ const overrideName = options.name;
124
+ if (typeof overrideName === 'string') name = overrideName;else if (typeof window !== 'undefined') {
126
125
  const detectedName = getInjectedName(window.ethereum);
127
- if (overrideName) name = typeof overrideName === 'function' ? overrideName(detectedName) : overrideName;else name = typeof detectedName === 'string' ? detectedName : detectedName[0];
126
+ if (overrideName) name = overrideName(detectedName);else name = typeof detectedName === 'string' ? detectedName : detectedName[0];
128
127
  }
129
-
130
128
  this.id = 'injected';
131
129
  this.name = name;
132
130
  }
@@ -163,7 +161,7 @@ class InjectedConnector extends Connector {
163
161
  } // Add shim to storage signalling wallet is connected
164
162
 
165
163
 
166
- if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimDisconnectKey, true);
164
+ if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(this.shimDisconnectKey, true);
167
165
  return {
168
166
  account,
169
167
  chain: {
@@ -188,7 +186,7 @@ class InjectedConnector extends Connector {
188
186
  provider.removeListener('chainChanged', this.onChainChanged);
189
187
  provider.removeListener('disconnect', this.onDisconnect); // Remove shim signalling wallet is disconnected
190
188
 
191
- if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimDisconnectKey);
189
+ if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(this.shimDisconnectKey);
192
190
  }
193
191
 
194
192
  async getAccount() {
@@ -224,7 +222,7 @@ class InjectedConnector extends Connector {
224
222
  var _this$options5, _getClient$storage4;
225
223
 
226
224
  if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && // If shim does not exist in storage, wallet is disconnected
227
- !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimDisconnectKey))) return false;
225
+ !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(this.shimDisconnectKey))) return false;
228
226
  const provider = await this.getProvider();
229
227
  if (!provider) throw new ConnectorNotFoundError();
230
228
  const accounts = await provider.request({
@@ -530,7 +528,13 @@ class Client {
530
528
 
531
529
  _classPrivateFieldSet(this, _isAutoConnecting, true);
532
530
 
533
- if (!this.connectors.length) return; // Try last used connector first
531
+ this.setState(x => {
532
+ var _x$data;
533
+
534
+ return { ...x,
535
+ status: (_x$data = x.data) !== null && _x$data !== void 0 && _x$data.account ? 'reconnecting' : 'connecting'
536
+ };
537
+ }); // Try last used connector first
534
538
 
535
539
  const sorted = _classPrivateFieldGet(this, _lastUsedConnector) ? [...this.connectors].sort(x => x.id === _classPrivateFieldGet(this, _lastUsedConnector) ? -1 : 1) : this.connectors;
536
540
  let connected = false;
@@ -644,4 +648,4 @@ function getClient() {
644
648
  return client;
645
649
  }
646
650
 
647
- export { Client as C, InjectedConnector as I, createStorage as a, createClient as c, getClient as g, noopStorage as n, shimDisconnectKey as s };
651
+ export { Client as C, InjectedConnector as I, createStorage as a, createClient as c, getClient as g, noopStorage as n };
@@ -11,6 +11,7 @@ export declare type FetchTokenArgs = {
11
11
  export declare type FetchTokenResult = {
12
12
  address: string;
13
13
  decimals: number;
14
+ name: string;
14
15
  symbol: string;
15
16
  totalSupply: {
16
17
  formatted: string;
@@ -25,7 +25,7 @@ export declare type ClientConfig<TProvider extends Provider = Provider, TWebSock
25
25
  }) => TWebSocketProvider | undefined) | TWebSocketProvider;
26
26
  };
27
27
  export declare type Data<TProvider extends Provider> = ConnectorData<TProvider>;
28
- export declare type State<TProvider extends Provider, TWebSocketProvider extends WebSocketProvider = WebSocketProvider> = {
28
+ export declare type State<TProvider extends Provider = Provider, TWebSocketProvider extends WebSocketProvider = WebSocketProvider> = {
29
29
  chains?: Connector['chains'];
30
30
  connector?: Connector;
31
31
  connectors: Connector[];
@@ -1,2 +1,2 @@
1
- export { InjectedConnector } from './injected';
1
+ export { InjectedConnector, type InjectedConnectorOptions } from './injected';
2
2
  export { Connector, type ConnectorData, type ConnectorEvents } from './base';
@@ -18,12 +18,12 @@ export declare type InjectedConnectorOptions = {
18
18
  */
19
19
  shimDisconnect?: boolean;
20
20
  };
21
- export declare const shimDisconnectKey = "injected.shimDisconnect";
22
21
  export declare class InjectedConnector extends Connector<Window['ethereum'], InjectedConnectorOptions | undefined> {
23
22
  #private;
24
23
  readonly id: string;
25
24
  readonly name: string;
26
25
  readonly ready: boolean;
26
+ protected shimDisconnectKey: string;
27
27
  constructor({ chains, options, }?: {
28
28
  chains?: Chain[];
29
29
  options?: InjectedConnectorOptions;
@@ -36,12 +36,12 @@ export declare class InjectedConnector extends Connector<Window['ethereum'], Inj
36
36
  id: number;
37
37
  unsupported: boolean;
38
38
  };
39
- provider: Ethereum;
39
+ provider: import("../types").Ethereum;
40
40
  }>;
41
41
  disconnect(): Promise<void>;
42
42
  getAccount(): Promise<string>;
43
43
  getChainId(): Promise<number>;
44
- getProvider(): Promise<Ethereum | undefined>;
44
+ getProvider(): Promise<import("../types").Ethereum | undefined>;
45
45
  getSigner(): Promise<providers.JsonRpcSigner>;
46
46
  isAuthorized(): Promise<boolean>;
47
47
  switchChain(chainId: number): Promise<Chain>;
@@ -1,4 +1,4 @@
1
- import { Chain } from '../types';
1
+ import { Chain, Ethereum } from '../types';
2
2
  import { InjectedConnector, InjectedConnectorOptions } from './injected';
3
3
  export declare type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChainChangedDisconnect' | 'shimDisconnect'> & {
4
4
  /**
@@ -3,11 +3,11 @@ export type { ConnectArgs, ConnectResult, FetchBalanceArgs, FetchBalanceResult,
3
3
  export { createClient, Client } from './client';
4
4
  export type { ClientConfig } from './client';
5
5
  export { Connector, InjectedConnector } from './connectors';
6
- export type { ConnectorData, ConnectorEvents } from './connectors';
6
+ export type { ConnectorData, ConnectorEvents, InjectedConnectorOptions, } from './connectors';
7
7
  export { alchemyRpcUrls, allChains, chain, chainId, defaultChains, defaultL2Chains, erc20ABI, erc721ABI, etherscanBlockExplorers, infuraRpcUrls, publicRpcUrls, units, } from './constants';
8
8
  export { AddChainError, ChainDoesNotSupportMulticallError, ChainMismatchError, ChainNotConfiguredError, ConnectorAlreadyConnectedError, ConnectorNotFoundError, ContractMethodNoResultError, ProviderChainsNotFound, ProviderRpcError, ResourceUnavailableError, RpcError, SwitchChainError, SwitchChainNotSupportedError, UserRejectedRequestError, } from './errors';
9
9
  export { createStorage, noopStorage } from './storage';
10
10
  export type { ClientStorage as Storage } from './storage';
11
- export type { Chain, ChainProviderFn, FallbackProviderConfig, ProviderWithFallbackConfig, Provider, Unit, WebSocketProvider, } from './types';
12
- export { configureChains, deepEqual, normalizeChainId } from './utils';
11
+ export type { Chain, ChainProviderFn, Ethereum, FallbackProviderConfig, ProviderWithFallbackConfig, Provider, Unit, WebSocketProvider, } from './types';
12
+ export { configureChains, deepEqual, normalizeChainId, parseContractResult, } from './utils';
13
13
  export type { ConfigureChainsConfig } from './utils';
@@ -49,139 +49,140 @@ export declare type WebSocketProvider = providers.WebSocketProvider & {
49
49
  chains?: Chain[];
50
50
  };
51
51
  export declare type Unit = typeof units[number];
52
- declare global {
53
- type AddEthereumChainParameter = {
54
- /** A 0x-prefixed hexadecimal string */
55
- chainId: string;
56
- chainName: string;
57
- nativeCurrency?: {
58
- name: string;
59
- /** 2-6 characters long */
60
- symbol: string;
61
- decimals: number;
62
- };
63
- rpcUrls: string[];
64
- blockExplorerUrls?: string[];
65
- /** Currently ignored. */
66
- iconUrls?: string[];
67
- };
68
- type WalletPermissionCaveat = {
69
- type: string;
70
- value: any;
52
+ declare type AddEthereumChainParameter = {
53
+ /** A 0x-prefixed hexadecimal string */
54
+ chainId: string;
55
+ chainName: string;
56
+ nativeCurrency?: {
57
+ name: string;
58
+ /** 2-6 characters long */
59
+ symbol: string;
60
+ decimals: number;
71
61
  };
72
- type WalletPermission = {
73
- caveats: WalletPermissionCaveat[];
74
- date: number;
75
- id: string;
76
- invoker: `http://${string}` | `https://${string}`;
77
- parentCapability: 'eth_accounts' | string;
78
- };
79
- type WatchAssetParams = {
80
- /** In the future, other standards will be supported */
81
- type: 'ERC20';
82
- options: {
83
- /** Address of token contract */
84
- address: string;
85
- /** Number of token decimals */
86
- decimals: number;
87
- /** String url of token logo */
88
- image?: string;
89
- /** A ticker symbol or shorthand, up to 5 characters */
90
- symbol: string;
91
- };
62
+ rpcUrls: string[];
63
+ blockExplorerUrls?: string[];
64
+ /** Currently ignored. */
65
+ iconUrls?: string[];
66
+ };
67
+ declare type WalletPermissionCaveat = {
68
+ type: string;
69
+ value: any;
70
+ };
71
+ declare type WalletPermission = {
72
+ caveats: WalletPermissionCaveat[];
73
+ date: number;
74
+ id: string;
75
+ invoker: `http://${string}` | `https://${string}`;
76
+ parentCapability: 'eth_accounts' | string;
77
+ };
78
+ declare type WatchAssetParams = {
79
+ /** In the future, other standards will be supported */
80
+ type: 'ERC20';
81
+ options: {
82
+ /** Address of token contract */
83
+ address: string;
84
+ /** Number of token decimals */
85
+ decimals: number;
86
+ /** String url of token logo */
87
+ image?: string;
88
+ /** A ticker symbol or shorthand, up to 5 characters */
89
+ symbol: string;
92
90
  };
93
- type InjectedProviderFlags = {
94
- isBraveWallet?: true;
95
- isCoinbaseWallet?: true;
96
- isExodus?: true;
97
- isFrame?: true;
98
- isMetaMask?: true;
99
- isOpera?: true;
100
- isTally?: true;
101
- isTokenPocket?: true;
102
- isTokenary?: true;
103
- isTrust?: true;
91
+ };
92
+ declare type InjectedProviderFlags = {
93
+ isBraveWallet?: true;
94
+ isCoinbaseWallet?: true;
95
+ isExodus?: true;
96
+ isFrame?: true;
97
+ isMetaMask?: true;
98
+ isOpera?: true;
99
+ isTally?: true;
100
+ isTokenPocket?: true;
101
+ isTokenary?: true;
102
+ isTrust?: true;
103
+ };
104
+ declare type InjectedProviders = InjectedProviderFlags & {
105
+ isMetaMask: true;
106
+ /** Only exists in MetaMask as of 2022/04/03 */
107
+ _events: {
108
+ connect?: () => void;
104
109
  };
105
- type InjectedProviders = InjectedProviderFlags & {
106
- isMetaMask: true;
107
- /** Only exists in MetaMask as of 2022/04/03 */
108
- _events: {
109
- connect?: () => void;
110
- };
111
- /** Only exists in MetaMask as of 2022/04/03 */
112
- _state?: {
113
- accounts?: string[];
114
- initialized?: boolean;
115
- isConnected?: boolean;
116
- isPermanentlyDisconnected?: boolean;
117
- isUnlocked?: boolean;
118
- };
110
+ /** Only exists in MetaMask as of 2022/04/03 */
111
+ _state?: {
112
+ accounts?: string[];
113
+ initialized?: boolean;
114
+ isConnected?: boolean;
115
+ isPermanentlyDisconnected?: boolean;
116
+ isUnlocked?: boolean;
119
117
  };
120
- interface Ethereum extends InjectedProviders {
121
- on?: (...args: any[]) => void;
122
- removeListener?: (...args: any[]) => void;
123
- providers?: Ethereum[];
124
- /**
125
- * EIP-747: Add wallet_watchAsset to Provider
126
- * https://eips.ethereum.org/EIPS/eip-747
127
- */
128
- request(args: {
129
- method: 'wallet_watchAsset';
130
- params: WatchAssetParams;
131
- }): Promise<boolean>;
132
- /**
133
- * EIP-1193: Ethereum Provider JavaScript API
134
- * https://eips.ethereum.org/EIPS/eip-1193
135
- */
136
- request(args: {
137
- method: 'eth_accounts';
138
- }): Promise<string[]>;
139
- request(args: {
140
- method: 'eth_chainId';
141
- }): Promise<string>;
142
- request(args: {
143
- method: 'eth_requestAccounts';
144
- }): Promise<string[]>;
145
- /**
146
- * EIP-1474: Remote procedure call specification
147
- * https://eips.ethereum.org/EIPS/eip-1474
148
- */
149
- request(args: {
150
- method: 'web3_clientVersion';
151
- }): Promise<string>;
152
- /**
153
- * EIP-2255: Wallet Permissions System
154
- * https://eips.ethereum.org/EIPS/eip-2255
155
- */
156
- request(args: {
157
- method: 'wallet_requestPermissions';
158
- params: [{
159
- eth_accounts: Record<string, any>;
160
- }];
161
- }): Promise<WalletPermission[]>;
162
- request(args: {
163
- method: 'wallet_getPermissions';
164
- }): Promise<WalletPermission[]>;
165
- /**
166
- * EIP-3085: Wallet Add Ethereum Chain RPC Method
167
- * https://eips.ethereum.org/EIPS/eip-3085
168
- */
169
- request(args: {
170
- method: 'wallet_addEthereumChain';
171
- params: AddEthereumChainParameter[];
172
- }): Promise<null>;
173
- /**
174
- * EIP-3326: Wallet Switch Ethereum Chain RPC Method
175
- * https://eips.ethereum.org/EIPS/eip-3326
176
- */
177
- request(args: {
178
- method: 'wallet_switchEthereumChain';
179
- params: [{
180
- chainId: string;
181
- }];
182
- }): Promise<null>;
183
- }
118
+ };
119
+ export interface Ethereum extends InjectedProviders {
120
+ on?: (...args: any[]) => void;
121
+ removeListener?: (...args: any[]) => void;
122
+ providers?: Ethereum[];
123
+ /**
124
+ * EIP-747: Add wallet_watchAsset to Provider
125
+ * https://eips.ethereum.org/EIPS/eip-747
126
+ */
127
+ request(args: {
128
+ method: 'wallet_watchAsset';
129
+ params: WatchAssetParams;
130
+ }): Promise<boolean>;
131
+ /**
132
+ * EIP-1193: Ethereum Provider JavaScript API
133
+ * https://eips.ethereum.org/EIPS/eip-1193
134
+ */
135
+ request(args: {
136
+ method: 'eth_accounts';
137
+ }): Promise<string[]>;
138
+ request(args: {
139
+ method: 'eth_chainId';
140
+ }): Promise<string>;
141
+ request(args: {
142
+ method: 'eth_requestAccounts';
143
+ }): Promise<string[]>;
144
+ /**
145
+ * EIP-1474: Remote procedure call specification
146
+ * https://eips.ethereum.org/EIPS/eip-1474
147
+ */
148
+ request(args: {
149
+ method: 'web3_clientVersion';
150
+ }): Promise<string>;
151
+ /**
152
+ * EIP-2255: Wallet Permissions System
153
+ * https://eips.ethereum.org/EIPS/eip-2255
154
+ */
155
+ request(args: {
156
+ method: 'wallet_requestPermissions';
157
+ params: [{
158
+ eth_accounts: Record<string, any>;
159
+ }];
160
+ }): Promise<WalletPermission[]>;
161
+ request(args: {
162
+ method: 'wallet_getPermissions';
163
+ }): Promise<WalletPermission[]>;
164
+ /**
165
+ * EIP-3085: Wallet Add Ethereum Chain RPC Method
166
+ * https://eips.ethereum.org/EIPS/eip-3085
167
+ */
168
+ request(args: {
169
+ method: 'wallet_addEthereumChain';
170
+ params: AddEthereumChainParameter[];
171
+ }): Promise<null>;
172
+ /**
173
+ * EIP-3326: Wallet Switch Ethereum Chain RPC Method
174
+ * https://eips.ethereum.org/EIPS/eip-3326
175
+ */
176
+ request(args: {
177
+ method: 'wallet_switchEthereumChain';
178
+ params: [{
179
+ chainId: string;
180
+ }];
181
+ }): Promise<null>;
182
+ }
183
+ declare global {
184
184
  interface Window {
185
185
  ethereum?: Ethereum;
186
186
  }
187
187
  }
188
+ export {};
@@ -1 +1,2 @@
1
- export declare function getInjectedName(ethereum?: Window['ethereum']): string | string[];
1
+ import { Ethereum } from '../types';
2
+ export declare function getInjectedName(ethereum?: Ethereum): string | string[];
@@ -3,4 +3,5 @@ export type { ConfigureChainsConfig } from './configureChains';
3
3
  export { deepEqual } from './deepEqual';
4
4
  export { getInjectedName } from './getInjectedName';
5
5
  export { normalizeChainId } from './normalizeChainId';
6
+ export { parseContractResult } from './parseContractResult';
6
7
  export { warn } from './warn';
@@ -0,0 +1,7 @@
1
+ import { ContractInterface } from 'ethers/lib/ethers';
2
+ import { Result } from 'ethers/lib/utils';
3
+ export declare function parseContractResult({ contractInterface, data, functionName, }: {
4
+ contractInterface: ContractInterface;
5
+ data: Result;
6
+ functionName: string;
7
+ }): any;
@@ -2,14 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var client = require('./client-71ece661.cjs.dev.js');
6
- var base = require('./base-90b7f3e4.cjs.dev.js');
5
+ var client = require('./client-4983a639.cjs.dev.js');
6
+ var base = require('./base-bd337280.cjs.dev.js');
7
7
  var ethers$1 = require('ethers/lib/ethers');
8
8
  var utils = require('ethers/lib/utils');
9
9
  var ethers = require('ethers');
10
10
  var shallow = require('zustand/shallow');
11
11
  var rpcs = require('./rpcs-f1d24f0e.cjs.dev.js');
12
- var chains = require('./chains-7e6dc59c.cjs.dev.js');
12
+ var chains = require('./chains-ba6218fb.cjs.dev.js');
13
13
  require('zustand/vanilla');
14
14
  require('zustand/middleware');
15
15
  require('eventemitter3');
@@ -170,6 +170,32 @@ function deepEqual(a, b) {
170
170
  return a !== a && b !== b;
171
171
  }
172
172
 
173
+ function isPlainArray(value) {
174
+ return Array.isArray(value) && Object.keys(value).length === value.length;
175
+ }
176
+
177
+ function parseContractResult(_ref) {
178
+ let {
179
+ contractInterface,
180
+ data,
181
+ functionName
182
+ } = _ref;
183
+
184
+ if (data && isPlainArray(data)) {
185
+ var _fragment$outputs;
186
+
187
+ const iface = ethers$1.Contract.getInterface(contractInterface);
188
+ const fragment = iface.getFunction(functionName);
189
+ const isTuple = (((_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : _fragment$outputs.length) || 0) > 1;
190
+ const data_ = isTuple ? data : [data];
191
+ const encodedResult = iface.encodeFunctionResult(functionName, data_);
192
+ const decodedResult = iface.decodeFunctionResult(functionName, encodedResult);
193
+ return isTuple ? decodedResult : decodedResult[0];
194
+ }
195
+
196
+ return data;
197
+ }
198
+
173
199
  // https://ethereum.org/en/developers/docs/standards/tokens/erc-20
174
200
  const erc20ABI = ['event Approval(address indexed _owner, address indexed _spender, uint256 _value)', 'event Transfer(address indexed _from, address indexed _to, uint256 _value)', 'function allowance(address _owner, address _spender) public view returns (uint256 remaining)', 'function approve(address _spender, uint256 _value) public returns (bool success)', 'function balanceOf(address _owner) public view returns (uint256 balance)', 'function decimals() public view returns (uint8)', 'function name() public view returns (string)', 'function symbol() public view returns (string)', 'function totalSupply() public view returns (uint256)', 'function transfer(address _to, uint256 _value) public returns (bool success)', 'function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)']; // https://ethereum.org/en/developers/docs/standards/tokens/erc-721
175
201
 
@@ -244,9 +270,12 @@ async function connect(_ref) {
244
270
  connector
245
271
  };
246
272
  } catch (err) {
247
- client$1.setState(x => ({ ...x,
248
- status: 'disconnected'
249
- }));
273
+ client$1.setState(x => {
274
+ return { ...x,
275
+ // Keep existing connector connected in case of error
276
+ status: x.connector ? 'connected' : 'disconnected'
277
+ };
278
+ });
250
279
  throw err;
251
280
  }
252
281
  }
@@ -1057,21 +1086,33 @@ async function fetchToken(_ref) {
1057
1086
  chainId,
1058
1087
  formatUnits: units = 'ether'
1059
1088
  } = _ref;
1060
- const provider = getProvider({
1089
+ const erc20Config = {
1090
+ addressOrName: address,
1091
+ contractInterface: erc20ABI,
1061
1092
  chainId
1093
+ };
1094
+ const [decimals, name, symbol, totalSupply] = await readContracts({
1095
+ allowFailure: false,
1096
+ contracts: [{ ...erc20Config,
1097
+ functionName: 'decimals'
1098
+ }, { ...erc20Config,
1099
+ functionName: 'name'
1100
+ }, { ...erc20Config,
1101
+ functionName: 'symbol'
1102
+ }, { ...erc20Config,
1103
+ functionName: 'totalSupply'
1104
+ }]
1062
1105
  });
1063
- const contract = new ethers$1.Contract(address, erc20ABI, provider);
1064
- const [symbol, decimals, totalSupply] = await Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
1065
- const token = {
1106
+ return {
1066
1107
  address,
1067
1108
  decimals,
1109
+ name,
1068
1110
  symbol,
1069
1111
  totalSupply: {
1070
1112
  formatted: utils.formatUnits(totalSupply, units),
1071
1113
  value: totalSupply
1072
1114
  }
1073
1115
  };
1074
- return token;
1075
1116
  }
1076
1117
 
1077
1118
  async function sendTransaction(_ref) {
@@ -1182,6 +1223,7 @@ exports.getContract = getContract;
1182
1223
  exports.getNetwork = getNetwork;
1183
1224
  exports.getProvider = getProvider;
1184
1225
  exports.getWebSocketProvider = getWebSocketProvider;
1226
+ exports.parseContractResult = parseContractResult;
1185
1227
  exports.readContract = readContract;
1186
1228
  exports.readContracts = readContracts;
1187
1229
  exports.sendTransaction = sendTransaction;