@0xsquid/react-hooks 8.0.1-tanstack-v5-beta.0 → 8.0.2

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.
Files changed (42) hide show
  1. package/dist/core/types/event.d.ts +17 -8
  2. package/dist/hooks/navigation/useKeyboardNavigation.d.ts +1 -4
  3. package/dist/hooks/onramp/useFiatToCrypto.d.ts +28 -6
  4. package/dist/hooks/squid/useSquid.d.ts +2 -2
  5. package/dist/hooks/swap/useDepositAddress.d.ts +2 -2
  6. package/dist/hooks/tokens/useAllConnectedWalletBalances.d.ts +11 -5
  7. package/dist/hooks/tokens/useAllTokensWithBalanceForChainType.d.ts +1 -1
  8. package/dist/hooks/tokens/useBalance.d.ts +1 -1
  9. package/dist/hooks/tokens/useMultipleTokenPrices.d.ts +2 -2
  10. package/dist/hooks/tokens/useNativeBalance.d.ts +2 -2
  11. package/dist/hooks/tokens/useTokenHistoricalData.d.ts +4 -4
  12. package/dist/hooks/transaction/send/useEstimateSendTransactionGas.d.ts +1 -1
  13. package/dist/hooks/transaction/send/useSendTransactionGas.d.ts +1 -1
  14. package/dist/hooks/transaction/useAllTransactionsStatus.d.ts +29 -3
  15. package/dist/hooks/transaction/useApproval.d.ts +2 -2
  16. package/dist/hooks/transaction/useExecuteTransaction.d.ts +2 -2
  17. package/dist/hooks/transaction/useGetRoute.d.ts +7 -7
  18. package/dist/hooks/transaction/useSwapTransactionStatus.d.ts +1 -1
  19. package/dist/hooks/wallet/useAddToken.d.ts +1 -1
  20. package/dist/hooks/wallet/useEns.d.ts +2 -2
  21. package/dist/hooks/wallet/useMultiChainWallet.d.ts +1 -1
  22. package/dist/hooks/wallet/useWallet.d.ts +1 -1
  23. package/dist/hooks/xrpl/useXrplTrustLine.d.ts +5 -5
  24. package/dist/{index-BA79s7uI.js → index-BKmIOD3t.js} +988 -1015
  25. package/dist/index-BKmIOD3t.js.map +1 -0
  26. package/dist/{index-CS74WzWX.js → index-BjIFR_GS.js} +989 -1013
  27. package/dist/index-BjIFR_GS.js.map +1 -0
  28. package/dist/index.esm.js +1 -1
  29. package/dist/index.js +4 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/{secretService-D3MB_TMv.js → secretService-C2TxPa-m.js} +2 -2
  32. package/dist/{secretService-D3MB_TMv.js.map → secretService-C2TxPa-m.js.map} +1 -1
  33. package/dist/{secretService-U8WiVPay.js → secretService-DT8cWLsm.js} +2 -2
  34. package/dist/{secretService-U8WiVPay.js.map → secretService-DT8cWLsm.js.map} +1 -1
  35. package/dist/services/internal/eventService.d.ts +1 -0
  36. package/dist/{stellarService.client-BUdrOP04.js → stellarService.client-DH1Yp2nE.js} +2 -2
  37. package/dist/{stellarService.client-BUdrOP04.js.map → stellarService.client-DH1Yp2nE.js.map} +1 -1
  38. package/dist/{stellarService.client-Dp4tvmUo.js → stellarService.client-deOQBP3h.js} +2 -2
  39. package/dist/{stellarService.client-Dp4tvmUo.js.map → stellarService.client-deOQBP3h.js.map} +1 -1
  40. package/package.json +12 -12
  41. package/dist/index-BA79s7uI.js.map +0 -1
  42. package/dist/index-CS74WzWX.js.map +0 -1
