@wagmi/core 0.4.5 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -159,7 +159,8 @@ class CoinbaseWalletConnector extends base.Connector {
159
159
  let CoinbaseWalletSDK = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); })).default; // Workaround for Vite dev import errors
160
160
  // https://github.com/vitejs/vite/issues/7112
161
161
 
162
- if (!CoinbaseWalletSDK.constructor) CoinbaseWalletSDK = CoinbaseWalletSDK.default;
162
+ if (typeof CoinbaseWalletSDK !== 'function' && // @ts-expect-error This import error is not visible to TypeScript
163
+ typeof CoinbaseWalletSDK.default === 'function') CoinbaseWalletSDK = CoinbaseWalletSDK.default;
163
164
 
164
165
  base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
165
166
 
@@ -159,7 +159,8 @@ class CoinbaseWalletConnector extends base.Connector {
159
159
  let CoinbaseWalletSDK = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@coinbase/wallet-sdk')); })).default; // Workaround for Vite dev import errors
160
160
  // https://github.com/vitejs/vite/issues/7112
161
161
 
162
- if (!CoinbaseWalletSDK.constructor) CoinbaseWalletSDK = CoinbaseWalletSDK.default;
162
+ if (typeof CoinbaseWalletSDK !== 'function' && // @ts-expect-error This import error is not visible to TypeScript
163
+ typeof CoinbaseWalletSDK.default === 'function') CoinbaseWalletSDK = CoinbaseWalletSDK.default;
163
164
 
164
165
  base._classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
165
166
 
@@ -137,7 +137,8 @@ class CoinbaseWalletConnector extends Connector {
137
137
  let CoinbaseWalletSDK = (await import('@coinbase/wallet-sdk')).default; // Workaround for Vite dev import errors
138
138
  // https://github.com/vitejs/vite/issues/7112
139
139
 
140
- if (!CoinbaseWalletSDK.constructor) CoinbaseWalletSDK = CoinbaseWalletSDK.default;
140
+ if (typeof CoinbaseWalletSDK !== 'function' && // @ts-expect-error This import error is not visible to TypeScript
141
+ typeof CoinbaseWalletSDK.default === 'function') CoinbaseWalletSDK = CoinbaseWalletSDK.default;
141
142
 
142
143
  _classPrivateFieldSet(this, _client, new CoinbaseWalletSDK(this.options));
143
144
 
@@ -9,5 +9,5 @@ export { AddChainError, ChainDoesNotSupportMulticallError, ChainMismatchError, C
9
9
  export { createStorage, noopStorage } from './storage';
10
10
  export type { ClientStorage as Storage } from './storage';
11
11
  export type { Chain, ChainProviderFn, FallbackProviderConfig, ProviderWithFallbackConfig, Provider, Unit, WebSocketProvider, } from './types';
12
- export { configureChains, normalizeChainId } from './utils';
12
+ export { configureChains, deepEqual, normalizeChainId, parseContractResult, } from './utils';
13
13
  export type { ConfigureChainsConfig } from './utils';
@@ -0,0 +1,2 @@
1
+ /** Forked from https://github.com/epoberezkin/fast-deep-equal */
2
+ export declare function deepEqual(a: any, b: any): boolean;
@@ -1,5 +1,7 @@
1
1
  export { configureChains } from './configureChains';
2
2
  export type { ConfigureChainsConfig } from './configureChains';
3
+ export { deepEqual } from './deepEqual';
3
4
  export { getInjectedName } from './getInjectedName';
4
5
  export { normalizeChainId } from './normalizeChainId';
6
+ export { parseContractResult } from './parseContractResult';
5
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;
@@ -132,6 +132,70 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
132
132
  }
133
133
  }
134
134
 
135
+ /** Forked from https://github.com/epoberezkin/fast-deep-equal */
136
+ function deepEqual(a, b) {
137
+ if (a === b) return true;
138
+
139
+ if (a && b && typeof a === 'object' && typeof b === 'object') {
140
+ if (a.constructor !== b.constructor) return false;
141
+ let length;
142
+ let i;
143
+
144
+ if (Array.isArray(a) && Array.isArray(b)) {
145
+ length = a.length;
146
+ if (length != b.length) return false;
147
+
148
+ for (i = length; i-- !== 0;) if (!deepEqual(a[i], b[i])) return false;
149
+
150
+ return true;
151
+ }
152
+
153
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
154
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
155
+ const keys = Object.keys(a);
156
+ length = keys.length;
157
+ if (length !== Object.keys(b).length) return false;
158
+
159
+ for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
160
+
161
+ for (i = length; i-- !== 0;) {
162
+ const key = keys[i];
163
+ if (key && !deepEqual(a[key], b[key])) return false;
164
+ }
165
+
166
+ return true;
167
+ } // true if both NaN, false otherwise
168
+
169
+
170
+ return a !== a && b !== b;
171
+ }
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
+
135
199
  // https://ethereum.org/en/developers/docs/standards/tokens/erc-20
136
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
137
201
 
@@ -358,7 +422,7 @@ async function multicall(_ref) {
358
422
  returnData,
359
423
  success
360
424
  } = _ref3;
361
- if (!success) return undefined;
425
+ if (!success) return null;
362
426
  const {
363
427
  addressOrName,
364
428
  contractInterface,
@@ -375,7 +439,7 @@ async function multicall(_ref) {
375
439
  });
376
440
  if (!allowFailure) throw err;
377
441
  console.warn(err.message);
378
- return undefined;
442
+ return null;
379
443
  }
