@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.
- package/chains/dist/wagmi-core-chains.cjs.dev.js +1 -1
- package/chains/dist/wagmi-core-chains.cjs.prod.js +1 -1
- package/chains/dist/wagmi-core-chains.esm.js +1 -1
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +4 -3
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +4 -3
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +4 -3
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +5 -5
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +5 -5
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +5 -5
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +2 -2
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +2 -2
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +2 -2
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +3 -3
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +3 -3
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +3 -3
- package/dist/{base-797ad073.cjs.prod.js → base-337e6424.cjs.prod.js} +1 -1
- package/dist/{base-90b7f3e4.cjs.dev.js → base-bd337280.cjs.dev.js} +1 -1
- package/dist/{base-b565d5d4.esm.js → base-f1bbf263.esm.js} +1 -1
- package/dist/{chains-fd2c546c.esm.js → chains-174cf4b4.esm.js} +3 -3
- package/dist/{chains-f7bb3211.cjs.prod.js → chains-b8e32454.cjs.prod.js} +3 -3
- package/dist/{chains-7e6dc59c.cjs.dev.js → chains-ba6218fb.cjs.dev.js} +3 -3
- package/dist/{client-71ece661.cjs.dev.js → client-4983a639.cjs.dev.js} +17 -14
- package/dist/{client-a6e61429.cjs.prod.js → client-dfad744f.cjs.prod.js} +17 -14
- package/dist/{client-a05fd511.esm.js → client-fbdcbdb2.esm.js} +18 -14
- package/dist/declarations/src/actions/tokens/fetchToken.d.ts +1 -0
- package/dist/declarations/src/client.d.ts +1 -1
- package/dist/declarations/src/connectors/index.d.ts +1 -1
- package/dist/declarations/src/connectors/injected.d.ts +3 -3
- package/dist/declarations/src/connectors/metaMask.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +3 -3
- package/dist/declarations/src/types/index.d.ts +129 -128
- package/dist/declarations/src/utils/getInjectedName.d.ts +2 -1
- package/dist/declarations/src/utils/index.d.ts +1 -0
- package/dist/declarations/src/utils/parseContractResult.d.ts +7 -0
- package/dist/wagmi-core.cjs.dev.js +53 -11
- package/dist/wagmi-core.cjs.prod.js +53 -11
- package/dist/wagmi-core.esm.js +58 -17
- package/package.json +1 -1
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var client = require('./client-
|
|
6
|
-
var base = require('./base-
|
|
5
|
+
var client = require('./client-dfad744f.cjs.prod.js');
|
|
6
|
+
var base = require('./base-337e6424.cjs.prod.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-1fd0a12f.cjs.prod.js');
|
|
12
|
-
var chains = require('./chains-
|
|
12
|
+
var chains = require('./chains-b8e32454.cjs.prod.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 =>
|
|
248
|
-
|
|
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
|
|
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
|
-
|
|
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;
|
package/dist/wagmi-core.esm.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { g as getClient } from './client-
|
|
2
|
-
export { C as Client, I as InjectedConnector, c as createClient, a as createStorage, n as noopStorage } from './client-
|
|
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-
|
|
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-
|
|
5
|
-
import {
|
|
1
|
+
import { g as getClient } from './client-fbdcbdb2.esm.js';
|
|
2
|
+
export { C as Client, I as InjectedConnector, c as createClient, a as createStorage, n as noopStorage } from './client-fbdcbdb2.esm.js';
|
|
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-f1bbf263.esm.js';
|
|
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-f1bbf263.esm.js';
|
|
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
|
-
export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-
|
|
10
|
+
export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-174cf4b4.esm.js';
|
|
11
11
|
import 'zustand/vanilla';
|
|
12
12
|
import 'zustand/middleware';
|
|
13
13
|
import 'eventemitter3';
|
|
@@ -164,6 +164,32 @@ function deepEqual(a, b) {
|
|
|
164
164
|
return a !== a && b !== b;
|
|
165
165
|
}
|
|
166
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
|
+
|
|
167
193
|
// https://ethereum.org/en/developers/docs/standards/tokens/erc-20
|
|
168
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
|
|
169
195
|
|
|
@@ -238,9 +264,12 @@ async function connect(_ref) {
|
|
|
238
264
|
connector
|
|
239
265
|
};
|
|
240
266
|
} catch (err) {
|
|
241
|
-
client.setState(x =>
|
|
242
|
-
|
|
243
|
-
|
|
267
|
+
client.setState(x => {
|
|
268
|
+
return { ...x,
|
|
269
|
+
// Keep existing connector connected in case of error
|
|
270
|
+
status: x.connector ? 'connected' : 'disconnected'
|
|
271
|
+
};
|
|
272
|
+
});
|
|
244
273
|
throw err;
|
|
245
274
|
}
|
|
246
275
|
}
|
|
@@ -258,7 +287,7 @@ function getContract(_ref) {
|
|
|
258
287
|
contractInterface,
|
|
259
288
|
signerOrProvider
|
|
260
289
|
} = _ref;
|
|
261
|
-
return new Contract(addressOrName, contractInterface, signerOrProvider);
|
|
290
|
+
return new Contract$1(addressOrName, contractInterface, signerOrProvider);
|
|
262
291
|
}
|
|
263
292
|
|
|
264
293
|
function getProvider() {
|
|
@@ -1051,21 +1080,33 @@ async function fetchToken(_ref) {
|
|
|
1051
1080
|
chainId,
|
|
1052
1081
|
formatUnits: units = 'ether'
|
|
1053
1082
|
} = _ref;
|
|
1054
|
-
const
|
|
1083
|
+
const erc20Config = {
|
|
1084
|
+
addressOrName: address,
|
|
1085
|
+
contractInterface: erc20ABI,
|
|
1055
1086
|
chainId
|
|
1087
|
+
};
|
|
1088
|
+
const [decimals, name, symbol, totalSupply] = await readContracts({
|
|
1089
|
+
allowFailure: false,
|
|
1090
|
+
contracts: [{ ...erc20Config,
|
|
1091
|
+
functionName: 'decimals'
|
|
1092
|
+
}, { ...erc20Config,
|
|
1093
|
+
functionName: 'name'
|
|
1094
|
+
}, { ...erc20Config,
|
|
1095
|
+
functionName: 'symbol'
|
|
1096
|
+
}, { ...erc20Config,
|
|
1097
|
+
functionName: 'totalSupply'
|
|
1098
|
+
}]
|
|
1056
1099
|
});
|
|
1057
|
-
|
|
1058
|
-
const [symbol, decimals, totalSupply] = await Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
|
|
1059
|
-
const token = {
|
|
1100
|
+
return {
|
|
1060
1101
|
address,
|
|
1061
1102
|
decimals,
|
|
1103
|
+
name,
|
|
1062
1104
|
symbol,
|
|
1063
1105
|
totalSupply: {
|
|
1064
1106
|
formatted: formatUnits(totalSupply, units),
|
|
1065
1107
|
value: totalSupply
|
|
1066
1108
|
}
|
|
1067
1109
|
};
|
|
1068
|
-
return token;
|
|
1069
1110
|
}
|
|
1070
1111
|
|
|
1071
1112
|
async function sendTransaction(_ref) {
|
|
@@ -1126,4 +1167,4 @@ async function waitForTransaction(_ref) {
|
|
|
1126
1167
|
return await promise;
|
|
1127
1168
|
}
|
|
1128
1169
|
|
|
1129
|
-
export { configureChains, connect, deepEqual, 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 };
|
|
1170
|
+
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 };
|