wagmi 0.4.9 → 0.4.12

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.
@@ -14,6 +14,10 @@ Object.defineProperty(exports, 'arbitrumRinkeby', {
14
14
  enumerable: true,
15
15
  get: function () { return chains.arbitrumRinkeby; }
16
16
  });
17
+ Object.defineProperty(exports, 'foundry', {
18
+ enumerable: true,
19
+ get: function () { return chains.foundry; }
20
+ });
17
21
  Object.defineProperty(exports, 'goerli', {
18
22
  enumerable: true,
19
23
  get: function () { return chains.goerli; }
@@ -14,6 +14,10 @@ Object.defineProperty(exports, 'arbitrumRinkeby', {
14
14
  enumerable: true,
15
15
  get: function () { return chains.arbitrumRinkeby; }
16
16
  });
17
+ Object.defineProperty(exports, 'foundry', {
18
+ enumerable: true,
19
+ get: function () { return chains.foundry; }
20
+ });
17
21
  Object.defineProperty(exports, 'goerli', {
18
22
  enumerable: true,
19
23
  get: function () { return chains.goerli; }
@@ -1 +1 @@
1
- export { arbitrum, arbitrumRinkeby, goerli, hardhat, kovan, localhost, mainnet, optimism, optimismKovan, polygon, polygonMumbai, rinkeby, ropsten } from '@wagmi/core/chains';
1
+ export { arbitrum, arbitrumRinkeby, foundry, goerli, hardhat, kovan, localhost, mainnet, optimism, optimismKovan, polygon, polygonMumbai, rinkeby, ropsten } from '@wagmi/core/chains';
@@ -1 +1 @@
1
- export { arbitrum, arbitrumRinkeby, goerli, hardhat, kovan, localhost, mainnet, optimism, optimismKovan, polygon, polygonMumbai, rinkeby, ropsten, } from '@wagmi/core/chains';
1
+ export { arbitrum, arbitrumRinkeby, foundry, goerli, hardhat, kovan, localhost, mainnet, optimism, optimismKovan, polygon, polygonMumbai, rinkeby, ropsten, } from '@wagmi/core/chains';
@@ -1,2 +1,3 @@
1
1
  export { deserialize } from './deserialize';
2
+ export { parseContractResult } from './parseContractResult';
2
3
  export { serialize } from './serialize';
@@ -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;
@@ -75,6 +75,32 @@ function deserialize(cachedString) {
75
75
  return deserializedCacheWithBigNumbers;
76
76
  }
77
77
 
78
+ function isPlainArray(value) {
79
+ return Array.isArray(value) && Object.keys(value).length === value.length;
80
+ }
81
+
82
+ function parseContractResult(_ref) {
83
+ let {
84
+ contractInterface,
85
+ data,
86
+ functionName
87
+ } = _ref;
88
+
89
+ if (data && isPlainArray(data)) {
90
+ var _fragment$outputs, _fragment$outputs$, _fragment$outputs2, _fragment$outputs2$;
91
+
92
+ const iface = ethers.Contract.getInterface(contractInterface);
93
+ const fragment = iface.getFunction(functionName);
94
+ const isArray = (fragment === null || fragment === void 0 ? void 0 : (_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : (_fragment$outputs$ = _fragment$outputs[0]) === null || _fragment$outputs$ === void 0 ? void 0 : _fragment$outputs$.baseType) === 'array' || (fragment === null || fragment === void 0 ? void 0 : (_fragment$outputs2 = fragment.outputs) === null || _fragment$outputs2 === void 0 ? void 0 : (_fragment$outputs2$ = _fragment$outputs2[0]) === null || _fragment$outputs2$ === void 0 ? void 0 : _fragment$outputs2$.baseType) === 'tuple';
95
+ const data_ = isArray ? [data] : data;
96
+ const encodedResult = iface.encodeFunctionResult(functionName, data_);
97
+ const decodedResult = iface.decodeFunctionResult(functionName, encodedResult);
98
+ return isArray ? decodedResult[0] : decodedResult;
99
+ }
100
+
101
+ return data;
102
+ }
103
+
78
104
  /**
79
105
  * @function getReferenceKey
80
106
  *
@@ -1271,6 +1297,11 @@ function useContractRead(contractConfig, functionName) {
1271
1297
  return useQuery(queryKey_, queryFn$6, {
1272
1298
  cacheTime,
1273
1299
  enabled,
1300
+ select: data => parseContractResult({
1301
+ contractInterface: contractConfig.contractInterface,
1302
+ data,
1303
+ functionName
1304
+ }),
1274
1305
  staleTime,
1275
1306
  suspense,
1276
1307
  onError,
@@ -75,6 +75,32 @@ function deserialize(cachedString) {
75
75
  return deserializedCacheWithBigNumbers;
76
76
  }
77
77
 
78
+ function isPlainArray(value) {
79
+ return Array.isArray(value) && Object.keys(value).length === value.length;
80
+ }
81
+
82
+ function parseContractResult(_ref) {
83
+ let {
84
+ contractInterface,
85
+ data,
86
+ functionName
87
+ } = _ref;
88
+
89
+ if (data && isPlainArray(data)) {
90
+ var _fragment$outputs, _fragment$outputs$, _fragment$outputs2, _fragment$outputs2$;
91
+
92
+ const iface = ethers.Contract.getInterface(contractInterface);
93
+ const fragment = iface.getFunction(functionName);
94
+ const isArray = (fragment === null || fragment === void 0 ? void 0 : (_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : (_fragment$outputs$ = _fragment$outputs[0]) === null || _fragment$outputs$ === void 0 ? void 0 : _fragment$outputs$.baseType) === 'array' || (fragment === null || fragment === void 0 ? void 0 : (_fragment$outputs2 = fragment.outputs) === null || _fragment$outputs2 === void 0 ? void 0 : (_fragment$outputs2$ = _fragment$outputs2[0]) === null || _fragment$outputs2$ === void 0 ? void 0 : _fragment$outputs2$.baseType) === 'tuple';
95
+ const data_ = isArray ? [data] : data;
96
+ const encodedResult = iface.encodeFunctionResult(functionName, data_);
97
+ const decodedResult = iface.decodeFunctionResult(functionName, encodedResult);
98
+ return isArray ? decodedResult[0] : decodedResult;
99
+ }
100
+
101
+ return data;
102
+ }
103
+
78
104
  /**
79
105
  * @function getReferenceKey
80
106
  *
@@ -1271,6 +1297,11 @@ function useContractRead(contractConfig, functionName) {
1271
1297
  return useQuery(queryKey_, queryFn$6, {
1272
1298
  cacheTime,
1273
1299
  enabled,
1300
+ select: data => parseContractResult({
1301
+ contractInterface: contractConfig.contractInterface,
1302
+ data,
1303
+ functionName
1304
+ }),
1274
1305
  staleTime,
1275
1306
  suspense,
1276
1307
  onError,
package/dist/wagmi.esm.js CHANGED
@@ -4,7 +4,7 @@ export { AddChainError, ChainNotConfiguredError, Client, Connector, ConnectorAlr
4
4
  import { QueryClient, QueryClientProvider, useQueryClient, useIsRestoring, useQueryErrorResetBoundary, notifyManager, QueryObserver, useMutation } from 'react-query';
5
5
  import { persistQueryClient } from 'react-query/persistQueryClient';
6
6
  import { createWebStoragePersister } from 'react-query/createWebStoragePersister';
7
- import { BigNumber } from 'ethers/lib/ethers';
7
+ import { BigNumber, Contract } from 'ethers/lib/ethers';
8
8
  import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
9
9
 
10
10
  const findAndReplace = (cacheRef, _ref) => {
@@ -52,6 +52,32 @@ function deserialize(cachedString) {
52
52
  return deserializedCacheWithBigNumbers;
53
53
  }
54
54
 
55
+ function isPlainArray(value) {
56
+ return Array.isArray(value) && Object.keys(value).length === value.length;
57
+ }
58
+
59
+ function parseContractResult(_ref) {
60
+ let {
61
+ contractInterface,
62
+ data,
63
+ functionName
64
+ } = _ref;
65
+
66
+ if (data && isPlainArray(data)) {
67
+ var _fragment$outputs, _fragment$outputs$, _fragment$outputs2, _fragment$outputs2$;
68
+
69
+ const iface = Contract.getInterface(contractInterface);
70
+ const fragment = iface.getFunction(functionName);
71
+ const isArray = (fragment === null || fragment === void 0 ? void 0 : (_fragment$outputs = fragment.outputs) === null || _fragment$outputs === void 0 ? void 0 : (_fragment$outputs$ = _fragment$outputs[0]) === null || _fragment$outputs$ === void 0 ? void 0 : _fragment$outputs$.baseType) === 'array' || (fragment === null || fragment === void 0 ? void 0 : (_fragment$outputs2 = fragment.outputs) === null || _fragment$outputs2 === void 0 ? void 0 : (_fragment$outputs2$ = _fragment$outputs2[0]) === null || _fragment$outputs2$ === void 0 ? void 0 : _fragment$outputs2$.baseType) === 'tuple';
72
+ const data_ = isArray ? [data] : data;
73
+ const encodedResult = iface.encodeFunctionResult(functionName, data_);
74
+ const decodedResult = iface.decodeFunctionResult(functionName, encodedResult);
75
+ return isArray ? decodedResult[0] : decodedResult;
76
+ }
77
+
78
+ return data;
79
+ }
80
+
55
81
  /**
56
82
  * @function getReferenceKey
57
83
  *
@@ -1248,6 +1274,11 @@ function useContractRead(contractConfig, functionName) {
1248
1274
  return useQuery(queryKey_, queryFn$6, {
1249
1275
  cacheTime,
1250
1276
  enabled,
1277
+ select: data => parseContractResult({
1278
+ contractInterface: contractConfig.contractInterface,
1279
+ data,
1280
+ functionName
1281
+ }),
1251
1282
  staleTime,
1252
1283
  suspense,
1253
1284
  onError,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "wagmi",
3
3
  "description": "React Hooks for Ethereum",
4
4
  "license": "WAGMIT",
5
- "version": "0.4.9",
5
+ "version": "0.4.12",
6
6
  "repository": "tmm/wagmi",
7
7
  "author": "awkweb.eth",
8
8
  "homepage": "https://wagmi.sh",
@@ -89,9 +89,9 @@
89
89
  },
90
90
  "dependencies": {
91
91
  "@coinbase/wallet-sdk": "^3.2.0",
92
- "@wagmi/core": "^0.3.7",
92
+ "@wagmi/core": "^0.3.8",
93
93
  "@walletconnect/ethereum-provider": "^1.7.8",
94
- "react-query": "^4.0.0-beta.19",
94
+ "react-query": "^4.0.0-beta.23",
95
95
  "use-sync-external-store": "^1.1.0"
96
96
  },
97
97
  "devDependencies": {