380
444
 
381
445
  const contract = getContract({
@@ -388,7 +452,7 @@ async function multicall(_ref) {
388
452
  return Array.isArray(result) && result.length === 1 ? result[0] : result;
389
453
  } catch (err) {
390
454
  if (!allowFailure) throw err;
391
- return undefined;
455
+ return null;
392
456
  }
393
457
  });
394
458
  }
@@ -1126,6 +1190,7 @@ exports.defaultL2Chains = chains.defaultL2Chains;
1126
1190
  exports.etherscanBlockExplorers = chains.etherscanBlockExplorers;
1127
1191
  exports.configureChains = configureChains;
1128
1192
  exports.connect = connect;
1193
+ exports.deepEqual = deepEqual;
1129
1194
  exports.disconnect = disconnect;
1130
1195
  exports.erc20ABI = erc20ABI;
1131
1196
  exports.erc721ABI = erc721ABI;
@@ -1143,6 +1208,7 @@ exports.getContract = getContract;
1143
1208
  exports.getNetwork = getNetwork;
1144
1209
  exports.getProvider = getProvider;
1145
1210
  exports.getWebSocketProvider = getWebSocketProvider;
1211
+ exports.parseContractResult = parseContractResult;
1146
1212
  exports.readContract = readContract;
1147
1213
  exports.readContracts = readContracts;
1148
1214
  exports.sendTransaction = sendTransaction;
@@ -132,6 +132,70 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
132
132
  }
133
133
  }
134
134
 
135
+ /** Forked from https://github.com/epoberezkin/fast-deep-equal */
136
+ function deepEqual(a, b) {
137
+ if (a === b) return true;
138
+
139
+ if (a && b && typeof a === 'object' && typeof b === 'object') {
140
+ if (a.constructor !== b.constructor) return false;
141
+ let length;
142
+ let i;
143
+
144
+ if (Array.isArray(a) && Array.isArray(b)) {
145
+ length = a.length;
146
+ if (length != b.length) return false;
147
+
148
+ for (i = length; i-- !== 0;) if (!deepEqual(a[i], b[i])) return false;
149
+
150
+ return true;
151
+ }
152
+
153
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
154
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
155
+ const keys = Object.keys(a);
156
+ length = keys.length;
157
+ if (length !== Object.keys(b).length) return false;
158
+
159
+ for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
160
+
161
+ for (i = length; i-- !== 0;) {
162
+ const key = keys[i];
163
+ if (key && !deepEqual(a[key], b[key])) return false;
164
+ }
165
+
166
+ return true;
167
+ } // true if both NaN, false otherwise
168
+
169
+
170
+ return a !== a && b !== b;
171
+ }
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
+
135
199
  // https://ethereum.org/en/developers/docs/standards/tokens/erc-20
136
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
137
201
 
@@ -358,7 +422,7 @@ async function multicall(_ref) {
358
422
  returnData,
359
423
  success
360
424
  } = _ref3;
361
- if (!success) return undefined;
425
+ if (!success) return null;
362
426
  const {
363
427
  addressOrName,
364
428
  contractInterface,
@@ -375,7 +439,7 @@ async function multicall(_ref) {
375
439
  });
376
440
  if (!allowFailure) throw err;
377
441
  console.warn(err.message);
378
- return undefined;
442
+ return null;
379
443
  }