@@ -4002,6 +4002,20 @@ class WidgetEvents extends EventTarget {
4002
4002
  constructor() {
4003
4003
  super();
4004
4004
  }
4005
+ getRouteEventPayload = (route, txHash) => {
4006
+ const { fromAddress, toAddress, fromChain, toChain, fromToken, toToken, fromAmount, } = route.params;
4007
+ return {
4008
+ fromAddress,
4009
+ toAddress,
4010
+ fromChain,
4011
+ toChain,
4012
+ fromToken,
4013
+ toToken,
4014
+ fromAmount,
4015
+ quoteId: route.quoteId,
4016
+ txHash,
4017
+ };
4018
+ };
4005
4019
  // Singleton, because we need to access this service outside the widget
4006
4020
  static getInstance() {
4007
4021
  if (!WidgetEvents.instance) {
@@ -4052,7 +4066,7 @@ class WidgetEvents extends EventTarget {
4052
4066
  * @param route
4053
4067
  */
4054
4068
  dispatchSwapExecuteCall(route, txHash) {
4055
- this.dispatch("swap", { route, txHash });
4069
+ this.dispatch("swap", this.getRouteEventPayload(route, txHash));
4056
4070
  }
4057
4071
  /**
4058
4072
  * Dispatch event when user changes chain/token
@@ -4131,7 +4145,18 @@ class WidgetEvents extends EventTarget {
4131
4145
  * @param data Quote execution parameters
4132
4146
  */
4133
4147
  dispatchOnrampQuoteExecute(data) {
4134
- this.dispatch("onrampQuoteExecute", data);
4148
+ this.dispatch("onrampQuoteExecute", {
4149
+ tokenAddress: data.squidToken?.address,
4150
+ tokenChainId: data.squidToken?.chainId,
4151
+ amount: data.cryptoAmount,
4152
+ paymentMethod: data.paymentMethod,
4153
+ walletAddress: data.walletAddress,
4154
+ orderId: data.orderId,
4155
+ fiatCurrency: data.fiatCurrency,
4156
+ cryptoCurrencyID: data.cryptoCurrencyID,
4157
+ region: data.region,
4158
+ onrampProviderId: data.onrampProviderId,
4159
+ });
4135
4160
  }
4136
4161
  /**
4137
4162
  * Dispatch event when the search query has no results
@@ -26816,9 +26841,7 @@ const fetchHighestBalanceToken = (fetchCachedBalance, chainId) => {
26816
26841
  if (fetchCachedBalance) {
26817
26842
  const queryCache = fetchCachedBalance?.queryClient?.getQueryCache();
26818
26843
  // get cached balance from key
26819
- const cache = queryCache?.find({
26820
- queryKey: keys().allTokensBalance(fetchCachedBalance?.address, !isNaN(Number(chainId)) ? squidTypes.ChainType.EVM : squidTypes.ChainType.COSMOS),
26821
- });
26844
+ const cache = queryCache?.find(keys().allTokensBalance(fetchCachedBalance?.address, !isNaN(Number(chainId)) ? squidTypes.ChainType.EVM : squidTypes.ChainType.COSMOS));
26822
26845
  // Parse result to TokenWithBalance[]
26823
26846
  const cacheResult = cache?.state.data ?? [];
26824
26847
  if (cacheResult.length > 0) {
@@ -27474,7 +27497,7 @@ const filterViewableTokens = (tokens, config, direction) => {
27474
27497
  };
27475
27498
  const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
27476
27499
  const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
27477
- const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-U8WiVPay.js'); });
27500
+ const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-DT8cWLsm.js'); });
27478
27501
  return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
27479
27502
  };
27480
27503
  function getTokenAssetsKey(token) {
@@ -29233,16 +29256,13 @@ const useSquid = () => {
29233
29256
  * Fetch squid info
29234
29257
  * Will refetch every minute
29235
29258
  */
29236
- const squidInfoQuery = reactQuery.useQuery({
29237
- queryKey: keys().squidInfo(),
29238
- queryFn: async () => {
29239
- if (squid) {
29240
- await squid?.init();
29241
- initializeSquidWithAssetsColors(squid, assetsColors);
29242
- return squid;
29243
- }
29244
- return null;
29259
+ const squidInfoQuery = reactQuery.useQuery(keys().squidInfo(), async () => {
29260
+ if (squid) {
29261
+ await squid?.init();
29262
+ initializeSquidWithAssetsColors(squid, assetsColors);
29263
+ return squid;
29245
29264
  }
29265
+ return null;
29246
29266
  });
29247
29267
  const tokens = React.useMemo(() => {
29248
29268
  if ((squidInfoQuery?.data?.tokens ?? []).length > 0) {
@@ -29358,11 +29378,47 @@ const FINAL_TRANSACTION_STATUSES = [
29358
29378
  "completed",
29359
29379
  "failed",
29360
29380
  ];
29381
+ /**
29382
+ * Configuration for transaction status tracking
29383
+ */
29384
+ const createTransactionStatusConfig = ({ transactionId, walletAddress, providerId, replaceTransactionStatus, }) => {
29385
+ return {
29386
+ queryKey: keys().fiatToCryptoStatus(transactionId),
29387
+ queryFn: () => new OnrampService().getTransactionStatus(transactionId, walletAddress, providerId),
29388
+ enabled: !!transactionId && !!walletAddress && !!providerId,
29389
+ retry: TX_STATUS_CONSTANTS.RETRY_COUNT,
29390
+ retryDelay: TX_STATUS_CONSTANTS.RETRY_DELAY,
29391
+ refetchInterval: (data) => {
29392
+ if (data?.status && FINAL_TRANSACTION_STATUSES.includes(data.status)) {
29393
+ return false;
29394
+ }
29395
+ return TX_STATUS_CONSTANTS.REFETCH_INTERVAL;
29396
+ },
29397
+ onSuccess: (data) => {
29398
+ if (data) {
29399
+ replaceTransactionStatus({
29400
+ txType: exports.HistoryTxType.BUY,
29401
+ orderId: transactionId,
29402
+ status: data.status,
29403
+ transactionHash: data.transactionHash,
29404
+ });
29405
+ }
29406
+ },
29407
+ onError: () => {
29408
+ replaceTransactionStatus({
29409
+ txType: exports.HistoryTxType.BUY,
29410
+ orderId: transactionId,
29411
+ status: "failed",
29412
+ transactionHash: undefined,
29413
+ });
29414
+ },
29415
+ };
29416
+ };
29361
29417
  /**
29362
29418
  * Fetches quotes for fiat to crypto conversion with provider details.
29363
29419
  * Returns available rates, fees, and supported payment methods for the conversion.
29364
29420
  */
29365
- const useGetFiatQuote = ({ fiatCurrency, cryptoCurrencyID, amount, region, paymentMethod, enabled = true, }) => {
29421
+ const useGetFiatQuote = ({ fiatCurrency, cryptoCurrencyID, amount, region, paymentMethod, enabled = true, onSuccess, }) => {
29366
29422
  const service = React.useMemo(() => new OnrampService(), []);
29367
29423
  const { data: config } = useGetOnRampConfig();
29368
29424
  return reactQuery.useQuery({
@@ -29398,6 +29454,7 @@ const useGetFiatQuote = ({ fiatCurrency, cryptoCurrencyID, amount, region, payme
29398
29454
  return quoteResponse;
29399
29455
  },
29400
29456
  enabled: enabled && !!fiatCurrency && !!cryptoCurrencyID && amount > 0,
29457
+ onSuccess,
29401
29458
  });
29402
29459
  };
29403
29460
  /**
@@ -29414,7 +29471,7 @@ const useGetOnRampConfig = () => {
29414
29471
  chains,
29415
29472
  tokens,
29416
29473
  }),
29417
- gcTime: 1000 * 60 * 60,
29474
+ cacheTime: 1000 * 60 * 60,
29418
29475
  staleTime: 1000 * 60 * 30, // 30 minutes
29419
29476
  });
29420
29477
  };
@@ -29472,11 +29529,49 @@ const useExecuteFiatQuote = () => {
29472
29529
  },
29473
29530
  });
29474
29531
  };
29532
+ /**
29533
+ * Tracks the status of a single fiat to crypto transaction.
29534
+ */
29535
+ const useFiatOnRampTxStatus = (transactionId, walletAddress, providerId) => {
29536
+ const replaceTransactionStatus = useHistoryStore((state) => state.replaceTransactionStatus);
29537
+ return reactQuery.useQuery({
29538
+ ...createTransactionStatusConfig({
29539
+ transactionId,
29540
+ walletAddress,
29541
+ providerId,
29542
+ replaceTransactionStatus,
29543
+ }),
29544
+ });
29545
+ };
29546
+ /**
29547
+ * Tracks all pending fiat transactions.
29548
+ */
29549
+ const useFiatTransactions = () => {
29550
+ const transactions = useHistoryStore((state) => state.transactions.filter((tx) => tx.txType === exports.HistoryTxType.BUY));
29551
+ const replaceTransactionStatus = useHistoryStore((state) => state.replaceTransactionStatus);
29552
+ const pendingTransactions = React.useMemo(() => transactions?.filter((tx) => !FINAL_TRANSACTION_STATUSES.includes(tx.data.status)) ?? [], [transactions]);
29553
+ const queries = reactQuery.useQueries({
29554
+ queries: pendingTransactions.map((tx) => ({
29555
+ ...createTransactionStatusConfig({
29556
+ transactionId: tx.data.orderId,
29557
+ walletAddress: tx.data.toAddress,
29558
+ providerId: tx.data.providerId,
29559
+ replaceTransactionStatus,
29560
+ }),
29561
+ })),
29562
+ });
29563
+ return {
29564
+ transactions: transactions.map((tx) => tx.data),
29565
+ isLoading: queries.some((q) => q.isLoading),
29566
+ isError: queries.some((q) => q.isError),
29567
+ };
29568
+ };
29475
29569
  /**
29476
29570
  * Gets currency details including symbol and limits.
29477
29571
  * Example: USD → { symbol: "$", name: "US Dollar", ... }
29478
29572
  */
29479
29573
  const useCurrencyDetails = (currencyCode) => {
29574
+ const { data: config } = useGetOnRampConfig();
29480
29575
  return React.useMemo(() => {
29481
29576
  if (!currencyCode)
29482
29577
  return undefined;
@@ -29489,7 +29584,7 @@ const useCurrencyDetails = (currencyCode) => {
29489
29584
  };
29490
29585
  }
29491
29586
  return undefined;
29492
- }, [currencyCode]);
29587
+ }, [currencyCode, config?.supportedFiats]);
29493
29588
  };
29494
29589
  /**
29495
29590
  * Gets country details with flag URL and localized name.
@@ -29516,6 +29611,23 @@ const useAvailableQuotes = (quotes) => {
29516
29611
  return uniqueQuotes;
29517
29612
  }, [quotes]);
29518
29613
  };
29614
+ /**
29615
+ * Gets the recommended quote based on best rates or provider preferences.
29616
+ * Falls back to first available quote if no specific recommendation.
29617
+ */
29618
+ const useRecommendedQuote = (quotes, recommendedQuote) => {
29619
+ const availableQuotes = useAvailableQuotes(quotes);
29620
+ return React.useMemo(() => {
29621
+ if (!availableQuotes.length)
29622
+ return undefined;
29623
+ if (!recommendedQuote)
29624
+ return availableQuotes[0];
29625
+ // Try to find the recommended quote among available quotes
29626
+ const recommendedAvailableQuote = availableQuotes.find((quote) => quote.onrampProviderId === recommendedQuote.onrampProviderId);
29627
+ // If recommended quote is not available, return first available quote
29628
+ return recommendedAvailableQuote ?? availableQuotes[0];
29629
+ }, [availableQuotes, recommendedQuote]);
29630
+ };
29519
29631
  /**
29520
29632
  * Fetches the available payment methods for a given fiat and crypto currency pair.
29521
29633
  * The first item in the returned array is the most recommended.
@@ -29618,7 +29730,7 @@ const middleStepChecker = (statusResponse) => {
29618
29730
  }
29619
29731
  return exports.TransactionStatus.ERROR;
29620
29732
  }
29621
- if (statusResponse?.isLoading) {
29733
+ if (statusResponse?.isInitialLoading) {
29622
29734
  return exports.TransactionStatus.INITIAL_LOADING;
29623
29735
  }
29624
29736
  return exports.TransactionStatus.ONGOING;
@@ -30063,7 +30175,7 @@ const useClient = () => {
30063
30175
  queryFn: getUserCountry,
30064
30176
  enabled: isClient,
30065
30177
  retry: false,
30066
- gcTime: CACHE_TIME,
30178
+ cacheTime: CACHE_TIME,
30067
30179
  staleTime: STALE_TIME,
30068
30180
  });
30069
30181
  const userCountry = countryData?.countryCode || DEFAULT_COUNTRY_CODE;
@@ -30164,13 +30276,11 @@ function useDebouncedValue(value, delay) {
30164
30276
  * @returns the ENS data of the given address
30165
30277
  */
30166
30278
  function useEnsDataForAddress({ address, options, }) {
30167
- const ensQuery = reactQuery.useQuery({
30168
- queryKey: keys().ensData(address?.toLowerCase()),
30169
- queryFn: () => EnsService.getEnsDataFromAddress(address),
30279
+ const ensQuery = reactQuery.useQuery(keys().ensData(address?.toLowerCase()), () => EnsService.getEnsDataFromAddress(address), {
30170
30280
  ...options,
30171
30281
  enabled: Boolean(address?.trim()) &&
30172
30282
  (options?.enabled === undefined ? true : options.enabled),
30173
- gcTime: Infinity,
30283
+ cacheTime: Infinity,
30174
30284
  });
30175
30285
  return ensQuery;
30176
30286
  }
@@ -30186,16 +30296,14 @@ function useEnsDataForAddress({ address, options, }) {
30186
30296
  */
30187
30297
  function useEnsSearch({ name, enabled = true, delayMs = 500, }) {
30188
30298
  const debouncedName = useDebouncedValue(enabled ? name : undefined, delayMs);
30189
- const ensSearchQuery = reactQuery.useQuery({
30190
- queryKey: keys().ensSearch(debouncedName),
30191
- queryFn: () => {
30192
- const isExactEnsSearch = checkIsExactEns(debouncedName);
30193
- return isExactEnsSearch
30194
- ? EnsService.getExactEns(debouncedName)
30195
- : EnsService.searchEnsNames(debouncedName);
30196
- },
30299
+ const ensSearchQuery = reactQuery.useQuery(keys().ensSearch(debouncedName), () => {
30300
+ const isExactEnsSearch = checkIsExactEns(debouncedName);
30301
+ return isExactEnsSearch
30302
+ ? EnsService.getExactEns(debouncedName)
30303
+ : EnsService.searchEnsNames(debouncedName);
30304
+ }, {
30197
30305
  enabled: Boolean(debouncedName?.trim()) && enabled,
30198
- gcTime: Infinity,
30306
+ cacheTime: Infinity,
30199
30307
  });
30200
30308
  return ensSearchQuery;
30201
30309
  }
@@ -30216,25 +30324,23 @@ function checkIsExactEns(name = "") {
30216
30324
 
30217
30325
  const useCosmosForChain = (chain) => {
30218
30326
  const { keplrTypeWallet } = useCosmosSigner({ chain });
30219
- const cosmosAddressQuery = reactQuery.useQuery({
30220
- queryKey: keys().cosmosAddress(chain?.chainId),
30221
- queryFn: async () => {
30222
- if (!chain || !keplrTypeWallet)
30223
- return "";
30224
- try {
30225
- const address = await getCosmosKey(chain.chainId, keplrTypeWallet);
30226
- return address ?? "";
30227
- }
30228
- catch (error) {
30229
- await suggestChainOrThrow({
30230
- chain: chain,
30231
- error,
30232
- keplrTypeWallet,
30233
- });
30234
- const address = await getCosmosKey(chain.chainId, keplrTypeWallet);
30235
- return address ?? "";
30236
- }
30237
- },
30327
+ const cosmosAddressQuery = reactQuery.useQuery(keys().cosmosAddress(chain?.chainId), async () => {
30328
+ if (!chain || !keplrTypeWallet)
30329
+ return "";
30330
+ try {
30331
+ const address = await getCosmosKey(chain.chainId, keplrTypeWallet);
30332
+ return address ?? "";
30333
+ }
30334
+ catch (error) {
30335
+ await suggestChainOrThrow({
30336
+ chain: chain,
30337
+ error,
30338
+ keplrTypeWallet,
30339
+ });
30340
+ const address = await getCosmosKey(chain.chainId, keplrTypeWallet);
30341
+ return address ?? "";
30342
+ }
30343
+ }, {
30238
30344
  enabled: !!keplrTypeWallet && chain?.chainType === squidTypes.ChainType.COSMOS,
30239
30345
  });
30240
30346
  return cosmosAddressQuery;
@@ -30311,14 +30417,12 @@ const useIsSameAddressAndGnosisContext = () => {
30311
30417
 
30312
30418
  function useBitcoin() {
30313
30419
  const connectedBitcoinWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.BTC]);
30314
- const connectBitcoin = reactQuery.useMutation({
30315
- mutationFn: async ({ wallet, }) => {
30316
- const { address } = await wallet.connector.requestAccount();
30317
- return {
30318
- wallet,
30319
- address,
30320
- };
30321
- }
30420
+ const connectBitcoin = reactQuery.useMutation(async ({ wallet, }) => {
30421
+ const { address } = await wallet.connector.requestAccount();
30422
+ return {
30423
+ wallet,
30424
+ address,
30425
+ };
30322
30426
  });
30323
30427
  return {
30324
30428
  connectBitcoin,
@@ -30358,17 +30462,15 @@ function useEvm() {
30358
30462
  const { wallets } = useEvmWallets();
30359
30463
  const connectedEvmWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.EVM]);
30360
30464
  const recentEvmWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.EVM]);
30361
- const connectEvm = reactQuery.useMutation({
30362
- mutationFn: async ({ wallet, }) => {
30363
- const result = await connectAsync({
30364
- connector: wallet.connector,
30365
- });
30366
- const [firstAddress] = result.accounts;
30367
- return {
30368
- wallet,
30369
- address: firstAddress,
30370
- };
30371
- }
30465
+ const connectEvm = reactQuery.useMutation(async ({ wallet, }) => {
30466
+ const result = await connectAsync({
30467
+ connector: wallet.connector,
30468
+ });
30469
+ const [firstAddress] = result.accounts;
30470
+ return {
30471
+ wallet,
30472
+ address: firstAddress,
30473
+ };
30372
30474
  });
30373
30475
  const disconnectEvm = React.useCallback(async () => {
30374
30476
  disconnect({ connector: connectedEvmWallet.wallet?.connector });
@@ -30462,23 +30564,21 @@ function useSolana() {
30462
30564
  const { wallets } = useSolanaWallets();
30463
30565
  const connectedSolanaWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.SOLANA]);
30464
30566
  const recentSolanaWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.SOLANA]);
30465
- const connectSolana = reactQuery.useMutation({
30466
- mutationFn: async ({ wallet, }) => {
30467
- try {
30468
- // try to connect silently first
30469
- await wallet.connector.autoConnect();
30470
- }
30471
- catch {
30472
- // if auto-connect fails (e.g. not authorized yet)
30473
- // fallback to connect via popup
30474
- await wallet.connector.connect();
30475
- }
30476
- const address = wallet.connector.wallet.accounts[0].address;
30477
- return {
30478
- wallet,
30479
- address,
30480
- };
30567
+ const connectSolana = reactQuery.useMutation(async ({ wallet, }) => {
30568
+ try {
30569
+ // try to connect silently first
30570
+ await wallet.connector.autoConnect();
30571
+ }
30572
+ catch {
30573
+ // if auto-connect fails (e.g. not authorized yet)
30574
+ // fallback to connect via popup
30575
+ await wallet.connector.connect();
30481
30576
  }
30577
+ const address = wallet.connector.wallet.accounts[0].address;
30578
+ return {
30579
+ wallet,
30580
+ address,
30581
+ };
30482
30582
  });
30483
30583
  const disconnectSolana = React.useCallback(async () => {
30484
30584
  await connectedSolanaWallet.wallet?.connector.disconnect();
@@ -30553,7 +30653,7 @@ function useStellarWallets() {
30553
30653
  return;
30554
30654
  try {
30555
30655
  const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
30556
- const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-BUdrOP04.js'); });
30656
+ const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-DH1Yp2nE.js'); });
30557
30657
  const modules = initializeAllModules();
30558
30658
  const promises = modules.map(async (module) => {
30559
30659
  const isAvailable = await module.isAvailable();
@@ -30581,14 +30681,12 @@ function useStellarWallets() {
30581
30681
  function useStellar() {
30582
30682
  const { wallets } = useStellarWallets();
30583
30683
  const connectedStellarWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.STELLAR]);
30584
- const connectStellar = reactQuery.useMutation({
30585
- mutationFn: async ({ wallet, }) => {
30586
- const { address } = await wallet.connector.getAddress();
30587
- return {
30588
- wallet,
30589
- address,
30590
- };
30591
- }
30684
+ const connectStellar = reactQuery.useMutation(async ({ wallet, }) => {
30685
+ const { address } = await wallet.connector.getAddress();
30686
+ return {
30687
+ wallet,
30688
+ address,
30689
+ };
30592
30690
  });
30593
30691
  const disconnectStellar = React.useCallback(async () => {
30594
30692
  await connectedStellarWallet.wallet?.connector.disconnect?.();
@@ -30640,24 +30738,22 @@ function useSui() {
30640
30738
  const recentSuiWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.SUI]);
30641
30739
  const setConnectedWallet = useWalletStore((store) => store.setConnectedWallet);
30642
30740
  const disconnectWallet = useWalletStore((store) => store.disconnectWallet);
30643
- const connectSui = reactQuery.useMutation({
30644
- mutationFn: async ({ wallet, }) => {
30645
- let account;
30646
- try {
30647
- // try to connect silently first
30648
- account = await wallet.connector.connect({ silent: true });
30649
- }
30650
- catch {
30651
- // if auto-connect fails (e.g. not authorized yet)
30652
- // fallback to connect via popup
30653
- account = await wallet.connector.connect();
30654
- }
30655
- return {
30656
- wallet,
30657
- address: account.account.address,
30658
- account: account.account,
30659
- };
30741
+ const connectSui = reactQuery.useMutation(async ({ wallet, }) => {
30742
+ let account;
30743
+ try {
30744
+ // try to connect silently first
30745
+ account = await wallet.connector.connect({ silent: true });
30660
30746
  }
30747
+ catch {
30748
+ // if auto-connect fails (e.g. not authorized yet)
30749
+ // fallback to connect via popup
30750
+ account = await wallet.connector.connect();
30751
+ }
30752
+ return {
30753
+ wallet,
30754
+ address: account.account.address,
30755
+ account: account.account,
30756
+ };
30661
30757
  });
30662
30758
  const disconnectSui = React.useCallback(async () => {
30663
30759
  await connectedSuiWallet.wallet?.connector.disconnect();
@@ -30966,14 +31062,12 @@ function useXrpl() {
30966
31062
  const recentXrplWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.XRPL]);
30967
31063
  const setConnectedWallet = useWalletStore((store) => store.setConnectedWallet);
30968
31064
  const disconnectWallet = useWalletStore((store) => store.disconnectWallet);
30969
- const connectXrpl = reactQuery.useMutation({
30970
- mutationFn: async ({ wallet, }) => {
30971
- const xrplConnectedAddress = await wallet.connector.connect();
30972
- return {
30973
- wallet,
30974
- address: xrplConnectedAddress,
30975
- };
30976
- }
31065
+ const connectXrpl = reactQuery.useMutation(async ({ wallet, }) => {
31066
+ const xrplConnectedAddress = await wallet.connector.connect();
31067
+ return {
31068
+ wallet,
31069
+ address: xrplConnectedAddress,
31070
+ };
30977
31071
  });
30978
31072
  const disconnectXrpl = React.useCallback(async () => {
30979
31073
  await connectedXrplWallet?.wallet?.connector.disconnect?.();
@@ -31360,19 +31454,18 @@ const useMultiChainWallet = (chain) => {
31360
31454
  /**
31361
31455
  * Change current network for desired chain
31362
31456
  */
31363
- const changeNetworkIfNeeded = reactQuery.useMutation({
31364
- mutationFn: async () => {
31365
- const isNotOnDesiredChain = chain?.chainType === squidTypes.ChainType.EVM &&
31366
- currentEvmChain?.id !== Number(chain.chainId);
31367
- if (isNotOnDesiredChain) {
31368
- await switchChainAsync({
31369
- chainId: Number(chain.chainId),
31370
- });
31371
- }
31372
- // Implement keplr change network
31373
- // Looks like there are no method to do that at the moment
31374
- return false;
31375
- },
31457
+ const changeNetworkIfNeeded = reactQuery.useMutation(async () => {
31458
+ const isNotOnDesiredChain = chain?.chainType === squidTypes.ChainType.EVM &&
31459
+ currentEvmChain?.id !== Number(chain.chainId);
31460
+ if (isNotOnDesiredChain) {
31461
+ await switchChainAsync({
31462
+ chainId: Number(chain.chainId),
31463
+ });
31464
+ }
31465
+ // Implement keplr change network
31466
+ // Looks like there are no method to do that at the moment
31467
+ return false;
31468
+ }, {
31376
31469
  onError: async (error) => {
31377
31470
  if (error instanceof viem.UserRejectedRequestError) {
31378
31471
  return;
@@ -31384,7 +31477,7 @@ const useMultiChainWallet = (chain) => {
31384
31477
  provider,
31385
31478
  });
31386
31479
  }
31387
- }
31480
+ },
31388
31481
  });
31389
31482
  const isChainTypeConnected = React.useCallback((chainType) => {
31390
31483
  if (isGnosisConnected && chainType === squidTypes.ChainType.EVM) {
@@ -31732,53 +31825,51 @@ const useCosmos = () => {
31732
31825
  clientWindow?.removeEventListener("keplr_keystorechange", () => handleKeplrAccountChanged());
31733
31826
  };
31734
31827
  }, [handleKeplrAccountChanged, clientWindow]);
31735
- const connectCosmos = reactQuery.useMutation({
31736
- mutationFn: async ({ chain, wallet, approveAllChains = true, }) => {
31737
- const chainInfos = getCosmosChainInfosObject(chain);
31738
- const cosmosWalletObject = wallet.connector().provider;
31739
- if (cosmosWalletObject) {
31740
- setCosmosChainId(chainInfos.chainId.toString());
31741
- try {
31742
- if (approveAllChains &&
31743
- typeof cosmosWalletObject.getChainInfosWithoutEndpoints ===
31744
- "function") {
31745
- try {
31746
- const addedChains = await cosmosWalletObject.getChainInfosWithoutEndpoints();
31747
- const addedChainIds = addedChains?.map((addedChain) => addedChain.chainId);
31748
- const chainsToEnable = cosmosChains
31749
- .filter((c) => addedChainIds?.includes(c.chainId.toString()))
31750
- .map((c) => c.chainId.toString());
31751
- await cosmosWalletObject.enable(chainsToEnable);
31752
- }
31753
- catch (error) {
31754
- console.warn("Failed to get chain infos, falling back to single chain enable", error);
31755
- await cosmosWalletObject.enable(chainInfos.chainId);
31756
- }
31828
+ const connectCosmos = reactQuery.useMutation(async ({ chain, wallet, approveAllChains = true, }) => {
31829
+ const chainInfos = getCosmosChainInfosObject(chain);
31830
+ const cosmosWalletObject = wallet.connector().provider;
31831
+ if (cosmosWalletObject) {
31832
+ setCosmosChainId(chainInfos.chainId.toString());
31833
+ try {
31834
+ if (approveAllChains &&
31835
+ typeof cosmosWalletObject.getChainInfosWithoutEndpoints ===
31836
+ "function") {
31837
+ try {
31838
+ const addedChains = await cosmosWalletObject.getChainInfosWithoutEndpoints();
31839
+ const addedChainIds = addedChains?.map((addedChain) => addedChain.chainId);
31840
+ const chainsToEnable = cosmosChains
31841
+ .filter((c) => addedChainIds?.includes(c.chainId.toString()))
31842
+ .map((c) => c.chainId.toString());
31843
+ await cosmosWalletObject.enable(chainsToEnable);
31757
31844
  }
31758
- else {
31845
+ catch (error) {
31846
+ console.warn("Failed to get chain infos, falling back to single chain enable", error);
31759
31847
  await cosmosWalletObject.enable(chainInfos.chainId);
31760
31848
  }
31761
- const address = await getAddress({
31762
- chainId: chain.chainId.toString(),
31763
- cosmosWalletObject,
31764
- wallet,
31765
- });
31766
- if (address) {
31767
- updateWalletStore(wallet, cosmosWalletObject, address);
31768
- return address;
31769
- }
31770
31849
  }
31771
- catch (error) {
31772
- await suggestChainOrThrow({
31773
- chain,
31774
- error,
31775
- keplrTypeWallet: cosmosWalletObject,
31776
- });
31777
- return connectCosmos.mutateAsync({ chain, wallet });
31850
+ else {
31851
+ await cosmosWalletObject.enable(chainInfos.chainId);
31852
+ }
31853
+ const address = await getAddress({
31854
+ chainId: chain.chainId.toString(),
31855
+ cosmosWalletObject,
31856
+ wallet,
31857
+ });
31858
+ if (address) {
31859
+ updateWalletStore(wallet, cosmosWalletObject, address);
31860
+ return address;
31778
31861
  }
31779
31862
  }
31780
- return undefined;
31863
+ catch (error) {
31864
+ await suggestChainOrThrow({
31865
+ chain,
31866
+ error,
31867
+ keplrTypeWallet: cosmosWalletObject,
31868
+ });
31869
+ return connectCosmos.mutateAsync({ chain, wallet });
31870
+ }
31781
31871
  }
31872
+ return undefined;
31782
31873
  });
31783
31874
  const clearData = () => {
31784
31875
  disconnectWallet(squidTypes.ChainType.COSMOS);
@@ -31862,64 +31953,13 @@ function useTrackSearchEmpty({ searchQuery, resultsLength, context, debounceMs =
31862
31953
  }, [context, debounceMs, resultsLength, searchQuery]);
31863
31954
  }
31864
31955
 
31865
- const useKeyboardNavigation = (props) => {
31866
- const { itemsListRef, activeListItemClassName = "", onEscape } = props ?? {};
31956
+ const useKeyboardNavigation = ({ onEscape }) => {
31867
31957
  const onKeyDown = React.useCallback((event) => {
31868
31958
  if (event.key === "Escape") {
31869
31959
  onEscape?.();
31870
31960
  return;
31871
31961
  }
31872
- if (activeListItemClassName.trim() === "")
31873
- return;
31874
- const itemsList = itemsListRef?.current;
31875
- const separatedActiveItemClassNames = activeListItemClassName.split(" ");
31876
- const defaultActiveItem = itemsList?.querySelector(`.${separatedActiveItemClassNames.join(".")}`);
31877
- if (event.key === "ArrowUp") {
31878
- if (!itemsList)
31879
- return;
31880
- event.preventDefault();
31881
- const activeItem = defaultActiveItem ?? itemsList.lastElementChild;
31882
- if (!activeItem)
31883
- return;
31884
- const previousItem = activeItem.previousElementSibling;
31885
- if (previousItem) {
31886
- activeItem.classList.remove(...separatedActiveItemClassNames);
31887
- previousItem.classList.add(...separatedActiveItemClassNames);
31888
- // scroll to previous item
31889
- itemsList.scrollTo({
31890
- top: (previousItem.offsetTop ?? 0) -
31891
- itemsList.clientHeight,
31892
- behavior: "smooth",
31893
- });
31894
- }
31895
- }
31896
- else if (event.key === "ArrowDown") {
31897
- if (!itemsList)
31898
- return;
31899
- event.preventDefault();
31900
- const activeItem = defaultActiveItem ?? itemsList.firstElementChild;
31901
- if (!activeItem)
31902
- return;
31903
- const nextItem = activeItem.nextElementSibling;
31904
- if (nextItem) {
31905
- activeItem.classList.remove(...separatedActiveItemClassNames);
31906
- nextItem.classList.add(...separatedActiveItemClassNames);
31907
- // scroll to next item
31908
- itemsList.scrollTo({
31909
- top: (nextItem.offsetTop ?? 0) -
31910
- itemsList.clientHeight,
31911
- behavior: "smooth",
31912
- });
31913
- }
31914
- }
31915
- else if (event.key === "Enter") {
31916
- event.preventDefault();
31917
- if (defaultActiveItem) {
31918
- // select active item
31919
- defaultActiveItem.querySelector("button")?.click();
31920
- }
31921
- }
31922
- }, [itemsListRef, activeListItemClassName]);
31962
+ }, [onEscape]);
31923
31963
  React.useEffect(() => {
31924
31964
  document.addEventListener("keydown", onKeyDown, false);
31925
31965
  return () => {
@@ -31932,11 +31972,11 @@ const useSquidQueryClient = () => {
31932
31972
  const queryClient = reactQuery.useQueryClient();
31933
31973
  const invalidateQueries = (key) => {
31934
31974
  const prefixKey = getPrefixKey(key);
31935
- queryClient.invalidateQueries({ queryKey: prefixKey });
31975
+ queryClient.invalidateQueries(prefixKey);
31936
31976
  };
31937
31977
  const refetchQueries = (key) => {
31938
31978
  const prefixKey = getPrefixKey(key);
31939
- queryClient.refetchQueries({ queryKey: prefixKey });
31979
+ queryClient.refetchQueries(prefixKey);
31940
31980
  };
31941
31981
  const invalidateAndRefetchQueries = (key) => {
31942
31982
  invalidateQueries(key);
@@ -33443,19 +33483,17 @@ function useDepositAddress(squidRoute) {
33443
33483
  toggleDepositFlow(false);
33444
33484
  setDeposit(null);
33445
33485
  }, [toggleDepositFlow, setDeposit]);
33446
- const getRouteWithDeposit = reactQuery.useMutation({
33447
- mutationFn: async ({ route }) => {
33448
- if (!squid)
33449
- throw new Error("Squid SDK not initialized");
33450
- const depositAddressResponse = (await squid.executeRoute({
33451
- signer: {},
33452
- route,
33453
- }));
33454
- setDeposit(depositAddressResponse);
33455
- return {
33456
- depositAddress: depositAddressResponse,
33457
- };
33458
- }
33486
+ const getRouteWithDeposit = reactQuery.useMutation(async ({ route }) => {
33487
+ if (!squid)
33488
+ throw new Error("Squid SDK not initialized");
33489
+ const depositAddressResponse = (await squid.executeRoute({
33490
+ signer: {},
33491
+ route,
33492
+ }));
33493
+ setDeposit(depositAddressResponse);
33494
+ return {
33495
+ depositAddress: depositAddressResponse,
33496
+ };
33459
33497
  });
33460
33498
  return {
33461
33499
  isEnabled,
@@ -33539,55 +33577,53 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
33539
33577
  xrplTokens.length,
33540
33578
  stellarTokens.length,
33541
33579
  ]);
33542
- const query = reactQuery.useQuery({
33543
- queryKey: keys().allTokensBalance(address, chainType, direction),
33544
- queryFn: async () => {
33545
- // Return zero balances if no address
33546
- if (!address) {
33547
- const defaultTokens = placeholderData.tokens;
33548
- return {
33549
- tokens: defaultTokens,
33550
- totalUsdBalance: calculateTotalUsdBalanceUSD(defaultTokens),
33551
- };
33552
- }
33553
- let fetchedTokens = [];
33554
- // Fetch tokens based on chain type
33555
- switch (chainType) {
33556
- case squidTypes.ChainType.EVM:
33557
- fetchedTokens = await getAllEvmTokensBalance(evmTokens, address, evmChains);
33558
- break;
33559
- case squidTypes.ChainType.COSMOS:
33560
- const addresses = await getAllKeysForSupportedCosmosChains(cosmosChains.map((c) => c.chainId), keplrTypeWallet);
33561
- fetchedTokens = await getAllCosmosBalances({
33562
- addresses,
33563
- cosmosChains,
33564
- cosmosTokens,
33565
- });
33566
- break;
33567
- case squidTypes.ChainType.SOLANA:
33568
- fetchedTokens = await getAllSolanaTokensBalance(solanaTokens, address);
33569
- break;
33570
- case squidTypes.ChainType.BTC:
33571
- fetchedTokens = await getAllBitcoinTokensBalance(address, bitcoinTokens);
33572
- break;
33573
- case squidTypes.ChainType.SUI:
33574
- fetchedTokens = await getAllSuiTokensBalance(address, suiTokens, suiChains);
33575
- break;
33576
- case squidTypes.ChainType.XRPL:
33577
- fetchedTokens = await getAllXrplTokensBalance(address, xrplTokens, xrplChains);
33578
- break;
33579
- case squidTypes.ChainType.STELLAR:
33580
- fetchedTokens = await getAllStellarTokensBalance(address, stellarTokens, stellarChains);
33581
- break;
33582
- default:
33583
- fetchedTokens = placeholderData.tokens;
33584
- break;
33585
- }
33580
+ const query = reactQuery.useQuery(keys().allTokensBalance(address, chainType, direction), async () => {
33581
+ // Return zero balances if no address
33582
+ if (!address) {
33583
+ const defaultTokens = placeholderData.tokens;
33586
33584
  return {
33587
- tokens: fetchedTokens,
33588
- totalUsdBalance: calculateTotalUsdBalanceUSD(fetchedTokens),
33585
+ tokens: defaultTokens,
33586
+ totalUsdBalance: calculateTotalUsdBalanceUSD(defaultTokens),
33589
33587
  };
33590
- },
33588
+ }
33589
+ let fetchedTokens = [];
33590
+ // Fetch tokens based on chain type
33591
+ switch (chainType) {
33592
+ case squidTypes.ChainType.EVM:
33593
+ fetchedTokens = await getAllEvmTokensBalance(evmTokens, address, evmChains);
33594
+ break;
33595
+ case squidTypes.ChainType.COSMOS:
33596
+ const addresses = await getAllKeysForSupportedCosmosChains(cosmosChains.map((c) => c.chainId), keplrTypeWallet);
33597
+ fetchedTokens = await getAllCosmosBalances({
33598
+ addresses,
33599
+ cosmosChains,
33600
+ cosmosTokens,
33601
+ });
33602
+ break;
33603
+ case squidTypes.ChainType.SOLANA:
33604
+ fetchedTokens = await getAllSolanaTokensBalance(solanaTokens, address);
33605
+ break;
33606
+ case squidTypes.ChainType.BTC:
33607
+ fetchedTokens = await getAllBitcoinTokensBalance(address, bitcoinTokens);
33608
+ break;
33609
+ case squidTypes.ChainType.SUI:
33610
+ fetchedTokens = await getAllSuiTokensBalance(address, suiTokens, suiChains);
33611
+ break;
33612
+ case squidTypes.ChainType.XRPL:
33613
+ fetchedTokens = await getAllXrplTokensBalance(address, xrplTokens, xrplChains);
33614
+ break;
33615
+ case squidTypes.ChainType.STELLAR:
33616
+ fetchedTokens = await getAllStellarTokensBalance(address, stellarTokens, stellarChains);
33617
+ break;
33618
+ default:
33619
+ fetchedTokens = placeholderData.tokens;
33620
+ break;
33621
+ }
33622
+ return {
33623
+ tokens: fetchedTokens,
33624
+ totalUsdBalance: calculateTotalUsdBalanceUSD(fetchedTokens),
33625
+ };
33626
+ }, {
33591
33627
  ...queryOptions,
33592
33628
  enabled: isQueryEnabled,
33593
33629
  });
@@ -33602,7 +33638,7 @@ const BALANCE_STALE_TIME = 60000; // 1 minute
33602
33638
  const BALANCE_CACHE_TIME = 300000; // 5 minutes
33603
33639
  const useAllConnectedWalletBalances = ({ direction, queryOptions = {
33604
33640
  staleTime: BALANCE_STALE_TIME,
33605
- gcTime: BALANCE_CACHE_TIME,
33641
+ cacheTime: BALANCE_CACHE_TIME,
33606
33642
  refetchOnWindowFocus: true,
33607
33643
  refetchOnMount: true,
33608
33644
  }, } = {}) => {
@@ -33683,9 +33719,9 @@ const useAllConnectedWalletBalances = ({ direction, queryOptions = {
33683
33719
  }, [balanceQueries]);
33684
33720
  // Aggregate loading states
33685
33721
  const queryStates = React.useMemo(() => ({
33686
- isLoading: Object.values(balanceQueries).some((q) => q.isLoading),
33722
+ isInitialLoading: Object.values(balanceQueries).some((q) => q.isInitialLoading),
33687
33723
  isFetching: Object.values(balanceQueries).some((q) => q.isFetching),
33688
- isPending: Object.values(balanceQueries).some((q) => q.isPending),
33724
+ isLoading: Object.values(balanceQueries).some((q) => q.isLoading),
33689
33725
  isRefetching: Object.values(balanceQueries).some((q) => q.isRefetching),
33690
33726
  isError: Object.values(balanceQueries).some((q) => q.isError),
33691
33727
  isSuccess: Object.values(balanceQueries).every((q) => q.isSuccess),
@@ -33727,7 +33763,7 @@ function useNativeTokenForChain(chain) {
33727
33763
 
33728
33764
  const useEvmNativeBalance = ({ address, chain, }) => {
33729
33765
  const { isChainTypeConnected } = useWallet();
33730
- const { data: nativeEvmBalance, isPending } = wagmi.useBalance({
33766
+ const { data: nativeEvmBalance, isLoading } = wagmi.useBalance({
33731
33767
  address: address,
33732
33768
  chainId: Number(chain?.chainId),
33733
33769
  query: {
@@ -33749,13 +33785,13 @@ const useEvmNativeBalance = ({ address, chain, }) => {
33749
33785
  }, [nativeEvmBalance?.decimals, nativeEvmBalance?.value]);
33750
33786
  return {
33751
33787
  balance,
33752
- isPending,
33788
+ isLoading,
33753
33789
  };
33754
33790
  };
33755
33791
  const useCosmosNativeBalance = ({ address, chain, }) => {
33756
33792
  const { isConnected: isCosmosConnected } = useCosmosContext();
33757
33793
  const { nativeToken: nativeCosmosToken } = useNativeTokenForChain(chain);
33758
- const { balance: rawBalance, isPending } = useCosmosBalance({
33794
+ const { balance: rawBalance, isLoading } = useCosmosBalance({
33759
33795
  chain,
33760
33796
  token: nativeCosmosToken,
33761
33797
  userAddress: address,
@@ -33770,18 +33806,16 @@ const useCosmosNativeBalance = ({ address, chain, }) => {
33770
33806
  };
33771
33807
  }
33772
33808
  }, [nativeCosmosToken?.decimals, rawBalance]);
33773
- return { balance, isPending };
33809
+ return { balance, isLoading };
33774
33810
  };
33775
33811
  const useBitcoinNativeBalance = ({ chain, address, }) => {
33776
33812
  const { nativeToken } = useNativeTokenForChain(chain);
33777
- const { data: rawBalance = "0", isPending } = reactQuery.useQuery({
33778
- queryKey: keys().balance(chain?.chainId, nativeToken?.address, address),
33779
- queryFn: async () => {
33780
- if (!address || !nativeToken)
33781
- return "0";
33782
- const balance = await getBitcoinNativeBalance(address);
33783
- return formatBNToReadable(balance, nativeToken.decimals);
33784
- },
33813
+ const { data: rawBalance = "0", isLoading } = reactQuery.useQuery(keys().balance(chain?.chainId, nativeToken?.address, address), async () => {
33814
+ if (!address || !nativeToken)
33815
+ return "0";
33816
+ const balance = await getBitcoinNativeBalance(address);
33817
+ return formatBNToReadable(balance, nativeToken.decimals);
33818
+ }, {
33785
33819
  enabled: chain?.chainType === squidTypes.ChainType.BTC &&
33786
33820
  nativeToken?.decimals != null &&
33787
33821
  isWalletAddressValid(chain, address),
@@ -33800,17 +33834,15 @@ const useBitcoinNativeBalance = ({ chain, address, }) => {
33800
33834
  }, [nativeToken?.decimals, rawBalance]);
33801
33835
  return {
33802
33836
  balance,
33803
- isPending,
33837
+ isLoading,
33804
33838
  };
33805
33839
  };
33806
33840
  const useSolanaNativeBalance = ({ chain, address, }) => {
33807
33841
  const { nativeToken } = useNativeTokenForChain(chain);
33808
- const { data: rawBalance, isPending } = reactQuery.useQuery({
33809
- queryKey: keys().balance(chain?.chainId, nativeToken?.address, address),
33810
- queryFn: async () => {
33811
- const balance = await getSolanaNativeBalance(address);
33812
- return formatBNToReadable(balance, nativeToken.decimals);
33813
- },
33842
+ const { data: rawBalance, isLoading } = reactQuery.useQuery(keys().balance(chain?.chainId, nativeToken?.address, address), async () => {
33843
+ const balance = await getSolanaNativeBalance(address);
33844
+ return formatBNToReadable(balance, nativeToken.decimals);
33845
+ }, {
33814
33846
  enabled: !!address &&
33815
33847
  nativeToken?.decimals != null &&
33816
33848
  chain?.chainType === squidTypes.ChainType.SOLANA,
@@ -33829,12 +33861,12 @@ const useSolanaNativeBalance = ({ chain, address, }) => {
33829
33861
  }, [nativeToken?.decimals, rawBalance]);
33830
33862
  return {
33831
33863
  balance,
33832
- isPending,
33864
+ isLoading,
33833
33865
  };
33834
33866
  };
33835
33867
  const useSuiNativeBalance = ({ address, chain, }) => {
33836
33868
  const { nativeToken } = useNativeTokenForChain(chain);
33837
- const { balance: rawBalance, isPending } = useSuiBalance({
33869
+ const { balance: rawBalance, isLoading } = useSuiBalance({
33838
33870
  chain,
33839
33871
  token: nativeToken,
33840
33872
  userAddress: address,
@@ -33849,12 +33881,12 @@ const useSuiNativeBalance = ({ address, chain, }) => {
33849
33881
  }, [nativeToken?.decimals, rawBalance]);
33850
33882
  return {
33851
33883
  balance,
33852
- isPending,
33884
+ isLoading,
33853
33885
  };
33854
33886
  };
33855
33887
  const useXrplNativeBalance = ({ address, chain, }) => {
33856
33888
  const { nativeToken } = useNativeTokenForChain(chain);
33857
- const { balance: rawBalance, isPending } = useXrplBalance({
33889
+ const { balance: rawBalance, isLoading } = useXrplBalance({
33858
33890
  chain,
33859
33891
  token: nativeToken,
33860
33892
  userAddress: address,
@@ -33870,12 +33902,12 @@ const useXrplNativeBalance = ({ address, chain, }) => {
33870
33902
  }, [nativeToken?.decimals, rawBalance]);
33871
33903
  return {
33872
33904
  balance,
33873
- isPending,
33905
+ isLoading,
33874
33906
  };
33875
33907
  };
33876
33908
  const useStellarNativeBalance = ({ address, chain, }) => {
33877
33909
  const { nativeToken } = useNativeTokenForChain(chain);
33878
- const { balance: rawBalance, isPending } = useStellarBalance({
33910
+ const { balance: rawBalance, isLoading } = useStellarBalance({
33879
33911
  chain,
33880
33912
  token: nativeToken,
33881
33913
  userAddress: address,
@@ -33891,7 +33923,7 @@ const useStellarNativeBalance = ({ address, chain, }) => {
33891
33923
  }, [nativeToken?.decimals, rawBalance]);
33892
33924
  return {
33893
33925
  balance,
33894
- isPending,
33926
+ isLoading,
33895
33927
  };
33896
33928
  };
33897
33929
  const useNativeBalance = (chain) => {
@@ -33899,28 +33931,28 @@ const useNativeBalance = (chain) => {
33899
33931
  const { data: cosmosAddressForChain } = useCosmosForChain(chain);
33900
33932
  // Cosmos is a special case because the address changes on every chain
33901
33933
  // so we can't use the default cosmos connected address
33902
- const { balance: nativeCosmosBalance, isPending: isCosmosPending } = useCosmosNativeBalance({
33934
+ const { balance: nativeCosmosBalance, isLoading: isCosmosLoading } = useCosmosNativeBalance({
33903
33935
  address: cosmosAddressForChain,
33904
33936
  chain,
33905
33937
  });
33906
- const { balance: nativeEvmBalance, isPending: isEvmPending } = useEvmNativeBalance({ address: connectedAddresses[squidTypes.ChainType.EVM], chain });
33907
- const { balance: nativeBitcoinBalance, isPending: isBitcoinPending } = useBitcoinNativeBalance({
33938
+ const { balance: nativeEvmBalance, isLoading: isEvmLoading } = useEvmNativeBalance({ address: connectedAddresses[squidTypes.ChainType.EVM], chain });
33939
+ const { balance: nativeBitcoinBalance, isLoading: isBitcoinLoading } = useBitcoinNativeBalance({
33908
33940
  address: connectedAddresses[squidTypes.ChainType.BTC],
33909
33941
  chain,
33910
33942
  });
33911
- const { balance: nativeSolanaBalance, isPending: isSolanaPending } = useSolanaNativeBalance({
33943
+ const { balance: nativeSolanaBalance, isLoading: isSolanaLoading } = useSolanaNativeBalance({
33912
33944
  address: connectedAddresses[squidTypes.ChainType.SOLANA],
33913
33945
  chain,
33914
33946
  });
33915
- const { balance: nativeSuiBalance, isPending: isSuiPending } = useSuiNativeBalance({
33947
+ const { balance: nativeSuiBalance, isLoading: isSuiLoading } = useSuiNativeBalance({
33916
33948
  address: connectedAddresses[squidTypes.ChainType.SUI],
33917
33949
  chain,
33918
33950
  });
33919
- const { balance: nativeXrplBalance, isPending: isXrplPending } = useXrplNativeBalance({
33951
+ const { balance: nativeXrplBalance, isLoading: isXrpLoading } = useXrplNativeBalance({
33920
33952
  address: connectedAddresses[squidTypes.ChainType.XRPL],
33921
33953
  chain,
33922
33954
  });
33923
- const { balance: nativeStellarBalance, isPending: isStellarPending } = useStellarNativeBalance({
33955
+ const { balance: nativeStellarBalance, isLoading: isStellarLoading } = useStellarNativeBalance({
33924
33956
  address: connectedAddresses[squidTypes.ChainType.STELLAR],
33925
33957
  chain,
33926
33958
  });
@@ -33965,36 +33997,36 @@ const useNativeBalance = (chain) => {
33965
33997
  nativeXrplBalance,
33966
33998
  nativeStellarBalance,
33967
33999
  ]);
33968
- const isPending = React.useMemo(() => {
34000
+ const isLoading = React.useMemo(() => {
33969
34001
  if (!chain?.chainType)
33970
34002
  return false;
33971
34003
  switch (chain.chainType) {
33972
34004
  case squidTypes.ChainType.EVM:
33973
- return isEvmPending;
34005
+ return isEvmLoading;
33974
34006
  case squidTypes.ChainType.COSMOS:
33975
- return isCosmosPending;
34007
+ return isCosmosLoading;
33976
34008
  case squidTypes.ChainType.BTC:
33977
- return isBitcoinPending;
34009
+ return isBitcoinLoading;
33978
34010
  case squidTypes.ChainType.SOLANA:
33979
- return isSolanaPending;
34011
+ return isSolanaLoading;
33980
34012
  case squidTypes.ChainType.SUI:
33981
- return isSuiPending;
34013
+ return isSuiLoading;
33982
34014
  case squidTypes.ChainType.XRPL:
33983
- return isXrplPending;
34015
+ return isXrpLoading;
33984
34016
  case squidTypes.ChainType.STELLAR:
33985
- return isStellarPending;
34017
+ return isStellarLoading;
33986
34018
  }
33987
34019
  }, [
33988
34020
  chain?.chainType,
33989
- isEvmPending,
33990
- isCosmosPending,
33991
- isBitcoinPending,
33992
- isSolanaPending,
33993
- isSuiPending,
33994
- isXrplPending,
33995
- isStellarPending,
34021
+ isEvmLoading,
34022
+ isCosmosLoading,
34023
+ isBitcoinLoading,
34024
+ isSolanaLoading,
34025
+ isSuiLoading,
34026
+ isXrpLoading,
34027
+ isStellarLoading,
33996
34028
  ]);
33997
- return { nativeBalance, nativeBalanceFormatted, isPending };
34029
+ return { nativeBalance, nativeBalanceFormatted, isLoading };
33998
34030
  };
33999
34031
 
34000
34032
  const DEFAULT_REFRESH_INTERVAL_MS = 15000;
@@ -34003,7 +34035,7 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
34003
34035
  const isNativeToken = token?.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
34004
34036
  const userAddressParsed = userAddress;
34005
34037
  // Only fetch using useBalance if it's a native token
34006
- const { data: nativeBalance, isPending: isNativeTokenPending } = wagmi.useBalance({
34038
+ const { data: nativeBalance, isLoading: isNativeTokenLoading } = wagmi.useBalance({
34007
34039
  address: userAddressParsed,
34008
34040
  chainId: Number(chain?.chainId),
34009
34041
  query: {
@@ -34019,7 +34051,7 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
34019
34051
  });
34020
34052
  // Only fetch using useReadContract if it's not a native token
34021
34053
  // This is temporary, because of wagmi error: https://github.com/wevm/wagmi/issues/4353
34022
- const { data: erc20Balance, isPending: isErc20Pending } = wagmi.useReadContract({
34054
+ const { data: erc20Balance, isLoading: isErc20Loading } = wagmi.useReadContract({
34023
34055
  address: token?.address,
34024
34056
  abi: viem.erc20Abi,
34025
34057
  functionName: "balanceOf",
@@ -34035,15 +34067,15 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
34035
34067
  },
34036
34068
  });
34037
34069
  const balance = isNativeToken ? nativeBalance?.value : erc20Balance;
34038
- const isPending = isNativeToken ? isNativeTokenPending : isErc20Pending;
34070
+ const isLoading = isNativeToken ? isNativeTokenLoading : isErc20Loading;
34039
34071
  const formattedBalance = balance != null && token?.decimals != null
34040
34072
  ? formatBNToReadable(balance, token.decimals)
34041
34073
  : "0";
34042
- return { balance: formattedBalance, isPending };
34074
+ return { balance: formattedBalance, isLoading };
34043
34075
  };
34044
34076
  const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
34045
34077
  const { isConnected } = useCosmosContext();
34046
- const { data: balance = "0", isPending } = reactQuery.useQuery({
34078
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
34047
34079
  queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
34048
34080
  queryFn: async () => {
34049
34081
  if (!userAddress || !token || chain?.chainType !== squidTypes.ChainType.COSMOS) {
@@ -34063,10 +34095,10 @@ const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIn
34063
34095
  refetchInterval: refreshIntervalMs,
34064
34096
  retry: 2,
34065
34097
  });
34066
- return { balance, isPending };
34098
+ return { balance, isLoading };
34067
34099
  };
34068
34100
  const useSolanaBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
34069
- const { data: balance = "0", isPending } = reactQuery.useQuery({
34101
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
34070
34102
  queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
34071
34103
  queryFn: async () => {
34072
34104
  if (!userAddress || !token)
@@ -34081,11 +34113,11 @@ const useSolanaBalance = ({ chain, token, userAddress, enabled = true, refreshIn
34081
34113
  refetchInterval: refreshIntervalMs,
34082
34114
  retry: 2,
34083
34115
  });
34084
- return { balance, isPending };
34116
+ return { balance, isLoading };
34085
34117
  };
34086
34118
  // TODO: implement fetching balances for all bitcoin tokens
34087
34119
  const useBitcoinBalance = ({ userAddress, chain, }) => {
34088
- const { balance: balanceBn, isPending } = useBitcoinNativeBalance({
34120
+ const { balance: balanceBn, isLoading } = useBitcoinNativeBalance({
34089
34121
  address: userAddress,
34090
34122
  chain,
34091
34123
  });
@@ -34094,10 +34126,10 @@ const useBitcoinBalance = ({ userAddress, chain, }) => {
34094
34126
  return "0";
34095
34127
  return formatBNToReadable(balanceBn?.value, balanceBn?.decimals);
34096
34128
  }, [balanceBn]);
34097
- return { balance, isPending };
34129
+ return { balance, isLoading };
34098
34130
  };
34099
34131
  const useSuiBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
34100
- const { data: balance = "0", isPending } = reactQuery.useQuery({
34132
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
34101
34133
  queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
34102
34134
  queryFn: async () => {
34103
34135
  if (!userAddress ||
@@ -34117,10 +34149,10 @@ const useSuiBalance = ({ chain, token, userAddress, enabled = true, refreshInter
34117
34149
  refetchInterval: refreshIntervalMs,
34118
34150
  retry: 2,
34119
34151
  });
34120
- return { balance, isPending };
34152
+ return { balance, isLoading };
34121
34153
  };
34122
34154
  const useXrplBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
34123
- const { data: balance = "0", isPending } = reactQuery.useQuery({
34155
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
34124
34156
  queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
34125
34157
  queryFn: async () => {
34126
34158
  if (!userAddress || !token || !chain)
@@ -34137,10 +34169,10 @@ const useXrplBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs
34137
34169
  refetchInterval: refreshIntervalMs,
34138
34170
  retry: 2,
34139
34171
  });
34140
- return { balance, isPending };
34172
+ return { balance, isLoading };
34141
34173
  };
34142
34174
  const useStellarBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
34143
- const { data: balance = "0", isPending } = reactQuery.useQuery({
34175
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
34144
34176
  queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
34145
34177
  queryFn: async () => {
34146
34178
  if (!userAddress || !token || !chain)
@@ -34157,7 +34189,7 @@ const useStellarBalance = ({ userAddress, chain, enabled, token, refreshInterval
34157
34189
  refetchInterval: refreshIntervalMs,
34158
34190
  retry: 2,
34159
34191
  });
34160
- return { balance, isPending };
34192
+ return { balance, isLoading };
34161
34193
  };
34162
34194
 
34163
34195
  /**
@@ -34278,7 +34310,7 @@ const useMultipleTokenPrices = (tokens) => {
34278
34310
  return {
34279
34311
  tokenPrices,
34280
34312
  getTokenPrice,
34281
- isPending: coinGeckoQuery.isPending,
34313
+ isLoading: coinGeckoQuery.isLoading,
34282
34314
  isError: coinGeckoQuery.isError,
34283
34315
  error: coinGeckoQuery.error,
34284
34316
  refetch: coinGeckoQuery.refetch,
@@ -34427,17 +34459,13 @@ const fetchTokensData = async (tokens) => {
34427
34459
 
34428
34460
  // Coingecko has a limit for some queries for multiple tokens, not sure what it is, but let's use 100 for now
34429
34461
  const useHistoricalData = (coingeckoId, timeFrame) => {
34430
- return reactQuery.useQuery({
34431
- queryKey: keys().historicalData(coingeckoId, timeFrame),
34432
- queryFn: () => fetchHistoricalData(coingeckoId, timeFrame),
34462
+ return reactQuery.useQuery(keys().historicalData(coingeckoId, timeFrame), () => fetchHistoricalData(coingeckoId, timeFrame), {
34433
34463
  staleTime: 5 * 60 * 1000,
34434
34464
  enabled: !!coingeckoId,
34435
34465
  });
34436
34466
  };
34437
34467
  const useTokensData = (tokens) => {
34438
- return reactQuery.useQuery({
34439
- queryKey: keys().tokensData(tokens),
34440
- queryFn: () => fetchTokensData(tokens),
34468
+ return reactQuery.useQuery(keys().tokensData(tokens), () => fetchTokensData(tokens), {
34441
34469
  staleTime: 60 * 1000,
34442
34470
  enabled: !!tokens && tokens.length > 0,
34443
34471
  });
@@ -34742,7 +34770,7 @@ function useSendTransactionGas({ chain, token, from, }) {
34742
34770
  }
34743
34771
 
34744
34772
  function useEstimateSendTransaction({ chain, token, amount, balance, from, }) {
34745
- const { data: estimatedGas = BigInt(0), isPending } = useSendTransactionGas({
34773
+ const { data: estimatedGas = BigInt(0), isLoading } = useSendTransactionGas({
34746
34774
  chain,
34747
34775
  token,
34748
34776
  from,
@@ -34787,7 +34815,7 @@ function useEstimateSendTransaction({ chain, token, amount, balance, from, }) {
34787
34815
  return {
34788
34816
  estimatedGas,
34789
34817
  isBalanceEnough,
34790
- isPending,
34818
+ isLoading,
34791
34819
  isNativeBalanceEnoughToPayGasFees,
34792
34820
  minAmountValueWarnMsg,
34793
34821
  };
@@ -35194,12 +35222,10 @@ function useSendTransaction({ to, amount, token, chain, }) {
35194
35222
  // amount is already formatted with the token decimals
35195
35223
  amount,
35196
35224
  toAddress: to,
35197
- token: {
35198
- address: token.address,
35199
- chainId: token.chainId,
35200
- symbol: token.symbol,
35201
- type: token.type,
35202
- },
35225
+ tokenAddress: token.address,
35226
+ tokenChainId: token.chainId,
35227
+ tokenSymbol: token.symbol,
35228
+ tokenType: token.type,
35203
35229
  });
35204
35230
  }, [
35205
35231
  allEventParamsDefined,
@@ -35219,12 +35245,10 @@ function useSendTransaction({ to, amount, token, chain, }) {
35219
35245
  // amount is already formatted with the token decimals
35220
35246
  amount,
35221
35247
  toAddress: to,
35222
- token: {
35223
- address: token.address,
35224
- chainId: token.chainId,
35225
- symbol: token.symbol,
35226
- type: token.type,
35227
- },
35248
+ tokenAddress: token.address,
35249
+ tokenChainId: token.chainId,
35250
+ tokenSymbol: token.symbol,
35251
+ tokenType: token.type,
35228
35252
  txHash,
35229
35253
  });
35230
35254
  }, [
@@ -35370,9 +35394,7 @@ function useSendTransaction({ to, amount, token, chain, }) {
35370
35394
  });
35371
35395
  },
35372
35396
  onSuccess: (tx, variables) => {
35373
- queryClient.invalidateQueries({
35374
- queryKey: getPrefixKey(QueryKeys.Balance),
35375
- });
35397
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balance));
35376
35398
  setTransactionState(variables.id, tx);
35377
35399
  persistTransaction({
35378
35400
  txType: exports.HistoryTxType.SEND,
@@ -35699,10 +35721,9 @@ const useAllTransactionsStatus = ({ enabled }) => {
35699
35721
  queryKey: keys().fiatToCryptoStatus(data.orderId),
35700
35722
  retry: TX_STATUS_CONSTANTS.RETRY_COUNT,
35701
35723
  retryDelay: TX_STATUS_CONSTANTS.RETRY_DELAY,
35702
- refetchInterval: (query) => {
35703
- const { state } = query;
35704
- if (state.data?.status &&
35705
- FINAL_TRANSACTION_STATUSES.includes(state.data.status)) {
35724
+ refetchInterval: (data) => {
35725
+ if (data?.status &&
35726
+ FINAL_TRANSACTION_STATUSES.includes(data.status)) {
35706
35727
  return false;
35707
35728
  }
35708
35729
  return TX_STATUS_CONSTANTS.REFETCH_INTERVAL;
@@ -35762,7 +35783,7 @@ const useAllTransactionsStatus = ({ enabled }) => {
35762
35783
  queries: enabled && config.apiUrl ? statusQueries : [],
35763
35784
  });
35764
35785
  return {
35765
- isPending: queries.some((q) => q.isPending),
35786
+ isLoading: queries.some((q) => q.isLoading),
35766
35787
  isError: queries.some((q) => q.isError),
35767
35788
  data: queries.map((q) => q.data).filter(Boolean),
35768
35789
  };
@@ -36021,18 +36042,16 @@ const useApproval = ({ squidRoute, }) => {
36021
36042
  * On Error: Showing the error message if any
36022
36043
  * @returns {boolean} approved
36023
36044
  */
36024
- const routeApproved = reactQuery.useQuery({
36025
- queryKey: keys().routeApproved(squidRoute, allowanceInWei),
36026
- queryFn: async () => {
36027
- // Approval is only needed for EVM chains
36028
- if (getChainType(squidRoute?.params.fromChain) === squidTypes.ChainType.EVM) {
36029
- return hasAllowance;
36030
- }
36031
- return true;
36032
- },
36045
+ const routeApproved = reactQuery.useQuery(keys().routeApproved(squidRoute, allowanceInWei), async () => {
36046
+ // Approval is only needed for EVM chains
36047
+ if (getChainType(squidRoute?.params.fromChain) === squidTypes.ChainType.EVM) {
36048
+ return hasAllowance;
36049
+ }
36050
+ return true;
36051
+ }, {
36033
36052
  enabled: !!squidRoute &&
36034
36053
  !!sourceUserAddress &&
36035
- !allowanceQuery?.isPending &&
36054
+ !allowanceQuery?.isLoading &&
36036
36055
  allowanceQuery?.isFetched,
36037
36056
  });
36038
36057
  // USDT has a very specific way of handling approvals
@@ -36121,84 +36140,81 @@ const useApproval = ({ squidRoute, }) => {
36121
36140
  /**
36122
36141
  * Manually approve route if necessary
36123
36142
  */
36124
- const approveRoute = reactQuery.useMutation({
36125
- mutationFn: async () => {
36126
- try {
36127
- if (fromToken?.address === nativeEvmTokenAddress) {
36128
- return true;
36143
+ const approveRoute = reactQuery.useMutation(async () => {
36144
+ try {
36145
+ if (fromToken?.address === nativeEvmTokenAddress) {
36146
+ return true;
36147
+ }
36148
+ if (!!squidRoute && walletClient && fromToken && evmSigner && squid) {
36149
+ await approveSpecificTokenToZero(fromToken);
36150
+ try {
36151
+ // If needed, we can switch the chain here
36152
+ // If already on the correct chain, this will do nothing
36153
+ await switchChainAsync({ chainId: Number(fromChain?.chainId) });
36129
36154
  }
36130
- if (!!squidRoute && walletClient && fromToken && evmSigner && squid) {
36131
- await approveSpecificTokenToZero(fromToken);
36132
- try {
36133
- // If needed, we can switch the chain here
36134
- // If already on the correct chain, this will do nothing
36135
- await switchChainAsync({ chainId: Number(fromChain?.chainId) });
36136
- }
36137
- catch (error) {
36138
- console.error("Error switching network:", error);
36139
- }
36140
- let approveTx;
36141
- if (useIcs20) {
36142
- const channel = squidRoute.estimate.actions[0].data
36143
- .ibcChannel;
36144
- const ics20Interface = new ethers.ethers.Interface(ics20Abi);
36145
- const approveData = ics20Interface.encodeFunctionData("approve", [
36146
- squidRoute.params.fromAddress,
36147
- [
36148
- {
36149
- sourcePort: "transfer",
36150
- sourceChannel: channel,
36151
- spendLimit: [
36152
- {
36153
- denom: squidRoute.estimate.actions[0].fromToken
36154
- .originalAddress,
36155
- amount: squidRoute.params.fromAmount,
36156
- },
36157
- ],
36158
- allowList: [],
36159
- allowedPacketData: ["*"],
36160
- },
36161
- ],
36162
- ]);
36163
- approveTx = await evmSigner.sendTransaction({
36164
- to: squidRoute.transactionRequest.target,
36165
- data: approveData,
36166
- value: "0",
36167
- gasLimit: squidRoute.transactionRequest
36168
- .gasLimit,
36169
- gasPrice: squidRoute.transactionRequest
36170
- .gasPrice,
36171
- });
36172
- }
36173
- else {
36174
- approveTx = await squid.approveRoute({
36175
- route: squidRoute,
36176
- signer: evmSigner,
36177
- // For security reasons, we don't want to allow infinite approvals in our frontends
36178
- executionSettings: {
36179
- infiniteApproval: false,
36155
+ catch (error) {
36156
+ console.error("Error switching network:", error);
36157
+ }
36158
+ let approveTx;
36159
+ if (useIcs20) {
36160
+ const channel = squidRoute.estimate.actions[0].data
36161
+ .ibcChannel;
36162
+ const ics20Interface = new ethers.ethers.Interface(ics20Abi);
36163
+ const approveData = ics20Interface.encodeFunctionData("approve", [
36164
+ squidRoute.params.fromAddress,
36165
+ [
36166
+ {
36167
+ sourcePort: "transfer",
36168
+ sourceChannel: channel,
36169
+ spendLimit: [
36170
+ {
36171
+ denom: squidRoute.estimate.actions[0].fromToken
36172
+ .originalAddress,
36173
+ amount: squidRoute.params.fromAmount,
36174
+ },
36175
+ ],
36176
+ allowList: [],
36177
+ allowedPacketData: ["*"],
36180
36178
  },
36181
- });
36182
- }
36183
- if (isProblematicConnector(activeConnector)) {
36184
- await sleep(3_000);
36185
- }
36186
- await approveTx?.wait();
36187
- return true;
36179
+ ],
36180
+ ]);
36181
+ approveTx = await evmSigner.sendTransaction({
36182
+ to: squidRoute.transactionRequest.target,
36183
+ data: approveData,
36184
+ value: "0",
36185
+ gasLimit: squidRoute.transactionRequest
36186
+ .gasLimit,
36187
+ gasPrice: squidRoute.transactionRequest
36188
+ .gasPrice,
36189
+ });
36188
36190
  }
36189
- return false;
36190
- }
36191
- catch (error) {
36192
- // Keep the error in the console to debug future issues
36193
- console.error(error);
36194
- return false;
36191
+ else {
36192
+ approveTx = await squid.approveRoute({
36193
+ route: squidRoute,
36194
+ signer: evmSigner,
36195
+ // For security reasons, we don't want to allow infinite approvals in our frontends
36196
+ executionSettings: {
36197
+ infiniteApproval: false,
36198
+ },
36199
+ });
36200
+ }
36201
+ if (isProblematicConnector(activeConnector)) {
36202
+ await sleep(3_000);
36203
+ }
36204
+ await approveTx?.wait();
36205
+ return true;
36195
36206
  }
36196
- },
36207
+ return false;
36208
+ }
36209
+ catch (error) {
36210
+ // Keep the error in the console to debug future issues
36211
+ console.error(error);
36212
+ return false;
36213
+ }
36214
+ }, {
36197
36215
  onSuccess: async () => {
36198
36216
  await allowanceQuery?.refetch();
36199
- queryClient.invalidateQueries({
36200
- queryKey: getPrefixKey(QueryKeys.RouteApproved),
36201
- });
36217
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.RouteApproved));
36202
36218
  // After an approval, we refetch the transaction query with all required parameters
36203
36219
  // This is to ensure we're using the latest expiry timestamp
36204
36220
  if (squidRoute) {
@@ -39318,10 +39334,8 @@ const useExecuteTransaction = (squidRoute) => {
39318
39334
  }
39319
39335
  }, [cosmosSigner, fromChain]);
39320
39336
  const resetQueriesAfterTxSigned = () => {
39321
- queryClient.refetchQueries({ queryKey: getPrefixKey(QueryKeys.Balance) });
39322
- queryClient.invalidateQueries({
39323
- queryKey: getPrefixKey(QueryKeys.Transaction),
39324
- });
39337
+ queryClient.refetchQueries(getPrefixKey(QueryKeys.Balance));
39338
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.Transaction));
39325
39339
  };
39326
39340
  const dispatchSignatureRequestEvent = React.useCallback((route) => {
39327
39341
  WidgetEvents.getInstance().dispatchSwapTxSignatureRequested({
@@ -39339,64 +39353,62 @@ const useExecuteTransaction = (squidRoute) => {
39339
39353
  txHash,
39340
39354
  }, findToken);
39341
39355
  }, [findToken]);
39342
- const swapMutationCosmos = reactQuery.useMutation({
39343
- mutationFn: async ({ id, route }) => {
39344
- const fromChainId = route?.params.fromChain;
39345
- if (cosmosSigner && fromChainId) {
39346
- try {
39347
- const signingClient = await getCosmosSignerClient();
39348
- const signerAddress = (await cosmosSigner.getAccounts())[0].address;
39349
- if (signerAddress && signingClient && route) {
39350
- dispatchSignatureRequestEvent(route);
39351
- const tx$1 = (await squid?.executeRoute({
39352
- signer: signingClient,
39353
- signerAddress,
39354
- route,
39355
- }));
39356
- // set the tx state to loading, as soon as user signed the tx
39357
- setTransactionState({
39358
- txHash: "",
39359
- route,
39360
- status: exports.TransactionStatus.ONGOING,
39361
- sourceStatus: exports.TransactionStatus.ONGOING,
39362
- id,
39363
- });
39364
- // broadcast the signed tx to get hash and listen to events
39365
- const response = await signingClient.broadcastTx(tx.TxRaw.encode(tx$1).finish());
39366
- const hash = response.transactionHash;
39367
- if (hash) {
39368
- resetQueriesAfterTxSigned();
39369
- }
39370
- // Dispatch event so it can be listened from outside the widget
39371
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39372
- const txParams = setTransactionState({
39373
- route,
39374
- txHash: hash,
39375
- userAddress: sourceUserAddress,
39376
- status: exports.TransactionStatus.ONGOING,
39377
- sourceStatus: exports.TransactionStatus.ONGOING,
39378
- axelarUrl: undefined,
39379
- id,
39356
+ const swapMutationCosmos = reactQuery.useMutation(async ({ id, route }) => {
39357
+ const fromChainId = route?.params.fromChain;
39358
+ if (cosmosSigner && fromChainId) {
39359
+ try {
39360
+ const signingClient = await getCosmosSignerClient();
39361
+ const signerAddress = (await cosmosSigner.getAccounts())[0].address;
39362
+ if (signerAddress && signingClient && route) {
39363
+ dispatchSignatureRequestEvent(route);
39364
+ const tx$1 = (await squid?.executeRoute({
39365
+ signer: signingClient,
39366
+ signerAddress,
39367
+ route,
39368
+ }));
39369
+ // set the tx state to loading, as soon as user signed the tx
39370
+ setTransactionState({
39371
+ txHash: "",
39372
+ route,
39373
+ status: exports.TransactionStatus.ONGOING,
39374
+ sourceStatus: exports.TransactionStatus.ONGOING,
39375
+ id,
39376
+ });
39377
+ // broadcast the signed tx to get hash and listen to events
39378
+ const response = await signingClient.broadcastTx(tx.TxRaw.encode(tx$1).finish());
39379
+ const hash = response.transactionHash;
39380
+ if (hash) {
39381
+ resetQueriesAfterTxSigned();
39382
+ }
39383
+ // Dispatch event so it can be listened from outside the widget
39384
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39385
+ const txParams = setTransactionState({
39386
+ route,
39387
+ txHash: hash,
39388
+ userAddress: sourceUserAddress,
39389
+ status: exports.TransactionStatus.ONGOING,
39390
+ sourceStatus: exports.TransactionStatus.ONGOING,
39391
+ axelarUrl: undefined,
39392
+ id,
39393
+ });
39394
+ if (txParams) {
39395
+ addSwapTransaction({
39396
+ ...txParams,
39397
+ params: route.params,
39398
+ estimate: route.estimate,
39380
39399
  });
39381
- if (txParams) {
39382
- addSwapTransaction({
39383
- ...txParams,
39384
- params: route.params,
39385
- estimate: route.estimate,
39386
- });
39387
- }
39388
- return response.code === 0;
39389
39400
  }
39401
+ return response.code === 0;
39390
39402
  }
39391
- catch (error) {
39392
- console.error("Error executing Cosmos transaction", error);
39393
- if (isUserRejectionError(normalizeError(error))) {
39394
- throw new Error("Request rejected");
39395
- }
39403
+ }
39404
+ catch (error) {
39405
+ console.error("Error executing Cosmos transaction", error);
39406
+ if (isUserRejectionError(normalizeError(error))) {
39407
+ throw new Error("Request rejected");
39396
39408
  }
39397
39409
  }
39398
- throw new Error("Need all parameters");
39399
- },
39410
+ }
39411
+ throw new Error("Need all parameters");
39400
39412
  });
39401
39413
  // If the transaction is replaced, we need to update the transaction hash
39402
39414
  // Transaction replaced can mean that the user has speed up the transaction for example
@@ -39449,126 +39461,97 @@ const useExecuteTransaction = (squidRoute) => {
39449
39461
  throw error;
39450
39462
  }
39451
39463
  }, [replaceSwapTransactionNonce, setTransactionState, sourceUserAddress]);
39452
- const swapMutationEvm = reactQuery.useMutation({
39453
- mutationFn: async ({ id, route }) => {
39454
- await changeNetworkIfNeeded.mutateAsync();
39455
- if (!route || !squid || !evmSigner) {
39456
- throw new Error("Need all parameters");
39457
- }
39458
- dispatchSignatureRequestEvent(route);
39459
- const txResponse = (await squid.executeRoute({
39460
- bypassBalanceChecks: true,
39461
- signer: evmSigner,
39464
+ const swapMutationEvm = reactQuery.useMutation(async ({ id, route }) => {
39465
+ await changeNetworkIfNeeded.mutateAsync();
39466
+ if (!route || !squid || !evmSigner) {
39467
+ throw new Error("Need all parameters");
39468
+ }
39469
+ dispatchSignatureRequestEvent(route);
39470
+ const txResponse = (await squid.executeRoute({
39471
+ bypassBalanceChecks: true,
39472
+ signer: evmSigner,
39473
+ route,
39474
+ }));
39475
+ let hash = txResponse.hash;
39476
+ if (activeConnector?.id === "safe") {
39477
+ hash = await getGnosisTransactionHash(txResponse.hash);
39478
+ }
39479
+ if (hash) {
39480
+ resetQueriesAfterTxSigned();
39481
+ }
39482
+ // Dispatch event so it can be listened from outside the widget
39483
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39484
+ if (route.transactionRequest) {
39485
+ const txParams = setTransactionState({
39462
39486
  route,
39463
- }));
39464
- let hash = txResponse.hash;
39465
- if (activeConnector?.id === "safe") {
39466
- hash = await getGnosisTransactionHash(txResponse.hash);
39487
+ txHash: hash,
39488
+ nonce: txResponse.nonce,
39489
+ userAddress: sourceUserAddress,
39490
+ status: exports.TransactionStatus.INITIAL_LOADING,
39491
+ sourceStatus: exports.TransactionStatus.ONGOING,
39492
+ axelarUrl: undefined,
39493
+ id,
39494
+ });
39495
+ if (txParams) {
39496
+ addSwapTransaction({
39497
+ ...txParams,
39498
+ params: route.params,
39499
+ estimate: route.estimate,
39500
+ });
39467
39501
  }
39468
- if (hash) {
39469
- resetQueriesAfterTxSigned();
39502
+ }
39503
+ try {
39504
+ if (isProblematicConnector(activeConnector)) {
39505
+ await sleep(3_000);
39470
39506
  }
39471
- // Dispatch event so it can be listened from outside the widget
39472
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39473
- if (route.transactionRequest) {
39474
- const txParams = setTransactionState({
39475
- route,
39476
- txHash: hash,
39477
- nonce: txResponse.nonce,
39478
- userAddress: sourceUserAddress,
39479
- status: exports.TransactionStatus.INITIAL_LOADING,
39480
- sourceStatus: exports.TransactionStatus.ONGOING,
39481
- axelarUrl: undefined,
39482
- id,
39483
- });
39484
- if (txParams) {
39485
- addSwapTransaction({
39486
- ...txParams,
39487
- params: route.params,
39488
- estimate: route.estimate,
39489
- });
39490
- }
39507
+ const response = await txResponse.wait();
39508
+ return response;
39509
+ }
39510
+ catch (error) {
39511
+ return handleTransactionReplacementError({
39512
+ error,
39513
+ route,
39514
+ status: exports.TransactionStatus.INITIAL_LOADING,
39515
+ sourceStatus: exports.TransactionStatus.ONGOING,
39516
+ userAddress: sourceUserAddress,
39517
+ axelarUrl: undefined,
39518
+ id,
39519
+ });
39520
+ }
39521
+ });
39522
+ const swapMutationSolana = reactQuery.useMutation(async ({ id, route }) => {
39523
+ try {
39524
+ if (!route) {
39525
+ throw new Error("Route is required");
39491
39526
  }
39492
- try {
39493
- if (isProblematicConnector(activeConnector)) {
39494
- await sleep(3_000);
39495
- }
39496
- const response = await txResponse.wait();
39497
- return response;
39527
+ if (!solanaSigner) {
39528
+ throw new Error("Solana signer is required");
39498
39529
  }
39499
- catch (error) {
39500
- return handleTransactionReplacementError({
39501
- error,
39502
- route,
39503
- status: exports.TransactionStatus.INITIAL_LOADING,
39504
- sourceStatus: exports.TransactionStatus.ONGOING,
39505
- userAddress: sourceUserAddress,
39506
- axelarUrl: undefined,
39507
- id,
39508
- });
39530
+ if (!route.params.fromAddress || !route.params.toAddress) {
39531
+ throw new Error("From or to address is required");
39509
39532
  }
39510
- },
39511
- });
39512
- const swapMutationSolana = reactQuery.useMutation({
39513
- mutationFn: async ({ id, route }) => {
39514
- try {
39515
- if (!route) {
39516
- throw new Error("Route is required");
39517
- }
39518
- if (!solanaSigner) {
39519
- throw new Error("Solana signer is required");
39533
+ const isDirectTransfer = isDepositRoute(route);
39534
+ // Means it's a transfer to a deposit address
39535
+ // Instead of a Swap/Contract call using a DEX like Jupiter
39536
+ if (isDirectTransfer) {
39537
+ // Get the deposit address from the squidRoute
39538
+ const depositData = useDepositAddressStore.getState().deposit;
39539
+ // Validate params
39540
+ if (!depositData?.depositAddress) {
39541
+ throw new Error("Deposit address is required");
39520
39542
  }
39521
- if (!route.params.fromAddress || !route.params.toAddress) {
39522
- throw new Error("From or to address is required");
39523
- }
39524
- const isDirectTransfer = isDepositRoute(route);
39525
- // Means it's a transfer to a deposit address
39526
- // Instead of a Swap/Contract call using a DEX like Jupiter
39527
- if (isDirectTransfer) {
39528
- // Get the deposit address from the squidRoute
39529
- const depositData = useDepositAddressStore.getState().deposit;
39530
- // Validate params
39531
- if (!depositData?.depositAddress) {
39532
- throw new Error("Deposit address is required");
39533
- }
39534
- const signature = await executeSolanaTransfer({
39535
- amount: BigInt(route.params.fromAmount),
39536
- target: depositData.depositAddress,
39537
- signer: solanaSigner,
39538
- connection: solanaConnection,
39539
- sourceToken: findToken(route.params.fromToken, route?.params?.fromChain),
39540
- onSigned: (txHash) => {
39541
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39542
- const txParams = setTransactionState({
39543
- route,
39544
- txHash,
39545
- transactionIdForStatus: depositData.chainflipStatusTrackingId,
39546
- userAddress: sourceUserAddress,
39547
- status: exports.TransactionStatus.INITIAL_LOADING,
39548
- sourceStatus: exports.TransactionStatus.ONGOING,
39549
- id,
39550
- });
39551
- if (txParams) {
39552
- addSwapTransaction({
39553
- ...txParams,
39554
- params: route.params,
39555
- estimate: route.estimate,
39556
- });
39557
- }
39558
- },
39559
- });
39560
- return signature;
39561
- }
39562
- const signature = await executeSolanaSwap({
39563
- route,
39543
+ const signature = await executeSolanaTransfer({
39544
+ amount: BigInt(route.params.fromAmount),
39545
+ target: depositData.depositAddress,
39564
39546
  signer: solanaSigner,
39565
39547
  connection: solanaConnection,
39548
+ sourceToken: findToken(route.params.fromToken, route?.params?.fromChain),
39566
39549
  onSigned: (txHash) => {
39567
39550
  WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39568
39551
  const txParams = setTransactionState({
39569
39552
  route,
39570
39553
  txHash,
39571
- transactionIdForStatus: undefined,
39554
+ transactionIdForStatus: depositData.chainflipStatusTrackingId,
39572
39555
  userAddress: sourceUserAddress,
39573
39556
  status: exports.TransactionStatus.INITIAL_LOADING,
39574
39557
  sourceStatus: exports.TransactionStatus.ONGOING,
@@ -39585,13 +39568,39 @@ const useExecuteTransaction = (squidRoute) => {
39585
39568
  });
39586
39569
  return signature;
39587
39570
  }
39588
- catch (error) {
39589
- console.error("Solana transaction failed:", error);
39590
- throw error instanceof Error
39591
- ? error
39592
- : new Error("Failed to execute Solana transaction");
39593
- }
39594
- },
39571
+ const signature = await executeSolanaSwap({
39572
+ route,
39573
+ signer: solanaSigner,
39574
+ connection: solanaConnection,
39575
+ onSigned: (txHash) => {
39576
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39577
+ const txParams = setTransactionState({
39578
+ route,
39579
+ txHash,
39580
+ transactionIdForStatus: undefined,
39581
+ userAddress: sourceUserAddress,
39582
+ status: exports.TransactionStatus.INITIAL_LOADING,
39583
+ sourceStatus: exports.TransactionStatus.ONGOING,
39584
+ id,
39585
+ });
39586
+ if (txParams) {
39587
+ addSwapTransaction({
39588
+ ...txParams,
39589
+ params: route.params,
39590
+ estimate: route.estimate,
39591
+ });
39592
+ }
39593
+ },
39594
+ });
39595
+ return signature;
39596
+ }
39597
+ catch (error) {
39598
+ console.error("Solana transaction failed:", error);
39599
+ throw error instanceof Error
39600
+ ? error
39601
+ : new Error("Failed to execute Solana transaction");
39602
+ }
39603
+ }, {
39595
39604
  onError: (error, variables) => {
39596
39605
  const currentTx = getTransaction(variables.id);
39597
39606
  const errorObject = getTransactionError(error);
@@ -39612,9 +39621,7 @@ const useExecuteTransaction = (squidRoute) => {
39612
39621
  },
39613
39622
  onSuccess: (_data, variables) => {
39614
39623
  const currentTx = getTransaction(variables.id);
39615
- queryClient.invalidateQueries({
39616
- queryKey: getPrefixKey(QueryKeys.Balances),
39617
- });
39624
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balances));
39618
39625
  if (isSameChain && currentTx?.transactionId) {
39619
39626
  replaceSwapTransactionStatus({
39620
39627
  transactionId: currentTx.transactionId,
@@ -39631,207 +39638,197 @@ const useExecuteTransaction = (squidRoute) => {
39631
39638
  });
39632
39639
  },
39633
39640
  });
39634
- const swapMutationBitcoin = reactQuery.useMutation({
39635
- mutationFn: async ({ id, route }) => {
39636
- const { depositAddress, amount: sendAmount, chainflipStatusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
39637
- if (!depositAddress) {
39638
- throw new Error(`Invalid deposit address: ${depositAddress}`);
39639
- }
39640
- if (!sendAmount) {
39641
- throw new Error(`Invalid send amount: ${sendAmount}`);
39642
- }
39643
- const allParamsValid = route && bitcoinSigner && depositAddress && sendAmount;
39644
- await changeNetworkIfNeeded.mutateAsync();
39645
- if (allParamsValid) {
39646
- dispatchSignatureRequestEvent(route);
39647
- const { txHash } = await bitcoinSigner.sendBTC(depositAddress, Number(sendAmount));
39648
- if (txHash) {
39649
- resetQueriesAfterTxSigned();
39650
- }
39651
- // Dispatch event so it can be listened from outside the widget
39652
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39653
- if (route.transactionRequest) {
39654
- const txParams = setTransactionState({
39655
- route,
39656
- txHash,
39657
- // When bridging from Bitcoin we need to send the chainflipId to the status endpoint
39658
- // instead of the Bitcoin transaction hash
39659
- transactionIdForStatus: chainflipStatusTrackingId,
39660
- userAddress: sourceUserAddress,
39661
- status: exports.TransactionStatus.INITIAL_LOADING,
39662
- sourceStatus: exports.TransactionStatus.ONGOING,
39663
- axelarUrl: undefined,
39664
- id,
39665
- });
39666
- if (txParams) {
39667
- addSwapTransaction({
39668
- ...txParams,
39669
- params: route.params,
39670
- estimate: route.estimate,
39671
- });
39672
- }
39673
- }
39674
- }
39675
- else {
39676
- throw new Error("Need all parameters");
39677
- }
39678
- },
39679
- });
39680
- const swapMutationXrpl = reactQuery.useMutation({
39681
- mutationFn: async ({ id, route }) => {
39682
- if (!route?.transactionRequest || !xrplSigner) {
39683
- throw new Error("Need all parameters");
39684
- }
39685
- if (route.transactionRequest.type !== squidTypes.SquidDataType.OnChainExecution) {
39686
- throw new Error("Invalid route type");
39687
- }
39688
- const { data } = route.transactionRequest;
39689
- const paymentTx = parseXrplPaymentTx(data);
39690
- if (!paymentTx)
39691
- throw new Error("Could not parse transaction");
39692
- const fromChainId = route.params.fromChain;
39693
- const xrplNetwork = getXrplNetwork(fromChainId);
39694
- if (xrplNetwork == null) {
39695
- throw new Error(`No XRPL network found for chainId '${fromChainId}'`);
39696
- }
39697
- const txRes = await xrplSigner.signAndSubmit({
39698
- tx: paymentTx,
39699
- network: xrplNetwork,
39700
- });
39701
- const txParams = setTransactionState({
39702
- txHash: txRes.hash,
39703
- id,
39704
- sourceStatus: exports.TransactionStatus.ONGOING,
39705
- status: exports.TransactionStatus.ONGOING,
39706
- route: route,
39707
- userAddress: sourceUserAddress,
39708
- });
39709
- if (txParams && route) {
39710
- addSwapTransaction({
39711
- ...txParams,
39712
- params: route.params,
39713
- estimate: route.estimate,
39714
- });
39715
- }
39716
- if (txRes.status !== XrplTxStatus.SUCCESS) {
39717
- throw new Error(`Transaction failed with status: ${txRes.status}`);
39718
- }
39719
- },
39720
- });
39721
- const swapMutationSui = reactQuery.useMutation({
39722
- mutationFn: async ({ id, route }) => {
39723
- if (!route || !suiSigner || !fromChain) {
39724
- throw new Error("Need all parameters");
39725
- }
39726
- if (route.transactionRequest?.type !== squidTypes.SquidDataType.OnChainExecution) {
39727
- throw new Error("Invalid route type");
39728
- }
39729
- const suiWalletState = connectedWalletsByChainType[squidTypes.ChainType.SUI];
39730
- if (!suiWalletState.account) {
39731
- throw new Error("Sui wallet is missing account data");
39732
- }
39733
- const fromChainId = route.params.fromChain;
39734
- const suiChain = getSuiChain(fromChainId);
39735
- if (!suiChain) {
39736
- throw new Error(`Source chain (${fromChainId}) does not match any Sui chain`);
39737
- }
39738
- const suiClient = await getClient(fromChain);
39739
- const txJson = route.transactionRequest.data;
39740
- const tx = transactions.Transaction.from(txJson);
39741
- const signedTx = await suiSigner.signTransaction({
39742
- transaction: tx,
39743
- account: suiWalletState.account,
39744
- chain: suiChain,
39745
- });
39746
- // execute transaction without waiting for confirmation
39747
- const txResponse = await suiClient.executeTransactionBlock({
39748
- signature: signedTx.signature,
39749
- transactionBlock: signedTx.bytes,
39750
- });
39751
- const txHash = txResponse.digest;
39641
+ const swapMutationBitcoin = reactQuery.useMutation(async ({ id, route }) => {
39642
+ const { depositAddress, amount: sendAmount, chainflipStatusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
39643
+ if (!depositAddress) {
39644
+ throw new Error(`Invalid deposit address: ${depositAddress}`);
39645
+ }
39646
+ if (!sendAmount) {
39647
+ throw new Error(`Invalid send amount: ${sendAmount}`);
39648
+ }
39649
+ const allParamsValid = route && bitcoinSigner && depositAddress && sendAmount;
39650
+ await changeNetworkIfNeeded.mutateAsync();
39651
+ if (allParamsValid) {
39652
+ dispatchSignatureRequestEvent(route);
39653
+ const { txHash } = await bitcoinSigner.sendBTC(depositAddress, Number(sendAmount));
39752
39654
  if (txHash) {
39753
39655
  resetQueriesAfterTxSigned();
39754
39656
  }
39657
+ // Dispatch event so it can be listened from outside the widget
39755
39658
  WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39756
- const txParams = setTransactionState({
39757
- route,
39758
- txHash,
39759
- userAddress: sourceUserAddress,
39760
- status: exports.TransactionStatus.INITIAL_LOADING,
39761
- sourceStatus: exports.TransactionStatus.ONGOING,
39762
- id,
39763
- });
39764
- if (txParams) {
39765
- addSwapTransaction({
39766
- ...txParams,
39767
- params: route.params,
39768
- estimate: route.estimate,
39659
+ if (route.transactionRequest) {
39660
+ const txParams = setTransactionState({
39661
+ route,
39662
+ txHash,
39663
+ // When bridging from Bitcoin we need to send the chainflipId to the status endpoint
39664
+ // instead of the Bitcoin transaction hash
39665
+ transactionIdForStatus: chainflipStatusTrackingId,
39666
+ userAddress: sourceUserAddress,
39667
+ status: exports.TransactionStatus.INITIAL_LOADING,
39668
+ sourceStatus: exports.TransactionStatus.ONGOING,
39669
+ axelarUrl: undefined,
39670
+ id,
39769
39671
  });
39672
+ if (txParams) {
39673
+ addSwapTransaction({
39674
+ ...txParams,
39675
+ params: route.params,
39676
+ estimate: route.estimate,
39677
+ });
39678
+ }
39770
39679
  }
39771
- // wait for transaction confirmation
39772
- await suiClient.waitForTransaction({
39773
- digest: txHash,
39774
- });
39775
- },
39680
+ }
39681
+ else {
39682
+ throw new Error("Need all parameters");
39683
+ }
39776
39684
  });
39777
- const swapMutationStellar = reactQuery.useMutation({
39778
- mutationFn: async ({ id, route }) => {
39779
- if (!stellarSigner || !route || !squid || !fromChain) {
39780
- throw new Error("Need all parameters");
39781
- }
39782
- const fromChainId = route.params.fromChain;
39783
- const stellarNetwork = getStellarNetwork(fromChainId);
39784
- if (stellarNetwork == null) {
39785
- throw new Error(`No Stellar network found for chainId ${fromChainId}`);
39786
- }
39787
- const { data: xdrHex, gasPrice } = route.transactionRequest;
39788
- const { address } = await stellarSigner.getAddress();
39789
- const client = await getClient(fromChain);
39790
- const account = await client.getAccount(address);
39791
- const operation = stellarSdk.xdr.Operation.fromXDR(xdrHex, "hex");
39792
- const builtTransaction = new stellarSdk.TransactionBuilder(account, {
39793
- fee: gasPrice || (BigInt(stellarSdk.BASE_FEE) * BigInt(2)).toString(),
39794
- networkPassphrase: stellarNetwork,
39795
- })
39796
- .addOperation(operation)
39797
- .setTimeout(300)
39798
- .build();
39799
- const preparedTransaction = await client.prepareTransaction(builtTransaction);
39800
- const { signedTxXdr } = await stellarSigner.signTransaction(preparedTransaction.toXDR(), {
39801
- networkPassphrase: stellarNetwork,
39685
+ const swapMutationXrpl = reactQuery.useMutation(async ({ id, route }) => {
39686
+ if (!route?.transactionRequest || !xrplSigner) {
39687
+ throw new Error("Need all parameters");
39688
+ }
39689
+ if (route.transactionRequest.type !== squidTypes.SquidDataType.OnChainExecution) {
39690
+ throw new Error("Invalid route type");
39691
+ }
39692
+ const { data } = route.transactionRequest;
39693
+ const paymentTx = parseXrplPaymentTx(data);
39694
+ if (!paymentTx)
39695
+ throw new Error("Could not parse transaction");
39696
+ const fromChainId = route.params.fromChain;
39697
+ const xrplNetwork = getXrplNetwork(fromChainId);
39698
+ if (xrplNetwork == null) {
39699
+ throw new Error(`No XRPL network found for chainId '${fromChainId}'`);
39700
+ }
39701
+ const txRes = await xrplSigner.signAndSubmit({
39702
+ tx: paymentTx,
39703
+ network: xrplNetwork,
39704
+ });
39705
+ const txParams = setTransactionState({
39706
+ txHash: txRes.hash,
39707
+ id,
39708
+ sourceStatus: exports.TransactionStatus.ONGOING,
39709
+ status: exports.TransactionStatus.ONGOING,
39710
+ route: route,
39711
+ userAddress: sourceUserAddress,
39712
+ });
39713
+ if (txParams && route) {
39714
+ addSwapTransaction({
39715
+ ...txParams,
39716
+ params: route.params,
39717
+ estimate: route.estimate,
39802
39718
  });
39803
- const signedTransaction = new stellarSdk.Transaction(signedTxXdr, stellarNetwork);
39804
- // get hash before submitting
39805
- const hash = signedTransaction.hash().toString("hex");
39806
- if (hash) {
39807
- resetQueriesAfterTxSigned();
39808
- }
39809
- // Dispatch event so it can be listened from outside the widget
39810
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39811
- const txParams = setTransactionState({
39812
- route,
39813
- txHash: hash,
39814
- userAddress: sourceUserAddress,
39815
- status: exports.TransactionStatus.INITIAL_LOADING,
39816
- sourceStatus: exports.TransactionStatus.ONGOING,
39817
- id,
39719
+ }
39720
+ if (txRes.status !== XrplTxStatus.SUCCESS) {
39721
+ throw new Error(`Transaction failed with status: ${txRes.status}`);
39722
+ }
39723
+ }, {});
39724
+ const swapMutationSui = reactQuery.useMutation(async ({ id, route }) => {
39725
+ if (!route || !suiSigner || !fromChain) {
39726
+ throw new Error("Need all parameters");
39727
+ }
39728
+ if (route.transactionRequest?.type !== squidTypes.SquidDataType.OnChainExecution) {
39729
+ throw new Error("Invalid route type");
39730
+ }
39731
+ const suiWalletState = connectedWalletsByChainType[squidTypes.ChainType.SUI];
39732
+ if (!suiWalletState.account) {
39733
+ throw new Error("Sui wallet is missing account data");
39734
+ }
39735
+ const fromChainId = route.params.fromChain;
39736
+ const suiChain = getSuiChain(fromChainId);
39737
+ if (!suiChain) {
39738
+ throw new Error(`Source chain (${fromChainId}) does not match any Sui chain`);
39739
+ }
39740
+ const suiClient = await getClient(fromChain);
39741
+ const txJson = route.transactionRequest.data;
39742
+ const tx = transactions.Transaction.from(txJson);
39743
+ const signedTx = await suiSigner.signTransaction({
39744
+ transaction: tx,
39745
+ account: suiWalletState.account,
39746
+ chain: suiChain,
39747
+ });
39748
+ // execute transaction without waiting for confirmation
39749
+ const txResponse = await suiClient.executeTransactionBlock({
39750
+ signature: signedTx.signature,
39751
+ transactionBlock: signedTx.bytes,
39752
+ });
39753
+ const txHash = txResponse.digest;
39754
+ if (txHash) {
39755
+ resetQueriesAfterTxSigned();
39756
+ }
39757
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39758
+ const txParams = setTransactionState({
39759
+ route,
39760
+ txHash,
39761
+ userAddress: sourceUserAddress,
39762
+ status: exports.TransactionStatus.INITIAL_LOADING,
39763
+ sourceStatus: exports.TransactionStatus.ONGOING,
39764
+ id,
39765
+ });
39766
+ if (txParams) {
39767
+ addSwapTransaction({
39768
+ ...txParams,
39769
+ params: route.params,
39770
+ estimate: route.estimate,
39818
39771
  });
39819
- if (txParams) {
39820
- addSwapTransaction({
39821
- ...txParams,
39822
- params: route.params,
39823
- estimate: route.estimate,
39824
- });
39825
- }
39826
- const sentTransaction = await client.sendTransaction(signedTransaction);
39827
- await client.waitForTransaction(sentTransaction.hash);
39828
- },
39829
- });
39772
+ }
39773
+ // wait for transaction confirmation
39774
+ await suiClient.waitForTransaction({
39775
+ digest: txHash,
39776
+ });
39777
+ }, {});
39778
+ const swapMutationStellar = reactQuery.useMutation(async ({ id, route }) => {
39779
+ if (!stellarSigner || !route || !squid || !fromChain) {
39780
+ throw new Error("Need all parameters");
39781
+ }
39782
+ const fromChainId = route.params.fromChain;
39783
+ const stellarNetwork = getStellarNetwork(fromChainId);
39784
+ if (stellarNetwork == null) {
39785
+ throw new Error(`No Stellar network found for chainId ${fromChainId}`);
39786
+ }
39787
+ const { data: xdrHex, gasPrice } = route.transactionRequest;
39788
+ const { address } = await stellarSigner.getAddress();
39789
+ const client = await getClient(fromChain);
39790
+ const account = await client.getAccount(address);
39791
+ const operation = stellarSdk.xdr.Operation.fromXDR(xdrHex, "hex");
39792
+ const builtTransaction = new stellarSdk.TransactionBuilder(account, {
39793
+ fee: gasPrice || (BigInt(stellarSdk.BASE_FEE) * BigInt(2)).toString(),
39794
+ networkPassphrase: stellarNetwork,
39795
+ })
39796
+ .addOperation(operation)
39797
+ .setTimeout(300)
39798
+ .build();
39799
+ const preparedTransaction = await client.prepareTransaction(builtTransaction);
39800
+ const { signedTxXdr } = await stellarSigner.signTransaction(preparedTransaction.toXDR(), {
39801
+ networkPassphrase: stellarNetwork,
39802
+ });
39803
+ const signedTransaction = new stellarSdk.Transaction(signedTxXdr, stellarNetwork);
39804
+ // get hash before submitting
39805
+ const hash = signedTransaction.hash().toString("hex");
39806
+ if (hash) {
39807
+ resetQueriesAfterTxSigned();
39808
+ }
39809
+ // Dispatch event so it can be listened from outside the widget
39810
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39811
+ const txParams = setTransactionState({
39812
+ route,
39813
+ txHash: hash,
39814
+ userAddress: sourceUserAddress,
39815
+ status: exports.TransactionStatus.INITIAL_LOADING,
39816
+ sourceStatus: exports.TransactionStatus.ONGOING,
39817
+ id,
39818
+ });
39819
+ if (txParams) {
39820
+ addSwapTransaction({
39821
+ ...txParams,
39822
+ params: route.params,
39823
+ estimate: route.estimate,
39824
+ });
39825
+ }
39826
+ const sentTransaction = await client.sendTransaction(signedTransaction);
39827
+ await client.waitForTransaction(sentTransaction.hash);
39828
+ }, {});
39830
39829
  const handleTransactionSuccess = React.useCallback((id) => {
39831
39830
  const currentTx = getTransaction(id);
39832
- queryClient.invalidateQueries({
39833
- queryKey: getPrefixKey(QueryKeys.Balances),
39834
- });
39831
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balances));
39835
39832
  if (isSameChain && currentTx?.transactionId) {
39836
39833
  replaceSwapTransactionStatus({
39837
39834
  transactionId: currentTx.transactionId,
@@ -39883,39 +39880,38 @@ const useExecuteTransaction = (squidRoute) => {
39883
39880
  setTransactionStoreState,
39884
39881
  squidRoute,
39885
39882
  ]);
39886
- const swapMutation = reactQuery.useMutation({
39887
- mutationFn: async (mutationParams) => {
39888
- if (!mutationParams.route)
39889
- throw new Error("route is required");
39890
- const sourceChain = findChain(mutationParams.route.params?.fromChain);
39891
- if (!sourceChain)
39892
- throw new Error("Could not find source chain");
39893
- switch (sourceChain.chainType) {
39894
- case squidTypes.ChainType.COSMOS: {
39895
- return swapMutationCosmos.mutateAsync(mutationParams);
39896
- }
39897
- case squidTypes.ChainType.EVM: {
39898
- return swapMutationEvm.mutateAsync(mutationParams);
39899
- }
39900
- case squidTypes.ChainType.BTC: {
39901
- return swapMutationBitcoin.mutateAsync(mutationParams);
39902
- }
39903
- case squidTypes.ChainType.SOLANA: {
39904
- return swapMutationSolana.mutateAsync(mutationParams);
39905
- }
39906
- case squidTypes.ChainType.SUI: {
39907
- return swapMutationSui.mutateAsync(mutationParams);
39908
- }
39909
- case squidTypes.ChainType.XRPL: {
39910
- return swapMutationXrpl.mutateAsync(mutationParams);
39911
- }
39912
- case squidTypes.ChainType.STELLAR: {
39913
- return swapMutationStellar.mutateAsync(mutationParams);
39914
- }
39915
- default:
39916
- throw new Error(`Swap mutation not implemented for chain type: ${sourceChain.chainType}`);
39883
+ const swapMutation = reactQuery.useMutation(async (mutationParams) => {
39884
+ if (!mutationParams.route)
39885
+ throw new Error("route is required");
39886
+ const sourceChain = findChain(mutationParams.route.params?.fromChain);
39887
+ if (!sourceChain)
39888
+ throw new Error("Could not find source chain");
39889
+ switch (sourceChain.chainType) {
39890
+ case squidTypes.ChainType.COSMOS: {
39891
+ return swapMutationCosmos.mutateAsync(mutationParams);
39917
39892
  }
39918
- },
39893
+ case squidTypes.ChainType.EVM: {
39894
+ return swapMutationEvm.mutateAsync(mutationParams);
39895
+ }
39896
+ case squidTypes.ChainType.BTC: {
39897
+ return swapMutationBitcoin.mutateAsync(mutationParams);
39898
+ }
39899
+ case squidTypes.ChainType.SOLANA: {
39900
+ return swapMutationSolana.mutateAsync(mutationParams);
39901
+ }
39902
+ case squidTypes.ChainType.SUI: {
39903
+ return swapMutationSui.mutateAsync(mutationParams);
39904
+ }
39905
+ case squidTypes.ChainType.XRPL: {
39906
+ return swapMutationXrpl.mutateAsync(mutationParams);
39907
+ }
39908
+ case squidTypes.ChainType.STELLAR: {
39909
+ return swapMutationStellar.mutateAsync(mutationParams);
39910
+ }
39911
+ default:
39912
+ throw new Error(`Swap mutation not implemented for chain type: ${sourceChain.chainType}`);
39913
+ }
39914
+ }, {
39919
39915
  onMutate: (variables) => {
39920
39916
  useTransactionStore.setState({
39921
39917
  txLocalId: variables.id,
@@ -39964,7 +39960,7 @@ const useExecuteTransaction = (squidRoute) => {
39964
39960
  toToken,
39965
39961
  toChain,
39966
39962
  fromChain,
39967
- isPending: swapMutation.isPending,
39963
+ isLoading: swapMutation.isLoading,
39968
39964
  error: swapMutation.error,
39969
39965
  };
39970
39966
  };
@@ -40025,59 +40021,57 @@ const useGetRoute = () => {
40025
40021
  * These data will be used to trigger the transaction
40026
40022
  * @returns {Route} Route data
40027
40023
  */
40028
- return reactQuery.useMutation({
40029
- mutationFn: async ({ fromChain, toChain, fromToken, toToken, sourceUserAddress, destinationAddress, fromPrice, bypassGuardrails, quoteOnly, fromChainType, postHook, preHook, }) => {
40030
- if (!fromChain || !toChain || !fromToken || !toToken || !fromPrice) {
40031
- return undefined;
40032
- }
40033
- // Dispatch requestQuote event
40034
- dispatchRequestQuoteEvent({
40035
- fromChain,
40036
- toChain,
40037
- fromToken: fromToken.address,
40038
- toToken: toToken.address,
40039
- fromAmount: fromPrice,
40040
- fromAddress: sourceUserAddress,
40041
- toAddress: destinationAddress,
40042
- });
40043
- const isEvmSwap = Number(fromChain) > 0 && Number(toChain) > 0;
40044
- const cosmosFallbackAddresses = quoteOnly || isEvmSwap ? undefined : await getCosmosFallbackAddresses();
40045
- const fromTokenAddress = fromToken.address;
40046
- const toTokenAddress = toToken.address;
40047
- const fromAmount = parseToBigInt(fromPrice?.toString() ?? "0", fromToken?.decimals).toString();
40048
- const fromAddress = sourceUserAddress ??
40049
- chainTypeToZeroAddressMap[fromChainType ?? squidTypes.ChainType.EVM];
40050
- const params = {
40051
- fromChain,
40052
- fromToken: fromTokenAddress,
40053
- fromAddress,
40054
- fromAmount,
40055
- toChain,
40056
- toToken: toTokenAddress,
40057
- toAddress: destinationAddress ?? "",
40058
- quoteOnly,
40059
- slippage: config.slippage === 0 ? undefined : config.slippage,
40060
- bypassGuardrails,
40061
- preHook,
40062
- postHook,
40063
- };
40064
- // If the swap is involving cosmos chains, we need to add the fallback addresses (if any)
40065
- if (cosmosFallbackAddresses &&
40066
- cosmosFallbackAddresses.length > 0 &&
40067
- cosmosFallbackAddresses[0].address) {
40068
- params.fallbackAddresses = cosmosFallbackAddresses;
40069
- }
40070
- const { route } = await squid.getRoute({
40071
- ...params,
40072
- });
40073
- // Cache the route data
40074
- // Useful when the getRoute mutation is called from another hook
40075
- queryClient.setQueryData(keys().transaction(fromChain, toChain, toToken.address, fromToken.address, fromPrice, config.slippage, config.enableGetGasOnDestination, sourceUserAddress, config.degenMode, destinationAddress, swapRoute?.fallbackAddress, quoteOnly, fromChainType, config.preHook, config.postHook), route);
40076
- return route;
40077
- },
40024
+ return reactQuery.useMutation(async ({ fromChain, toChain, fromToken, toToken, sourceUserAddress, destinationAddress, fromPrice, bypassGuardrails, quoteOnly, fromChainType, postHook, preHook, }) => {
40025
+ if (!fromChain || !toChain || !fromToken || !toToken || !fromPrice) {
40026
+ return undefined;
40027
+ }
40028
+ // Dispatch requestQuote event
40029
+ dispatchRequestQuoteEvent({
40030
+ fromChain,
40031
+ toChain,
40032
+ fromToken: fromToken.address,
40033
+ toToken: toToken.address,
40034
+ fromAmount: fromPrice,
40035
+ fromAddress: sourceUserAddress,
40036
+ toAddress: destinationAddress,
40037
+ });
40038
+ const isEvmSwap = Number(fromChain) > 0 && Number(toChain) > 0;
40039
+ const cosmosFallbackAddresses = quoteOnly || isEvmSwap ? undefined : await getCosmosFallbackAddresses();
40040
+ const fromTokenAddress = fromToken.address;
40041
+ const toTokenAddress = toToken.address;
40042
+ const fromAmount = parseToBigInt(fromPrice?.toString() ?? "0", fromToken?.decimals).toString();
40043
+ const fromAddress = sourceUserAddress ??
40044
+ chainTypeToZeroAddressMap[fromChainType ?? squidTypes.ChainType.EVM];
40045
+ const params = {
40046
+ fromChain,
40047
+ fromToken: fromTokenAddress,
40048
+ fromAddress,
40049
+ fromAmount,
40050
+ toChain,
40051
+ toToken: toTokenAddress,
40052
+ toAddress: destinationAddress ?? "",
40053
+ quoteOnly,
40054
+ slippage: config.slippage === 0 ? undefined : config.slippage,
40055
+ bypassGuardrails,
40056
+ preHook,
40057
+ postHook,
40058
+ };
40059
+ // If the swap is involving cosmos chains, we need to add the fallback addresses (if any)
40060
+ if (cosmosFallbackAddresses &&
40061
+ cosmosFallbackAddresses.length > 0 &&
40062
+ cosmosFallbackAddresses[0].address) {
40063
+ params.fallbackAddresses = cosmosFallbackAddresses;
40064
+ }
40065
+ const { route } = await squid.getRoute({
40066
+ ...params,
40067
+ });
40068
+ // Cache the route data
40069
+ // Useful when the getRoute mutation is called from another hook
40070
+ queryClient.setQueryData(keys().transaction(fromChain, toChain, toToken.address, fromToken.address, fromPrice, config.slippage, config.enableGetGasOnDestination, sourceUserAddress, config.degenMode, destinationAddress, swapRoute?.fallbackAddress, quoteOnly, fromChainType, config.preHook, config.postHook), route);
40071
+ return route;
40078
40072
  });
40079
40073
  };
40080
- const useGetRouteWrapper = ({ enabled, gcTime = 5 * 60 * 1000, // 5 minutes
40074
+ const useGetRouteWrapper = ({ enabled, cacheTime = 5 * 60 * 1000, // 5 minutes
40081
40075
  staleTime = 60 * 1000, // 1 minute
40082
40076
  refetchOnWindowFocus = (query) => Date.now() - query.state.dataUpdatedAt > 30000, // Update if older than 30 seconds, when window is focused
40083
40077
  refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true, }) => {
@@ -40127,27 +40121,25 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
40127
40121
  * These data will be used to trigger the transaction
40128
40122
  * @returns {Route} Route data
40129
40123
  */
40130
- const squidRoute = reactQuery.useQuery({
40131
- queryKey: squidRouteQueryKeys,
40132
- queryFn: async () => {
40133
- const route = await getRouteMutation.mutateAsync({
40134
- fromChain: fromChain?.chainId,
40135
- toChain: toChain?.chainId,
40136
- fromToken,
40137
- toToken,
40138
- sourceUserAddress,
40139
- destinationAddress,
40140
- fromPrice,
40141
- bypassGuardrails: config.degenMode,
40142
- quoteOnly,
40143
- fromChainType: fromChain?.chainType,
40144
- postHook: config.postHook,
40145
- preHook: config.preHook,
40146
- });
40147
- return route;
40148
- },
40124
+ const squidRoute = reactQuery.useQuery(squidRouteQueryKeys, async () => {
40125
+ const route = await getRouteMutation.mutateAsync({
40126
+ fromChain: fromChain?.chainId,
40127
+ toChain: toChain?.chainId,
40128
+ fromToken,
40129
+ toToken,
40130
+ sourceUserAddress,
40131
+ destinationAddress,
40132
+ fromPrice,
40133
+ bypassGuardrails: config.degenMode,
40134
+ quoteOnly,
40135
+ fromChainType: fromChain?.chainType,
40136
+ postHook: config.postHook,
40137
+ preHook: config.preHook,
40138
+ });
40139
+ return route;
40140
+ }, {
40149
40141
  enabled: queryEnabled,
40150
- gcTime,
40142
+ cacheTime,
40151
40143
  staleTime,
40152
40144
  refetchOnWindowFocus,
40153
40145
  refetchIntervalInBackground,
@@ -40156,7 +40148,7 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
40156
40148
  /**
40157
40149
  * If last updated data is older than X seconds and the query is currently loading, show loading indicator
40158
40150
  */
40159
- const showLoading = squidRoute.isFetching || squidRoute.isRefetching;
40151
+ const showLoading = React.useMemo(() => squidRoute.isFetching || squidRoute.isRefetching, [squidRoute.isFetching, squidRoute.isRefetching]);
40160
40152
  return {
40161
40153
  squidRoute,
40162
40154
  showLoading,
@@ -40188,7 +40180,7 @@ function useSendTransactionStatus({ chain, txHash, }) {
40188
40180
  transactionId: txHash,
40189
40181
  txType: exports.HistoryTxType.SEND,
40190
40182
  });
40191
- const { data: status, isSuccess, isError, } = reactQuery.useQuery({
40183
+ const { data: status } = reactQuery.useQuery({
40192
40184
  queryKey: keys().sendTransactionStatus(txHash, chain?.chainId),
40193
40185
  queryFn: async () => {
40194
40186
  if (!chain || !txHash)
@@ -40198,30 +40190,17 @@ function useSendTransactionStatus({ chain, txHash, }) {
40198
40190
  txHash,
40199
40191
  });
40200
40192
  },
40201
- refetchInterval: chain
40202
- ? getSendTxStatusRefetchInterval(chain.chainType)
40203
- : false,
40204
- enabled: !!chain &&
40205
- !!txHash &&
40206
- !isTransactionComplete &&
40207
- !!currentHistoryItem &&
40208
- !isHistoryTransactionEnded({
40209
- data: currentHistoryItem?.data,
40210
- txType: exports.HistoryTxType.SEND,
40211
- }),
40212
- });
40213
- React.useEffect(() => {
40214
- if (isSuccess) {
40215
- setIsTransactionComplete(status !== exports.SendTransactionStatus.ONGOING);
40216
- if (status != null && !!txHash) {
40193
+ onSuccess: (txStatus) => {
40194
+ setIsTransactionComplete(txStatus !== exports.SendTransactionStatus.ONGOING);
40195
+ if (txStatus != null && !!txHash) {
40217
40196
  replaceTransactionStatus({
40218
40197
  txType: exports.HistoryTxType.SEND,
40219
- status: status,
40198
+ status: txStatus,
40220
40199
  hash: txHash,
40221
40200
  });
40222
40201
  }
40223
- }
40224
- if (isError) {
40202
+ },
40203
+ onError() {
40225
40204
  setIsTransactionComplete(true);
40226
40205
  if (txHash) {
40227
40206
  replaceTransactionStatus({
@@ -40230,8 +40209,19 @@ function useSendTransactionStatus({ chain, txHash, }) {
40230
40209
  hash: txHash,
40231
40210
  });
40232
40211
  }
40233
- }
40234
- }, [isError, isSuccess, replaceTransactionStatus, status, txHash]);
40212
+ },
40213
+ refetchInterval: chain
40214
+ ? getSendTxStatusRefetchInterval(chain.chainType)
40215
+ : false,
40216
+ enabled: !!chain &&
40217
+ !!txHash &&
40218
+ !isTransactionComplete &&
40219
+ !!currentHistoryItem &&
40220
+ !isHistoryTransactionEnded({
40221
+ data: currentHistoryItem?.data,
40222
+ txType: exports.HistoryTxType.SEND,
40223
+ }),
40224
+ });
40235
40225
  return {
40236
40226
  status: status ?? currentHistoryItem?.data?.status,
40237
40227
  };
@@ -40265,9 +40255,7 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
40265
40255
  apiUrl: latestConfig.apiUrl,
40266
40256
  });
40267
40257
  }, [transaction]);
40268
- const transactionStatusQuery = reactQuery.useQuery({
40269
- queryKey: keys().swapTransactionStatus(transaction?.transactionId),
40270
- queryFn: fetchTransactionStatusWithLatestConfig,
40258
+ const transactionStatusQuery = reactQuery.useQuery(keys().swapTransactionStatus(transaction?.transactionId), fetchTransactionStatusWithLatestConfig, {
40271
40259
  enabled: enabled &&
40272
40260
  transaction?.transactionId !== "0" &&
40273
40261
  !!transaction?.transactionId &&
@@ -40281,12 +40269,12 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
40281
40269
  data: currentHistoryItem?.data,
40282
40270
  txType: exports.HistoryTxType.SWAP,
40283
40271
  }),
40284
- refetchInterval({ state }) {
40272
+ refetchInterval(statusResponse) {
40285
40273
  // If the status response is something telling that the transaction
40286
40274
  // is finished, then store transaction history state if success
40287
40275
  // And return false to indicate refetcher to stop
40288
- if (state.data &&
40289
- transactionEndStatuses.includes(getTransactionStatus(state.data) ?? "")) {
40276
+ if (statusResponse &&
40277
+ transactionEndStatuses.includes(getTransactionStatus(statusResponse) ?? "")) {
40290
40278
  return false;
40291
40279
  }
40292
40280
  return refetchInterval; // Had to handle a variable here because after onError, we want the interval to stop
@@ -40295,10 +40283,7 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
40295
40283
  retryDelay: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 5000 : 3000,
40296
40284
  retry: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 6 : retry,
40297
40285
  refetchOnWindowFocus,
40298
- });
40299
- React.useEffect(() => {
40300
- if (transactionStatusQuery.isSuccess && transactionStatusQuery.data) {
40301
- const statusResponse = transactionStatusQuery.data;
40286
+ onSuccess: (statusResponse) => {
40302
40287
  // Dispatch event
40303
40288
  WidgetEvents.getInstance().dispatchSwapStatus(statusResponse.squidTransactionStatus ?? "");
40304
40289
  const endStatus = getTransactionEndStatus({ statusResponse });
@@ -40310,9 +40295,8 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
40310
40295
  status: endStatus,
40311
40296
  });
40312
40297
  }
40313
- }
40314
- if (transactionStatusQuery.isError) {
40315
- const error = transactionStatusQuery.error;
40298
+ },
40299
+ onError: (error) => {
40316
40300
  // `fetchTransactionStatus` throws an error with a cause being an AxiosError
40317
40301
  const is404 = is404Error(error.cause);
40318
40302
  if (!transaction?.transactionId)
@@ -40333,15 +40317,8 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
40333
40317
  status: exports.TransactionStatus.ERROR,
40334
40318
  });
40335
40319
  }
40336
- }
40337
- }, [
40338
- transactionStatusQuery.isSuccess,
40339
- transactionStatusQuery.isError,
40340
- transaction?.transactionId,
40341
- transactionStatusQuery.error,
40342
- replaceSwapTransactionStatus,
40343
- transactionStatusQuery.data,
40344
- ]);
40320
+ },
40321
+ });
40345
40322
  return {
40346
40323
  transactionStatusQuery,
40347
40324
  latestStatus: transactionStatusQuery.data
@@ -40384,7 +40361,7 @@ const useAvatar = (seed = zeroAddress) => {
40384
40361
  },
40385
40362
  // data is static, so no need to refetch
40386
40363
  refetchOnWindowFocus: false,
40387
- gcTime: Infinity,
40364
+ cacheTime: Infinity,
40388
40365
  staleTime: Infinity,
40389
40366
  });
40390
40367
  return avatar || "";
@@ -40426,40 +40403,38 @@ const useAddToken = (chainToCompare, tokenToCompare) => {
40426
40403
  /**
40427
40404
  * Add token to wallet
40428
40405
  */
40429
- const addToken = reactQuery.useMutation({
40430
- mutationFn: async ({ chain: _chain, token: _token, }) => {
40431
- const token = _token ?? tokenToCompare;
40432
- const chain = _chain ?? chainToCompare;
40433
- if (token && chain?.chainType === squidTypes.ChainType.EVM) {
40434
- const provider = await connector?.getProvider();
40435
- // Switch network if needed
40436
- if (currentEvmChain?.id.toString() !== token?.chainId) {
40437
- try {
40406
+ const addToken = reactQuery.useMutation(async ({ chain: _chain, token: _token, }) => {
40407
+ const token = _token ?? tokenToCompare;
40408
+ const chain = _chain ?? chainToCompare;
40409
+ if (token && chain?.chainType === squidTypes.ChainType.EVM) {
40410
+ const provider = await connector?.getProvider();
40411
+ // Switch network if needed
40412
+ if (currentEvmChain?.id.toString() !== token?.chainId) {
40413
+ try {
40414
+ await switchChainAsync({
40415
+ chainId: +token.chainId,
40416
+ });
40417
+ }
40418
+ catch (error) {
40419
+ console.debug("Error switching network:", error);
40420
+ if (isEvmChainNotSupportedError(error)) {
40421
+ await addEthereumChain({
40422
+ chain,
40423
+ provider,
40424
+ });
40438
40425
  await switchChainAsync({
40439
40426
  chainId: +token.chainId,
40440
40427
  });
40441
40428
  }
40442
- catch (error) {
40443
- console.debug("Error switching network:", error);
40444
- if (isEvmChainNotSupportedError(error)) {
40445
- await addEthereumChain({
40446
- chain,
40447
- provider,
40448
- });
40449
- await switchChainAsync({
40450
- chainId: +token.chainId,
40451
- });
40452
- }
40453
- }
40454
- // Metamask is not popping the second modal if we don't wait a bit
40455
- // eslint-disable-next-line no-promise-executor-return
40456
- await new Promise((resolve) => setTimeout(resolve, 100));
40457
40429
  }
40458
- await addTokenToWallet({ token, provider });
40430
+ // Metamask is not popping the second modal if we don't wait a bit
40431
+ // eslint-disable-next-line no-promise-executor-return
40432
+ await new Promise((resolve) => setTimeout(resolve, 100));
40459
40433
  }
40460
- // TODO: Implement keplr add token
40461
- return false;
40434
+ await addTokenToWallet({ token, provider });
40462
40435
  }
40436
+ // TODO: Implement keplr add token
40437
+ return false;
40463
40438
  });
40464
40439
  return {
40465
40440
  addToken,
@@ -40664,9 +40639,7 @@ function useXrplTrustLine({ address, chain, token, amount }) {
40664
40639
  }
40665
40640
  },
40666
40641
  async onSuccess() {
40667
- queryClient.invalidateQueries({
40668
- queryKey: getPrefixKey(QueryKeys.XrplTrustLine),
40669
- });
40642
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.XrplTrustLine));
40670
40643
  },
40671
40644
  });
40672
40645
  /**
@@ -41024,6 +40997,8 @@ exports.useEvmBalance = useEvmBalance;
41024
40997
  exports.useExecuteFiatQuote = useExecuteFiatQuote;
41025
40998
  exports.useExecuteTransaction = useExecuteTransaction;
41026
40999
  exports.useFavoriteTokensStore = useFavoriteTokensStore;
41000
+ exports.useFiatOnRampTxStatus = useFiatOnRampTxStatus;
41001
+ exports.useFiatTransactions = useFiatTransactions;
41027
41002
  exports.useGetFiatQuote = useGetFiatQuote;
41028
41003
  exports.useGetOnRampConfig = useGetOnRampConfig;
41029
41004
  exports.useGetOnrampPaymentTypes = useGetOnrampPaymentTypes;
@@ -41041,6 +41016,7 @@ exports.useMultiChainWallet = useMultiChainWallet;
41041
41016
  exports.useMultipleTokenPrices = useMultipleTokenPrices;
41042
41017
  exports.useNativeBalance = useNativeBalance;
41043
41018
  exports.useNativeTokenForChain = useNativeTokenForChain;
41019
+ exports.useRecommendedQuote = useRecommendedQuote;
41044
41020
  exports.useRouteWarnings = useRouteWarnings;
41045
41021
  exports.useSendTransaction = useSendTransaction;
41046
41022
  exports.useSendTransactionGas = useSendTransactionGas;
@@ -41068,4 +41044,4 @@ exports.useWallets = useWallets;
41068
41044
  exports.useXrplTrustLine = useXrplTrustLine;
41069
41045
  exports.walletIconBaseUrl = walletIconBaseUrl;
41070
41046
  exports.walletSupportsChainType = walletSupportsChainType;
41071
- //# sourceMappingURL=index-CS74WzWX.js.map
41047
+ //# sourceMappingURL=index-BjIFR_GS.js.map