@wagmi/core 0.4.9 → 0.5.1
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/README.md +6 -6
- package/chains/dist/wagmi-core-chains.cjs.dev.js +4 -2
- package/chains/dist/wagmi-core-chains.cjs.prod.js +4 -2
- package/chains/dist/wagmi-core-chains.esm.js +2 -2
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +28 -26
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +28 -26
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +5 -3
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +22 -23
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +22 -23
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +5 -6
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +33 -31
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +33 -31
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +6 -4
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +24 -25
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +24 -25
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +5 -6
- package/dist/{chains-b8e32454.cjs.prod.js → chains-acd25777.cjs.prod.js} +68 -9
- package/dist/{chains-174cf4b4.esm.js → chains-ce86f5e0.esm.js} +67 -10
- package/dist/{chains-ba6218fb.cjs.dev.js → chains-e81629e7.cjs.dev.js} +68 -9
- package/dist/declarations/src/actions/accounts/fetchBalance.d.ts +0 -1
- package/dist/declarations/src/actions/accounts/fetchSigner.d.ts +3 -3
- package/dist/declarations/src/actions/contracts/deprecatedWriteContract.d.ts +16 -0
- package/dist/declarations/src/actions/{tokens → contracts}/fetchToken.d.ts +0 -0
- package/dist/declarations/src/actions/contracts/index.d.ts +4 -1
- package/dist/declarations/src/actions/contracts/prepareWriteContract.d.ts +37 -0
- package/dist/declarations/src/actions/contracts/writeContract.d.ts +44 -8
- package/dist/declarations/src/actions/ens/fetchEnsAddress.d.ts +2 -1
- package/dist/declarations/src/actions/index.d.ts +2 -3
- package/dist/declarations/src/actions/transactions/deprecatedSendTransaction.d.ts +12 -0
- package/dist/declarations/src/actions/transactions/fetchTransaction.d.ts +21 -0
- package/dist/declarations/src/actions/transactions/index.d.ts +4 -1
- package/dist/declarations/src/actions/transactions/prepareSendTransaction.d.ts +36 -0
- package/dist/declarations/src/actions/transactions/sendTransaction.d.ts +43 -8
- package/dist/declarations/src/chains.d.ts +1 -1
- package/dist/declarations/src/client.d.ts +2 -2
- package/dist/declarations/src/connectors/base.d.ts +1 -2
- package/dist/declarations/src/connectors/coinbaseWallet.d.ts +2 -2
- package/dist/declarations/src/connectors/injected.d.ts +1 -1
- package/dist/declarations/src/connectors/mock/provider.d.ts +3 -2
- package/dist/declarations/src/connectors/walletConnect.d.ts +3 -2
- package/dist/declarations/src/constants/chains.d.ts +5 -0
- package/dist/declarations/src/constants/index.d.ts +1 -1
- package/dist/declarations/src/constants/rpcs.d.ts +5 -5
- package/dist/declarations/src/errors.d.ts +10 -3
- package/dist/declarations/src/index.d.ts +4 -4
- package/dist/declarations/src/providers/alchemy.d.ts +2 -3
- package/dist/declarations/src/providers/infura.d.ts +2 -3
- package/dist/declarations/src/providers/jsonRpc.d.ts +1 -2
- package/dist/declarations/src/providers/public.d.ts +2 -4
- package/dist/declarations/src/types/index.d.ts +6 -1
- package/dist/declarations/src/utils/configureChains.d.ts +3 -1
- package/dist/{client-fbdcbdb2.esm.js → getProvider-073f640f.esm.js} +369 -3
- package/dist/{client-4983a639.cjs.dev.js → getProvider-5c497ca0.cjs.dev.js} +436 -45
- package/dist/{client-dfad744f.cjs.prod.js → getProvider-868752e4.cjs.prod.js} +436 -45
- package/dist/{rpcs-1fd0a12f.cjs.prod.js → rpcs-3cf5a783.cjs.dev.js} +18 -12
- package/dist/{rpcs-f1d24f0e.cjs.dev.js → rpcs-afd1cc09.cjs.prod.js} +18 -12
- package/dist/{rpcs-b73a8f60.esm.js → rpcs-e837abf2.esm.js} +17 -11
- package/dist/wagmi-core.cjs.dev.js +586 -308
- package/dist/wagmi-core.cjs.prod.js +586 -308
- package/dist/wagmi-core.esm.js +493 -222
- package/package.json +9 -5
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +5 -7
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +5 -7
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +5 -7
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +5 -7
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +5 -7
- package/providers/infura/dist/wagmi-core-providers-infura.esm.js +5 -7
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.dev.js +0 -2
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.prod.js +0 -2
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js +0 -2
- package/providers/public/dist/wagmi-core-providers-public.cjs.dev.js +0 -2
- package/providers/public/dist/wagmi-core-providers-public.cjs.prod.js +0 -2
- package/providers/public/dist/wagmi-core-providers-public.esm.js +0 -2
- package/dist/base-337e6424.cjs.prod.js +0 -343
- package/dist/base-bd337280.cjs.dev.js +0 -343
- package/dist/base-f1bbf263.esm.js +0 -316
- package/dist/declarations/src/actions/tokens/index.d.ts +0 -1
package/dist/wagmi-core.esm.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { g as getClient } from './
|
|
2
|
-
export {
|
|
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
|
-
import { isAddress, Logger, formatUnits, getAddress } from 'ethers/lib/utils';
|
|
1
|
+
import { g as getClient, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, b as ChainMismatchError, U as UserRejectedRequestError, c as ContractMethodDoesNotExistError, d as getProvider, P as ProviderChainsNotFound, e as ChainDoesNotSupportMulticallError, f as ContractMethodNoResultError, n as normalizeChainId, S as SwitchChainNotSupportedError } from './getProvider-073f640f.esm.js';
|
|
2
|
+
export { A as AddChainError, e as ChainDoesNotSupportMulticallError, b as ChainMismatchError, k as ChainNotConfiguredError, i as Client, j as Connector, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, c as ContractMethodDoesNotExistError, f as ContractMethodNoResultError, I as InjectedConnector, P as ProviderChainsNotFound, l as ProviderRpcError, R as ResourceUnavailableError, m as RpcError, o as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, h as createClient, p as createStorage, d as getProvider, q as noopStorage, n as normalizeChainId } from './getProvider-073f640f.esm.js';
|
|
7
3
|
import { providers, Contract as Contract$1 } from 'ethers';
|
|
4
|
+
import { Contract, logger } from 'ethers/lib/ethers';
|
|
5
|
+
import { formatUnits, getAddress, isAddress, Logger } from 'ethers/lib/utils';
|
|
8
6
|
import shallow from 'zustand/shallow';
|
|
9
|
-
export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-
|
|
10
|
-
export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-
|
|
11
|
-
import 'zustand/vanilla';
|
|
7
|
+
export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-e837abf2.esm.js';
|
|
8
|
+
export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-ce86f5e0.esm.js';
|
|
12
9
|
import 'zustand/middleware';
|
|
10
|
+
import 'zustand/vanilla';
|
|
13
11
|
import 'eventemitter3';
|
|
14
12
|
|
|
15
13
|
function configureChains(defaultChains, providers) {
|
|
16
14
|
let {
|
|
17
15
|
minQuorum = 1,
|
|
16
|
+
pollingInterval = 4000,
|
|
18
17
|
targetQuorum = 1,
|
|
19
18
|
stallTimeout
|
|
20
19
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -60,21 +59,27 @@ function configureChains(defaultChains, providers) {
|
|
|
60
59
|
return {
|
|
61
60
|
chains,
|
|
62
61
|
provider: _ref2 => {
|
|
63
|
-
var _defaultChains
|
|
62
|
+
var _defaultChains$;
|
|
64
63
|
|
|
65
64
|
let {
|
|
66
65
|
chainId
|
|
67
66
|
} = _ref2;
|
|
68
67
|
const activeChainId = chainId && chains.some(x => x.id === chainId) ? chainId : (_defaultChains$ = defaultChains[0]) === null || _defaultChains$ === void 0 ? void 0 : _defaultChains$.id;
|
|
69
68
|
const chainProviders = providers_[activeChainId];
|
|
70
|
-
if (!chainProviders) throw new Error("No providers configured for chain \"".concat(activeChainId, "\""));
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
if (!chainProviders || !chainProviders[0]) throw new Error("No providers configured for chain \"".concat(activeChainId, "\""));
|
|
70
|
+
|
|
71
|
+
if (chainProviders.length === 1) {
|
|
72
|
+
return Object.assign(chainProviders[0](), {
|
|
73
|
+
chains,
|
|
74
|
+
pollingInterval
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
74
78
|
return Object.assign(fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
75
79
|
stallTimeout
|
|
76
80
|
}), {
|
|
77
|
-
chains
|
|
81
|
+
chains,
|
|
82
|
+
pollingInterval
|
|
78
83
|
});
|
|
79
84
|
},
|
|
80
85
|
webSocketProvider: _ref3 => {
|
|
@@ -290,15 +295,151 @@ function getContract(_ref) {
|
|
|
290
295
|
return new Contract$1(addressOrName, contractInterface, signerOrProvider);
|
|
291
296
|
}
|
|
292
297
|
|
|
293
|
-
function
|
|
298
|
+
async function deprecatedWriteContract(_ref) {
|
|
294
299
|
let {
|
|
300
|
+
addressOrName,
|
|
301
|
+
args,
|
|
302
|
+
chainId,
|
|
303
|
+
contractInterface,
|
|
304
|
+
functionName,
|
|
305
|
+
overrides,
|
|
306
|
+
signerOrProvider
|
|
307
|
+
} = _ref;
|
|
308
|
+
const {
|
|
309
|
+
connector
|
|
310
|
+
} = getClient();
|
|
311
|
+
if (!connector) throw new ConnectorNotFoundError();
|
|
312
|
+
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
313
|
+
|
|
314
|
+
try {
|
|
315
|
+
var _chain;
|
|
316
|
+
|
|
317
|
+
let chain;
|
|
318
|
+
|
|
319
|
+
if (chainId) {
|
|
320
|
+
const activeChainId = await connector.getChainId(); // Try to switch chain to provided `chainId`
|
|
321
|
+
|
|
322
|
+
if (chainId !== activeChainId) {
|
|
323
|
+
var _connector$chains$fin, _connector$chains$fin2, _connector$chains$fin3, _connector$chains$fin4;
|
|
324
|
+
|
|
325
|
+
if (connector.switchChain) chain = await connector.switchChain(chainId);else throw new ChainMismatchError({
|
|
326
|
+
activeChain: (_connector$chains$fin = (_connector$chains$fin2 = connector.chains.find(x => x.id === activeChainId)) === null || _connector$chains$fin2 === void 0 ? void 0 : _connector$chains$fin2.name) !== null && _connector$chains$fin !== void 0 ? _connector$chains$fin : "Chain ".concat(activeChainId),
|
|
327
|
+
targetChain: (_connector$chains$fin3 = (_connector$chains$fin4 = connector.chains.find(x => x.id === chainId)) === null || _connector$chains$fin4 === void 0 ? void 0 : _connector$chains$fin4.name) !== null && _connector$chains$fin3 !== void 0 ? _connector$chains$fin3 : "Chain ".concat(chainId)
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const signer = await connector.getSigner({
|
|
333
|
+
chainId: (_chain = chain) === null || _chain === void 0 ? void 0 : _chain.id
|
|
334
|
+
});
|
|
335
|
+
const contract = getContract({
|
|
336
|
+
addressOrName,
|
|
337
|
+
contractInterface,
|
|
338
|
+
signerOrProvider
|
|
339
|
+
});
|
|
340
|
+
const contractWithSigner = contract.connect(signer);
|
|
341
|
+
const contractFunction = contractWithSigner[functionName];
|
|
342
|
+
if (!contractFunction) console.warn("\"".concat(functionName, "\" does not exist in interface for contract \"").concat(addressOrName, "\""));
|
|
343
|
+
return await contractFunction(...params);
|
|
344
|
+
} catch (error) {
|
|
345
|
+
if (error.code === 4001) throw new UserRejectedRequestError(error);
|
|
346
|
+
throw error;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async function fetchToken(_ref) {
|
|
351
|
+
let {
|
|
352
|
+
address,
|
|
353
|
+
chainId,
|
|
354
|
+
formatUnits: units = 'ether'
|
|
355
|
+
} = _ref;
|
|
356
|
+
const erc20Config = {
|
|
357
|
+
addressOrName: address,
|
|
358
|
+
contractInterface: erc20ABI,
|
|
295
359
|
chainId
|
|
296
|
-
}
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
360
|
+
};
|
|
361
|
+
const [decimals, name, symbol, totalSupply] = await readContracts({
|
|
362
|
+
allowFailure: false,
|
|
363
|
+
contracts: [{ ...erc20Config,
|
|
364
|
+
functionName: 'decimals'
|
|
365
|
+
}, { ...erc20Config,
|
|
366
|
+
functionName: 'name'
|
|
367
|
+
}, { ...erc20Config,
|
|
368
|
+
functionName: 'symbol'
|
|
369
|
+
}, { ...erc20Config,
|
|
370
|
+
functionName: 'totalSupply'
|
|
371
|
+
}]
|
|
300
372
|
});
|
|
301
|
-
return
|
|
373
|
+
return {
|
|
374
|
+
address,
|
|
375
|
+
decimals,
|
|
376
|
+
name,
|
|
377
|
+
symbol,
|
|
378
|
+
totalSupply: {
|
|
379
|
+
formatted: formatUnits(totalSupply, units),
|
|
380
|
+
value: totalSupply
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* @description Prepares the parameters required for a contract write transaction.
|
|
387
|
+
*
|
|
388
|
+
* Returns config to be passed through to `writeContract`.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* import { prepareWriteContract, writeContract } from '@wagmi/core'
|
|
392
|
+
*
|
|
393
|
+
* const config = await prepareWriteContract({
|
|
394
|
+
* addressOrName: '0x...',
|
|
395
|
+
* contractInterface: wagmiAbi,
|
|
396
|
+
* functionName: 'mint',
|
|
397
|
+
* })
|
|
398
|
+
* const result = await writeContract(config)
|
|
399
|
+
*/
|
|
400
|
+
async function prepareWriteContract(_ref) {
|
|
401
|
+
let {
|
|
402
|
+
addressOrName,
|
|
403
|
+
args,
|
|
404
|
+
chainId,
|
|
405
|
+
contractInterface,
|
|
406
|
+
functionName,
|
|
407
|
+
overrides,
|
|
408
|
+
signer: signer_
|
|
409
|
+
} = _ref;
|
|
410
|
+
const signer = signer_ !== null && signer_ !== void 0 ? signer_ : await fetchSigner();
|
|
411
|
+
if (!signer) throw new ConnectorNotFoundError();
|
|
412
|
+
const contract = getContract({
|
|
413
|
+
addressOrName,
|
|
414
|
+
contractInterface,
|
|
415
|
+
signerOrProvider: signer
|
|
416
|
+
});
|
|
417
|
+
const populateTransactionFn = contract.populateTransaction[functionName];
|
|
418
|
+
|
|
419
|
+
if (!populateTransactionFn) {
|
|
420
|
+
throw new ContractMethodDoesNotExistError({
|
|
421
|
+
addressOrName,
|
|
422
|
+
functionName
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
427
|
+
const unsignedTransaction = await populateTransactionFn(...params);
|
|
428
|
+
const gasLimit = unsignedTransaction.gasLimit || (await signer.estimateGas(unsignedTransaction));
|
|
429
|
+
return {
|
|
430
|
+
addressOrName,
|
|
431
|
+
args,
|
|
432
|
+
...(chainId ? {
|
|
433
|
+
chainId
|
|
434
|
+
} : {}),
|
|
435
|
+
contractInterface,
|
|
436
|
+
functionName,
|
|
437
|
+
overrides,
|
|
438
|
+
request: { ...unsignedTransaction,
|
|
439
|
+
gasLimit
|
|
440
|
+
},
|
|
441
|
+
mode: 'prepared'
|
|
442
|
+
};
|
|
302
443
|
}
|
|
303
444
|
|
|
304
445
|
function getWebSocketProvider() {
|
|
@@ -427,11 +568,9 @@ async function multicall(_ref) {
|
|
|
427
568
|
} = contracts[i];
|
|
428
569
|
|
|
429
570
|
if (returnData === '0x') {
|
|
430
|
-
var _chain$blockExplorers;
|
|
431
|
-
|
|
432
571
|
const err = new ContractMethodNoResultError({
|
|
433
572
|
addressOrName,
|
|
434
|
-
|
|
573
|
+
chainId: chain.id,
|
|
435
574
|
functionName
|
|
436
575
|
});
|
|
437
576
|
if (!allowFailure) throw err;
|
|
@@ -660,21 +799,15 @@ function watchReadContracts(config, callback) {
|
|
|
660
799
|
};
|
|
661
800
|
}
|
|
662
801
|
|
|
663
|
-
async function
|
|
802
|
+
async function deprecatedSendTransaction(_ref) {
|
|
664
803
|
let {
|
|
665
|
-
addressOrName,
|
|
666
|
-
args,
|
|
667
804
|
chainId,
|
|
668
|
-
|
|
669
|
-
functionName,
|
|
670
|
-
overrides,
|
|
671
|
-
signerOrProvider
|
|
805
|
+
request
|
|
672
806
|
} = _ref;
|
|
673
807
|
const {
|
|
674
808
|
connector
|
|
675
809
|
} = getClient();
|
|
676
810
|
if (!connector) throw new ConnectorNotFoundError();
|
|
677
|
-
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
678
811
|
|
|
679
812
|
try {
|
|
680
813
|
var _chain;
|
|
@@ -697,28 +830,325 @@ async function writeContract(_ref) {
|
|
|
697
830
|
const signer = await connector.getSigner({
|
|
698
831
|
chainId: (_chain = chain) === null || _chain === void 0 ? void 0 : _chain.id
|
|
699
832
|
});
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
833
|
+
return await signer.sendTransaction(request);
|
|
834
|
+
} catch (error) {
|
|
835
|
+
if (error.code === 4001) throw new UserRejectedRequestError(error);
|
|
836
|
+
throw error;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* @description Fetches transaction for hash
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
* import { fetchTransaction } from '@wagmi/core'
|
|
845
|
+
*
|
|
846
|
+
* const transaction = await fetchTransaction({
|
|
847
|
+
* chainId: 1,
|
|
848
|
+
* hash: '0x...',
|
|
849
|
+
* })
|
|
850
|
+
*/
|
|
851
|
+
async function fetchTransaction(_ref) {
|
|
852
|
+
let {
|
|
853
|
+
chainId,
|
|
854
|
+
hash
|
|
855
|
+
} = _ref;
|
|
856
|
+
const provider = getProvider({
|
|
857
|
+
chainId
|
|
858
|
+
});
|
|
859
|
+
return await provider.getTransaction(hash);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
async function fetchEnsAddress(_ref) {
|
|
863
|
+
let {
|
|
864
|
+
chainId,
|
|
865
|
+
name
|
|
866
|
+
} = _ref;
|
|
867
|
+
const provider = getProvider({
|
|
868
|
+
chainId
|
|
869
|
+
});
|
|
870
|
+
const address = await provider.resolveName(name);
|
|
871
|
+
|
|
872
|
+
try {
|
|
873
|
+
return address ? getAddress(address) : null;
|
|
874
|
+
} catch (_error) {
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
async function fetchEnsAvatar(_ref) {
|
|
880
|
+
let {
|
|
881
|
+
addressOrName,
|
|
882
|
+
chainId
|
|
883
|
+
} = _ref;
|
|
884
|
+
const provider = getProvider({
|
|
885
|
+
chainId
|
|
886
|
+
}); // TODO: Update with more advanced logic
|
|
887
|
+
// https://github.com/ensdomains/ens-avatar
|
|
888
|
+
|
|
889
|
+
const avatar = await provider.getAvatar(addressOrName);
|
|
890
|
+
return avatar;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
async function fetchEnsName(_ref) {
|
|
894
|
+
let {
|
|
895
|
+
address,
|
|
896
|
+
chainId
|
|
897
|
+
} = _ref;
|
|
898
|
+
const provider = getProvider({
|
|
899
|
+
chainId
|
|
900
|
+
});
|
|
901
|
+
return await provider.lookupAddress(address);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
async function fetchEnsResolver(_ref) {
|
|
905
|
+
let {
|
|
906
|
+
chainId,
|
|
907
|
+
name
|
|
908
|
+
} = _ref;
|
|
909
|
+
const provider = getProvider({
|
|
910
|
+
chainId
|
|
911
|
+
});
|
|
912
|
+
const resolver = await provider.getResolver(name);
|
|
913
|
+
return resolver;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/**
|
|
917
|
+
* @description Prepares the parameters required for sending a transaction.
|
|
918
|
+
*
|
|
919
|
+
* Returns config to be passed through to `sendTransaction`.
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* import { prepareSendTransaction, sendTransaction } from '@wagmi/core'
|
|
923
|
+
*
|
|
924
|
+
* const config = await prepareSendTransaction({
|
|
925
|
+
* request: {
|
|
926
|
+
* to: 'moxey.eth',
|
|
927
|
+
* value: parseEther('1'),
|
|
928
|
+
* }
|
|
929
|
+
* })
|
|
930
|
+
* const result = await sendTransaction(config)
|
|
931
|
+
*/
|
|
932
|
+
async function prepareSendTransaction(_ref) {
|
|
933
|
+
let {
|
|
934
|
+
chainId,
|
|
935
|
+
request,
|
|
936
|
+
signerOrProvider = getProvider({
|
|
937
|
+
chainId
|
|
938
|
+
})
|
|
939
|
+
} = _ref;
|
|
940
|
+
const [to, gasLimit] = await Promise.all([isAddress(request.to) ? Promise.resolve(request.to) : fetchEnsAddress({
|
|
941
|
+
name: request.to
|
|
942
|
+
}), request.gasLimit ? Promise.resolve(request.gasLimit) : signerOrProvider.estimateGas(request)]);
|
|
943
|
+
if (!to) throw new Error('Could not resolve ENS name');
|
|
944
|
+
return { ...(chainId ? {
|
|
945
|
+
chainId
|
|
946
|
+
} : {}),
|
|
947
|
+
request: { ...request,
|
|
948
|
+
gasLimit,
|
|
949
|
+
to
|
|
950
|
+
},
|
|
951
|
+
mode: 'prepared'
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* @description Function to send a transaction.
|
|
957
|
+
*
|
|
958
|
+
* It is recommended to pair this with the `prepareSendTransaction` function to avoid
|
|
959
|
+
* [UX pitfalls](https://wagmi.sh/docs/prepare-hooks/intro#ux-pitfalls-without-prepare-hooks).
|
|
960
|
+
*
|
|
961
|
+
* @example
|
|
962
|
+
* import { prepareSendTransaction, sendTransaction } from '@wagmi/core'
|
|
963
|
+
*
|
|
964
|
+
* const config = await prepareSendTransaction({
|
|
965
|
+
* to: 'moxey.eth',
|
|
966
|
+
* value: parseEther('1'),
|
|
967
|
+
* })
|
|
968
|
+
* const result = await sendTransaction(config)
|
|
969
|
+
*/
|
|
970
|
+
async function sendTransaction(_ref) {
|
|
971
|
+
let {
|
|
972
|
+
chainId,
|
|
973
|
+
mode,
|
|
974
|
+
request
|
|
975
|
+
} = _ref;
|
|
976
|
+
|
|
977
|
+
/********************************************************************/
|
|
978
|
+
|
|
979
|
+
/** START: iOS App Link cautious code. */
|
|
980
|
+
|
|
981
|
+
/** Do not perform any async operations in this block. */
|
|
982
|
+
|
|
983
|
+
/** Ref: wagmi.sh/docs/prepare-hooks/intro#ios-app-link-constraints */
|
|
984
|
+
|
|
985
|
+
/********************************************************************/
|
|
986
|
+
// `fetchSigner` isn't really "asynchronous" as we have already
|
|
987
|
+
// initialized the provider upon user connection, so it will return
|
|
988
|
+
// immediately.
|
|
989
|
+
const signer = await fetchSigner();
|
|
990
|
+
if (!signer) throw new ConnectorNotFoundError();
|
|
991
|
+
|
|
992
|
+
if (mode === 'prepared') {
|
|
993
|
+
if (!request.gasLimit) throw new Error('`gasLimit` is required');
|
|
994
|
+
if (!request.to) throw new Error('`to` is required');
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
const {
|
|
998
|
+
chain: activeChain,
|
|
999
|
+
chains
|
|
1000
|
+
} = getNetwork();
|
|
1001
|
+
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
1002
|
+
|
|
1003
|
+
if (chainId && chainId !== (activeChain === null || activeChain === void 0 ? void 0 : activeChain.id)) {
|
|
1004
|
+
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1005
|
+
|
|
1006
|
+
throw new ChainMismatchError({
|
|
1007
|
+
activeChain: (_chains$find$name = (_chains$find = chains.find(x => x.id === activeChainId)) === null || _chains$find === void 0 ? void 0 : _chains$find.name) !== null && _chains$find$name !== void 0 ? _chains$find$name : "Chain ".concat(activeChainId),
|
|
1008
|
+
targetChain: (_chains$find$name2 = (_chains$find2 = chains.find(x => x.id === chainId)) === null || _chains$find2 === void 0 ? void 0 : _chains$find2.name) !== null && _chains$find$name2 !== void 0 ? _chains$find$name2 : "Chain ".concat(chainId)
|
|
704
1009
|
});
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
try {
|
|
1013
|
+
var _connectUnchecked, _ref2;
|
|
1014
|
+
|
|
1015
|
+
// Why don't we just use `signer.sendTransaction`?
|
|
1016
|
+
// The `signer.sendTransaction` method performs async
|
|
1017
|
+
// heavy operations (such as fetching block number)
|
|
1018
|
+
// which is not really needed for our case.
|
|
1019
|
+
// Having async heavy operations has side effects
|
|
1020
|
+
// when using it in a click handler (iOS deep linking issues,
|
|
1021
|
+
// delay to open wallet, etc).
|
|
1022
|
+
const uncheckedSigner = (_connectUnchecked = (_ref2 = signer).connectUnchecked) === null || _connectUnchecked === void 0 ? void 0 : _connectUnchecked.call(_ref2);
|
|
1023
|
+
const {
|
|
1024
|
+
hash,
|
|
1025
|
+
wait
|
|
1026
|
+
} = await (uncheckedSigner !== null && uncheckedSigner !== void 0 ? uncheckedSigner : signer).sendTransaction(request);
|
|
1027
|
+
/********************************************************************/
|
|
1028
|
+
|
|
1029
|
+
/** END: iOS App Link cautious code. */
|
|
1030
|
+
|
|
1031
|
+
/** Go nuts! */
|
|
1032
|
+
|
|
1033
|
+
/********************************************************************/
|
|
1034
|
+
|
|
1035
|
+
return {
|
|
1036
|
+
hash,
|
|
1037
|
+
wait
|
|
1038
|
+
};
|
|
709
1039
|
} catch (error) {
|
|
710
1040
|
if (error.code === 4001) throw new UserRejectedRequestError(error);
|
|
711
1041
|
throw error;
|
|
712
1042
|
}
|
|
713
1043
|
}
|
|
714
1044
|
|
|
1045
|
+
async function waitForTransaction(_ref) {
|
|
1046
|
+
let {
|
|
1047
|
+
chainId,
|
|
1048
|
+
confirmations,
|
|
1049
|
+
hash,
|
|
1050
|
+
timeout,
|
|
1051
|
+
wait: wait_
|
|
1052
|
+
} = _ref;
|
|
1053
|
+
let promise;
|
|
1054
|
+
|
|
1055
|
+
if (hash) {
|
|
1056
|
+
const provider = getProvider({
|
|
1057
|
+
chainId
|
|
1058
|
+
});
|
|
1059
|
+
promise = provider.waitForTransaction(hash, confirmations, timeout);
|
|
1060
|
+
} else if (wait_) promise = wait_(confirmations);else throw new Error('hash or wait is required');
|
|
1061
|
+
|
|
1062
|
+
return await promise;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* @description Function to call a contract write method.
|
|
1067
|
+
*
|
|
1068
|
+
* It is recommended to pair this with the {@link prepareWriteContract} function
|
|
1069
|
+
* to avoid [UX pitfalls](https://wagmi.sh/docs/prepare-hooks/intro#ux-pitfalls-without-prepare-hooks).
|
|
1070
|
+
*
|
|
1071
|
+
* @example
|
|
1072
|
+
* import { prepareWriteContract, writeContract } from '@wagmi/core'
|
|
1073
|
+
*
|
|
1074
|
+
* const config = await prepareWriteContract({
|
|
1075
|
+
* addressOrName: '0x...',
|
|
1076
|
+
* contractInterface: wagmiAbi,
|
|
1077
|
+
* functionName: 'mint',
|
|
1078
|
+
* })
|
|
1079
|
+
* const result = await writeContract(config)
|
|
1080
|
+
*/
|
|
1081
|
+
async function writeContract(_ref) {
|
|
1082
|
+
let {
|
|
1083
|
+
addressOrName,
|
|
1084
|
+
args,
|
|
1085
|
+
chainId,
|
|
1086
|
+
contractInterface,
|
|
1087
|
+
functionName,
|
|
1088
|
+
mode,
|
|
1089
|
+
overrides,
|
|
1090
|
+
request: request_
|
|
1091
|
+
} = _ref;
|
|
1092
|
+
|
|
1093
|
+
/********************************************************************/
|
|
1094
|
+
|
|
1095
|
+
/** START: iOS App Link cautious code. */
|
|
1096
|
+
|
|
1097
|
+
/** Do not perform any async operations in this block. */
|
|
1098
|
+
|
|
1099
|
+
/** Ref: wagmi.sh/docs/prepare-hooks/intro#ios-app-link-constraints */
|
|
1100
|
+
|
|
1101
|
+
/********************************************************************/
|
|
1102
|
+
const signer = await fetchSigner();
|
|
1103
|
+
if (!signer) throw new ConnectorNotFoundError();
|
|
1104
|
+
const {
|
|
1105
|
+
chain: activeChain,
|
|
1106
|
+
chains
|
|
1107
|
+
} = getNetwork();
|
|
1108
|
+
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
1109
|
+
|
|
1110
|
+
if (chainId && chainId !== activeChainId) {
|
|
1111
|
+
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
1112
|
+
|
|
1113
|
+
throw new ChainMismatchError({
|
|
1114
|
+
activeChain: (_chains$find$name = (_chains$find = chains.find(x => x.id === activeChainId)) === null || _chains$find === void 0 ? void 0 : _chains$find.name) !== null && _chains$find$name !== void 0 ? _chains$find$name : "Chain ".concat(activeChainId),
|
|
1115
|
+
targetChain: (_chains$find$name2 = (_chains$find2 = chains.find(x => x.id === chainId)) === null || _chains$find2 === void 0 ? void 0 : _chains$find2.name) !== null && _chains$find$name2 !== void 0 ? _chains$find$name2 : "Chain ".concat(chainId)
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
if (mode === 'prepared') {
|
|
1120
|
+
if (!request_) throw new Error('`request` is required');
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
const request = mode === 'recklesslyUnprepared' ? (await prepareWriteContract({
|
|
1124
|
+
addressOrName,
|
|
1125
|
+
args,
|
|
1126
|
+
contractInterface,
|
|
1127
|
+
functionName,
|
|
1128
|
+
overrides
|
|
1129
|
+
})).request : request_;
|
|
1130
|
+
const transaction = await sendTransaction({
|
|
1131
|
+
request,
|
|
1132
|
+
mode: 'prepared'
|
|
1133
|
+
});
|
|
1134
|
+
/********************************************************************/
|
|
1135
|
+
|
|
1136
|
+
/** END: iOS App Link cautious code. */
|
|
1137
|
+
|
|
1138
|
+
/** Go nuts! */
|
|
1139
|
+
|
|
1140
|
+
/********************************************************************/
|
|
1141
|
+
|
|
1142
|
+
return transaction;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
715
1145
|
async function fetchBalance(_ref) {
|
|
716
1146
|
var _client$chains, _chain$nativeCurrency, _chain$nativeCurrency2, _chain$nativeCurrency3, _chain$nativeCurrency4;
|
|
717
1147
|
|
|
718
1148
|
let {
|
|
719
1149
|
addressOrName,
|
|
720
1150
|
chainId,
|
|
721
|
-
formatUnits: unit
|
|
1151
|
+
formatUnits: unit,
|
|
722
1152
|
token
|
|
723
1153
|
} = _ref;
|
|
724
1154
|
const client = getClient();
|
|
@@ -755,9 +1185,8 @@ async function fetchBalance(_ref) {
|
|
|
755
1185
|
});
|
|
756
1186
|
return {
|
|
757
1187
|
decimals,
|
|
758
|
-
formatted: formatUnits(value !== null && value !== void 0 ? value : '0', unit),
|
|
1188
|
+
formatted: formatUnits(value !== null && value !== void 0 ? value : '0', unit !== null && unit !== void 0 ? unit : decimals),
|
|
759
1189
|
symbol,
|
|
760
|
-
unit,
|
|
761
1190
|
value
|
|
762
1191
|
};
|
|
763
1192
|
}
|
|
@@ -767,9 +1196,8 @@ async function fetchBalance(_ref) {
|
|
|
767
1196
|
const chain = chains.find(x => x.id === provider.network.chainId);
|
|
768
1197
|
return {
|
|
769
1198
|
decimals: (_chain$nativeCurrency = chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency2 = chain.nativeCurrency) === null || _chain$nativeCurrency2 === void 0 ? void 0 : _chain$nativeCurrency2.decimals) !== null && _chain$nativeCurrency !== void 0 ? _chain$nativeCurrency : 18,
|
|
770
|
-
formatted: formatUnits(value !== null && value !== void 0 ? value : '0', unit),
|
|
1199
|
+
formatted: formatUnits(value !== null && value !== void 0 ? value : '0', unit !== null && unit !== void 0 ? unit : 'ether'),
|
|
771
1200
|
symbol: (_chain$nativeCurrency3 = chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency4 = chain.nativeCurrency) === null || _chain$nativeCurrency4 === void 0 ? void 0 : _chain$nativeCurrency4.symbol) !== null && _chain$nativeCurrency3 !== void 0 ? _chain$nativeCurrency3 : 'ETH',
|
|
772
|
-
unit,
|
|
773
1201
|
value
|
|
774
1202
|
};
|
|
775
1203
|
}
|
|
@@ -876,42 +1304,32 @@ async function signTypedData(_ref) {
|
|
|
876
1304
|
types,
|
|
877
1305
|
value
|
|
878
1306
|
} = _ref;
|
|
1307
|
+
const signer = await fetchSigner();
|
|
1308
|
+
if (!signer) throw new ConnectorNotFoundError();
|
|
879
1309
|
const {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
const {
|
|
888
|
-
chainId
|
|
889
|
-
} = domain;
|
|
890
|
-
let chain;
|
|
1310
|
+
chain: activeChain,
|
|
1311
|
+
chains
|
|
1312
|
+
} = getNetwork();
|
|
1313
|
+
const {
|
|
1314
|
+
chainId: chainId_
|
|
1315
|
+
} = domain;
|
|
891
1316
|
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1317
|
+
if (chainId_) {
|
|
1318
|
+
const chainId = normalizeChainId(chainId_);
|
|
1319
|
+
const activeChainId = activeChain === null || activeChain === void 0 ? void 0 : activeChain.id;
|
|
895
1320
|
|
|
896
|
-
|
|
897
|
-
|
|
1321
|
+
if (chainId !== (activeChain === null || activeChain === void 0 ? void 0 : activeChain.id)) {
|
|
1322
|
+
var _chains$find$name, _chains$find, _chains$find$name2, _chains$find2;
|
|
898
1323
|
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
1324
|
+
throw new ChainMismatchError({
|
|
1325
|
+
activeChain: (_chains$find$name = (_chains$find = chains.find(x => x.id === activeChainId)) === null || _chains$find === void 0 ? void 0 : _chains$find.name) !== null && _chains$find$name !== void 0 ? _chains$find$name : "Chain ".concat(activeChainId),
|
|
1326
|
+
targetChain: (_chains$find$name2 = (_chains$find2 = chains.find(x => x.id === chainId)) === null || _chains$find2 === void 0 ? void 0 : _chains$find2.name) !== null && _chains$find$name2 !== void 0 ? _chains$find$name2 : "Chain ".concat(chainId)
|
|
1327
|
+
});
|
|
904
1328
|
}
|
|
1329
|
+
} // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
905
1330
|
|
|
906
|
-
const signer = await connector.getSigner({
|
|
907
|
-
chainId: (_chain = chain) === null || _chain === void 0 ? void 0 : _chain.id
|
|
908
|
-
}); // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
909
1331
|
|
|
910
|
-
|
|
911
|
-
} catch (error) {
|
|
912
|
-
if (error.code === 4001) throw new UserRejectedRequestError(error);
|
|
913
|
-
throw error;
|
|
914
|
-
}
|
|
1332
|
+
return await signer._signTypedData(domain, types, value);
|
|
915
1333
|
}
|
|
916
1334
|
|
|
917
1335
|
async function switchNetwork(_ref) {
|
|
@@ -1001,60 +1419,6 @@ function watchSigner(callback) {
|
|
|
1001
1419
|
return unsubscribe;
|
|
1002
1420
|
}
|
|
1003
1421
|
|
|
1004
|
-
async function fetchEnsAddress(_ref) {
|
|
1005
|
-
let {
|
|
1006
|
-
chainId,
|
|
1007
|
-
name
|
|
1008
|
-
} = _ref;
|
|
1009
|
-
const provider = getProvider({
|
|
1010
|
-
chainId
|
|
1011
|
-
});
|
|
1012
|
-
const address = await provider.resolveName(name);
|
|
1013
|
-
|
|
1014
|
-
try {
|
|
1015
|
-
return address ? getAddress(address) : null;
|
|
1016
|
-
} catch (_error) {
|
|
1017
|
-
return null;
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
async function fetchEnsAvatar(_ref) {
|
|
1022
|
-
let {
|
|
1023
|
-
addressOrName,
|
|
1024
|
-
chainId
|
|
1025
|
-
} = _ref;
|
|
1026
|
-
const provider = getProvider({
|
|
1027
|
-
chainId
|
|
1028
|
-
}); // TODO: Update with more advanced logic
|
|
1029
|
-
// https://github.com/ensdomains/ens-avatar
|
|
1030
|
-
|
|
1031
|
-
const avatar = await provider.getAvatar(addressOrName);
|
|
1032
|
-
return avatar;
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
async function fetchEnsName(_ref) {
|
|
1036
|
-
let {
|
|
1037
|
-
address,
|
|
1038
|
-
chainId
|
|
1039
|
-
} = _ref;
|
|
1040
|
-
const provider = getProvider({
|
|
1041
|
-
chainId
|
|
1042
|
-
});
|
|
1043
|
-
return await provider.lookupAddress(address);
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
async function fetchEnsResolver(_ref) {
|
|
1047
|
-
let {
|
|
1048
|
-
chainId,
|
|
1049
|
-
name
|
|
1050
|
-
} = _ref;
|
|
1051
|
-
const provider = getProvider({
|
|
1052
|
-
chainId
|
|
1053
|
-
});
|
|
1054
|
-
const resolver = await provider.getResolver(name);
|
|
1055
|
-
return resolver;
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
1422
|
async function fetchFeeData() {
|
|
1059
1423
|
let {
|
|
1060
1424
|
chainId,
|
|
@@ -1074,97 +1438,4 @@ async function fetchFeeData() {
|
|
|
1074
1438
|
};
|
|
1075
1439
|
}
|
|
1076
1440
|
|
|
1077
|
-
|
|
1078
|
-
let {
|
|
1079
|
-
address,
|
|
1080
|
-
chainId,
|
|
1081
|
-
formatUnits: units = 'ether'
|
|
1082
|
-
} = _ref;
|
|
1083
|
-
const erc20Config = {
|
|
1084
|
-
addressOrName: address,
|
|
1085
|
-
contractInterface: erc20ABI,
|
|
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
|
-
}]
|
|
1099
|
-
});
|
|
1100
|
-
return {
|
|
1101
|
-
address,
|
|
1102
|
-
decimals,
|
|
1103
|
-
name,
|
|
1104
|
-
symbol,
|
|
1105
|
-
totalSupply: {
|
|
1106
|
-
formatted: formatUnits(totalSupply, units),
|
|
1107
|
-
value: totalSupply
|
|
1108
|
-
}
|
|
1109
|
-
};
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
async function sendTransaction(_ref) {
|
|
1113
|
-
let {
|
|
1114
|
-
chainId,
|
|
1115
|
-
request
|
|
1116
|
-
} = _ref;
|
|
1117
|
-
const {
|
|
1118
|
-
connector
|
|
1119
|
-
} = getClient();
|
|
1120
|
-
if (!connector) throw new ConnectorNotFoundError();
|
|
1121
|
-
|
|
1122
|
-
try {
|
|
1123
|
-
var _chain;
|
|
1124
|
-
|
|
1125
|
-
let chain;
|
|
1126
|
-
|
|
1127
|
-
if (chainId) {
|
|
1128
|
-
const activeChainId = await connector.getChainId(); // Try to switch chain to provided `chainId`
|
|
1129
|
-
|
|
1130
|
-
if (chainId !== activeChainId) {
|
|
1131
|
-
var _connector$chains$fin, _connector$chains$fin2, _connector$chains$fin3, _connector$chains$fin4;
|
|
1132
|
-
|
|
1133
|
-
if (connector.switchChain) chain = await connector.switchChain(chainId);else throw new ChainMismatchError({
|
|
1134
|
-
activeChain: (_connector$chains$fin = (_connector$chains$fin2 = connector.chains.find(x => x.id === activeChainId)) === null || _connector$chains$fin2 === void 0 ? void 0 : _connector$chains$fin2.name) !== null && _connector$chains$fin !== void 0 ? _connector$chains$fin : "Chain ".concat(activeChainId),
|
|
1135
|
-
targetChain: (_connector$chains$fin3 = (_connector$chains$fin4 = connector.chains.find(x => x.id === chainId)) === null || _connector$chains$fin4 === void 0 ? void 0 : _connector$chains$fin4.name) !== null && _connector$chains$fin3 !== void 0 ? _connector$chains$fin3 : "Chain ".concat(chainId)
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
const signer = await connector.getSigner({
|
|
1141
|
-
chainId: (_chain = chain) === null || _chain === void 0 ? void 0 : _chain.id
|
|
1142
|
-
});
|
|
1143
|
-
return await signer.sendTransaction(request);
|
|
1144
|
-
} catch (error) {
|
|
1145
|
-
if (error.code === 4001) throw new UserRejectedRequestError(error);
|
|
1146
|
-
throw error;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
async function waitForTransaction(_ref) {
|
|
1151
|
-
let {
|
|
1152
|
-
chainId,
|
|
1153
|
-
confirmations,
|
|
1154
|
-
hash,
|
|
1155
|
-
timeout,
|
|
1156
|
-
wait: wait_
|
|
1157
|
-
} = _ref;
|
|
1158
|
-
let promise;
|
|
1159
|
-
|
|
1160
|
-
if (hash) {
|
|
1161
|
-
const provider = getProvider({
|
|
1162
|
-
chainId
|
|
1163
|
-
});
|
|
1164
|
-
promise = provider.waitForTransaction(hash, confirmations, timeout);
|
|
1165
|
-
} else if (wait_) promise = wait_(confirmations);else throw new Error('hash or wait is required');
|
|
1166
|
-
|
|
1167
|
-
return await promise;
|
|
1168
|
-
}
|
|
1169
|
-
|
|
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 };
|
|
1441
|
+
export { configureChains, connect, deepEqual, deprecatedSendTransaction, deprecatedWriteContract, disconnect, erc20ABI, erc721ABI, fetchBalance, fetchBlockNumber, fetchEnsAddress, fetchEnsAvatar, fetchEnsName, fetchEnsResolver, fetchFeeData, fetchSigner, fetchToken, fetchTransaction, getAccount, getContract, getNetwork, getWebSocketProvider, parseContractResult, prepareSendTransaction, prepareWriteContract, readContract, readContracts, sendTransaction, signMessage, signTypedData, switchNetwork, units, waitForTransaction, watchAccount, watchBlockNumber, watchContractEvent, watchNetwork, watchProvider, watchReadContract, watchReadContracts, watchSigner, watchWebSocketProvider, writeContract };
|