380
444
 
381
445
  const contract = getContract({
@@ -388,7 +452,7 @@ async function multicall(_ref) {
388
452
  return Array.isArray(result) && result.length === 1 ? result[0] : result;
389
453
  } catch (err) {
390
454
  if (!allowFailure) throw err;
391
- return undefined;
455
+ return null;
392
456
  }
393
457
  });
394
458
  }
@@ -1126,6 +1190,7 @@ exports.defaultL2Chains = chains.defaultL2Chains;
1126
1190
  exports.etherscanBlockExplorers = chains.etherscanBlockExplorers;
1127
1191
  exports.configureChains = configureChains;
1128
1192
  exports.connect = connect;
1193
+ exports.deepEqual = deepEqual;
1129
1194
  exports.disconnect = disconnect;
1130
1195
  exports.erc20ABI = erc20ABI;
1131
1196
  exports.erc721ABI = erc721ABI;
@@ -1143,6 +1208,7 @@ exports.getContract = getContract;
1143
1208
  exports.getNetwork = getNetwork;
1144
1209
  exports.getProvider = getProvider;
1145
1210
  exports.getWebSocketProvider = getWebSocketProvider;
1211
+ exports.parseContractResult = parseContractResult;
1146
1212
  exports.readContract = readContract;
1147
1213
  exports.readContracts = readContracts;
1148
1214
  exports.sendTransaction = sendTransaction;
@@ -2,9 +2,9 @@ import { g as getClient } from './client-a05fd511.esm.js';
2
2
  export { C as Client, I as InjectedConnector, c as createClient, a as createStorage, n as noopStorage } from './client-a05fd511.esm.js';
3
3
  import { C as ConnectorAlreadyConnectedError, P as ProviderChainsNotFound, a as ChainDoesNotSupportMulticallError, b as ContractMethodNoResultError, c as ConnectorNotFoundError, d as ChainMismatchError, U as UserRejectedRequestError, n as normalizeChainId, S as SwitchChainNotSupportedError } from './base-b565d5d4.esm.js';
4
4
  export { A as AddChainError, a as ChainDoesNotSupportMulticallError, d as ChainMismatchError, f as ChainNotConfiguredError, e as Connector, C as ConnectorAlreadyConnectedError, c as ConnectorNotFoundError, b as ContractMethodNoResultError, P as ProviderChainsNotFound, g as ProviderRpcError, R as ResourceUnavailableError, h as RpcError, i as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, n as normalizeChainId } from './base-b565d5d4.esm.js';
5
- import { logger, Contract as Contract$1 } from 'ethers/lib/ethers';
5
+ import { Contract, logger } from 'ethers/lib/ethers';
6
6
  import { isAddress, Logger, formatUnits, getAddress } from 'ethers/lib/utils';
7
- import { providers, Contract } from 'ethers';
7
+ import { providers, Contract as Contract$1 } from 'ethers';
8
8
  import shallow from 'zustand/shallow';
9
9
  export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-b73a8f60.esm.js';
10
10
  export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-fd2c546c.esm.js';
@@ -126,6 +126,70 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
126
126
  }
127
127
  }
128
128
 
