@0xsquid/react-hooks 7.8.0 → 8.0.0-beta.0
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/dist/index-B3FG6tRj.js +6021 -0
- package/dist/index-B3FG6tRj.js.map +1 -0
- package/dist/index-CeIwio11.js +41015 -0
- package/dist/index-CeIwio11.js.map +1 -0
- package/dist/index-CjYMwYuT.js +41267 -0
- package/dist/index-CjYMwYuT.js.map +1 -0
- package/dist/index-CoxuUJzG.js +6021 -0
- package/dist/index-CoxuUJzG.js.map +1 -0
- package/dist/index.esm.js +36 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +292 -6
- package/dist/index.js.map +1 -1
- package/dist/secretService-C6ack504.js +168 -0
- package/dist/secretService-C6ack504.js.map +1 -0
- package/dist/{services/external/secretService.js → secretService-CgLleYSR.js} +43 -8
- package/dist/secretService-CgLleYSR.js.map +1 -0
- package/package.json +18 -4
- package/dist/core/abis/ics20.json +0 -128
- package/dist/core/client/index.js +0 -38
- package/dist/core/client/index.js.map +0 -1
- package/dist/core/connectors/bitcoin/errors/index.js +0 -22
- package/dist/core/connectors/bitcoin/errors/index.js.map +0 -1
- package/dist/core/connectors/bitcoin/helpers.js +0 -91
- package/dist/core/connectors/bitcoin/helpers.js.map +0 -1
- package/dist/core/connectors/bitcoin/index.js +0 -2
- package/dist/core/connectors/bitcoin/index.js.map +0 -1
- package/dist/core/connectors/bitcoin/wallets/index.js +0 -4
- package/dist/core/connectors/bitcoin/wallets/index.js.map +0 -1
- package/dist/core/connectors/bitcoin/wallets/keplr.js +0 -28
- package/dist/core/connectors/bitcoin/wallets/keplr.js.map +0 -1
- package/dist/core/connectors/bitcoin/wallets/phantom.js +0 -56
- package/dist/core/connectors/bitcoin/wallets/phantom.js.map +0 -1
- package/dist/core/connectors/bitcoin/wallets/unisat.js +0 -28
- package/dist/core/connectors/bitcoin/wallets/unisat.js.map +0 -1
- package/dist/core/connectors/xrpl/CrossMark.js +0 -76
- package/dist/core/connectors/xrpl/CrossMark.js.map +0 -1
- package/dist/core/connectors/xrpl/WalletConnect.js +0 -194
- package/dist/core/connectors/xrpl/WalletConnect.js.map +0 -1
- package/dist/core/connectors/xrpl/Xaman.js +0 -71
- package/dist/core/connectors/xrpl/Xaman.js.map +0 -1
- package/dist/core/connectors/xrpl/XamanQr.js +0 -95
- package/dist/core/connectors/xrpl/XamanQr.js.map +0 -1
- package/dist/core/connectors/xrpl/XrplMetamaskSnap.js +0 -176
- package/dist/core/connectors/xrpl/XrplMetamaskSnap.js.map +0 -1
- package/dist/core/constants.js +0 -157
- package/dist/core/constants.js.map +0 -1
- package/dist/core/externalLinks.js +0 -21
- package/dist/core/externalLinks.js.map +0 -1
- package/dist/core/index.js +0 -4
- package/dist/core/index.js.map +0 -1
- package/dist/core/multicall3.js +0 -462
- package/dist/core/multicall3.js.map +0 -1
- package/dist/core/providers/BitcoinProvider.js +0 -15
- package/dist/core/providers/BitcoinProvider.js.map +0 -1
- package/dist/core/providers/CosmosProvider.js +0 -13
- package/dist/core/providers/CosmosProvider.js.map +0 -1
- package/dist/core/providers/EvmProvider.js +0 -15
- package/dist/core/providers/EvmProvider.js.map +0 -1
- package/dist/core/providers/SolanaProvider.js +0 -15
- package/dist/core/providers/SolanaProvider.js.map +0 -1
- package/dist/core/providers/SuiProvider.js +0 -15
- package/dist/core/providers/SuiProvider.js.map +0 -1
- package/dist/core/providers/XrplProvider.js +0 -15
- package/dist/core/providers/XrplProvider.js.map +0 -1
- package/dist/core/queries/queries-keys.js +0 -232
- package/dist/core/queries/queries-keys.js.map +0 -1
- package/dist/core/queries/react-query-config.js +0 -11
- package/dist/core/queries/react-query-config.js.map +0 -1
- package/dist/core/types/bitcoin.js +0 -2
- package/dist/core/types/bitcoin.js.map +0 -1
- package/dist/core/types/config.js +0 -2
- package/dist/core/types/config.js.map +0 -1
- package/dist/core/types/error.js +0 -18
- package/dist/core/types/error.js.map +0 -1
- package/dist/core/types/event.js +0 -2
- package/dist/core/types/event.js.map +0 -1
- package/dist/core/types/evm.js +0 -2
- package/dist/core/types/evm.js.map +0 -1
- package/dist/core/types/history.js +0 -7
- package/dist/core/types/history.js.map +0 -1
- package/dist/core/types/index.js +0 -4
- package/dist/core/types/index.js.map +0 -1
- package/dist/core/types/onramps/index.js +0 -3
- package/dist/core/types/onramps/index.js.map +0 -1
- package/dist/core/types/onramps/onramp.js +0 -2
- package/dist/core/types/onramps/onramp.js.map +0 -1
- package/dist/core/types/onramps/revolut.js +0 -2
- package/dist/core/types/onramps/revolut.js.map +0 -1
- package/dist/core/types/rpc.js +0 -2
- package/dist/core/types/rpc.js.map +0 -1
- package/dist/core/types/solana.js +0 -2
- package/dist/core/types/solana.js.map +0 -1
- package/dist/core/types/sui.js +0 -2
- package/dist/core/types/sui.js.map +0 -1
- package/dist/core/types/swap.js +0 -2
- package/dist/core/types/swap.js.map +0 -1
- package/dist/core/types/tokens.js +0 -2
- package/dist/core/types/tokens.js.map +0 -1
- package/dist/core/types/transaction.js +0 -47
- package/dist/core/types/transaction.js.map +0 -1
- package/dist/core/types/wallet.js +0 -19
- package/dist/core/types/wallet.js.map +0 -1
- package/dist/core/types/xrpl.js +0 -32
- package/dist/core/types/xrpl.js.map +0 -1
- package/dist/core/wagmiConfig.js +0 -81
- package/dist/core/wagmiConfig.js.map +0 -1
- package/dist/core/wallets.js +0 -357
- package/dist/core/wallets.js.map +0 -1
- package/dist/hooks/analytics/useTrackSearchEmpty.js +0 -22
- package/dist/hooks/analytics/useTrackSearchEmpty.js.map +0 -1
- package/dist/hooks/bitcoin/useBitcoin.js +0 -18
- package/dist/hooks/bitcoin/useBitcoin.js.map +0 -1
- package/dist/hooks/chains/useSquidChains.js +0 -96
- package/dist/hooks/chains/useSquidChains.js.map +0 -1
- package/dist/hooks/client/useClient.js +0 -63
- package/dist/hooks/client/useClient.js.map +0 -1
- package/dist/hooks/cosmos/useCosmos.js +0 -167
- package/dist/hooks/cosmos/useCosmos.js.map +0 -1
- package/dist/hooks/cosmos/useCosmosForChain.js +0 -29
- package/dist/hooks/cosmos/useCosmosForChain.js.map +0 -1
- package/dist/hooks/evm/useEvm.js +0 -68
- package/dist/hooks/evm/useEvm.js.map +0 -1
- package/dist/hooks/evm/useEvmWallets.js +0 -13
- package/dist/hooks/evm/useEvmWallets.js.map +0 -1
- package/dist/hooks/index.js +0 -54
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/navigation/useKeyboardNavigation.js +0 -67
- package/dist/hooks/navigation/useKeyboardNavigation.js.map +0 -1
- package/dist/hooks/onramp/useFiatToCrypto.js +0 -298
- package/dist/hooks/onramp/useFiatToCrypto.js.map +0 -1
- package/dist/hooks/query/useSquidQueryClient.js +0 -23
- package/dist/hooks/query/useSquidQueryClient.js.map +0 -1
- package/dist/hooks/solana/useSolana.js +0 -81
- package/dist/hooks/solana/useSolana.js.map +0 -1
- package/dist/hooks/solana/useSolanaWallets.js +0 -8
- package/dist/hooks/solana/useSolanaWallets.js.map +0 -1
- package/dist/hooks/squid/useSquid.js +0 -55
- package/dist/hooks/squid/useSquid.js.map +0 -1
- package/dist/hooks/store/useAddressBookStore.js +0 -30
- package/dist/hooks/store/useAddressBookStore.js.map +0 -1
- package/dist/hooks/store/useAssetsColorsStore.js +0 -7
- package/dist/hooks/store/useAssetsColorsStore.js.map +0 -1
- package/dist/hooks/store/useDepositAddressStore.js +0 -12
- package/dist/hooks/store/useDepositAddressStore.js.map +0 -1
- package/dist/hooks/store/useFavoriteTokensStore.js +0 -28
- package/dist/hooks/store/useFavoriteTokensStore.js.map +0 -1
- package/dist/hooks/store/useHistoryStore.js +0 -129
- package/dist/hooks/store/useHistoryStore.js.map +0 -1
- package/dist/hooks/store/useSendTransactionStore.js +0 -21
- package/dist/hooks/store/useSendTransactionStore.js.map +0 -1
- package/dist/hooks/store/useSquidStore.js +0 -54
- package/dist/hooks/store/useSquidStore.js.map +0 -1
- package/dist/hooks/store/useWalletStore.js +0 -61
- package/dist/hooks/store/useWalletStore.js.map +0 -1
- package/dist/hooks/sui/useSui.js +0 -81
- package/dist/hooks/sui/useSui.js.map +0 -1
- package/dist/hooks/sui/useSuiWallets.js +0 -23
- package/dist/hooks/sui/useSuiWallets.js.map +0 -1
- package/dist/hooks/swap/useDepositAddress.js +0 -63
- package/dist/hooks/swap/useDepositAddress.js.map +0 -1
- package/dist/hooks/swap/useSwap.js +0 -228
- package/dist/hooks/swap/useSwap.js.map +0 -1
- package/dist/hooks/tokens/useAllConnectedWalletBalances.js +0 -114
- package/dist/hooks/tokens/useAllConnectedWalletBalances.js.map +0 -1
- package/dist/hooks/tokens/useAllTokensWithBalanceForChainType.js +0 -130
- package/dist/hooks/tokens/useAllTokensWithBalanceForChainType.js.map +0 -1
- package/dist/hooks/tokens/useBalance.js +0 -157
- package/dist/hooks/tokens/useBalance.js.map +0 -1
- package/dist/hooks/tokens/useMultiChainBalance.js +0 -77
- package/dist/hooks/tokens/useMultiChainBalance.js.map +0 -1
- package/dist/hooks/tokens/useMultipleTokenPrices.js +0 -46
- package/dist/hooks/tokens/useMultipleTokenPrices.js.map +0 -1
- package/dist/hooks/tokens/useNativeBalance.js +0 -249
- package/dist/hooks/tokens/useNativeBalance.js.map +0 -1
- package/dist/hooks/tokens/useNativeTokenForChain.js +0 -30
- package/dist/hooks/tokens/useNativeTokenForChain.js.map +0 -1
- package/dist/hooks/tokens/useSingleTokenPrice.js +0 -38
- package/dist/hooks/tokens/useSingleTokenPrice.js.map +0 -1
- package/dist/hooks/tokens/useSquidTokens.js +0 -75
- package/dist/hooks/tokens/useSquidTokens.js.map +0 -1
- package/dist/hooks/tokens/useTokenHistoricalData.js +0 -23
- package/dist/hooks/tokens/useTokenHistoricalData.js.map +0 -1
- package/dist/hooks/transaction/send/useEstimateSendTransactionGas.js +0 -58
- package/dist/hooks/transaction/send/useEstimateSendTransactionGas.js.map +0 -1
- package/dist/hooks/transaction/send/useSendTransaction.js +0 -245
- package/dist/hooks/transaction/send/useSendTransaction.js.map +0 -1
- package/dist/hooks/transaction/send/useSendTransactionGas.js +0 -73
- package/dist/hooks/transaction/send/useSendTransactionGas.js.map +0 -1
- package/dist/hooks/transaction/useAllTransactionsStatus.js +0 -127
- package/dist/hooks/transaction/useAllTransactionsStatus.js.map +0 -1
- package/dist/hooks/transaction/useApproval.js +0 -246
- package/dist/hooks/transaction/useApproval.js.map +0 -1
- package/dist/hooks/transaction/useErc20Allowance.js +0 -43
- package/dist/hooks/transaction/useErc20Allowance.js.map +0 -1
- package/dist/hooks/transaction/useEstimate.js +0 -115
- package/dist/hooks/transaction/useEstimate.js.map +0 -1
- package/dist/hooks/transaction/useEstimatePriceImpact.js +0 -31
- package/dist/hooks/transaction/useEstimatePriceImpact.js.map +0 -1
- package/dist/hooks/transaction/useExecuteTransaction.js +0 -678
- package/dist/hooks/transaction/useExecuteTransaction.js.map +0 -1
- package/dist/hooks/transaction/useGetRoute.js +0 -207
- package/dist/hooks/transaction/useGetRoute.js.map +0 -1
- package/dist/hooks/transaction/useIcs20Allowance.js +0 -46
- package/dist/hooks/transaction/useIcs20Allowance.js.map +0 -1
- package/dist/hooks/transaction/useRouteWarnings.js +0 -19
- package/dist/hooks/transaction/useRouteWarnings.js.map +0 -1
- package/dist/hooks/transaction/useSendTransactionStatus.js +0 -63
- package/dist/hooks/transaction/useSendTransactionStatus.js.map +0 -1
- package/dist/hooks/transaction/useSwapTransactionStatus.js +0 -114
- package/dist/hooks/transaction/useSwapTransactionStatus.js.map +0 -1
- package/dist/hooks/user/useAvatar.js +0 -40
- package/dist/hooks/user/useAvatar.js.map +0 -1
- package/dist/hooks/user/useHistory.js +0 -103
- package/dist/hooks/user/useHistory.js.map +0 -1
- package/dist/hooks/user/useUserParams.js +0 -33
- package/dist/hooks/user/useUserParams.js.map +0 -1
- package/dist/hooks/utils/useUtils.js +0 -20
- package/dist/hooks/utils/useUtils.js.map +0 -1
- package/dist/hooks/wallet/useAddToken.js +0 -49
- package/dist/hooks/wallet/useAddToken.js.map +0 -1
- package/dist/hooks/wallet/useAutoConnect.js +0 -92
- package/dist/hooks/wallet/useAutoConnect.js.map +0 -1
- package/dist/hooks/wallet/useEns.js +0 -57
- package/dist/hooks/wallet/useEns.js.map +0 -1
- package/dist/hooks/wallet/useGnosisContext.js +0 -74
- package/dist/hooks/wallet/useGnosisContext.js.map +0 -1
- package/dist/hooks/wallet/useIntegratorContext.js +0 -39
- package/dist/hooks/wallet/useIntegratorContext.js.map +0 -1
- package/dist/hooks/wallet/useMultiChainWallet.js +0 -210
- package/dist/hooks/wallet/useMultiChainWallet.js.map +0 -1
- package/dist/hooks/wallet/useSigner.js +0 -68
- package/dist/hooks/wallet/useSigner.js.map +0 -1
- package/dist/hooks/wallet/useStandardWallets.js +0 -26
- package/dist/hooks/wallet/useStandardWallets.js.map +0 -1
- package/dist/hooks/wallet/useWallet.js +0 -199
- package/dist/hooks/wallet/useWallet.js.map +0 -1
- package/dist/hooks/wallet/useWallets.js +0 -33
- package/dist/hooks/wallet/useWallets.js.map +0 -1
- package/dist/hooks/xrpl/useXrpl.js +0 -55
- package/dist/hooks/xrpl/useXrpl.js.map +0 -1
- package/dist/hooks/xrpl/useXrplTrustLine.js +0 -159
- package/dist/hooks/xrpl/useXrplTrustLine.js.map +0 -1
- package/dist/hooks/xrpl/useXrplWallets.js +0 -51
- package/dist/hooks/xrpl/useXrplWallets.js.map +0 -1
- package/dist/provider/index.js +0 -118
- package/dist/provider/index.js.map +0 -1
- package/dist/services/external/cosmosRestClient.js +0 -45
- package/dist/services/external/cosmosRestClient.js.map +0 -1
- package/dist/services/external/ens.js +0 -66
- package/dist/services/external/ens.js.map +0 -1
- package/dist/services/external/index.js +0 -3
- package/dist/services/external/index.js.map +0 -1
- package/dist/services/external/onrampAdapter.js +0 -52
- package/dist/services/external/onrampAdapter.js.map +0 -1
- package/dist/services/external/rpcService.js +0 -411
- package/dist/services/external/rpcService.js.map +0 -1
- package/dist/services/external/secretService.js.map +0 -1
- package/dist/services/external/suiRpcClient.js +0 -80
- package/dist/services/external/suiRpcClient.js.map +0 -1
- package/dist/services/external/tokenDataService.js +0 -108
- package/dist/services/external/tokenDataService.js.map +0 -1
- package/dist/services/external/websocket.js +0 -34
- package/dist/services/external/websocket.js.map +0 -1
- package/dist/services/external/xaman.js +0 -78
- package/dist/services/external/xaman.js.map +0 -1
- package/dist/services/external/xrplRpcClient.js +0 -167
- package/dist/services/external/xrplRpcClient.js.map +0 -1
- package/dist/services/index.js +0 -19
- package/dist/services/index.js.map +0 -1
- package/dist/services/internal/apiService.js +0 -21
- package/dist/services/internal/apiService.js.map +0 -1
- package/dist/services/internal/assetsService.js +0 -575
- package/dist/services/internal/assetsService.js.map +0 -1
- package/dist/services/internal/bitcoinService.js +0 -20
- package/dist/services/internal/bitcoinService.js.map +0 -1
- package/dist/services/internal/configService.js +0 -198
- package/dist/services/internal/configService.js.map +0 -1
- package/dist/services/internal/cosmosService.js +0 -141
- package/dist/services/internal/cosmosService.js.map +0 -1
- package/dist/services/internal/countryCurrencyMap.js +0 -1102
- package/dist/services/internal/countryCurrencyMap.js.map +0 -1
- package/dist/services/internal/errorService.js +0 -190
- package/dist/services/internal/errorService.js.map +0 -1
- package/dist/services/internal/estimateService.js +0 -225
- package/dist/services/internal/estimateService.js.map +0 -1
- package/dist/services/internal/eventService.js +0 -219
- package/dist/services/internal/eventService.js.map +0 -1
- package/dist/services/internal/evmService.js +0 -67
- package/dist/services/internal/evmService.js.map +0 -1
- package/dist/services/internal/fiatToCryptoService.js +0 -84
- package/dist/services/internal/fiatToCryptoService.js.map +0 -1
- package/dist/services/internal/fiatToCryptoService.test.js +0 -45
- package/dist/services/internal/fiatToCryptoService.test.js.map +0 -1
- package/dist/services/internal/numberService.js +0 -199
- package/dist/services/internal/numberService.js.map +0 -1
- package/dist/services/internal/priceService.js +0 -53
- package/dist/services/internal/priceService.js.map +0 -1
- package/dist/services/internal/searchService.js +0 -98
- package/dist/services/internal/searchService.js.map +0 -1
- package/dist/services/internal/sendTransaction.js +0 -191
- package/dist/services/internal/sendTransaction.js.map +0 -1
- package/dist/services/internal/sendTransactionStatus.js +0 -134
- package/dist/services/internal/sendTransactionStatus.js.map +0 -1
- package/dist/services/internal/solanaService.js +0 -142
- package/dist/services/internal/solanaService.js.map +0 -1
- package/dist/services/internal/suiService.js +0 -81
- package/dist/services/internal/suiService.js.map +0 -1
- package/dist/services/internal/transactionService.js +0 -210
- package/dist/services/internal/transactionService.js.map +0 -1
- package/dist/services/internal/transactionStatusService.js +0 -390
- package/dist/services/internal/transactionStatusService.js.map +0 -1
- package/dist/services/internal/walletService.js +0 -546
- package/dist/services/internal/walletService.js.map +0 -1
- package/dist/services/internal/walletStandardService.js +0 -128
- package/dist/services/internal/walletStandardService.js.map +0 -1
- package/dist/services/internal/xionService.js +0 -6
- package/dist/services/internal/xionService.js.map +0 -1
- package/dist/services/internal/xrplService.js +0 -52
- package/dist/services/internal/xrplService.js.map +0 -1
- package/dist/tests/apiService.test.js +0 -40
- package/dist/tests/apiService.test.js.map +0 -1
- package/dist/tests/assetsService.test.js +0 -614
- package/dist/tests/assetsService.test.js.map +0 -1
- package/dist/tests/configService.test.js +0 -641
- package/dist/tests/configService.test.js.map +0 -1
- package/dist/tests/estimateService.test.js +0 -429
- package/dist/tests/estimateService.test.js.map +0 -1
- package/dist/tests/fetchSquidData.js +0 -36
- package/dist/tests/fetchSquidData.js.map +0 -1
- package/dist/tests/jest-svg-transform.d.ts +0 -0
- package/dist/tests/jest-svg-transform.js +0 -21
- package/dist/tests/jest-svg-transform.js.map +0 -1
- package/dist/tests/numberService.test.js +0 -166
- package/dist/tests/numberService.test.js.map +0 -1
- package/dist/tests/priceService.test.js +0 -38
- package/dist/tests/priceService.test.js.map +0 -1
- package/dist/tests/sample.json +0 -0
- package/dist/tests/searchService.test.js +0 -86
- package/dist/tests/searchService.test.js.map +0 -1
- package/dist/tests/swapConfig.test.js +0 -332
- package/dist/tests/swapConfig.test.js.map +0 -1
- package/dist/tests/transactionService.test.js +0 -53
- package/dist/tests/transactionService.test.js.map +0 -1
- package/dist/tests/transactionStatusService.test.js +0 -165
- package/dist/tests/transactionStatusService.test.js.map +0 -1
- package/dist/tests/walletService.test.js +0 -488
- package/dist/tests/walletService.test.js.map +0 -1
|
@@ -1,678 +0,0 @@
|
|
|
1
|
-
import { ChainType, SquidDataType } from "@0xsquid/squid-types";
|
|
2
|
-
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
|
|
3
|
-
import { InjectiveSigningStargateClient } from "@injectivelabs/sdk-ts/dist/cjs/core/stargate";
|
|
4
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
5
|
-
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
6
|
-
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
7
|
-
import { isError } from "ethers";
|
|
8
|
-
import { useCallback, useMemo } from "react";
|
|
9
|
-
import { useAccount } from "wagmi";
|
|
10
|
-
import { getClient } from "../../core/client";
|
|
11
|
-
import { CHAIN_IDS } from "../../core/constants";
|
|
12
|
-
import { getPrefixKey, QueryKeys } from "../../core/queries/queries-keys";
|
|
13
|
-
import { TransactionErrorType } from "../../core/types/error";
|
|
14
|
-
import { TransactionStatus } from "../../core/types/transaction";
|
|
15
|
-
import { XrplTxStatus } from "../../core/types/xrpl";
|
|
16
|
-
import { executeSolanaSwap, executeSolanaTransfer, getCosmosSigningClient, getTransactionError, getXrplNetwork, handleTransactionErrorEvents, isProblematicConnector, isUserRejectionError, normalizeError, parseXrplPaymentTx, } from "../../services";
|
|
17
|
-
import { getWorkingCosmosRpcUrl } from "../../services/external/rpcService";
|
|
18
|
-
import { WidgetEvents } from "../../services/internal/eventService";
|
|
19
|
-
import { getSuiChain } from "../../services/internal/suiService";
|
|
20
|
-
import { getSourceExplorerTxUrl, isDepositRoute, sleep, } from "../../services/internal/transactionService";
|
|
21
|
-
import { useSquidChains } from "../chains/useSquidChains";
|
|
22
|
-
import { useSolanaConnection } from "../solana/useSolana";
|
|
23
|
-
import { useDepositAddressStore } from "../store/useDepositAddressStore";
|
|
24
|
-
import { useSquidStore, useTransactionStore } from "../store/useSquidStore";
|
|
25
|
-
import { useSwap } from "../swap/useSwap";
|
|
26
|
-
import { useSquidTokens } from "../tokens/useSquidTokens";
|
|
27
|
-
import { useHistory } from "../user/useHistory";
|
|
28
|
-
import { useGnosisContext } from "../wallet/useGnosisContext";
|
|
29
|
-
import { useMultiChainWallet } from "../wallet/useMultiChainWallet";
|
|
30
|
-
import { useSigner } from "../wallet/useSigner";
|
|
31
|
-
import { useWallet } from "../wallet/useWallet";
|
|
32
|
-
export const useExecuteTransaction = (squidRoute) => {
|
|
33
|
-
const { fromChain, toChain, fromToken, toToken, isSameChain } = useSwap();
|
|
34
|
-
const { evmSigner, cosmosSigner, solanaSigner, bitcoinSigner, suiSigner, xrplSigner, } = useSigner({
|
|
35
|
-
chain: fromChain,
|
|
36
|
-
});
|
|
37
|
-
const { findToken } = useSquidTokens();
|
|
38
|
-
const solanaConnection = useSolanaConnection();
|
|
39
|
-
const { findChain } = useSquidChains();
|
|
40
|
-
const queryClient = useQueryClient();
|
|
41
|
-
const { connectedWalletsByChainType } = useWallet();
|
|
42
|
-
const squid = useSquidStore((state) => state.squid);
|
|
43
|
-
const getTransaction = useTransactionStore((state) => state.getTransaction);
|
|
44
|
-
const setTransactionStoreState = useTransactionStore((state) => state.setTransactionState);
|
|
45
|
-
const { connector: activeConnector } = useAccount();
|
|
46
|
-
const { getGnosisTransactionHash } = useGnosisContext();
|
|
47
|
-
const { addSwapTransaction, replaceSwapTransactionNonce, replaceSwapTransactionStatus, } = useHistory();
|
|
48
|
-
const { connectedAddress: { address: sourceUserAddress }, changeNetworkIfNeeded, } = useMultiChainWallet(fromChain);
|
|
49
|
-
const connectedSourceWallet = useMemo(() => {
|
|
50
|
-
return fromChain?.chainType
|
|
51
|
-
? connectedWalletsByChainType[fromChain.chainType]
|
|
52
|
-
: undefined;
|
|
53
|
-
}, [fromChain?.chainType, connectedWalletsByChainType]);
|
|
54
|
-
/**
|
|
55
|
-
* Set the transaction state in the store
|
|
56
|
-
* This is useful to access the latest transaction from any hook
|
|
57
|
-
*/
|
|
58
|
-
const setTransactionState = useCallback(({ route, txHash, transactionIdForStatus, nonce, status, sourceStatus, userAddress, axelarUrl, id, }) => {
|
|
59
|
-
if (!route?.transactionRequest)
|
|
60
|
-
return undefined;
|
|
61
|
-
// TODO: update types
|
|
62
|
-
const { quoteId } = route;
|
|
63
|
-
const tx = {
|
|
64
|
-
fromChain,
|
|
65
|
-
toChain,
|
|
66
|
-
routeType: route.transactionRequest.type,
|
|
67
|
-
nonce,
|
|
68
|
-
transactionId: txHash,
|
|
69
|
-
transactionIdForStatus: transactionIdForStatus ?? txHash,
|
|
70
|
-
quoteId,
|
|
71
|
-
status,
|
|
72
|
-
sourceStatus,
|
|
73
|
-
timestamp: Date.now(),
|
|
74
|
-
fromAddress: userAddress,
|
|
75
|
-
sourceTxExplorerUrl: getSourceExplorerTxUrl(fromChain, txHash),
|
|
76
|
-
sourceExplorerImgUrl: fromChain?.chainIconURI,
|
|
77
|
-
axelarUrl,
|
|
78
|
-
};
|
|
79
|
-
setTransactionStoreState(id, tx);
|
|
80
|
-
return tx;
|
|
81
|
-
}, [fromChain, setTransactionStoreState, toChain]);
|
|
82
|
-
const getCosmosSignerClient = useCallback(async () => {
|
|
83
|
-
if (!fromChain)
|
|
84
|
-
return null;
|
|
85
|
-
const rpc = await getWorkingCosmosRpcUrl(fromChain);
|
|
86
|
-
if (!cosmosSigner)
|
|
87
|
-
return null;
|
|
88
|
-
switch (fromChain.chainId) {
|
|
89
|
-
case CHAIN_IDS.INJECTIVE:
|
|
90
|
-
return InjectiveSigningStargateClient.connectWithSigner(rpc, cosmosSigner);
|
|
91
|
-
default: {
|
|
92
|
-
const cosmosClient = await getCosmosSigningClient({
|
|
93
|
-
chainRpc: rpc,
|
|
94
|
-
cosmosSigner,
|
|
95
|
-
defaultSigningClient: SigningCosmWasmClient,
|
|
96
|
-
});
|
|
97
|
-
return cosmosClient;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}, [cosmosSigner, fromChain]);
|
|
101
|
-
const resetQueriesAfterTxSigned = () => {
|
|
102
|
-
queryClient.refetchQueries(getPrefixKey(QueryKeys.Balance));
|
|
103
|
-
queryClient.invalidateQueries(getPrefixKey(QueryKeys.Transaction));
|
|
104
|
-
};
|
|
105
|
-
const dispatchSignatureRequestEvent = useCallback((route) => {
|
|
106
|
-
WidgetEvents.getInstance().dispatchSwapTxSignatureRequested({
|
|
107
|
-
route,
|
|
108
|
-
});
|
|
109
|
-
}, []);
|
|
110
|
-
const dispatchPreSwapEvent = useCallback((route) => {
|
|
111
|
-
WidgetEvents.getInstance().dispatchPreSwap({
|
|
112
|
-
...route.params,
|
|
113
|
-
}, findToken);
|
|
114
|
-
}, [findToken]);
|
|
115
|
-
const dispatchPostSwapEvent = useCallback((route, txHash) => {
|
|
116
|
-
WidgetEvents.getInstance().dispatchPostSwap({
|
|
117
|
-
...route.params,
|
|
118
|
-
txHash,
|
|
119
|
-
}, findToken);
|
|
120
|
-
}, [findToken]);
|
|
121
|
-
const swapQueryCosmos = useMutation(async ({ id, route }) => {
|
|
122
|
-
const fromChainId = route?.params.fromChain;
|
|
123
|
-
if (cosmosSigner && fromChainId) {
|
|
124
|
-
try {
|
|
125
|
-
const signingClient = await getCosmosSignerClient();
|
|
126
|
-
const signerAddress = (await cosmosSigner.getAccounts())[0].address;
|
|
127
|
-
if (signerAddress && signingClient && route) {
|
|
128
|
-
dispatchSignatureRequestEvent(route);
|
|
129
|
-
const tx = (await squid?.executeRoute({
|
|
130
|
-
signer: signingClient,
|
|
131
|
-
signerAddress,
|
|
132
|
-
route,
|
|
133
|
-
}));
|
|
134
|
-
// set the tx state to loading, as soon as user signed the tx
|
|
135
|
-
setTransactionState({
|
|
136
|
-
txHash: "",
|
|
137
|
-
route,
|
|
138
|
-
status: TransactionStatus.ONGOING,
|
|
139
|
-
sourceStatus: TransactionStatus.ONGOING,
|
|
140
|
-
id,
|
|
141
|
-
});
|
|
142
|
-
// broadcast the signed tx to get hash and listen to events
|
|
143
|
-
const response = await signingClient.broadcastTx(TxRaw.encode(tx).finish());
|
|
144
|
-
const hash = response.transactionHash;
|
|
145
|
-
if (hash) {
|
|
146
|
-
resetQueriesAfterTxSigned();
|
|
147
|
-
}
|
|
148
|
-
// Dispatch event so it can be listened from outside the widget
|
|
149
|
-
WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
|
|
150
|
-
const txParams = setTransactionState({
|
|
151
|
-
route,
|
|
152
|
-
txHash: hash,
|
|
153
|
-
userAddress: sourceUserAddress,
|
|
154
|
-
status: TransactionStatus.ONGOING,
|
|
155
|
-
sourceStatus: TransactionStatus.ONGOING,
|
|
156
|
-
axelarUrl: undefined,
|
|
157
|
-
id,
|
|
158
|
-
});
|
|
159
|
-
if (txParams) {
|
|
160
|
-
addSwapTransaction({
|
|
161
|
-
...txParams,
|
|
162
|
-
params: route.params,
|
|
163
|
-
estimate: route.estimate,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return response.code === 0;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
console.error("Error executing Cosmos transaction", error);
|
|
171
|
-
if (isUserRejectionError(normalizeError(error))) {
|
|
172
|
-
throw new Error("Request rejected");
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
throw new Error("Need all parameters");
|
|
177
|
-
});
|
|
178
|
-
// If the transaction is replaced, we need to update the transaction hash
|
|
179
|
-
// Transaction replaced can mean that the user has speed up the transaction for example
|
|
180
|
-
// Could also be cancelled
|
|
181
|
-
const handleTransactionReplacementError = useCallback(async ({ error, route, status, sourceStatus, userAddress, axelarUrl, id, }) => {
|
|
182
|
-
if (route && isError(error, "TRANSACTION_REPLACED")) {
|
|
183
|
-
const txReplacementError = error;
|
|
184
|
-
const { hash: newHash, nonce: newNonce } = txReplacementError.replacement;
|
|
185
|
-
if (route.transactionRequest) {
|
|
186
|
-
const txParams = setTransactionState({
|
|
187
|
-
route,
|
|
188
|
-
txHash: newHash,
|
|
189
|
-
nonce: newNonce,
|
|
190
|
-
userAddress: sourceUserAddress,
|
|
191
|
-
status,
|
|
192
|
-
sourceStatus,
|
|
193
|
-
axelarUrl: undefined,
|
|
194
|
-
id,
|
|
195
|
-
});
|
|
196
|
-
if (txParams) {
|
|
197
|
-
replaceSwapTransactionNonce(newNonce, sourceUserAddress, {
|
|
198
|
-
...txParams,
|
|
199
|
-
params: route.params,
|
|
200
|
-
estimate: route.estimate,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
try {
|
|
205
|
-
const response = await txReplacementError.replacement.wait();
|
|
206
|
-
if (!response) {
|
|
207
|
-
throw new Error("Transaction receipt is null");
|
|
208
|
-
}
|
|
209
|
-
return response;
|
|
210
|
-
}
|
|
211
|
-
catch (replacementError) {
|
|
212
|
-
// Maybe the transaction was replaced again
|
|
213
|
-
// recursive call
|
|
214
|
-
return handleTransactionReplacementError({
|
|
215
|
-
error,
|
|
216
|
-
route,
|
|
217
|
-
status,
|
|
218
|
-
sourceStatus,
|
|
219
|
-
userAddress,
|
|
220
|
-
axelarUrl,
|
|
221
|
-
id,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
throw error;
|
|
227
|
-
}
|
|
228
|
-
}, [replaceSwapTransactionNonce, setTransactionState, sourceUserAddress]);
|
|
229
|
-
const swapQueryEvm = useMutation(async ({ id, route }) => {
|
|
230
|
-
await changeNetworkIfNeeded.mutateAsync();
|
|
231
|
-
if (!route || !squid || !evmSigner) {
|
|
232
|
-
throw new Error("Need all parameters");
|
|
233
|
-
}
|
|
234
|
-
dispatchSignatureRequestEvent(route);
|
|
235
|
-
const txResponse = (await squid.executeRoute({
|
|
236
|
-
bypassBalanceChecks: true,
|
|
237
|
-
signer: evmSigner,
|
|
238
|
-
route,
|
|
239
|
-
}));
|
|
240
|
-
let hash = txResponse.hash;
|
|
241
|
-
if (activeConnector?.id === "safe") {
|
|
242
|
-
hash = await getGnosisTransactionHash(txResponse.hash);
|
|
243
|
-
}
|
|
244
|
-
if (hash) {
|
|
245
|
-
resetQueriesAfterTxSigned();
|
|
246
|
-
}
|
|
247
|
-
// Dispatch event so it can be listened from outside the widget
|
|
248
|
-
WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
|
|
249
|
-
if (route.transactionRequest) {
|
|
250
|
-
const txParams = setTransactionState({
|
|
251
|
-
route,
|
|
252
|
-
txHash: hash,
|
|
253
|
-
nonce: txResponse.nonce,
|
|
254
|
-
userAddress: sourceUserAddress,
|
|
255
|
-
status: TransactionStatus.INITIAL_LOADING,
|
|
256
|
-
sourceStatus: TransactionStatus.ONGOING,
|
|
257
|
-
axelarUrl: undefined,
|
|
258
|
-
id,
|
|
259
|
-
});
|
|
260
|
-
if (txParams) {
|
|
261
|
-
addSwapTransaction({
|
|
262
|
-
...txParams,
|
|
263
|
-
params: route.params,
|
|
264
|
-
estimate: route.estimate,
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
try {
|
|
269
|
-
if (isProblematicConnector(activeConnector)) {
|
|
270
|
-
await sleep(3_000);
|
|
271
|
-
}
|
|
272
|
-
const response = await txResponse.wait();
|
|
273
|
-
return response;
|
|
274
|
-
}
|
|
275
|
-
catch (error) {
|
|
276
|
-
return handleTransactionReplacementError({
|
|
277
|
-
error,
|
|
278
|
-
route,
|
|
279
|
-
status: TransactionStatus.INITIAL_LOADING,
|
|
280
|
-
sourceStatus: TransactionStatus.ONGOING,
|
|
281
|
-
userAddress: sourceUserAddress,
|
|
282
|
-
axelarUrl: undefined,
|
|
283
|
-
id,
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
const swapQuerySolana = useMutation(async ({ id, route }) => {
|
|
288
|
-
try {
|
|
289
|
-
if (!route) {
|
|
290
|
-
throw new Error("Route is required");
|
|
291
|
-
}
|
|
292
|
-
if (!solanaSigner) {
|
|
293
|
-
throw new Error("Solana signer is required");
|
|
294
|
-
}
|
|
295
|
-
if (!route.params.fromAddress || !route.params.toAddress) {
|
|
296
|
-
throw new Error("From or to address is required");
|
|
297
|
-
}
|
|
298
|
-
const isDirectTransfer = isDepositRoute(route);
|
|
299
|
-
// Means it's a transfer to a deposit address
|
|
300
|
-
// Instead of a Swap/Contract call using a DEX like Jupiter
|
|
301
|
-
if (isDirectTransfer) {
|
|
302
|
-
// Get the deposit address from the squidRoute
|
|
303
|
-
const depositData = useDepositAddressStore.getState().deposit;
|
|
304
|
-
// Validate params
|
|
305
|
-
if (!depositData?.depositAddress) {
|
|
306
|
-
throw new Error("Deposit address is required");
|
|
307
|
-
}
|
|
308
|
-
const signature = await executeSolanaTransfer({
|
|
309
|
-
amount: BigInt(route.params.fromAmount),
|
|
310
|
-
target: depositData.depositAddress,
|
|
311
|
-
signer: solanaSigner,
|
|
312
|
-
connection: solanaConnection,
|
|
313
|
-
sourceToken: findToken(route.params.fromToken, route?.params?.fromChain),
|
|
314
|
-
onSigned: (txHash) => {
|
|
315
|
-
WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
|
|
316
|
-
const txParams = setTransactionState({
|
|
317
|
-
route,
|
|
318
|
-
txHash,
|
|
319
|
-
transactionIdForStatus: depositData.chainflipStatusTrackingId,
|
|
320
|
-
userAddress: sourceUserAddress,
|
|
321
|
-
status: TransactionStatus.INITIAL_LOADING,
|
|
322
|
-
sourceStatus: TransactionStatus.ONGOING,
|
|
323
|
-
id,
|
|
324
|
-
});
|
|
325
|
-
if (txParams) {
|
|
326
|
-
addSwapTransaction({
|
|
327
|
-
...txParams,
|
|
328
|
-
params: route.params,
|
|
329
|
-
estimate: route.estimate,
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
},
|
|
333
|
-
});
|
|
334
|
-
return signature;
|
|
335
|
-
}
|
|
336
|
-
const signature = await executeSolanaSwap({
|
|
337
|
-
route,
|
|
338
|
-
signer: solanaSigner,
|
|
339
|
-
connection: solanaConnection,
|
|
340
|
-
onSigned: (txHash) => {
|
|
341
|
-
WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
|
|
342
|
-
const txParams = setTransactionState({
|
|
343
|
-
route,
|
|
344
|
-
txHash,
|
|
345
|
-
transactionIdForStatus: undefined,
|
|
346
|
-
userAddress: sourceUserAddress,
|
|
347
|
-
status: TransactionStatus.INITIAL_LOADING,
|
|
348
|
-
sourceStatus: TransactionStatus.ONGOING,
|
|
349
|
-
id,
|
|
350
|
-
});
|
|
351
|
-
if (txParams) {
|
|
352
|
-
addSwapTransaction({
|
|
353
|
-
...txParams,
|
|
354
|
-
params: route.params,
|
|
355
|
-
estimate: route.estimate,
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
},
|
|
359
|
-
});
|
|
360
|
-
return signature;
|
|
361
|
-
}
|
|
362
|
-
catch (error) {
|
|
363
|
-
console.error("Solana transaction failed:", error);
|
|
364
|
-
throw error instanceof Error
|
|
365
|
-
? error
|
|
366
|
-
: new Error("Failed to execute Solana transaction");
|
|
367
|
-
}
|
|
368
|
-
}, {
|
|
369
|
-
onError: (error, variables) => {
|
|
370
|
-
const currentTx = getTransaction(variables.id);
|
|
371
|
-
const errorObject = getTransactionError(error);
|
|
372
|
-
setTransactionStoreState(variables.id, {
|
|
373
|
-
...currentTx,
|
|
374
|
-
status: TransactionStatus.ERROR,
|
|
375
|
-
sourceStatus: TransactionStatus.ERROR,
|
|
376
|
-
error: errorObject,
|
|
377
|
-
});
|
|
378
|
-
if (currentTx?.transactionId &&
|
|
379
|
-
errorObject.type === TransactionErrorType.CALL_EXCEPTION) {
|
|
380
|
-
replaceSwapTransactionStatus({
|
|
381
|
-
transactionId: currentTx.transactionId,
|
|
382
|
-
statusResponse: currentTx.statusResponse,
|
|
383
|
-
status: TransactionStatus.ERROR,
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
},
|
|
387
|
-
onSuccess: (_data, variables) => {
|
|
388
|
-
const currentTx = getTransaction(variables.id);
|
|
389
|
-
queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balances));
|
|
390
|
-
if (isSameChain && currentTx?.transactionId) {
|
|
391
|
-
replaceSwapTransactionStatus({
|
|
392
|
-
transactionId: currentTx.transactionId,
|
|
393
|
-
statusResponse: currentTx.statusResponse,
|
|
394
|
-
status: TransactionStatus.SUCCESS,
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
setTransactionStoreState(variables.id, {
|
|
398
|
-
...currentTx,
|
|
399
|
-
sourceStatus: TransactionStatus.SUCCESS,
|
|
400
|
-
status: isSameChain
|
|
401
|
-
? TransactionStatus.SUCCESS
|
|
402
|
-
: TransactionStatus.ONGOING,
|
|
403
|
-
});
|
|
404
|
-
},
|
|
405
|
-
});
|
|
406
|
-
const swapQueryBitcoin = useMutation(async ({ id, route }) => {
|
|
407
|
-
const { depositAddress, amount: sendAmount, chainflipStatusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
|
|
408
|
-
if (!depositAddress) {
|
|
409
|
-
throw new Error(`Invalid deposit address: ${depositAddress}`);
|
|
410
|
-
}
|
|
411
|
-
if (!sendAmount) {
|
|
412
|
-
throw new Error(`Invalid send amount: ${sendAmount}`);
|
|
413
|
-
}
|
|
414
|
-
const allParamsValid = route && bitcoinSigner && depositAddress && sendAmount;
|
|
415
|
-
await changeNetworkIfNeeded.mutateAsync();
|
|
416
|
-
if (allParamsValid) {
|
|
417
|
-
dispatchSignatureRequestEvent(route);
|
|
418
|
-
const { txHash } = await bitcoinSigner.sendBTC(depositAddress, Number(sendAmount));
|
|
419
|
-
if (txHash) {
|
|
420
|
-
resetQueriesAfterTxSigned();
|
|
421
|
-
}
|
|
422
|
-
// Dispatch event so it can be listened from outside the widget
|
|
423
|
-
WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
|
|
424
|
-
if (route.transactionRequest) {
|
|
425
|
-
const txParams = setTransactionState({
|
|
426
|
-
route,
|
|
427
|
-
txHash,
|
|
428
|
-
// When bridging from Bitcoin we need to send the chainflipId to the status endpoint
|
|
429
|
-
// instead of the Bitcoin transaction hash
|
|
430
|
-
transactionIdForStatus: chainflipStatusTrackingId,
|
|
431
|
-
userAddress: sourceUserAddress,
|
|
432
|
-
status: TransactionStatus.INITIAL_LOADING,
|
|
433
|
-
sourceStatus: TransactionStatus.ONGOING,
|
|
434
|
-
axelarUrl: undefined,
|
|
435
|
-
id,
|
|
436
|
-
});
|
|
437
|
-
if (txParams) {
|
|
438
|
-
addSwapTransaction({
|
|
439
|
-
...txParams,
|
|
440
|
-
params: route.params,
|
|
441
|
-
estimate: route.estimate,
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
else {
|
|
447
|
-
throw new Error("Need all parameters");
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
const swapQueryXrpl = useMutation(async ({ id, route }) => {
|
|
451
|
-
if (!route?.transactionRequest || !xrplSigner) {
|
|
452
|
-
throw new Error("Need all parameters");
|
|
453
|
-
}
|
|
454
|
-
if (route.transactionRequest.type !== SquidDataType.OnChainExecution) {
|
|
455
|
-
throw new Error("Invalid route type");
|
|
456
|
-
}
|
|
457
|
-
const { data } = route.transactionRequest;
|
|
458
|
-
const paymentTx = parseXrplPaymentTx(data);
|
|
459
|
-
if (!paymentTx)
|
|
460
|
-
throw new Error("Could not parse transaction");
|
|
461
|
-
const fromChainId = route.params.fromChain;
|
|
462
|
-
const xrplNetwork = getXrplNetwork(fromChainId);
|
|
463
|
-
if (xrplNetwork == null) {
|
|
464
|
-
throw new Error(`No XRPL network found for chainId '${fromChainId}'`);
|
|
465
|
-
}
|
|
466
|
-
const txRes = await xrplSigner.signAndSubmit({
|
|
467
|
-
tx: paymentTx,
|
|
468
|
-
network: xrplNetwork,
|
|
469
|
-
});
|
|
470
|
-
const txParams = setTransactionState({
|
|
471
|
-
txHash: txRes.hash,
|
|
472
|
-
id,
|
|
473
|
-
sourceStatus: TransactionStatus.ONGOING,
|
|
474
|
-
status: TransactionStatus.ONGOING,
|
|
475
|
-
route: route,
|
|
476
|
-
userAddress: sourceUserAddress,
|
|
477
|
-
});
|
|
478
|
-
if (txParams && route) {
|
|
479
|
-
addSwapTransaction({
|
|
480
|
-
...txParams,
|
|
481
|
-
params: route.params,
|
|
482
|
-
estimate: route.estimate,
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
if (txRes.status !== XrplTxStatus.SUCCESS) {
|
|
486
|
-
throw new Error(`Transaction failed with status: ${txRes.status}`);
|
|
487
|
-
}
|
|
488
|
-
}, {});
|
|
489
|
-
const swapQuerySui = useMutation(async ({ id, route }) => {
|
|
490
|
-
if (!route || !suiSigner || !fromChain) {
|
|
491
|
-
throw new Error("Need all parameters");
|
|
492
|
-
}
|
|
493
|
-
if (route.transactionRequest?.type !== SquidDataType.OnChainExecution) {
|
|
494
|
-
throw new Error("Invalid route type");
|
|
495
|
-
}
|
|
496
|
-
const suiWalletState = connectedWalletsByChainType[ChainType.SUI];
|
|
497
|
-
if (!suiWalletState.account) {
|
|
498
|
-
throw new Error("Sui wallet is missing account data");
|
|
499
|
-
}
|
|
500
|
-
const fromChainId = route.params.fromChain;
|
|
501
|
-
const suiChain = getSuiChain(fromChainId);
|
|
502
|
-
if (!suiChain) {
|
|
503
|
-
throw new Error(`Source chain (${fromChainId}) does not match any Sui chain`);
|
|
504
|
-
}
|
|
505
|
-
const suiClient = await getClient(fromChain);
|
|
506
|
-
const txJson = route.transactionRequest.data;
|
|
507
|
-
const tx = Transaction.from(txJson);
|
|
508
|
-
const signedTx = await suiSigner.signTransaction({
|
|
509
|
-
transaction: tx,
|
|
510
|
-
account: suiWalletState.account,
|
|
511
|
-
chain: suiChain,
|
|
512
|
-
});
|
|
513
|
-
// execute transaction without waiting for confirmation
|
|
514
|
-
const txResponse = await suiClient.executeTransactionBlock({
|
|
515
|
-
signature: signedTx.signature,
|
|
516
|
-
transactionBlock: signedTx.bytes,
|
|
517
|
-
});
|
|
518
|
-
const txHash = txResponse.digest;
|
|
519
|
-
if (txHash) {
|
|
520
|
-
resetQueriesAfterTxSigned();
|
|
521
|
-
}
|
|
522
|
-
WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
|
|
523
|
-
const txParams = setTransactionState({
|
|
524
|
-
route,
|
|
525
|
-
txHash,
|
|
526
|
-
userAddress: sourceUserAddress,
|
|
527
|
-
status: TransactionStatus.INITIAL_LOADING,
|
|
528
|
-
sourceStatus: TransactionStatus.ONGOING,
|
|
529
|
-
id,
|
|
530
|
-
});
|
|
531
|
-
if (txParams) {
|
|
532
|
-
addSwapTransaction({
|
|
533
|
-
...txParams,
|
|
534
|
-
params: route.params,
|
|
535
|
-
estimate: route.estimate,
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
// wait for transaction confirmation
|
|
539
|
-
await suiClient.waitForTransaction({
|
|
540
|
-
digest: txHash,
|
|
541
|
-
});
|
|
542
|
-
}, {});
|
|
543
|
-
const handleTransactionSuccess = useCallback((id) => {
|
|
544
|
-
const currentTx = getTransaction(id);
|
|
545
|
-
queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balances));
|
|
546
|
-
if (isSameChain && currentTx?.transactionId) {
|
|
547
|
-
replaceSwapTransactionStatus({
|
|
548
|
-
transactionId: currentTx.transactionId,
|
|
549
|
-
statusResponse: currentTx.statusResponse,
|
|
550
|
-
status: TransactionStatus.SUCCESS,
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
setTransactionStoreState(id, {
|
|
554
|
-
...currentTx,
|
|
555
|
-
sourceStatus: TransactionStatus.SUCCESS,
|
|
556
|
-
status: isSameChain
|
|
557
|
-
? TransactionStatus.SUCCESS
|
|
558
|
-
: TransactionStatus.ONGOING,
|
|
559
|
-
});
|
|
560
|
-
}, [
|
|
561
|
-
getTransaction,
|
|
562
|
-
isSameChain,
|
|
563
|
-
queryClient,
|
|
564
|
-
replaceSwapTransactionStatus,
|
|
565
|
-
setTransactionStoreState,
|
|
566
|
-
]);
|
|
567
|
-
const handleTransactionError = useCallback((error, id) => {
|
|
568
|
-
const currentTx = getTransaction(id);
|
|
569
|
-
const errorObject = getTransactionError(error);
|
|
570
|
-
handleTransactionErrorEvents({
|
|
571
|
-
error: errorObject,
|
|
572
|
-
transactionParams: currentTx,
|
|
573
|
-
walletProviderName: connectedSourceWallet?.wallet?.name,
|
|
574
|
-
squidRoute,
|
|
575
|
-
});
|
|
576
|
-
setTransactionStoreState(id, {
|
|
577
|
-
...currentTx,
|
|
578
|
-
status: TransactionStatus.ERROR,
|
|
579
|
-
sourceStatus: TransactionStatus.ERROR,
|
|
580
|
-
error: errorObject,
|
|
581
|
-
});
|
|
582
|
-
if (currentTx?.transactionId &&
|
|
583
|
-
errorObject.type === TransactionErrorType.CALL_EXCEPTION) {
|
|
584
|
-
replaceSwapTransactionStatus({
|
|
585
|
-
transactionId: currentTx?.transactionId,
|
|
586
|
-
statusResponse: currentTx?.statusResponse,
|
|
587
|
-
status: TransactionStatus.ERROR,
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
}, [
|
|
591
|
-
connectedSourceWallet?.wallet?.name,
|
|
592
|
-
getTransaction,
|
|
593
|
-
replaceSwapTransactionStatus,
|
|
594
|
-
setTransactionStoreState,
|
|
595
|
-
squidRoute,
|
|
596
|
-
]);
|
|
597
|
-
const swapQuery = useMutation(async (mutationParams) => {
|
|
598
|
-
if (!mutationParams.route)
|
|
599
|
-
throw new Error("route is required");
|
|
600
|
-
const sourceChain = findChain(mutationParams.route.params?.fromChain);
|
|
601
|
-
if (!sourceChain)
|
|
602
|
-
throw new Error("Could not find source chain");
|
|
603
|
-
switch (sourceChain.chainType) {
|
|
604
|
-
case ChainType.COSMOS: {
|
|
605
|
-
return swapQueryCosmos.mutateAsync(mutationParams);
|
|
606
|
-
}
|
|
607
|
-
case ChainType.EVM: {
|
|
608
|
-
return swapQueryEvm.mutateAsync(mutationParams);
|
|
609
|
-
}
|
|
610
|
-
case ChainType.BTC: {
|
|
611
|
-
return swapQueryBitcoin.mutateAsync(mutationParams);
|
|
612
|
-
}
|
|
613
|
-
case ChainType.SOLANA: {
|
|
614
|
-
return swapQuerySolana.mutateAsync(mutationParams);
|
|
615
|
-
}
|
|
616
|
-
case ChainType.SUI: {
|
|
617
|
-
return swapQuerySui.mutateAsync(mutationParams);
|
|
618
|
-
}
|
|
619
|
-
case ChainType.XRPL: {
|
|
620
|
-
return swapQueryXrpl.mutateAsync(mutationParams);
|
|
621
|
-
}
|
|
622
|
-
default:
|
|
623
|
-
throw new Error(`Swap query not implemented for chain type: ${sourceChain.chainType}`);
|
|
624
|
-
}
|
|
625
|
-
}, {
|
|
626
|
-
onMutate: (variables) => {
|
|
627
|
-
useTransactionStore.setState({
|
|
628
|
-
txLocalId: variables.id,
|
|
629
|
-
currentTransaction: undefined,
|
|
630
|
-
});
|
|
631
|
-
},
|
|
632
|
-
onError: (error, variables) => handleTransactionError(error, variables.id),
|
|
633
|
-
onSuccess: (_data, variables) => {
|
|
634
|
-
const currentTx = getTransaction(variables.id);
|
|
635
|
-
handleTransactionSuccess(variables.id);
|
|
636
|
-
// Dispatch postSwap event after successful swap
|
|
637
|
-
if (squidRoute && sourceUserAddress && currentTx?.transactionId) {
|
|
638
|
-
dispatchPostSwapEvent(squidRoute, currentTx.transactionId);
|
|
639
|
-
}
|
|
640
|
-
},
|
|
641
|
-
});
|
|
642
|
-
/**
|
|
643
|
-
* Execute transaction wrapper
|
|
644
|
-
* Generate a unique id for the transaction (as they don't have tx hash yet)
|
|
645
|
-
*/
|
|
646
|
-
const executeSwap = useCallback(async () => {
|
|
647
|
-
const transactionId = Date.now().toString();
|
|
648
|
-
// Dispatch preSwap event before executing the swap
|
|
649
|
-
if (squidRoute) {
|
|
650
|
-
dispatchPreSwapEvent(squidRoute);
|
|
651
|
-
}
|
|
652
|
-
return swapQuery.mutate({
|
|
653
|
-
id: transactionId,
|
|
654
|
-
route: squidRoute,
|
|
655
|
-
});
|
|
656
|
-
}, [swapQuery, squidRoute, dispatchPreSwapEvent]);
|
|
657
|
-
/**
|
|
658
|
-
* In QR-based wallets, cleans up listeners and network requests (e.g. websockets)
|
|
659
|
-
* Useful to save resources i.e when the user dismisses the QR code or aborts the connection process
|
|
660
|
-
*/
|
|
661
|
-
const cancelSwap = useCallback(() => {
|
|
662
|
-
switch (fromChain?.chainType) {
|
|
663
|
-
case ChainType.XRPL:
|
|
664
|
-
return xrplSigner?.cancelSignAndSubmit?.();
|
|
665
|
-
}
|
|
666
|
-
}, [fromChain?.chainType, xrplSigner]);
|
|
667
|
-
return {
|
|
668
|
-
executeSwap,
|
|
669
|
-
cancelSwap,
|
|
670
|
-
fromToken,
|
|
671
|
-
toToken,
|
|
672
|
-
toChain,
|
|
673
|
-
fromChain,
|
|
674
|
-
isLoading: swapQuery.isLoading,
|
|
675
|
-
error: swapQuery.error,
|
|
676
|
-
};
|
|
677
|
-
};
|
|
678
|
-
//# sourceMappingURL=useExecuteTransaction.js.map
|