@0xsquid/react-hooks 8.0.4 → 8.0.6

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.
@@ -1,7 +1,6 @@
1
1
  import { ChainType, RouteResponse } from "@0xsquid/squid-types";
2
2
  import { HistoryTransaction } from "../../core/types/history";
3
3
  import { AppConfig, SlippageOption } from "../types/config";
4
- import { ApprovalType } from "../types/evm";
5
4
  import { SwapDirection } from "../types/swap";
6
5
  import { Timeframe, TokenWithBalance } from "../types/tokens";
7
6
  export declare enum QueryKeys {
@@ -57,7 +56,7 @@ export declare const keys: () => {
57
56
  fiatToCryptoStatus: (transactionId?: string) => (string | undefined)[];
58
57
  sendTransactionStatus: (txHash: string | undefined, chainId: string | undefined) => (string | undefined)[];
59
58
  allTransactionsStatus: (transactions: HistoryTransaction[] | undefined) => string[];
60
- routeApproved: (routeData: RouteResponse["route"] | undefined, allowanceInWei: bigint | undefined, approvalType: ApprovalType | null) => (string | null | undefined)[];
59
+ routeApproved: (routeData: RouteResponse["route"] | undefined, allowanceInWei: bigint | undefined) => (string | undefined)[];
61
60
  sendTransactionGas: (chainId: string | undefined, tokenAddress: string | undefined, from: string | undefined) => (string | undefined)[];
62
61
  ensData: (address?: string) => (string | undefined)[];
63
62
  ensSearch: (query?: string) => (string | undefined)[];
@@ -1,3 +1,2 @@
1
1
  import { Connector as WagmiConnector } from "wagmi";
2
2
  export type EvmConnector = WagmiConnector;
3
- export type ApprovalType = "erc20" | "ics20";
@@ -1,21 +1,15 @@
1
+ import { SquidDataType } from "@0xsquid/squid-types";
1
2
  interface Erc20AllowanceParams {
2
3
  tokenAddress: string | undefined;
3
4
  ownerAddress: string | undefined;
4
5
  spenderAddress: string | undefined;
5
6
  amount: bigint | undefined;
6
7
  chainId: number | undefined;
8
+ transactionType: SquidDataType | undefined;
7
9
  enabled?: boolean;
8
10
  }
9
- export declare const useErc20Allowance: ({ tokenAddress, ownerAddress, spenderAddress, amount, chainId, enabled, }: Erc20AllowanceParams) => {
11
+ export declare const useErc20Allowance: ({ tokenAddress, ownerAddress, spenderAddress, amount, chainId, transactionType, enabled, }: Erc20AllowanceParams) => {
10
12
  hasAllowance: boolean;
11
- error: Error;
12
- isNativeToken?: undefined;
13
- query?: undefined;
14
- allowanceInWei?: undefined;
15
- } | {
16
- hasAllowance: boolean;
17
- isNativeToken: boolean;
18
- error?: undefined;
19
13
  query?: undefined;
20
14
  allowanceInWei?: undefined;
21
15
  } | {
@@ -156,7 +150,5 @@ export declare const useErc20Allowance: ({ tokenAddress, ownerAddress, spenderAd
156
150
  }], "allowance", readonly [`0x${string}`, `0x${string}`], bigint>;
157
151
  hasAllowance: boolean;
158
152
  allowanceInWei: bigint;
159
- error?: undefined;
160
- isNativeToken?: undefined;
161
153
  };
162
154
  export {};
@@ -22249,7 +22249,7 @@ const keys = () => ({
22249
22249
  // ============
22250
22250
  // Approval
22251
22251
  // ============
22252
- routeApproved: (routeData, allowanceInWei, approvalType) => [
22252
+ routeApproved: (routeData, allowanceInWei) => [
22253
22253
  ...keys().transactions(),
22254
22254
  QueryKeys.RouteApproved,
22255
22255
  routeData?.params.fromAddress,
@@ -22257,7 +22257,6 @@ const keys = () => ({
22257
22257
  routeData?.params.fromToken,
22258
22258
  routeData?.params.fromAmount,
22259
22259
  allowanceInWei?.toString(),
22260
- approvalType,
22261
22260
  ],
22262
22261
  sendTransactionGas: (chainId, tokenAddress, from) => [
22263
22262
  QueryKeys.All,
@@ -23064,7 +23063,7 @@ const filterViewableTokens = (tokens, config, direction) => {
23064
23063
  };
23065
23064
  const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
23066
23065
  const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
23067
- const { fetchAllSecretBalances } = await import('./secretService-CV_qKM-f.js');
23066
+ const { fetchAllSecretBalances } = await import('./secretService-Bt57DxoX.js');
23068
23067
  return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
23069
23068
  };
23070
23069
  function getTokenAssetsKey(token) {
@@ -26240,7 +26239,7 @@ function useStellarWallets() {
26240
26239
  return;
26241
26240
  try {
26242
26241
  const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
26243
- const { formatStellarWallet } = await import('./stellarService.client-BK4en2TV.js');
26242
+ const { formatStellarWallet } = await import('./stellarService.client-BHe6Jfr-.js');
26244
26243
  const modules = initializeAllModules();
26245
26244
  const promises = modules.map(async (module) => {
26246
26245
  const isAvailable = await module.isAvailable();
@@ -31505,11 +31504,12 @@ var ics20Abi = [
31505
31504
  }
31506
31505
  ];
31507
31506
 
31508
- const useErc20Allowance = ({ tokenAddress, ownerAddress, spenderAddress, amount = BigInt(0), chainId, enabled = true, }) => {
31507
+ const useErc20Allowance = ({ tokenAddress, ownerAddress, spenderAddress, amount = BigInt(0), chainId, transactionType, enabled = true, }) => {
31509
31508
  const parsedTokenAddress = parseEvmAddress(tokenAddress);
31510
31509
  const parsedOwnerAddress = parseEvmAddress(ownerAddress);
31511
31510
  const parsedSpenderAddress = parseEvmAddress(spenderAddress);
31512
31511
  const isNativeToken = parsedTokenAddress?.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
31512
+ const isDepositAddressTx = transactionType === SquidDataType.DepositAddressCalldata;
31513
31513
  const result = useReadContract({
31514
31514
  abi: erc20Abi,
31515
31515
  address: parsedTokenAddress ?? undefined,
@@ -31523,17 +31523,16 @@ const useErc20Allowance = ({ tokenAddress, ownerAddress, spenderAddress, amount
31523
31523
  Boolean(parsedTokenAddress &&
31524
31524
  parsedOwnerAddress &&
31525
31525
  parsedSpenderAddress &&
31526
- !isNativeToken),
31526
+ !isNativeToken &&
31527
+ !isDepositAddressTx),
31527
31528
  },
31528
31529
  });
31529
31530
  if (!parsedTokenAddress || !parsedOwnerAddress || !parsedSpenderAddress) {
31530
- return {
31531
- hasAllowance: false,
31532
- error: new Error("Invalid or missing address"),
31533
- };
31531
+ return { hasAllowance: false };
31534
31532
  }
31535
- if (isNativeToken) {
31536
- return { hasAllowance: true, isNativeToken: true };
31533
+ // Native tokens and deposit address transactions don't need approval
31534
+ if (isNativeToken || isDepositAddressTx) {
31535
+ return { hasAllowance: true };
31537
31536
  }
31538
31537
  const allowanceInWei = result.data ?? BigInt(0);
31539
31538
  const hasAllowance = allowanceInWei >= amount;
@@ -31601,26 +31600,8 @@ const useApproval = ({ squidRoute, }) => {
31601
31600
  const isSrcChainEvmos = isEvmosChain(fromChain);
31602
31601
  const isSagaSameChainSwap = isSameChain &&
31603
31602
  fromChain?.chainId.toString() === CHAIN_IDS.SAGA_EVM.toString();
31604
- const approvalType = useMemo(() => {
31605
- if (squidRoute?.transactionRequest?.type ===
31606
- SquidDataType.DepositAddressCalldata) {
31607
- // No approvals needed for deposit address calls
31608
- return null;
31609
- }
31610
- if (isSrcChainEvmos && !isSagaSameChainSwap) {
31611
- // Use ICS20 for Evmos chains, except for SagaEVM same-chain swaps
31612
- return "ics20";
31613
- }
31614
- else {
31615
- return "erc20";
31616
- }
31617
- }, [
31618
- isSagaSameChainSwap,
31619
- isSrcChainEvmos,
31620
- squidRoute?.transactionRequest?.type,
31621
- ]);
31622
- const useIcs20 = approvalType === "ics20";
31623
- const useErc20 = approvalType === "erc20";
31603
+ // Use ICS20 for Evmos chains, except for SagaEVM same-chain swaps
31604
+ const useIcs20 = isSrcChainEvmos && !isSagaSameChainSwap;
31624
31605
  const { hasAllowance: hasErc20Allowance, query: erc20AllowanceQuery, allowanceInWei: erc20AllowanceInWei, } = useErc20Allowance({
31625
31606
  tokenAddress: fromToken?.address,
31626
31607
  ownerAddress: sourceUserAddress,
@@ -31628,7 +31609,8 @@ const useApproval = ({ squidRoute, }) => {
31628
31609
  ?.target,
31629
31610
  amount: BigInt(squidRoute?.params.fromAmount ?? "0"),
31630
31611
  chainId: Number(fromChain?.chainId),
31631
- enabled: useErc20,
31612
+ transactionType: squidRoute?.transactionRequest?.type,
31613
+ enabled: !useIcs20,
31632
31614
  });
31633
31615
  const { hasAllowance: hasIcs20Allowance, query: ics20AllowanceQuery, allowanceInWei: ics20AllowanceInWei, } = useIcs20Allowance({
31634
31616
  ownerAddress: sourceUserAddress,
@@ -31647,10 +31629,7 @@ const useApproval = ({ squidRoute, }) => {
31647
31629
  * On Error: Showing the error message if any
31648
31630
  * @returns {boolean} approved
31649
31631
  */
31650
- const routeApproved = useQuery(keys().routeApproved(squidRoute, allowanceInWei, approvalType), async () => {
31651
- if (approvalType === null) {
31652
- return true;
31653
- }
31632
+ const routeApproved = useQuery(keys().routeApproved(squidRoute, allowanceInWei), async () => {
31654
31633
  // Approval is only needed for EVM chains
31655
31634
  if (getChainType(squidRoute?.params.fromChain) === ChainType.EVM) {
31656
31635
  return hasAllowance;
@@ -31659,8 +31638,8 @@ const useApproval = ({ squidRoute, }) => {
31659
31638
  }, {
31660
31639
  enabled: !!squidRoute &&
31661
31640
  !!sourceUserAddress &&
31662
- ((!allowanceQuery?.isLoading && allowanceQuery?.isFetched) ||
31663
- approvalType === null),
31641
+ !allowanceQuery?.isLoading &&
31642
+ allowanceQuery?.isFetched,
31664
31643
  });
31665
31644
  // USDT has a very specific way of handling approvals
31666
31645
  // ```
@@ -31750,9 +31729,6 @@ const useApproval = ({ squidRoute, }) => {
31750
31729
  */
31751
31730
  const approveRoute = useMutation(async () => {
31752
31731
  try {
31753
- if (approvalType === null) {
31754
- return true;
31755
- }
31756
31732
  if (fromToken?.address === nativeEvmTokenAddress) {
31757
31733
  return true;
31758
31734
  }
@@ -36428,4 +36404,4 @@ const SquidProvider = ({ children, config, placeholder, }) => {
36428
36404
  };
36429
36405
 
36430
36406
  export { useNativeBalance as $, AxelarStatusResponseType as A, useAddressBookStore as B, CHAIN_IDS as C, DEFAULT_LOCALE as D, useAssetsColorsStore as E, useFavoriteTokensStore as F, useHistoryStore as G, HistoryTxType as H, useSendTransactionStore as I, useConfigStore as J, useSquidStore as K, useSwapRoutePersistStore as L, useTransactionStore as M, ConnectingWalletStatus as N, useWalletStore as O, useDepositAddress as P, useSwap as Q, useAllConnectedWalletBalances as R, SquidStatusErrorType as S, TransactionErrorType as T, useAllTokensWithBalanceForChainType as U, useCosmosBalance as V, WindowWalletFlag as W, XamanXrplNetwork as X, useEvmBalance as Y, useMultiChainBalance as Z, useMultipleTokenPrices as _, chainTypeToZeroAddressMap as a, findToken as a$, useNativeTokenForChain as a0, useSingleTokenPrice as a1, useSquidTokens as a2, useHistoricalData as a3, useTokensData as a4, useEstimateSendTransaction as a5, useSendTransaction as a6, useSendTransactionGas as a7, useAllTransactionsStatus as a8, useApproval as a9, useGetFiatQuote as aA, useGetOnRampConfig as aB, useExecuteFiatQuote as aC, useFiatOnRampTxStatus as aD, useFiatTransactions as aE, useCurrencyDetails as aF, useCountryDetails as aG, useAvailableQuotes as aH, useRecommendedQuote as aI, useGetOnrampPaymentTypes as aJ, useSuggestedFiatAmounts as aK, SquidProvider as aL, EnsService as aM, getXummClient as aN, isXamanXAppContext as aO, getQueryHeaders as aP, getStatusCode as aQ, is404Error as aR, assetsBaseUrl as aS, shareSubgraphId as aT, sortTokensBySharedSubgraphIds as aU, getSupportedChainIdsForDirection as aV, filterChains as aW, filterTokens as aX, getTokenImage as aY, getNewSwapParamsFromInput as aZ, sortAllTokens as a_, useEstimate as aa, useEstimatePriceImpact as ab, useExecuteTransaction as ac, useGetRoute as ad, useGetRouteWrapper as ae, useRouteWarnings as af, useSendTransactionStatus as ag, useSwapTransactionStatus as ah, useAvatar as ai, useHistory as aj, useUserParams as ak, useDebouncedValue as al, useAddToken as am, useAutoConnect as an, useEnsDataForAddress as ao, useEnsSearch as ap, useGnosisContext as aq, useIsSameAddressAndGnosisContext as ar, useIntegratorContext as as, useMultiChainWallet as at, useSigner as au, useWallet as av, useWallets as aw, useXrplTrustLine as ax, TX_STATUS_CONSTANTS as ay, FINAL_TRANSACTION_STATUSES as az, destinationAddressResetValue as b, filterSolanaWallets as b$, findNativeToken as b0, normalizeIbcAddress as b1, groupTokensBySymbol as b2, groupTokensByChainId as b3, filterViewableTokens as b4, getSecretNetworkBalances as b5, getTokenAssetsKey as b6, fetchAssetsColors as b7, initializeSquidWithAssetsColors as b8, isEmptyObject as b9, isSwapRouteError as bA, isStatusError as bB, createQuoteRequestParamsHash as bC, WidgetEvents as bD, EvmNetworkNotSupportedErrorCode as bE, addEthereumChain as bF, parseEvmAddress as bG, formatEvmWallet as bH, filterWagmiConnector as bI, waitForReceiptWithRetry as bJ, getUserCountry as bK, getCountryData as bL, getCurrencyData as bM, adaptiveRound as bN, getSuggestedAmountsForCurrency as bO, parseToBigInt as bP, roundNumericValue as bQ, formatUnitsRounded as bR, formatTokenAmount as bS, formatUsdAmount as bT, trimExtraDecimals as bU, getNumericValue as bV, cleanAmount as bW, convertTokenAmountToUSD as bX, convertUSDToTokenAmount as bY, calculateTotal24hChange as bZ, searchTokens as b_, normalizeTokenSymbol as ba, areTokenSymbolsCompatible as bb, isEvmosChain as bc, getConfigWithDefaults as bd, randomIntFromInterval as be, getTokensForChain as bf, getFirstAvailableChainId as bg, fetchHighestBalanceToken as bh, getInitialOrDefaultTokenAddressForChain as bi, getInitialTokenAddressForChain as bj, filterTokensForDestination as bk, getInitialChainIdFromConfig as bl, getCosmosKey as bm, getKeysSettled as bn, getAllKeysForSupportedCosmosChains as bo, isCosmosAddressValid as bp, getCosmosSigningClient as bq, getCosmosChainInfosObject as br, connectCosmosWallet as bs, isFallbackAddressNeeded as bt, suggestChainOrThrow as bu, normalizeError as bv, transactionErrorCode as bw, isUserRejectionError as bx, getTransactionError as by, handleTransactionErrorEvents as bz, chainTypeToNativeTokenAddressMap as c, isSolanaAddressValid as c0, executeSolanaSwap as c1, executeSolanaTransfer as c2, formatTransactionHistoryDate as c3, getAxelarExplorerTxUrl as c4, getSourceExplorerTxUrl as c5, getMainExplorerUrl as c6, formatDistance as c7, formatSeconds as c8, formatSwapTxStatusResponseForStorage as c9, getDefaultChain as cA, sortWallets as cB, areSameAddress as cC, sortAddressBook as cD, calculateTotalUsdBalanceUSD as cE, addTokenToWallet as cF, isEvmChainNotSupportedError as cG, getWalletSupportedChainTypes as cH, getConnectorForChainType as cI, walletSupportsChainType as cJ, connectWallet as cK, cancelConnectWallet as cL, isProblematicConnector as cM, mergeWallets as cN, isXionSmartContractAddress as cO, isXrplAddressValid as cP, buildXrplTrustSetTx as cQ, getXrplNetwork as cR, parseXrplPaymentTx as cS, simplifyRouteAction as ca, fetchSwapTransactionStatus as cb, compareTransactionIds as cc, isCoralBridgeAction as cd, sleep as ce, isDepositRoute as cf, isChainflipBridgeTransaction as cg, getHistoryTransactionId as ch, getStepStatuses as ci, getHalfSuccessState as cj, getStepsInfos as ck, getSwapTxStatusRefetchInterval as cl, getSendTxStatusRefetchInterval as cm, chainflipMultihopBridgeType as cn, getBridgeType as co, getTransactionStatus as cp, getTransactionEndStatus as cq, isHistoryTransactionPending as cr, isHistoryTransactionFailed as cs, isHistoryTransactionWarning as ct, isHistoryTransactionEnded as cu, formatHash as cv, isWalletAddressValid as cw, redirectToExtensionsStore as cx, accessProperty as cy, populateWallets as cz, definedInWindow as d, fallbackAddressResetValue as e, formatBNToReadable as f, nativeCosmosTokenAddress as g, nativeEvmTokenAddress as h, nativeSolanaTokenAddress as i, nativeStellarTokenAddress as j, nativeSuiTokenAddress as k, nativeXrplTokenAddress as l, CosmosProvider as m, nativeBitcoinTokenAddress as n, SendTransactionStatus as o, TransactionStatus as p, useTrackSearchEmpty as q, useSquidChains as r, useClient as s, useCosmosForChain as t, useCosmosContext as u, useKeyboardNavigation as v, walletIconBaseUrl as w, useSquidQueryClient as x, useSquid as y, useStellarAccountActivation as z };
36431
- //# sourceMappingURL=index-B402hKhN.js.map
36407
+ //# sourceMappingURL=index-Bbnh4iOc.js.map