129
+ /** Forked from https://github.com/epoberezkin/fast-deep-equal */
130
+ function deepEqual(a, b) {
131
+ if (a === b) return true;
132
+
133
+ if (a && b && typeof a === 'object' && typeof b === 'object') {
134
+ if (a.constructor !== b.constructor) return false;
135
+ let length;
136
+ let i;
137
+
138
+ if (Array.isArray(a) && Array.isArray(b)) {
139
+ length = a.length;
140
+ if (length != b.length) return false;
141
+
142
+ for (i = length; i-- !== 0;) if (!deepEqual(a[i], b[i])) return false;
143
+
144
+ return true;
145
+ }
146
+
147
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
148
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
149
+ const keys = Object.keys(a);
150
+ length = keys.length;
151
+ if (length !== Object.keys(b).length) return false;
152
+
153
+ for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
154
+
155
+ for (i = length; i-- !== 0;) {
156
+ const key = keys[i];
157
+ if (key && !deepEqual(a[key], b[key])) return false;
158
+ }
159
+
160
+ return true;
161
+ } // true if both NaN, false otherwise
162
+
163
+
164
+ return a !== a && b !== b;
165
+ }
166
+
167
+ function isPlainArray(value) {
168
+ return Array.isArray(value) && Object.keys(value).length === value.length;
169
+ }
170
+
171
+ function parseContractResult(_ref) {
172
+ let {
173
+ contractInterface,
174
+ data,
175
+ functionName
176
+ } = _ref;
177
+
178
+ if (data && isPlainArray(data)) {
179
+ var _fragment$outputs;
180
+
181
+ const iface = Contract.getInterface(contractInterface);
182
+ const fragment = iface.getFunction(functionName);
183
+ const isTuple = (((_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : _fragment$outputs.length) || 0) > 1;
184
+ const data_ = isTuple ? data : [data];
185
+ const encodedResult = iface.encodeFunctionResult(functionName, data_);
186
+ const decodedResult = iface.decodeFunctionResult(functionName, encodedResult);
187
+ return isTuple ? decodedResult : decodedResult[0];
188
+ }
189
+
190
+ return data;
191
+ }
192
+
129
193
  // https://ethereum.org/en/developers/docs/standards/tokens/erc-20
130
194
  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
131
195
 
@@ -220,7 +284,7 @@ function getContract(_ref) {
220
284
  contractInterface,
221
285
  signerOrProvider
222
286
  } = _ref;
223
- return new Contract(addressOrName, contractInterface, signerOrProvider);
287
+ return new Contract$1(addressOrName, contractInterface, signerOrProvider);
224
288
  }
225
289
 
226
290
  function getProvider() {
@@ -352,7 +416,7 @@ async function multicall(_ref) {
352
416
  returnData,
353
417
  success
354
418
  } = _ref3;
355
- if (!success) return undefined;
419
+ if (!success) return null;
356
420
  const {
357
421
  addressOrName,
358
422
  contractInterface,
@@ -369,7 +433,7 @@ async function multicall(_ref) {
369
433
  });
370
434
  if (!allowFailure) throw err;
371
435
  console.warn(err.message);
372
- return undefined;
436
+ return null;
373
437
  }
374
438
 
375
439
  const contract = getContract({
@@ -382,7 +446,7 @@ async function multicall(_ref) {
382
446
  return Array.isArray(result) && result.length === 1 ? result[0] : result;
383
447
  } catch (err) {
384
448
  if (!allowFailure) throw err;
385
- return undefined;
449
+ return null;
386
450
  }
387
451
  });
388
452
  }
@@ -1016,7 +1080,7 @@ async function fetchToken(_ref) {
1016
1080
  const provider = getProvider({
1017
1081
  chainId
1018
1082
  });
1019
- const contract = new Contract$1(address, erc20ABI, provider);
1083
+ const contract = new Contract(address, erc20ABI, provider);
1020
1084
  const [symbol, decimals, totalSupply] = await Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
1021
1085
  const token = {
1022
1086
  address,
@@ -1088,4 +1152,4 @@ async function waitForTransaction(_ref) {
1088
1152
  return await promise;
1089
1153
  }
1090
1154
 
1091
- export { configureChains, connect, disconnect, erc20ABI, erc721ABI, fetchBalance, fetchBlockNumber, fetchEnsAddress, fetchEnsAvatar, fetchEnsName, fetchEnsResolver, fetchFeeData, fetchSigner, fetchToken, getAccount, getContract, getNetwork, getProvider, getWebSocketProvider, readContract, readContracts, sendTransaction, signMessage, signTypedData, switchNetwork, units, waitForTransaction, watchAccount, watchBlockNumber, watchContractEvent, watchNetwork, watchProvider, watchReadContract, watchReadContracts, watchSigner, watchWebSocketProvider, writeContract };
1155
+ export { configureChains, connect, deepEqual, disconnect, erc20ABI, erc721ABI, fetchBalance, fetchBlockNumber, fetchEnsAddress, fetchEnsAvatar, fetchEnsName, fetchEnsResolver, fetchFeeData, fetchSigner, fetchToken, getAccount, getContract, getNetwork, getProvider, getWebSocketProvider, parseContractResult, readContract, readContracts, sendTransaction, signMessage, signTypedData, switchNetwork, units, waitForTransaction, watchAccount, watchBlockNumber, watchContractEvent, watchNetwork, watchProvider, watchReadContract, watchReadContracts, watchSigner, watchWebSocketProvider, writeContract };
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.4.5",
5
+ "version": "0.4.8",
6
6
  "repository": "tmm/wagmi",
7
7
  "author": "awkweb.eth",
8
8
  "ethereum": "awkweb.eth",