@0xsquid/react-hooks 8.0.1-para-beta.5 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/core/types/event.d.ts +17 -8
  2. package/dist/hooks/onramp/useFiatToCrypto.d.ts +28 -6
  3. package/dist/hooks/squid/useSquid.d.ts +2 -2
  4. package/dist/hooks/swap/useDepositAddress.d.ts +2 -2
  5. package/dist/hooks/tokens/useAllConnectedWalletBalances.d.ts +11 -5
  6. package/dist/hooks/tokens/useAllTokensWithBalanceForChainType.d.ts +1 -1
  7. package/dist/hooks/tokens/useBalance.d.ts +1 -1
  8. package/dist/hooks/tokens/useMultipleTokenPrices.d.ts +2 -2
  9. package/dist/hooks/tokens/useNativeBalance.d.ts +2 -2
  10. package/dist/hooks/tokens/useTokenHistoricalData.d.ts +4 -4
  11. package/dist/hooks/transaction/send/useEstimateSendTransactionGas.d.ts +1 -1
  12. package/dist/hooks/transaction/send/useSendTransactionGas.d.ts +1 -1
  13. package/dist/hooks/transaction/useAllTransactionsStatus.d.ts +29 -3
  14. package/dist/hooks/transaction/useApproval.d.ts +2 -2
  15. package/dist/hooks/transaction/useExecuteTransaction.d.ts +2 -2
  16. package/dist/hooks/transaction/useGetRoute.d.ts +13 -19
  17. package/dist/hooks/transaction/useSwapTransactionStatus.d.ts +1 -1
  18. package/dist/hooks/wallet/useAddToken.d.ts +1 -1
  19. package/dist/hooks/wallet/useEns.d.ts +2 -2
  20. package/dist/hooks/wallet/useMultiChainWallet.d.ts +1 -1
  21. package/dist/hooks/wallet/useWallet.d.ts +1 -1
  22. package/dist/hooks/xrpl/useXrplTrustLine.d.ts +5 -5
  23. package/dist/{index-CjNxoWnC.js → index-DVmnHUzP.js} +1148 -1168
  24. package/dist/{index-CjNxoWnC.js.map → index-DVmnHUzP.js.map} +1 -1
  25. package/dist/{index-gPUCtJnZ.js → index-jI-SulDo.js} +1147 -1170
  26. package/dist/index-jI-SulDo.js.map +1 -0
  27. package/dist/index.esm.js +3 -5
  28. package/dist/index.esm.js.map +1 -1
  29. package/dist/index.js +7 -6
  30. package/dist/index.js.map +1 -1
  31. package/dist/provider/index.d.ts +0 -2
  32. package/dist/{secretService-Dp2zmZW_.js → secretService-DBxDcfuA.js} +4 -6
  33. package/dist/{secretService-Dp2zmZW_.js.map → secretService-DBxDcfuA.js.map} +1 -1
  34. package/dist/{secretService-7WbMaDcW.js → secretService-DN5IzV4w.js} +4 -6
  35. package/dist/{secretService-7WbMaDcW.js.map → secretService-DN5IzV4w.js.map} +1 -1
  36. package/dist/services/internal/configService.d.ts +1 -0
  37. package/dist/services/internal/eventService.d.ts +1 -0
  38. package/dist/{stellarService.client-CfGdqxtp.js → stellarService.client-7sSrAZi2.js} +4 -6
  39. package/dist/{stellarService.client-CfGdqxtp.js.map → stellarService.client-7sSrAZi2.js.map} +1 -1
  40. package/dist/{stellarService.client-CqP7EehD.js → stellarService.client-DTFEi5m2.js} +4 -6
  41. package/dist/{stellarService.client-CqP7EehD.js.map → stellarService.client-DTFEi5m2.js.map} +1 -1
  42. package/package.json +14 -19
  43. package/dist/index-gPUCtJnZ.js.map +0 -1
  44. package/scripts/setup-para.js +0 -62
@@ -31,13 +31,11 @@ var stargate = require('@cosmjs/stargate');
31
31
  var client = require('@mysten/sui/client');
32
32
  var protoSigning = require('@cosmjs/proto-signing');
33
33
  var transactions = require('@mysten/sui/transactions');
34
- var wagmiV2Integration = require('@getpara/wagmi-v2-integration');
35
- var Para = require('@getpara/web-sdk');
36
34
  var connectors = require('wagmi/connectors');
37
- var sdk = require('@0xsquid/sdk');
38
- var chains$1 = require('viem/chains');
39
35
  var cosmwasmStargate = require('@cosmjs/cosmwasm-stargate');
40
36
  var index_js = require('@injectivelabs/sdk-ts/dist/cjs/core/stargate/index.js');
37
+ var sdk = require('@0xsquid/sdk');
38
+ var chains$1 = require('viem/chains');
41
39
 
42
40
  function _interopNamespaceDefault(e) {
43
41
  var n = Object.create(null);
@@ -4004,6 +4002,20 @@ class WidgetEvents extends EventTarget {
4004
4002
  constructor() {
4005
4003
  super();
4006
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
+ };
4007
4019
  // Singleton, because we need to access this service outside the widget
4008
4020
  static getInstance() {
4009
4021
  if (!WidgetEvents.instance) {
@@ -4054,7 +4066,7 @@ class WidgetEvents extends EventTarget {
4054
4066
  * @param route
4055
4067
  */
4056
4068
  dispatchSwapExecuteCall(route, txHash) {
4057
- this.dispatch("swap", { route, txHash });
4069
+ this.dispatch("swap", this.getRouteEventPayload(route, txHash));
4058
4070
  }
4059
4071
  /**
4060
4072
  * Dispatch event when user changes chain/token
@@ -4133,7 +4145,18 @@ class WidgetEvents extends EventTarget {
4133
4145
  * @param data Quote execution parameters
4134
4146
  */
4135
4147
  dispatchOnrampQuoteExecute(data) {
4136
- 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
+ });
4137
4160
  }
4138
4161
  /**
4139
4162
  * Dispatch event when the search query has no results
@@ -26788,6 +26811,9 @@ const getConfigWithDefaults = (config) => {
26788
26811
  postHook: get$3(config, "postHook", defaultConfigValues.postHook),
26789
26812
  };
26790
26813
  };
26814
+ const randomIntFromInterval = (min, max) => {
26815
+ return Math.floor(Math.random() * (max - min + 1) + min);
26816
+ };
26791
26817
  const getTokensForChain = (tokens, chainId) => {
26792
26818
  return chainId ? tokens.filter((t) => t.chainId === chainId) : tokens;
26793
26819
  };
@@ -26815,9 +26841,7 @@ const fetchHighestBalanceToken = (fetchCachedBalance, chainId) => {
26815
26841
  if (fetchCachedBalance) {
26816
26842
  const queryCache = fetchCachedBalance?.queryClient?.getQueryCache();
26817
26843
  // get cached balance from key
26818
- const cache = queryCache?.find({
26819
- queryKey: keys().allTokensBalance(fetchCachedBalance?.address, !isNaN(Number(chainId)) ? squidTypes.ChainType.EVM : squidTypes.ChainType.COSMOS),
26820
- });
26844
+ const cache = queryCache?.find(keys().allTokensBalance(fetchCachedBalance?.address, !isNaN(Number(chainId)) ? squidTypes.ChainType.EVM : squidTypes.ChainType.COSMOS));
26821
26845
  // Parse result to TokenWithBalance[]
26822
26846
  const cacheResult = cache?.state.data ?? [];
26823
26847
  if (cacheResult.length > 0) {
@@ -27473,7 +27497,7 @@ const filterViewableTokens = (tokens, config, direction) => {
27473
27497
  };
27474
27498
  const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
27475
27499
  const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
27476
- const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-Dp2zmZW_.js'); });
27500
+ const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-DBxDcfuA.js'); });
27477
27501
  return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
27478
27502
  };
27479
27503
  function getTokenAssetsKey(token) {
@@ -29232,16 +29256,13 @@ const useSquid = () => {
29232
29256
  * Fetch squid info
29233
29257
  * Will refetch every minute
29234
29258
  */
29235
- const squidInfoQuery = reactQuery.useQuery({
29236
- queryKey: keys().squidInfo(),
29237
- queryFn: async () => {
29238
- if (squid) {
29239
- await squid?.init();
29240
- initializeSquidWithAssetsColors(squid, assetsColors);
29241
- return squid;
29242
- }
29243
- return null;
29259
+ const squidInfoQuery = reactQuery.useQuery(keys().squidInfo(), async () => {
29260
+ if (squid) {
29261
+ await squid?.init();
29262
+ initializeSquidWithAssetsColors(squid, assetsColors);
29263
+ return squid;
29244
29264
  }
29265
+ return null;
29245
29266
  });
29246
29267
  const tokens = React.useMemo(() => {
29247
29268
  if ((squidInfoQuery?.data?.tokens ?? []).length > 0) {
@@ -29357,11 +29378,47 @@ const FINAL_TRANSACTION_STATUSES = [
29357
29378
  "completed",
29358
29379
  "failed",
29359
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
+ };
29360
29417
  /**
29361
29418
  * Fetches quotes for fiat to crypto conversion with provider details.
29362
29419
  * Returns available rates, fees, and supported payment methods for the conversion.
29363
29420
  */
29364
- const useGetFiatQuote = ({ fiatCurrency, cryptoCurrencyID, amount, region, paymentMethod, enabled = true, }) => {
29421
+ const useGetFiatQuote = ({ fiatCurrency, cryptoCurrencyID, amount, region, paymentMethod, enabled = true, onSuccess, }) => {
29365
29422
  const service = React.useMemo(() => new OnrampService(), []);
29366
29423
  const { data: config } = useGetOnRampConfig();
29367
29424
  return reactQuery.useQuery({
@@ -29397,6 +29454,7 @@ const useGetFiatQuote = ({ fiatCurrency, cryptoCurrencyID, amount, region, payme
29397
29454
  return quoteResponse;
29398
29455
  },
29399
29456
  enabled: enabled && !!fiatCurrency && !!cryptoCurrencyID && amount > 0,
29457
+ onSuccess,
29400
29458
  });
29401
29459
  };
29402
29460
  /**
@@ -29413,7 +29471,7 @@ const useGetOnRampConfig = () => {
29413
29471
  chains,
29414
29472
  tokens,
29415
29473
  }),
29416
- gcTime: 1000 * 60 * 60,
29474
+ cacheTime: 1000 * 60 * 60,
29417
29475
  staleTime: 1000 * 60 * 30, // 30 minutes
29418
29476
  });
29419
29477
  };
@@ -29471,11 +29529,49 @@ const useExecuteFiatQuote = () => {
29471
29529
  },
29472
29530
  });
29473
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
+ };
29474
29569
  /**
29475
29570
  * Gets currency details including symbol and limits.
29476
29571
  * Example: USD → { symbol: "$", name: "US Dollar", ... }
29477
29572
  */
29478
29573
  const useCurrencyDetails = (currencyCode) => {
29574
+ const { data: config } = useGetOnRampConfig();
29479
29575
  return React.useMemo(() => {
29480
29576
  if (!currencyCode)
29481
29577
  return undefined;
@@ -29488,7 +29584,7 @@ const useCurrencyDetails = (currencyCode) => {
29488
29584
  };
29489
29585
  }
29490
29586
  return undefined;
29491
- }, [currencyCode]);
29587
+ }, [currencyCode, config?.supportedFiats]);
29492
29588
  };
29493
29589
  /**
29494
29590
  * Gets country details with flag URL and localized name.
@@ -29515,6 +29611,23 @@ const useAvailableQuotes = (quotes) => {
29515
29611
  return uniqueQuotes;
29516
29612
  }, [quotes]);
29517
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
+ };
29518
29631
  /**
29519
29632
  * Fetches the available payment methods for a given fiat and crypto currency pair.
29520
29633
  * The first item in the returned array is the most recommended.
@@ -29617,7 +29730,7 @@ const middleStepChecker = (statusResponse) => {
29617
29730
  }
29618
29731
  return exports.TransactionStatus.ERROR;
29619
29732
  }
29620
- if (statusResponse?.isLoading) {
29733
+ if (statusResponse?.isInitialLoading) {
29621
29734
  return exports.TransactionStatus.INITIAL_LOADING;
29622
29735
  }
29623
29736
  return exports.TransactionStatus.ONGOING;
@@ -30062,7 +30175,7 @@ const useClient = () => {
30062
30175
  queryFn: getUserCountry,
30063
30176
  enabled: isClient,
30064
30177
  retry: false,
30065
- gcTime: CACHE_TIME,
30178
+ cacheTime: CACHE_TIME,
30066
30179
  staleTime: STALE_TIME,
30067
30180
  });
30068
30181
  const userCountry = countryData?.countryCode || DEFAULT_COUNTRY_CODE;
@@ -30163,13 +30276,11 @@ function useDebouncedValue(value, delay) {
30163
30276
  * @returns the ENS data of the given address
30164
30277
  */
30165
30278
  function useEnsDataForAddress({ address, options, }) {
30166
- const ensQuery = reactQuery.useQuery({
30167
- queryKey: keys().ensData(address?.toLowerCase()),
30168
- queryFn: () => EnsService.getEnsDataFromAddress(address),
30279
+ const ensQuery = reactQuery.useQuery(keys().ensData(address?.toLowerCase()), () => EnsService.getEnsDataFromAddress(address), {
30169
30280
  ...options,
30170
30281
  enabled: Boolean(address?.trim()) &&
30171
30282
  (options?.enabled === undefined ? true : options.enabled),
30172
- gcTime: Infinity,
30283
+ cacheTime: Infinity,
30173
30284
  });
30174
30285
  return ensQuery;
30175
30286
  }
@@ -30185,16 +30296,14 @@ function useEnsDataForAddress({ address, options, }) {
30185
30296
  */
30186
30297
  function useEnsSearch({ name, enabled = true, delayMs = 500, }) {
30187
30298
  const debouncedName = useDebouncedValue(enabled ? name : undefined, delayMs);
30188
- const ensSearchQuery = reactQuery.useQuery({
30189
- queryKey: keys().ensSearch(debouncedName),
30190
- queryFn: () => {
30191
- const isExactEnsSearch = checkIsExactEns(debouncedName);
30192
- return isExactEnsSearch
30193
- ? EnsService.getExactEns(debouncedName)
30194
- : EnsService.searchEnsNames(debouncedName);
30195
- },
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
+ }, {
30196
30305
  enabled: Boolean(debouncedName?.trim()) && enabled,
30197
- gcTime: Infinity,
30306
+ cacheTime: Infinity,
30198
30307
  });
30199
30308
  return ensSearchQuery;
30200
30309
  }
@@ -30215,25 +30324,23 @@ function checkIsExactEns(name = "") {
30215
30324
 
30216
30325
  const useCosmosForChain = (chain) => {
30217
30326
  const { keplrTypeWallet } = useCosmosSigner({ chain });
30218
- const cosmosAddressQuery = reactQuery.useQuery({
30219
- queryKey: keys().cosmosAddress(chain?.chainId),
30220
- queryFn: async () => {
30221
- if (!chain || !keplrTypeWallet)
30222
- return "";
30223
- try {
30224
- const address = await getCosmosKey(chain.chainId, keplrTypeWallet);
30225
- return address ?? "";
30226
- }
30227
- catch (error) {
30228
- await suggestChainOrThrow({
30229
- chain: chain,
30230
- error,
30231
- keplrTypeWallet,
30232
- });
30233
- const address = await getCosmosKey(chain.chainId, keplrTypeWallet);
30234
- return address ?? "";
30235
- }
30236
- },
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
+ }, {
30237
30344
  enabled: !!keplrTypeWallet && chain?.chainType === squidTypes.ChainType.COSMOS,
30238
30345
  });
30239
30346
  return cosmosAddressQuery;
@@ -30310,14 +30417,12 @@ const useIsSameAddressAndGnosisContext = () => {
30310
30417
 
30311
30418
  function useBitcoin() {
30312
30419
  const connectedBitcoinWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.BTC]);
30313
- const connectBitcoin = reactQuery.useMutation({
30314
- mutationFn: async ({ wallet, }) => {
30315
- const { address } = await wallet.connector.requestAccount();
30316
- return {
30317
- wallet,
30318
- address,
30319
- };
30320
- }
30420
+ const connectBitcoin = reactQuery.useMutation(async ({ wallet, }) => {
30421
+ const { address } = await wallet.connector.requestAccount();
30422
+ return {
30423
+ wallet,
30424
+ address,
30425
+ };
30321
30426
  });
30322
30427
  return {
30323
30428
  connectBitcoin,
@@ -30357,17 +30462,15 @@ function useEvm() {
30357
30462
  const { wallets } = useEvmWallets();
30358
30463
  const connectedEvmWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.EVM]);
30359
30464
  const recentEvmWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.EVM]);
30360
- const connectEvm = reactQuery.useMutation({
30361
- mutationFn: async ({ wallet, }) => {
30362
- const result = await connectAsync({
30363
- connector: wallet.connector,
30364
- });
30365
- const [firstAddress] = result.accounts;
30366
- return {
30367
- wallet,
30368
- address: firstAddress,
30369
- };
30370
- }
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
+ };
30371
30474
  });
30372
30475
  const disconnectEvm = React.useCallback(async () => {
30373
30476
  disconnect({ connector: connectedEvmWallet.wallet?.connector });
@@ -30461,23 +30564,21 @@ function useSolana() {
30461
30564
  const { wallets } = useSolanaWallets();
30462
30565
  const connectedSolanaWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.SOLANA]);
30463
30566
  const recentSolanaWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.SOLANA]);
30464
- const connectSolana = reactQuery.useMutation({
30465
- mutationFn: async ({ wallet, }) => {
30466
- try {
30467
- // try to connect silently first
30468
- await wallet.connector.autoConnect();
30469
- }
30470
- catch {
30471
- // if auto-connect fails (e.g. not authorized yet)
30472
- // fallback to connect via popup
30473
- await wallet.connector.connect();
30474
- }
30475
- const address = wallet.connector.wallet.accounts[0].address;
30476
- return {
30477
- wallet,
30478
- address,
30479
- };
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();
30480
30576
  }
30577
+ const address = wallet.connector.wallet.accounts[0].address;
30578
+ return {
30579
+ wallet,
30580
+ address,
30581
+ };
30481
30582
  });
30482
30583
  const disconnectSolana = React.useCallback(async () => {
30483
30584
  await connectedSolanaWallet.wallet?.connector.disconnect();
@@ -30552,7 +30653,7 @@ function useStellarWallets() {
30552
30653
  return;
30553
30654
  try {
30554
30655
  const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
30555
- const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-CqP7EehD.js'); });
30656
+ const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-DTFEi5m2.js'); });
30556
30657
  const modules = initializeAllModules();
30557
30658
  const promises = modules.map(async (module) => {
30558
30659
  const isAvailable = await module.isAvailable();
@@ -30580,14 +30681,12 @@ function useStellarWallets() {
30580
30681
  function useStellar() {
30581
30682
  const { wallets } = useStellarWallets();
30582
30683
  const connectedStellarWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.STELLAR]);
30583
- const connectStellar = reactQuery.useMutation({
30584
- mutationFn: async ({ wallet, }) => {
30585
- const { address } = await wallet.connector.getAddress();
30586
- return {
30587
- wallet,
30588
- address,
30589
- };
30590
- }
30684
+ const connectStellar = reactQuery.useMutation(async ({ wallet, }) => {
30685
+ const { address } = await wallet.connector.getAddress();
30686
+ return {
30687
+ wallet,
30688
+ address,
30689
+ };
30591
30690
  });
30592
30691
  const disconnectStellar = React.useCallback(async () => {
30593
30692
  await connectedStellarWallet.wallet?.connector.disconnect?.();
@@ -30639,24 +30738,22 @@ function useSui() {
30639
30738
  const recentSuiWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.SUI]);
30640
30739
  const setConnectedWallet = useWalletStore((store) => store.setConnectedWallet);
30641
30740
  const disconnectWallet = useWalletStore((store) => store.disconnectWallet);
30642
- const connectSui = reactQuery.useMutation({
30643
- mutationFn: async ({ wallet, }) => {
30644
- let account;
30645
- try {
30646
- // try to connect silently first
30647
- account = await wallet.connector.connect({ silent: true });
30648
- }
30649
- catch {
30650
- // if auto-connect fails (e.g. not authorized yet)
30651
- // fallback to connect via popup
30652
- account = await wallet.connector.connect();
30653
- }
30654
- return {
30655
- wallet,
30656
- address: account.account.address,
30657
- account: account.account,
30658
- };
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 });
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();
30659
30751
  }
30752
+ return {
30753
+ wallet,
30754
+ address: account.account.address,
30755
+ account: account.account,
30756
+ };
30660
30757
  });
30661
30758
  const disconnectSui = React.useCallback(async () => {
30662
30759
  await connectedSuiWallet.wallet?.connector.disconnect();
@@ -30965,14 +31062,12 @@ function useXrpl() {
30965
31062
  const recentXrplWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.XRPL]);
30966
31063
  const setConnectedWallet = useWalletStore((store) => store.setConnectedWallet);
30967
31064
  const disconnectWallet = useWalletStore((store) => store.disconnectWallet);
30968
- const connectXrpl = reactQuery.useMutation({
30969
- mutationFn: async ({ wallet, }) => {
30970
- const xrplConnectedAddress = await wallet.connector.connect();
30971
- return {
30972
- wallet,
30973
- address: xrplConnectedAddress,
30974
- };
30975
- }
31065
+ const connectXrpl = reactQuery.useMutation(async ({ wallet, }) => {
31066
+ const xrplConnectedAddress = await wallet.connector.connect();
31067
+ return {
31068
+ wallet,
31069
+ address: xrplConnectedAddress,
31070
+ };
30976
31071
  });
30977
31072
  const disconnectXrpl = React.useCallback(async () => {
30978
31073
  await connectedXrplWallet?.wallet?.connector.disconnect?.();
@@ -31359,19 +31454,18 @@ const useMultiChainWallet = (chain) => {
31359
31454
  /**
31360
31455
  * Change current network for desired chain
31361
31456
  */
31362
- const changeNetworkIfNeeded = reactQuery.useMutation({
31363
- mutationFn: async () => {
31364
- const isNotOnDesiredChain = chain?.chainType === squidTypes.ChainType.EVM &&
31365
- currentEvmChain?.id !== Number(chain.chainId);
31366
- if (isNotOnDesiredChain) {
31367
- await switchChainAsync({
31368
- chainId: Number(chain.chainId),
31369
- });
31370
- }
31371
- // Implement keplr change network
31372
- // Looks like there are no method to do that at the moment
31373
- return false;
31374
- },
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
+ }, {
31375
31469
  onError: async (error) => {
31376
31470
  if (error instanceof viem.UserRejectedRequestError) {
31377
31471
  return;
@@ -31383,7 +31477,7 @@ const useMultiChainWallet = (chain) => {
31383
31477
  provider,
31384
31478
  });
31385
31479
  }
31386
- }
31480
+ },
31387
31481
  });
31388
31482
  const isChainTypeConnected = React.useCallback((chainType) => {
31389
31483
  if (isGnosisConnected && chainType === squidTypes.ChainType.EVM) {
@@ -31731,53 +31825,51 @@ const useCosmos = () => {
31731
31825
  clientWindow?.removeEventListener("keplr_keystorechange", () => handleKeplrAccountChanged());
31732
31826
  };
31733
31827
  }, [handleKeplrAccountChanged, clientWindow]);
31734
- const connectCosmos = reactQuery.useMutation({
31735
- mutationFn: async ({ chain, wallet, approveAllChains = true, }) => {
31736
- const chainInfos = getCosmosChainInfosObject(chain);
31737
- const cosmosWalletObject = wallet.connector().provider;
31738
- if (cosmosWalletObject) {
31739
- setCosmosChainId(chainInfos.chainId.toString());
31740
- try {
31741
- if (approveAllChains &&
31742
- typeof cosmosWalletObject.getChainInfosWithoutEndpoints ===
31743
- "function") {
31744
- try {
31745
- const addedChains = await cosmosWalletObject.getChainInfosWithoutEndpoints();
31746
- const addedChainIds = addedChains?.map((addedChain) => addedChain.chainId);
31747
- const chainsToEnable = cosmosChains
31748
- .filter((c) => addedChainIds?.includes(c.chainId.toString()))
31749
- .map((c) => c.chainId.toString());
31750
- await cosmosWalletObject.enable(chainsToEnable);
31751
- }
31752
- catch (error) {
31753
- console.warn("Failed to get chain infos, falling back to single chain enable", error);
31754
- await cosmosWalletObject.enable(chainInfos.chainId);
31755
- }
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);
31756
31844
  }
31757
- else {
31845
+ catch (error) {
31846
+ console.warn("Failed to get chain infos, falling back to single chain enable", error);
31758
31847
  await cosmosWalletObject.enable(chainInfos.chainId);
31759
31848
  }
31760
- const address = await getAddress({
31761
- chainId: chain.chainId.toString(),
31762
- cosmosWalletObject,
31763
- wallet,
31764
- });
31765
- if (address) {
31766
- updateWalletStore(wallet, cosmosWalletObject, address);
31767
- return address;
31768
- }
31769
31849
  }
31770
- catch (error) {
31771
- await suggestChainOrThrow({
31772
- chain,
31773
- error,
31774
- keplrTypeWallet: cosmosWalletObject,
31775
- });
31776
- 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;
31777
31861
  }
31778
31862
  }
31779
- return undefined;
31780
- },
31863
+ catch (error) {
31864
+ await suggestChainOrThrow({
31865
+ chain,
31866
+ error,
31867
+ keplrTypeWallet: cosmosWalletObject,
31868
+ });
31869
+ return connectCosmos.mutateAsync({ chain, wallet });
31870
+ }
31871
+ }
31872
+ return undefined;
31781
31873
  });
31782
31874
  const clearData = () => {
31783
31875
  disconnectWallet(squidTypes.ChainType.COSMOS);
@@ -31826,7 +31918,7 @@ function useCosmosSigner({ chain }) {
31826
31918
  // use Amino signer for Ledger compatibility
31827
31919
  const newCosmosSigner = getCosmosSignerForChain(chain.chainId, connector);
31828
31920
  return newCosmosSigner;
31829
- }, [chain?.chainId, chain?.chainType, connector, getCosmosSignerForChain]);
31921
+ }, [chain?.chainId, chain?.chainType, connector]);
31830
31922
  return { signer, keplrTypeWallet: connector };
31831
31923
  }
31832
31924
 
@@ -31931,11 +32023,11 @@ const useSquidQueryClient = () => {
31931
32023
  const queryClient = reactQuery.useQueryClient();
31932
32024
  const invalidateQueries = (key) => {
31933
32025
  const prefixKey = getPrefixKey(key);
31934
- queryClient.invalidateQueries({ queryKey: prefixKey });
32026
+ queryClient.invalidateQueries(prefixKey);
31935
32027
  };
31936
32028
  const refetchQueries = (key) => {
31937
32029
  const prefixKey = getPrefixKey(key);
31938
- queryClient.refetchQueries({ queryKey: prefixKey });
32030
+ queryClient.refetchQueries(prefixKey);
31939
32031
  };
31940
32032
  const invalidateAndRefetchQueries = (key) => {
31941
32033
  invalidateQueries(key);
@@ -33442,19 +33534,17 @@ function useDepositAddress(squidRoute) {
33442
33534
  toggleDepositFlow(false);
33443
33535
  setDeposit(null);
33444
33536
  }, [toggleDepositFlow, setDeposit]);
33445
- const getRouteWithDeposit = reactQuery.useMutation({
33446
- mutationFn: async ({ route }) => {
33447
- if (!squid)
33448
- throw new Error("Squid SDK not initialized");
33449
- const depositAddressResponse = (await squid.executeRoute({
33450
- signer: {},
33451
- route,
33452
- }));
33453
- setDeposit(depositAddressResponse);
33454
- return {
33455
- depositAddress: depositAddressResponse,
33456
- };
33457
- }
33537
+ const getRouteWithDeposit = reactQuery.useMutation(async ({ route }) => {
33538
+ if (!squid)
33539
+ throw new Error("Squid SDK not initialized");
33540
+ const depositAddressResponse = (await squid.executeRoute({
33541
+ signer: {},
33542
+ route,
33543
+ }));
33544
+ setDeposit(depositAddressResponse);
33545
+ return {
33546
+ depositAddress: depositAddressResponse,
33547
+ };
33458
33548
  });
33459
33549
  return {
33460
33550
  isEnabled,
@@ -33538,55 +33628,53 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
33538
33628
  xrplTokens.length,
33539
33629
  stellarTokens.length,
33540
33630
  ]);
33541
- const query = reactQuery.useQuery({
33542
- queryKey: keys().allTokensBalance(address, chainType, direction),
33543
- queryFn: async () => {
33544
- // Return zero balances if no address
33545
- if (!address) {
33546
- const defaultTokens = placeholderData.tokens;
33547
- return {
33548
- tokens: defaultTokens,
33549
- totalUsdBalance: calculateTotalUsdBalanceUSD(defaultTokens),
33550
- };
33551
- }
33552
- let fetchedTokens = [];
33553
- // Fetch tokens based on chain type
33554
- switch (chainType) {
33555
- case squidTypes.ChainType.EVM:
33556
- fetchedTokens = await getAllEvmTokensBalance(evmTokens, address, evmChains);
33557
- break;
33558
- case squidTypes.ChainType.COSMOS:
33559
- const addresses = await getAllKeysForSupportedCosmosChains(cosmosChains.map((c) => c.chainId), keplrTypeWallet);
33560
- fetchedTokens = await getAllCosmosBalances({
33561
- addresses,
33562
- cosmosChains,
33563
- cosmosTokens,
33564
- });
33565
- break;
33566
- case squidTypes.ChainType.SOLANA:
33567
- fetchedTokens = await getAllSolanaTokensBalance(solanaTokens, address);
33568
- break;
33569
- case squidTypes.ChainType.BTC:
33570
- fetchedTokens = await getAllBitcoinTokensBalance(address, bitcoinTokens);
33571
- break;
33572
- case squidTypes.ChainType.SUI:
33573
- fetchedTokens = await getAllSuiTokensBalance(address, suiTokens, suiChains);
33574
- break;
33575
- case squidTypes.ChainType.XRPL:
33576
- fetchedTokens = await getAllXrplTokensBalance(address, xrplTokens, xrplChains);
33577
- break;
33578
- case squidTypes.ChainType.STELLAR:
33579
- fetchedTokens = await getAllStellarTokensBalance(address, stellarTokens, stellarChains);
33580
- break;
33581
- default:
33582
- fetchedTokens = placeholderData.tokens;
33583
- break;
33584
- }
33631
+ const query = reactQuery.useQuery(keys().allTokensBalance(address, chainType, direction), async () => {
33632
+ // Return zero balances if no address
33633
+ if (!address) {
33634
+ const defaultTokens = placeholderData.tokens;
33585
33635
  return {
33586
- tokens: fetchedTokens,
33587
- totalUsdBalance: calculateTotalUsdBalanceUSD(fetchedTokens),
33636
+ tokens: defaultTokens,
33637
+ totalUsdBalance: calculateTotalUsdBalanceUSD(defaultTokens),
33588
33638
  };
33589
- },
33639
+ }
33640
+ let fetchedTokens = [];
33641
+ // Fetch tokens based on chain type
33642
+ switch (chainType) {
33643
+ case squidTypes.ChainType.EVM:
33644
+ fetchedTokens = await getAllEvmTokensBalance(evmTokens, address, evmChains);
33645
+ break;
33646
+ case squidTypes.ChainType.COSMOS:
33647
+ const addresses = await getAllKeysForSupportedCosmosChains(cosmosChains.map((c) => c.chainId), keplrTypeWallet);
33648
+ fetchedTokens = await getAllCosmosBalances({
33649
+ addresses,
33650
+ cosmosChains,
33651
+ cosmosTokens,
33652
+ });
33653
+ break;
33654
+ case squidTypes.ChainType.SOLANA:
33655
+ fetchedTokens = await getAllSolanaTokensBalance(solanaTokens, address);
33656
+ break;
33657
+ case squidTypes.ChainType.BTC:
33658
+ fetchedTokens = await getAllBitcoinTokensBalance(address, bitcoinTokens);
33659
+ break;
33660
+ case squidTypes.ChainType.SUI:
33661
+ fetchedTokens = await getAllSuiTokensBalance(address, suiTokens, suiChains);
33662
+ break;
33663
+ case squidTypes.ChainType.XRPL:
33664
+ fetchedTokens = await getAllXrplTokensBalance(address, xrplTokens, xrplChains);
33665
+ break;
33666
+ case squidTypes.ChainType.STELLAR:
33667
+ fetchedTokens = await getAllStellarTokensBalance(address, stellarTokens, stellarChains);
33668
+ break;
33669
+ default:
33670
+ fetchedTokens = placeholderData.tokens;
33671
+ break;
33672
+ }
33673
+ return {
33674
+ tokens: fetchedTokens,
33675
+ totalUsdBalance: calculateTotalUsdBalanceUSD(fetchedTokens),
33676
+ };
33677
+ }, {
33590
33678
  ...queryOptions,
33591
33679
  enabled: isQueryEnabled,
33592
33680
  });
@@ -33601,7 +33689,7 @@ const BALANCE_STALE_TIME = 60000; // 1 minute
33601
33689
  const BALANCE_CACHE_TIME = 300000; // 5 minutes
33602
33690
  const useAllConnectedWalletBalances = ({ direction, queryOptions = {
33603
33691
  staleTime: BALANCE_STALE_TIME,
33604
- gcTime: BALANCE_CACHE_TIME,
33692
+ cacheTime: BALANCE_CACHE_TIME,
33605
33693
  refetchOnWindowFocus: true,
33606
33694
  refetchOnMount: true,
33607
33695
  }, } = {}) => {
@@ -33682,9 +33770,9 @@ const useAllConnectedWalletBalances = ({ direction, queryOptions = {
33682
33770
  }, [balanceQueries]);
33683
33771
  // Aggregate loading states
33684
33772
  const queryStates = React.useMemo(() => ({
33685
- isLoading: Object.values(balanceQueries).some((q) => q.isLoading),
33773
+ isInitialLoading: Object.values(balanceQueries).some((q) => q.isInitialLoading),
33686
33774
  isFetching: Object.values(balanceQueries).some((q) => q.isFetching),
33687
- isPending: Object.values(balanceQueries).some((q) => q.isPending),
33775
+ isLoading: Object.values(balanceQueries).some((q) => q.isLoading),
33688
33776
  isRefetching: Object.values(balanceQueries).some((q) => q.isRefetching),
33689
33777
  isError: Object.values(balanceQueries).some((q) => q.isError),
33690
33778
  isSuccess: Object.values(balanceQueries).every((q) => q.isSuccess),
@@ -33726,7 +33814,7 @@ function useNativeTokenForChain(chain) {
33726
33814
 
33727
33815
  const useEvmNativeBalance = ({ address, chain, }) => {
33728
33816
  const { isChainTypeConnected } = useWallet();
33729
- const { data: nativeEvmBalance, isPending } = wagmi.useBalance({
33817
+ const { data: nativeEvmBalance, isLoading } = wagmi.useBalance({
33730
33818
  address: address,
33731
33819
  chainId: Number(chain?.chainId),
33732
33820
  query: {
@@ -33748,13 +33836,13 @@ const useEvmNativeBalance = ({ address, chain, }) => {
33748
33836
  }, [nativeEvmBalance?.decimals, nativeEvmBalance?.value]);
33749
33837
  return {
33750
33838
  balance,
33751
- isPending,
33839
+ isLoading,
33752
33840
  };
33753
33841
  };
33754
33842
  const useCosmosNativeBalance = ({ address, chain, }) => {
33755
33843
  const { isConnected: isCosmosConnected } = useCosmosContext();
33756
33844
  const { nativeToken: nativeCosmosToken } = useNativeTokenForChain(chain);
33757
- const { balance: rawBalance, isPending } = useCosmosBalance({
33845
+ const { balance: rawBalance, isLoading } = useCosmosBalance({
33758
33846
  chain,
33759
33847
  token: nativeCosmosToken,
33760
33848
  userAddress: address,
@@ -33769,18 +33857,16 @@ const useCosmosNativeBalance = ({ address, chain, }) => {
33769
33857
  };
33770
33858
  }
33771
33859
  }, [nativeCosmosToken?.decimals, rawBalance]);
33772
- return { balance, isPending };
33860
+ return { balance, isLoading };
33773
33861
  };
33774
33862
  const useBitcoinNativeBalance = ({ chain, address, }) => {
33775
33863
  const { nativeToken } = useNativeTokenForChain(chain);
33776
- const { data: rawBalance = "0", isPending } = reactQuery.useQuery({
33777
- queryKey: keys().balance(chain?.chainId, nativeToken?.address, address),
33778
- queryFn: async () => {
33779
- if (!address || !nativeToken)
33780
- return "0";
33781
- const balance = await getBitcoinNativeBalance(address);
33782
- return formatBNToReadable(balance, nativeToken.decimals);
33783
- },
33864
+ const { data: rawBalance = "0", isLoading } = reactQuery.useQuery(keys().balance(chain?.chainId, nativeToken?.address, address), async () => {
33865
+ if (!address || !nativeToken)
33866
+ return "0";
33867
+ const balance = await getBitcoinNativeBalance(address);
33868
+ return formatBNToReadable(balance, nativeToken.decimals);
33869
+ }, {
33784
33870
  enabled: chain?.chainType === squidTypes.ChainType.BTC &&
33785
33871
  nativeToken?.decimals != null &&
33786
33872
  isWalletAddressValid(chain, address),
@@ -33799,17 +33885,15 @@ const useBitcoinNativeBalance = ({ chain, address, }) => {
33799
33885
  }, [nativeToken?.decimals, rawBalance]);
33800
33886
  return {
33801
33887
  balance,
33802
- isPending,
33888
+ isLoading,
33803
33889
  };
33804
33890
  };
33805
33891
  const useSolanaNativeBalance = ({ chain, address, }) => {
33806
33892
  const { nativeToken } = useNativeTokenForChain(chain);
33807
- const { data: rawBalance, isPending } = reactQuery.useQuery({
33808
- queryKey: keys().balance(chain?.chainId, nativeToken?.address, address),
33809
- queryFn: async () => {
33810
- const balance = await getSolanaNativeBalance(address);
33811
- return formatBNToReadable(balance, nativeToken.decimals);
33812
- },
33893
+ const { data: rawBalance, isLoading } = reactQuery.useQuery(keys().balance(chain?.chainId, nativeToken?.address, address), async () => {
33894
+ const balance = await getSolanaNativeBalance(address);
33895
+ return formatBNToReadable(balance, nativeToken.decimals);
33896
+ }, {
33813
33897
  enabled: !!address &&
33814
33898
  nativeToken?.decimals != null &&
33815
33899
  chain?.chainType === squidTypes.ChainType.SOLANA,
@@ -33828,12 +33912,12 @@ const useSolanaNativeBalance = ({ chain, address, }) => {
33828
33912
  }, [nativeToken?.decimals, rawBalance]);
33829
33913
  return {
33830
33914
  balance,
33831
- isPending,
33915
+ isLoading,
33832
33916
  };
33833
33917
  };
33834
33918
  const useSuiNativeBalance = ({ address, chain, }) => {
33835
33919
  const { nativeToken } = useNativeTokenForChain(chain);
33836
- const { balance: rawBalance, isPending } = useSuiBalance({
33920
+ const { balance: rawBalance, isLoading } = useSuiBalance({
33837
33921
  chain,
33838
33922
  token: nativeToken,
33839
33923
  userAddress: address,
@@ -33848,12 +33932,12 @@ const useSuiNativeBalance = ({ address, chain, }) => {
33848
33932
  }, [nativeToken?.decimals, rawBalance]);
33849
33933
  return {
33850
33934
  balance,
33851
- isPending,
33935
+ isLoading,
33852
33936
  };
33853
33937
  };
33854
33938
  const useXrplNativeBalance = ({ address, chain, }) => {
33855
33939
  const { nativeToken } = useNativeTokenForChain(chain);
33856
- const { balance: rawBalance, isPending } = useXrplBalance({
33940
+ const { balance: rawBalance, isLoading } = useXrplBalance({
33857
33941
  chain,
33858
33942
  token: nativeToken,
33859
33943
  userAddress: address,
@@ -33869,12 +33953,12 @@ const useXrplNativeBalance = ({ address, chain, }) => {
33869
33953
  }, [nativeToken?.decimals, rawBalance]);
33870
33954
  return {
33871
33955
  balance,
33872
- isPending,
33956
+ isLoading,
33873
33957
  };
33874
33958
  };
33875
33959
  const useStellarNativeBalance = ({ address, chain, }) => {
33876
33960
  const { nativeToken } = useNativeTokenForChain(chain);
33877
- const { balance: rawBalance, isPending } = useStellarBalance({
33961
+ const { balance: rawBalance, isLoading } = useStellarBalance({
33878
33962
  chain,
33879
33963
  token: nativeToken,
33880
33964
  userAddress: address,
@@ -33890,7 +33974,7 @@ const useStellarNativeBalance = ({ address, chain, }) => {
33890
33974
  }, [nativeToken?.decimals, rawBalance]);
33891
33975
  return {
33892
33976
  balance,
33893
- isPending,
33977
+ isLoading,
33894
33978
  };
33895
33979
  };
33896
33980
  const useNativeBalance = (chain) => {
@@ -33898,28 +33982,28 @@ const useNativeBalance = (chain) => {
33898
33982
  const { data: cosmosAddressForChain } = useCosmosForChain(chain);
33899
33983
  // Cosmos is a special case because the address changes on every chain
33900
33984
  // so we can't use the default cosmos connected address
33901
- const { balance: nativeCosmosBalance, isPending: isCosmosPending } = useCosmosNativeBalance({
33985
+ const { balance: nativeCosmosBalance, isLoading: isCosmosLoading } = useCosmosNativeBalance({
33902
33986
  address: cosmosAddressForChain,
33903
33987
  chain,
33904
33988
  });
33905
- const { balance: nativeEvmBalance, isPending: isEvmPending } = useEvmNativeBalance({ address: connectedAddresses[squidTypes.ChainType.EVM], chain });
33906
- const { balance: nativeBitcoinBalance, isPending: isBitcoinPending } = useBitcoinNativeBalance({
33989
+ const { balance: nativeEvmBalance, isLoading: isEvmLoading } = useEvmNativeBalance({ address: connectedAddresses[squidTypes.ChainType.EVM], chain });
33990
+ const { balance: nativeBitcoinBalance, isLoading: isBitcoinLoading } = useBitcoinNativeBalance({
33907
33991
  address: connectedAddresses[squidTypes.ChainType.BTC],
33908
33992
  chain,
33909
33993
  });
33910
- const { balance: nativeSolanaBalance, isPending: isSolanaPending } = useSolanaNativeBalance({
33994
+ const { balance: nativeSolanaBalance, isLoading: isSolanaLoading } = useSolanaNativeBalance({
33911
33995
  address: connectedAddresses[squidTypes.ChainType.SOLANA],
33912
33996
  chain,
33913
33997
  });
33914
- const { balance: nativeSuiBalance, isPending: isSuiPending } = useSuiNativeBalance({
33998
+ const { balance: nativeSuiBalance, isLoading: isSuiLoading } = useSuiNativeBalance({
33915
33999
  address: connectedAddresses[squidTypes.ChainType.SUI],
33916
34000
  chain,
33917
34001
  });
33918
- const { balance: nativeXrplBalance, isPending: isXrplPending } = useXrplNativeBalance({
34002
+ const { balance: nativeXrplBalance, isLoading: isXrpLoading } = useXrplNativeBalance({
33919
34003
  address: connectedAddresses[squidTypes.ChainType.XRPL],
33920
34004
  chain,
33921
34005
  });
33922
- const { balance: nativeStellarBalance, isPending: isStellarPending } = useStellarNativeBalance({
34006
+ const { balance: nativeStellarBalance, isLoading: isStellarLoading } = useStellarNativeBalance({
33923
34007
  address: connectedAddresses[squidTypes.ChainType.STELLAR],
33924
34008
  chain,
33925
34009
  });
@@ -33964,36 +34048,36 @@ const useNativeBalance = (chain) => {
33964
34048
  nativeXrplBalance,
33965
34049
  nativeStellarBalance,
33966
34050
  ]);
33967
- const isPending = React.useMemo(() => {
34051
+ const isLoading = React.useMemo(() => {
33968
34052
  if (!chain?.chainType)
33969
34053
  return false;
33970
34054
  switch (chain.chainType) {
33971
34055
  case squidTypes.ChainType.EVM:
33972
- return isEvmPending;
34056
+ return isEvmLoading;
33973
34057
  case squidTypes.ChainType.COSMOS:
33974
- return isCosmosPending;
34058
+ return isCosmosLoading;
33975
34059
  case squidTypes.ChainType.BTC:
33976
- return isBitcoinPending;
34060
+ return isBitcoinLoading;
33977
34061
  case squidTypes.ChainType.SOLANA:
33978
- return isSolanaPending;
34062
+ return isSolanaLoading;
33979
34063
  case squidTypes.ChainType.SUI:
33980
- return isSuiPending;
34064
+ return isSuiLoading;
33981
34065
  case squidTypes.ChainType.XRPL:
33982
- return isXrplPending;
34066
+ return isXrpLoading;
33983
34067
  case squidTypes.ChainType.STELLAR:
33984
- return isStellarPending;
34068
+ return isStellarLoading;
33985
34069
  }
33986
34070
  }, [
33987
34071
  chain?.chainType,
33988
- isEvmPending,
33989
- isCosmosPending,
33990
- isBitcoinPending,
33991
- isSolanaPending,
33992
- isSuiPending,
33993
- isXrplPending,
33994
- isStellarPending,
34072
+ isEvmLoading,
34073
+ isCosmosLoading,
34074
+ isBitcoinLoading,
34075
+ isSolanaLoading,
34076
+ isSuiLoading,
34077
+ isXrpLoading,
34078
+ isStellarLoading,
33995
34079
  ]);
33996
- return { nativeBalance, nativeBalanceFormatted, isPending };
34080
+ return { nativeBalance, nativeBalanceFormatted, isLoading };
33997
34081
  };
33998
34082
 
33999
34083
  const DEFAULT_REFRESH_INTERVAL_MS = 15000;
@@ -34002,7 +34086,7 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
34002
34086
  const isNativeToken = token?.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
34003
34087
  const userAddressParsed = userAddress;
34004
34088
  // Only fetch using useBalance if it's a native token
34005
- const { data: nativeBalance, isPending: isNativeTokenPending } = wagmi.useBalance({
34089
+ const { data: nativeBalance, isLoading: isNativeTokenLoading } = wagmi.useBalance({
34006
34090
  address: userAddressParsed,
34007
34091
  chainId: Number(chain?.chainId),
34008
34092
  query: {
@@ -34018,7 +34102,7 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
34018
34102
  });
34019
34103
  // Only fetch using useReadContract if it's not a native token
34020
34104
  // This is temporary, because of wagmi error: https://github.com/wevm/wagmi/issues/4353
34021
- const { data: erc20Balance, isPending: isErc20Pending } = wagmi.useReadContract({
34105
+ const { data: erc20Balance, isLoading: isErc20Loading } = wagmi.useReadContract({
34022
34106
  address: token?.address,
34023
34107
  abi: viem.erc20Abi,
34024
34108
  functionName: "balanceOf",
@@ -34034,15 +34118,15 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
34034
34118
  },
34035
34119
  });
34036
34120
  const balance = isNativeToken ? nativeBalance?.value : erc20Balance;
34037
- const isPending = isNativeToken ? isNativeTokenPending : isErc20Pending;
34121
+ const isLoading = isNativeToken ? isNativeTokenLoading : isErc20Loading;
34038
34122
  const formattedBalance = balance != null && token?.decimals != null
34039
34123
  ? formatBNToReadable(balance, token.decimals)
34040
34124
  : "0";
34041
- return { balance: formattedBalance, isPending };
34125
+ return { balance: formattedBalance, isLoading };
34042
34126
  };
34043
34127
  const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
34044
34128
  const { isConnected } = useCosmosContext();
34045
- const { data: balance = "0", isPending } = reactQuery.useQuery({
34129
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
34046
34130
  queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
34047
34131
  queryFn: async () => {
34048
34132
  if (!userAddress || !token || chain?.chainType !== squidTypes.ChainType.COSMOS) {
@@ -34062,10 +34146,10 @@ const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIn
34062
34146
  refetchInterval: refreshIntervalMs,
34063
34147
  retry: 2,
34064
34148
  });
34065
- return { balance, isPending };
34149
+ return { balance, isLoading };
34066
34150
  };
34067
34151
  const useSolanaBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
34068
- const { data: balance = "0", isPending } = reactQuery.useQuery({
34152
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
34069
34153
  queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
34070
34154
  queryFn: async () => {
34071
34155
  if (!userAddress || !token)
@@ -34080,11 +34164,11 @@ const useSolanaBalance = ({ chain, token, userAddress, enabled = true, refreshIn
34080
34164
  refetchInterval: refreshIntervalMs,
34081
34165
  retry: 2,
34082
34166
  });
34083
- return { balance, isPending };
34167
+ return { balance, isLoading };
34084
34168
  };
34085
34169
  // TODO: implement fetching balances for all bitcoin tokens
34086
34170
  const useBitcoinBalance = ({ userAddress, chain, }) => {
34087
- const { balance: balanceBn, isPending } = useBitcoinNativeBalance({
34171
+ const { balance: balanceBn, isLoading } = useBitcoinNativeBalance({
34088
34172
  address: userAddress,
34089
34173
  chain,
34090
34174
  });
@@ -34093,10 +34177,10 @@ const useBitcoinBalance = ({ userAddress, chain, }) => {
34093
34177
  return "0";
34094
34178
  return formatBNToReadable(balanceBn?.value, balanceBn?.decimals);
34095
34179
  }, [balanceBn]);
34096
- return { balance, isPending };
34180
+ return { balance, isLoading };
34097
34181
  };
34098
34182
  const useSuiBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
34099
- const { data: balance = "0", isPending } = reactQuery.useQuery({
34183
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
34100
34184
  queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
34101
34185
  queryFn: async () => {
34102
34186
  if (!userAddress ||
@@ -34116,10 +34200,10 @@ const useSuiBalance = ({ chain, token, userAddress, enabled = true, refreshInter
34116
34200
  refetchInterval: refreshIntervalMs,
34117
34201
  retry: 2,
34118
34202
  });
34119
- return { balance, isPending };
34203
+ return { balance, isLoading };
34120
34204
  };
34121
34205
  const useXrplBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
34122
- const { data: balance = "0", isPending } = reactQuery.useQuery({
34206
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
34123
34207
  queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
34124
34208
  queryFn: async () => {
34125
34209
  if (!userAddress || !token || !chain)
@@ -34136,10 +34220,10 @@ const useXrplBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs
34136
34220
  refetchInterval: refreshIntervalMs,
34137
34221
  retry: 2,
34138
34222
  });
34139
- return { balance, isPending };
34223
+ return { balance, isLoading };
34140
34224
  };
34141
34225
  const useStellarBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
34142
- const { data: balance = "0", isPending } = reactQuery.useQuery({
34226
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
34143
34227
  queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
34144
34228
  queryFn: async () => {
34145
34229
  if (!userAddress || !token || !chain)
@@ -34156,7 +34240,7 @@ const useStellarBalance = ({ userAddress, chain, enabled, token, refreshInterval
34156
34240
  refetchInterval: refreshIntervalMs,
34157
34241
  retry: 2,
34158
34242
  });
34159
- return { balance, isPending };
34243
+ return { balance, isLoading };
34160
34244
  };
34161
34245
 
34162
34246
  /**
@@ -34277,7 +34361,7 @@ const useMultipleTokenPrices = (tokens) => {
34277
34361
  return {
34278
34362
  tokenPrices,
34279
34363
  getTokenPrice,
34280
- isPending: coinGeckoQuery.isPending,
34364
+ isLoading: coinGeckoQuery.isLoading,
34281
34365
  isError: coinGeckoQuery.isError,
34282
34366
  error: coinGeckoQuery.error,
34283
34367
  refetch: coinGeckoQuery.refetch,
@@ -34426,17 +34510,13 @@ const fetchTokensData = async (tokens) => {
34426
34510
 
34427
34511
  // Coingecko has a limit for some queries for multiple tokens, not sure what it is, but let's use 100 for now
34428
34512
  const useHistoricalData = (coingeckoId, timeFrame) => {
34429
- return reactQuery.useQuery({
34430
- queryKey: keys().historicalData(coingeckoId, timeFrame),
34431
- queryFn: () => fetchHistoricalData(coingeckoId, timeFrame),
34513
+ return reactQuery.useQuery(keys().historicalData(coingeckoId, timeFrame), () => fetchHistoricalData(coingeckoId, timeFrame), {
34432
34514
  staleTime: 5 * 60 * 1000,
34433
34515
  enabled: !!coingeckoId,
34434
34516
  });
34435
34517
  };
34436
34518
  const useTokensData = (tokens) => {
34437
- return reactQuery.useQuery({
34438
- queryKey: keys().tokensData(tokens),
34439
- queryFn: () => fetchTokensData(tokens),
34519
+ return reactQuery.useQuery(keys().tokensData(tokens), () => fetchTokensData(tokens), {
34440
34520
  staleTime: 60 * 1000,
34441
34521
  enabled: !!tokens && tokens.length > 0,
34442
34522
  });
@@ -34741,7 +34821,7 @@ function useSendTransactionGas({ chain, token, from, }) {
34741
34821
  }
34742
34822
 
34743
34823
  function useEstimateSendTransaction({ chain, token, amount, balance, from, }) {
34744
- const { data: estimatedGas = BigInt(0), isPending } = useSendTransactionGas({
34824
+ const { data: estimatedGas = BigInt(0), isLoading } = useSendTransactionGas({
34745
34825
  chain,
34746
34826
  token,
34747
34827
  from,
@@ -34786,7 +34866,7 @@ function useEstimateSendTransaction({ chain, token, amount, balance, from, }) {
34786
34866
  return {
34787
34867
  estimatedGas,
34788
34868
  isBalanceEnough,
34789
- isPending,
34869
+ isLoading,
34790
34870
  isNativeBalanceEnoughToPayGasFees,
34791
34871
  minAmountValueWarnMsg,
34792
34872
  };
@@ -35032,126 +35112,6 @@ async function sendTransactionStellar({ amount, signer, to, token, chain, }) {
35032
35112
  };
35033
35113
  }
35034
35114
 
35035
- // Prevent fetching too soon after the first successful request.
35036
- const DEFAULT_STALE_TIME = 8000;
35037
- const defaultOptions = {
35038
- queries: {
35039
- staleTime: DEFAULT_STALE_TIME,
35040
- refetchOnWindowFocus: false,
35041
- retry: false,
35042
- retryOnMount: false,
35043
- },
35044
- };
35045
-
35046
- const queryClient = new reactQuery.QueryClient({ defaultOptions });
35047
- const verifyIntegratorIdValidity = (integratorId) => {
35048
- if (!integratorId) {
35049
- throw new Error("Integrator ID is required");
35050
- }
35051
- };
35052
- const SquidProvider = ({ children, config, placeholder, }) => {
35053
- verifyIntegratorIdValidity(config.integratorId);
35054
- const [wagmiConfig, setWagmiConfig] = React.useState();
35055
- const sdkInitializedRef = React.useRef(false);
35056
- const initializeSdk = React.useCallback(async () => {
35057
- if (sdkInitializedRef.current) {
35058
- return;
35059
- }
35060
- sdkInitializedRef.current = true;
35061
- try {
35062
- const squid = new sdk.Squid({
35063
- integratorId: config.integratorId,
35064
- baseUrl: config.apiUrl ?? squidApiBaseUrl,
35065
- });
35066
- const [sdkInfoResponse, assetsColorsResponse] = await Promise.allSettled([
35067
- squid.init(),
35068
- fetchAssetsColors(),
35069
- ]);
35070
- if (sdkInfoResponse.status === "rejected") {
35071
- throw sdkInfoResponse.reason;
35072
- }
35073
- if (assetsColorsResponse.status === "fulfilled") {
35074
- useAssetsColorsStore.setState(assetsColorsResponse.value);
35075
- initializeSquidWithAssetsColors(squid, assetsColorsResponse.value);
35076
- }
35077
- const shouldResetSwapRouteStore =
35078
- // reset swap route if specified in config
35079
- !config?.loadPreviousStateFromLocalStorage ||
35080
- // or if initial assets are provided
35081
- !isEmptyObject(config.initialAssets?.from) ||
35082
- !isEmptyObject(config.initialAssets?.to);
35083
- if (shouldResetSwapRouteStore) {
35084
- useSwapRoutePersistStore.setState({
35085
- swapRoute: undefined,
35086
- });
35087
- }
35088
- useSquidStore.setState((_) => ({
35089
- squid,
35090
- maintenanceMode: { active: false, message: undefined },
35091
- }));
35092
- const newWagmiConfig = createWagmiConfig(squid.chains);
35093
- setWagmiConfig(newWagmiConfig);
35094
- useConfigStore.setState({
35095
- isInitialized: true,
35096
- config: getConfigWithDefaults(config),
35097
- });
35098
- }
35099
- catch (error) {
35100
- const isAxios503Error = error.isAxiosError &&
35101
- error.response?.status === 503;
35102
- if (isAxios503Error) {
35103
- const maintenanceMessage = error.response?.data
35104
- ?.message ?? undefined;
35105
- // Even with an error, we want wagmi to be defined so that we can display the maintenance mode layout
35106
- // Create wagmi config with mainnet as fallback in maintenance mode
35107
- const newWagmiConfig = wagmi.createConfig({
35108
- chains: [chains$1.mainnet],
35109
- connectors: [connectors.injected()],
35110
- transports: {
35111
- [chains$1.mainnet.id]: wagmi.http(),
35112
- },
35113
- });
35114
- setWagmiConfig(newWagmiConfig);
35115
- useConfigStore.setState({
35116
- isInitialized: false,
35117
- config: getConfigWithDefaults(config),
35118
- });
35119
- useSquidStore.setState({
35120
- squid: undefined,
35121
- maintenanceMode: {
35122
- active: true,
35123
- message: maintenanceMessage,
35124
- },
35125
- });
35126
- }
35127
- else {
35128
- console.error("Error initializing SDK:", error);
35129
- }
35130
- }
35131
- }, [config]);
35132
- React.useEffect(() => {
35133
- initializeSdk();
35134
- }, [initializeSdk]);
35135
- return wagmiConfig ? (React.createElement(wagmi.WagmiProvider, { reconnectOnMount: false, config: wagmiConfig },
35136
- React.createElement(reactQuery.QueryClientProvider, { client: queryClient },
35137
- React.createElement(StellarProvider, null,
35138
- React.createElement(EvmProvider, null,
35139
- React.createElement(XrplProvider, null,
35140
- React.createElement(SuiProvider, null,
35141
- React.createElement(SolanaProvider, null,
35142
- React.createElement(BitcoinProvider, null,
35143
- React.createElement(CosmosProvider, null, children)))))))))) : (placeholder);
35144
- };
35145
-
35146
- const para = new Para("beta_c529f95c6a31bfb50487b0929a19b682");
35147
- const connector = wagmiV2Integration.paraConnector({
35148
- para,
35149
- appName: SQUID_METADATA.name,
35150
- isGuestModeEnabled: false,
35151
- hideWallets: true,
35152
- options: {},
35153
- queryClient: queryClient,
35154
- });
35155
35115
  const createWagmiConfig = (squidChains) => {
35156
35116
  const filteredEvmChains = squidChains.filter((chain) => chain.chainType === squidTypes.ChainType.EVM);
35157
35117
  if (filteredEvmChains.length === 0) {
@@ -35207,8 +35167,6 @@ const createWagmiConfig = (squidChains) => {
35207
35167
  description: SQUID_METADATA.description,
35208
35168
  },
35209
35169
  }),
35210
- // @ts-expect-error - TODO: fix types
35211
- connector,
35212
35170
  ],
35213
35171
  });
35214
35172
  };
@@ -35315,12 +35273,10 @@ function useSendTransaction({ to, amount, token, chain, }) {
35315
35273
  // amount is already formatted with the token decimals
35316
35274
  amount,
35317
35275
  toAddress: to,
35318
- token: {
35319
- address: token.address,
35320
- chainId: token.chainId,
35321
- symbol: token.symbol,
35322
- type: token.type,
35323
- },
35276
+ tokenAddress: token.address,
35277
+ tokenChainId: token.chainId,
35278
+ tokenSymbol: token.symbol,
35279
+ tokenType: token.type,
35324
35280
  });
35325
35281
  }, [
35326
35282
  allEventParamsDefined,
@@ -35340,12 +35296,10 @@ function useSendTransaction({ to, amount, token, chain, }) {
35340
35296
  // amount is already formatted with the token decimals
35341
35297
  amount,
35342
35298
  toAddress: to,
35343
- token: {
35344
- address: token.address,
35345
- chainId: token.chainId,
35346
- symbol: token.symbol,
35347
- type: token.type,
35348
- },
35299
+ tokenAddress: token.address,
35300
+ tokenChainId: token.chainId,
35301
+ tokenSymbol: token.symbol,
35302
+ tokenType: token.type,
35349
35303
  txHash,
35350
35304
  });
35351
35305
  }, [
@@ -35491,9 +35445,7 @@ function useSendTransaction({ to, amount, token, chain, }) {
35491
35445
  });
35492
35446
  },
35493
35447
  onSuccess: (tx, variables) => {
35494
- queryClient.invalidateQueries({
35495
- queryKey: getPrefixKey(QueryKeys.Balance),
35496
- });
35448
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balance));
35497
35449
  setTransactionState(variables.id, tx);
35498
35450
  persistTransaction({
35499
35451
  txType: exports.HistoryTxType.SEND,
@@ -35798,6 +35750,20 @@ const useAllTransactionsStatus = ({ enabled }) => {
35798
35750
  retry: 4,
35799
35751
  retryDelay: getSwapTxStatusRefetchInterval(data),
35800
35752
  refetchInterval: 5000,
35753
+ onSuccess: (statusResponse) => {
35754
+ if (!statusResponse)
35755
+ return;
35756
+ const endStatus = getTransactionEndStatus({
35757
+ statusResponse,
35758
+ });
35759
+ if (!endStatus)
35760
+ return;
35761
+ replaceSwapTransactionStatus({
35762
+ transactionId: data.transactionId,
35763
+ statusResponse,
35764
+ status: endStatus,
35765
+ });
35766
+ },
35801
35767
  };
35802
35768
  }
35803
35769
  case exports.HistoryTxType.BUY:
@@ -35806,14 +35772,29 @@ const useAllTransactionsStatus = ({ enabled }) => {
35806
35772
  queryKey: keys().fiatToCryptoStatus(data.orderId),
35807
35773
  retry: TX_STATUS_CONSTANTS.RETRY_COUNT,
35808
35774
  retryDelay: TX_STATUS_CONSTANTS.RETRY_DELAY,
35809
- refetchInterval: (query) => {
35810
- const { state } = query;
35811
- if (state.data?.status &&
35812
- FINAL_TRANSACTION_STATUSES.includes(state.data.status)) {
35775
+ refetchInterval: (data) => {
35776
+ if (data?.status &&
35777
+ FINAL_TRANSACTION_STATUSES.includes(data.status)) {
35813
35778
  return false;
35814
35779
  }
35815
35780
  return TX_STATUS_CONSTANTS.REFETCH_INTERVAL;
35816
35781
  },
35782
+ onSuccess: (statusData) => {
35783
+ replaceTransactionStatus({
35784
+ orderId: data.orderId,
35785
+ status: statusData.status,
35786
+ transactionHash: statusData.transactionHash,
35787
+ txType: exports.HistoryTxType.BUY,
35788
+ });
35789
+ },
35790
+ onError: () => {
35791
+ replaceTransactionStatus({
35792
+ txType: exports.HistoryTxType.BUY,
35793
+ orderId: data.orderId,
35794
+ status: "failed",
35795
+ transactionHash: undefined,
35796
+ });
35797
+ },
35817
35798
  enabled: true,
35818
35799
  };
35819
35800
  case exports.HistoryTxType.SEND:
@@ -35830,97 +35811,30 @@ const useAllTransactionsStatus = ({ enabled }) => {
35830
35811
  });
35831
35812
  },
35832
35813
  refetchInterval: getSendTxStatusRefetchInterval(data.token.type),
35833
- };
35834
- }
35835
- });
35836
- const queries = reactQuery.useQueries({
35837
- queries: enabled && config.apiUrl ? statusQueries : [],
35838
- });
35839
- React.useEffect(() => {
35840
- queries.forEach((query, index) => {
35841
- const transaction = pendingTransactions[index];
35842
- switch (transaction.txType) {
35843
- case exports.HistoryTxType.SWAP:
35844
- if (query.isSuccess && query.data) {
35845
- const statusResponse = query.data;
35846
- const endStatus = getTransactionEndStatus({
35847
- statusResponse,
35848
- });
35849
- if (!endStatus)
35850
- return;
35851
- replaceSwapTransactionStatus({
35852
- transactionId: transaction.data.transactionId,
35853
- statusResponse,
35854
- status: endStatus,
35855
- });
35856
- }
35857
- if (query.isError) {
35858
- const error = query.error;
35859
- const is404 = is404Error(error.cause);
35860
- if (is404) {
35861
- replaceSwapTransactionStatus({
35862
- transactionId: transaction.data.transactionId,
35863
- statusResponse: undefined,
35864
- status: exports.TransactionStatus.NOT_FOUND,
35865
- });
35866
- }
35867
- else {
35868
- replaceSwapTransactionStatus({
35869
- transactionId: transaction.data.transactionId,
35870
- statusResponse: undefined,
35871
- status: exports.TransactionStatus.ERROR,
35872
- });
35873
- }
35874
- }
35875
- break;
35876
- case exports.HistoryTxType.BUY:
35877
- if (query.isSuccess && query.data) {
35878
- const statusData = query.data;
35879
- replaceTransactionStatus({
35880
- orderId: transaction.data.orderId,
35881
- status: statusData.status,
35882
- transactionHash: statusData.transactionHash,
35883
- txType: exports.HistoryTxType.BUY,
35884
- });
35885
- }
35886
- if (query.isError) {
35887
- replaceTransactionStatus({
35888
- txType: exports.HistoryTxType.BUY,
35889
- orderId: transaction.data.orderId,
35890
- status: "failed",
35891
- transactionHash: undefined,
35892
- });
35893
- }
35894
- break;
35895
- case exports.HistoryTxType.SEND:
35896
- if (query.isSuccess && query.data) {
35897
- const status = query.data;
35814
+ onSuccess: (status) => {
35898
35815
  if (status !== exports.SendTransactionStatus.ONGOING) {
35899
35816
  replaceTransactionStatus({
35900
35817
  txType: exports.HistoryTxType.SEND,
35901
35818
  status,
35902
- hash: transaction.data.hash,
35819
+ hash: data.hash,
35903
35820
  });
35904
35821
  }
35905
- }
35906
- if (query.isError) {
35822
+ },
35823
+ onError: () => {
35907
35824
  replaceTransactionStatus({
35908
35825
  txType: exports.HistoryTxType.SEND,
35909
35826
  status: exports.SendTransactionStatus.ERROR,
35910
- hash: transaction.data.hash,
35827
+ hash: data.hash,
35911
35828
  });
35912
- }
35913
- break;
35914
- }
35915
- });
35916
- }, [
35917
- pendingTransactions,
35918
- queries,
35919
- replaceSwapTransactionStatus,
35920
- replaceTransactionStatus,
35921
- ]);
35829
+ },
35830
+ };
35831
+ }
35832
+ });
35833
+ const queries = reactQuery.useQueries({
35834
+ queries: enabled && config.apiUrl ? statusQueries : [],
35835
+ });
35922
35836
  return {
35923
- isPending: queries.some((q) => q.isPending),
35837
+ isLoading: queries.some((q) => q.isLoading),
35924
35838
  isError: queries.some((q) => q.isError),
35925
35839
  data: queries.map((q) => q.data).filter(Boolean),
35926
35840
  };
@@ -36179,18 +36093,16 @@ const useApproval = ({ squidRoute, }) => {
36179
36093
  * On Error: Showing the error message if any
36180
36094
  * @returns {boolean} approved
36181
36095
  */
36182
- const routeApproved = reactQuery.useQuery({
36183
- queryKey: keys().routeApproved(squidRoute, allowanceInWei),
36184
- queryFn: async () => {
36185
- // Approval is only needed for EVM chains
36186
- if (getChainType(squidRoute?.params.fromChain) === squidTypes.ChainType.EVM) {
36187
- return hasAllowance;
36188
- }
36189
- return true;
36190
- },
36096
+ const routeApproved = reactQuery.useQuery(keys().routeApproved(squidRoute, allowanceInWei), async () => {
36097
+ // Approval is only needed for EVM chains
36098
+ if (getChainType(squidRoute?.params.fromChain) === squidTypes.ChainType.EVM) {
36099
+ return hasAllowance;
36100
+ }
36101
+ return true;
36102
+ }, {
36191
36103
  enabled: !!squidRoute &&
36192
36104
  !!sourceUserAddress &&
36193
- !allowanceQuery?.isPending &&
36105
+ !allowanceQuery?.isLoading &&
36194
36106
  allowanceQuery?.isFetched,
36195
36107
  });
36196
36108
  // USDT has a very specific way of handling approvals
@@ -36279,84 +36191,81 @@ const useApproval = ({ squidRoute, }) => {
36279
36191
  /**
36280
36192
  * Manually approve route if necessary
36281
36193
  */
36282
- const approveRoute = reactQuery.useMutation({
36283
- mutationFn: async () => {
36284
- try {
36285
- if (fromToken?.address === nativeEvmTokenAddress) {
36286
- return true;
36194
+ const approveRoute = reactQuery.useMutation(async () => {
36195
+ try {
36196
+ if (fromToken?.address === nativeEvmTokenAddress) {
36197
+ return true;
36198
+ }
36199
+ if (!!squidRoute && walletClient && fromToken && evmSigner && squid) {
36200
+ await approveSpecificTokenToZero(fromToken);
36201
+ try {
36202
+ // If needed, we can switch the chain here
36203
+ // If already on the correct chain, this will do nothing
36204
+ await switchChainAsync({ chainId: Number(fromChain?.chainId) });
36287
36205
  }
36288
- if (!!squidRoute && walletClient && fromToken && evmSigner && squid) {
36289
- await approveSpecificTokenToZero(fromToken);
36290
- try {
36291
- // If needed, we can switch the chain here
36292
- // If already on the correct chain, this will do nothing
36293
- await switchChainAsync({ chainId: Number(fromChain?.chainId) });
36294
- }
36295
- catch (error) {
36296
- console.error("Error switching network:", error);
36297
- }
36298
- let approveTx;
36299
- if (useIcs20) {
36300
- const channel = squidRoute.estimate.actions[0].data
36301
- .ibcChannel;
36302
- const ics20Interface = new ethers.ethers.Interface(ics20Abi);
36303
- const approveData = ics20Interface.encodeFunctionData("approve", [
36304
- squidRoute.params.fromAddress,
36305
- [
36306
- {
36307
- sourcePort: "transfer",
36308
- sourceChannel: channel,
36309
- spendLimit: [
36310
- {
36311
- denom: squidRoute.estimate.actions[0].fromToken
36312
- .originalAddress,
36313
- amount: squidRoute.params.fromAmount,
36314
- },
36315
- ],
36316
- allowList: [],
36317
- allowedPacketData: ["*"],
36318
- },
36319
- ],
36320
- ]);
36321
- approveTx = await evmSigner.sendTransaction({
36322
- to: squidRoute.transactionRequest.target,
36323
- data: approveData,
36324
- value: "0",
36325
- gasLimit: squidRoute.transactionRequest
36326
- .gasLimit,
36327
- gasPrice: squidRoute.transactionRequest
36328
- .gasPrice,
36329
- });
36330
- }
36331
- else {
36332
- approveTx = await squid.approveRoute({
36333
- route: squidRoute,
36334
- signer: evmSigner,
36335
- // For security reasons, we don't want to allow infinite approvals in our frontends
36336
- executionSettings: {
36337
- infiniteApproval: false,
36206
+ catch (error) {
36207
+ console.error("Error switching network:", error);
36208
+ }
36209
+ let approveTx;
36210
+ if (useIcs20) {
36211
+ const channel = squidRoute.estimate.actions[0].data
36212
+ .ibcChannel;
36213
+ const ics20Interface = new ethers.ethers.Interface(ics20Abi);
36214
+ const approveData = ics20Interface.encodeFunctionData("approve", [
36215
+ squidRoute.params.fromAddress,
36216
+ [
36217
+ {
36218
+ sourcePort: "transfer",
36219
+ sourceChannel: channel,
36220
+ spendLimit: [
36221
+ {
36222
+ denom: squidRoute.estimate.actions[0].fromToken
36223
+ .originalAddress,
36224
+ amount: squidRoute.params.fromAmount,
36225
+ },
36226
+ ],
36227
+ allowList: [],
36228
+ allowedPacketData: ["*"],
36338
36229
  },
36339
- });
36340
- }
36341
- if (isProblematicConnector(activeConnector)) {
36342
- await sleep(3_000);
36343
- }
36344
- await approveTx?.wait();
36345
- return true;
36230
+ ],
36231
+ ]);
36232
+ approveTx = await evmSigner.sendTransaction({
36233
+ to: squidRoute.transactionRequest.target,
36234
+ data: approveData,
36235
+ value: "0",
36236
+ gasLimit: squidRoute.transactionRequest
36237
+ .gasLimit,
36238
+ gasPrice: squidRoute.transactionRequest
36239
+ .gasPrice,
36240
+ });
36346
36241
  }
36347
- return false;
36348
- }
36349
- catch (error) {
36350
- // Keep the error in the console to debug future issues
36351
- console.error(error);
36352
- return false;
36242
+ else {
36243
+ approveTx = await squid.approveRoute({
36244
+ route: squidRoute,
36245
+ signer: evmSigner,
36246
+ // For security reasons, we don't want to allow infinite approvals in our frontends
36247
+ executionSettings: {
36248
+ infiniteApproval: false,
36249
+ },
36250
+ });
36251
+ }
36252
+ if (isProblematicConnector(activeConnector)) {
36253
+ await sleep(3_000);
36254
+ }
36255
+ await approveTx?.wait();
36256
+ return true;
36353
36257
  }
36354
- },
36258
+ return false;
36259
+ }
36260
+ catch (error) {
36261
+ // Keep the error in the console to debug future issues
36262
+ console.error(error);
36263
+ return false;
36264
+ }
36265
+ }, {
36355
36266
  onSuccess: async () => {
36356
36267
  await allowanceQuery?.refetch();
36357
- queryClient.invalidateQueries({
36358
- queryKey: getPrefixKey(QueryKeys.RouteApproved),
36359
- });
36268
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.RouteApproved));
36360
36269
  // After an approval, we refetch the transaction query with all required parameters
36361
36270
  // This is to ensure we're using the latest expiry timestamp
36362
36271
  if (squidRoute) {
@@ -39476,10 +39385,8 @@ const useExecuteTransaction = (squidRoute) => {
39476
39385
  }
39477
39386
  }, [cosmosSigner, fromChain]);
39478
39387
  const resetQueriesAfterTxSigned = () => {
39479
- queryClient.refetchQueries({ queryKey: getPrefixKey(QueryKeys.Balance) });
39480
- queryClient.invalidateQueries({
39481
- queryKey: getPrefixKey(QueryKeys.Transaction),
39482
- });
39388
+ queryClient.refetchQueries(getPrefixKey(QueryKeys.Balance));
39389
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.Transaction));
39483
39390
  };
39484
39391
  const dispatchSignatureRequestEvent = React.useCallback((route) => {
39485
39392
  WidgetEvents.getInstance().dispatchSwapTxSignatureRequested({
@@ -39497,64 +39404,62 @@ const useExecuteTransaction = (squidRoute) => {
39497
39404
  txHash,
39498
39405
  }, findToken);
39499
39406
  }, [findToken]);
39500
- const swapMutationCosmos = reactQuery.useMutation({
39501
- mutationFn: async ({ id, route }) => {
39502
- const fromChainId = route?.params.fromChain;
39503
- if (cosmosSigner && fromChainId) {
39504
- try {
39505
- const signingClient = await getCosmosSignerClient();
39506
- const signerAddress = (await cosmosSigner.getAccounts())[0].address;
39507
- if (signerAddress && signingClient && route) {
39508
- dispatchSignatureRequestEvent(route);
39509
- const tx$1 = (await squid?.executeRoute({
39510
- signer: signingClient,
39511
- signerAddress,
39512
- route,
39513
- }));
39514
- // set the tx state to loading, as soon as user signed the tx
39515
- setTransactionState({
39516
- txHash: "",
39517
- route,
39518
- status: exports.TransactionStatus.ONGOING,
39519
- sourceStatus: exports.TransactionStatus.ONGOING,
39520
- id,
39521
- });
39522
- // broadcast the signed tx to get hash and listen to events
39523
- const response = await signingClient.broadcastTx(tx.TxRaw.encode(tx$1).finish());
39524
- const hash = response.transactionHash;
39525
- if (hash) {
39526
- resetQueriesAfterTxSigned();
39527
- }
39528
- // Dispatch event so it can be listened from outside the widget
39529
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39530
- const txParams = setTransactionState({
39531
- route,
39532
- txHash: hash,
39533
- userAddress: sourceUserAddress,
39534
- status: exports.TransactionStatus.ONGOING,
39535
- sourceStatus: exports.TransactionStatus.ONGOING,
39536
- axelarUrl: undefined,
39537
- id,
39407
+ const swapMutationCosmos = reactQuery.useMutation(async ({ id, route }) => {
39408
+ const fromChainId = route?.params.fromChain;
39409
+ if (cosmosSigner && fromChainId) {
39410
+ try {
39411
+ const signingClient = await getCosmosSignerClient();
39412
+ const signerAddress = (await cosmosSigner.getAccounts())[0].address;
39413
+ if (signerAddress && signingClient && route) {
39414
+ dispatchSignatureRequestEvent(route);
39415
+ const tx$1 = (await squid?.executeRoute({
39416
+ signer: signingClient,
39417
+ signerAddress,
39418
+ route,
39419
+ }));
39420
+ // set the tx state to loading, as soon as user signed the tx
39421
+ setTransactionState({
39422
+ txHash: "",
39423
+ route,
39424
+ status: exports.TransactionStatus.ONGOING,
39425
+ sourceStatus: exports.TransactionStatus.ONGOING,
39426
+ id,
39427
+ });
39428
+ // broadcast the signed tx to get hash and listen to events
39429
+ const response = await signingClient.broadcastTx(tx.TxRaw.encode(tx$1).finish());
39430
+ const hash = response.transactionHash;
39431
+ if (hash) {
39432
+ resetQueriesAfterTxSigned();
39433
+ }
39434
+ // Dispatch event so it can be listened from outside the widget
39435
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39436
+ const txParams = setTransactionState({
39437
+ route,
39438
+ txHash: hash,
39439
+ userAddress: sourceUserAddress,
39440
+ status: exports.TransactionStatus.ONGOING,
39441
+ sourceStatus: exports.TransactionStatus.ONGOING,
39442
+ axelarUrl: undefined,
39443
+ id,
39444
+ });
39445
+ if (txParams) {
39446
+ addSwapTransaction({
39447
+ ...txParams,
39448
+ params: route.params,
39449
+ estimate: route.estimate,
39538
39450
  });
39539
- if (txParams) {
39540
- addSwapTransaction({
39541
- ...txParams,
39542
- params: route.params,
39543
- estimate: route.estimate,
39544
- });
39545
- }
39546
- return response.code === 0;
39547
39451
  }
39452
+ return response.code === 0;
39548
39453
  }
39549
- catch (error) {
39550
- console.error("Error executing Cosmos transaction", error);
39551
- if (isUserRejectionError(normalizeError(error))) {
39552
- throw new Error("Request rejected");
39553
- }
39454
+ }
39455
+ catch (error) {
39456
+ console.error("Error executing Cosmos transaction", error);
39457
+ if (isUserRejectionError(normalizeError(error))) {
39458
+ throw new Error("Request rejected");
39554
39459
  }
39555
39460
  }
39556
- throw new Error("Need all parameters");
39557
- },
39461
+ }
39462
+ throw new Error("Need all parameters");
39558
39463
  });
39559
39464
  // If the transaction is replaced, we need to update the transaction hash
39560
39465
  // Transaction replaced can mean that the user has speed up the transaction for example
@@ -39607,126 +39512,97 @@ const useExecuteTransaction = (squidRoute) => {
39607
39512
  throw error;
39608
39513
  }
39609
39514
  }, [replaceSwapTransactionNonce, setTransactionState, sourceUserAddress]);
39610
- const swapMutationEvm = reactQuery.useMutation({
39611
- mutationFn: async ({ id, route }) => {
39612
- await changeNetworkIfNeeded.mutateAsync();
39613
- if (!route || !squid || !evmSigner) {
39614
- throw new Error("Need all parameters");
39615
- }
39616
- dispatchSignatureRequestEvent(route);
39617
- const txResponse = (await squid.executeRoute({
39618
- bypassBalanceChecks: true,
39619
- signer: evmSigner,
39515
+ const swapMutationEvm = reactQuery.useMutation(async ({ id, route }) => {
39516
+ await changeNetworkIfNeeded.mutateAsync();
39517
+ if (!route || !squid || !evmSigner) {
39518
+ throw new Error("Need all parameters");
39519
+ }
39520
+ dispatchSignatureRequestEvent(route);
39521
+ const txResponse = (await squid.executeRoute({
39522
+ bypassBalanceChecks: true,
39523
+ signer: evmSigner,
39524
+ route,
39525
+ }));
39526
+ let hash = txResponse.hash;
39527
+ if (activeConnector?.id === "safe") {
39528
+ hash = await getGnosisTransactionHash(txResponse.hash);
39529
+ }
39530
+ if (hash) {
39531
+ resetQueriesAfterTxSigned();
39532
+ }
39533
+ // Dispatch event so it can be listened from outside the widget
39534
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39535
+ if (route.transactionRequest) {
39536
+ const txParams = setTransactionState({
39620
39537
  route,
39621
- }));
39622
- let hash = txResponse.hash;
39623
- if (activeConnector?.id === "safe") {
39624
- hash = await getGnosisTransactionHash(txResponse.hash);
39538
+ txHash: hash,
39539
+ nonce: txResponse.nonce,
39540
+ userAddress: sourceUserAddress,
39541
+ status: exports.TransactionStatus.INITIAL_LOADING,
39542
+ sourceStatus: exports.TransactionStatus.ONGOING,
39543
+ axelarUrl: undefined,
39544
+ id,
39545
+ });
39546
+ if (txParams) {
39547
+ addSwapTransaction({
39548
+ ...txParams,
39549
+ params: route.params,
39550
+ estimate: route.estimate,
39551
+ });
39625
39552
  }
39626
- if (hash) {
39627
- resetQueriesAfterTxSigned();
39553
+ }
39554
+ try {
39555
+ if (isProblematicConnector(activeConnector)) {
39556
+ await sleep(3_000);
39628
39557
  }
39629
- // Dispatch event so it can be listened from outside the widget
39630
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39631
- if (route.transactionRequest) {
39632
- const txParams = setTransactionState({
39633
- route,
39634
- txHash: hash,
39635
- nonce: txResponse.nonce,
39636
- userAddress: sourceUserAddress,
39637
- status: exports.TransactionStatus.INITIAL_LOADING,
39638
- sourceStatus: exports.TransactionStatus.ONGOING,
39639
- axelarUrl: undefined,
39640
- id,
39641
- });
39642
- if (txParams) {
39643
- addSwapTransaction({
39644
- ...txParams,
39645
- params: route.params,
39646
- estimate: route.estimate,
39647
- });
39648
- }
39558
+ const response = await txResponse.wait();
39559
+ return response;
39560
+ }
39561
+ catch (error) {
39562
+ return handleTransactionReplacementError({
39563
+ error,
39564
+ route,
39565
+ status: exports.TransactionStatus.INITIAL_LOADING,
39566
+ sourceStatus: exports.TransactionStatus.ONGOING,
39567
+ userAddress: sourceUserAddress,
39568
+ axelarUrl: undefined,
39569
+ id,
39570
+ });
39571
+ }
39572
+ });
39573
+ const swapMutationSolana = reactQuery.useMutation(async ({ id, route }) => {
39574
+ try {
39575
+ if (!route) {
39576
+ throw new Error("Route is required");
39649
39577
  }
39650
- try {
39651
- if (isProblematicConnector(activeConnector)) {
39652
- await sleep(3_000);
39653
- }
39654
- const response = await txResponse.wait();
39655
- return response;
39578
+ if (!solanaSigner) {
39579
+ throw new Error("Solana signer is required");
39656
39580
  }
39657
- catch (error) {
39658
- return handleTransactionReplacementError({
39659
- error,
39660
- route,
39661
- status: exports.TransactionStatus.INITIAL_LOADING,
39662
- sourceStatus: exports.TransactionStatus.ONGOING,
39663
- userAddress: sourceUserAddress,
39664
- axelarUrl: undefined,
39665
- id,
39666
- });
39581
+ if (!route.params.fromAddress || !route.params.toAddress) {
39582
+ throw new Error("From or to address is required");
39667
39583
  }
39668
- },
39669
- });
39670
- const swapMutationSolana = reactQuery.useMutation({
39671
- mutationFn: async ({ id, route }) => {
39672
- try {
39673
- if (!route) {
39674
- throw new Error("Route is required");
39675
- }
39676
- if (!solanaSigner) {
39677
- throw new Error("Solana signer is required");
39678
- }
39679
- if (!route.params.fromAddress || !route.params.toAddress) {
39680
- throw new Error("From or to address is required");
39584
+ const isDirectTransfer = isDepositRoute(route);
39585
+ // Means it's a transfer to a deposit address
39586
+ // Instead of a Swap/Contract call using a DEX like Jupiter
39587
+ if (isDirectTransfer) {
39588
+ // Get the deposit address from the squidRoute
39589
+ const depositData = useDepositAddressStore.getState().deposit;
39590
+ // Validate params
39591
+ if (!depositData?.depositAddress) {
39592
+ throw new Error("Deposit address is required");
39681
39593
  }
39682
- const isDirectTransfer = isDepositRoute(route);
39683
- // Means it's a transfer to a deposit address
39684
- // Instead of a Swap/Contract call using a DEX like Jupiter
39685
- if (isDirectTransfer) {
39686
- // Get the deposit address from the squidRoute
39687
- const depositData = useDepositAddressStore.getState().deposit;
39688
- // Validate params
39689
- if (!depositData?.depositAddress) {
39690
- throw new Error("Deposit address is required");
39691
- }
39692
- const signature = await executeSolanaTransfer({
39693
- amount: BigInt(route.params.fromAmount),
39694
- target: depositData.depositAddress,
39695
- signer: solanaSigner,
39696
- connection: solanaConnection,
39697
- sourceToken: findToken(route.params.fromToken, route?.params?.fromChain),
39698
- onSigned: (txHash) => {
39699
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39700
- const txParams = setTransactionState({
39701
- route,
39702
- txHash,
39703
- transactionIdForStatus: depositData.chainflipStatusTrackingId,
39704
- userAddress: sourceUserAddress,
39705
- status: exports.TransactionStatus.INITIAL_LOADING,
39706
- sourceStatus: exports.TransactionStatus.ONGOING,
39707
- id,
39708
- });
39709
- if (txParams) {
39710
- addSwapTransaction({
39711
- ...txParams,
39712
- params: route.params,
39713
- estimate: route.estimate,
39714
- });
39715
- }
39716
- },
39717
- });
39718
- return signature;
39719
- }
39720
- const signature = await executeSolanaSwap({
39721
- route,
39594
+ const signature = await executeSolanaTransfer({
39595
+ amount: BigInt(route.params.fromAmount),
39596
+ target: depositData.depositAddress,
39722
39597
  signer: solanaSigner,
39723
39598
  connection: solanaConnection,
39599
+ sourceToken: findToken(route.params.fromToken, route?.params?.fromChain),
39724
39600
  onSigned: (txHash) => {
39725
39601
  WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39726
39602
  const txParams = setTransactionState({
39727
39603
  route,
39728
39604
  txHash,
39729
- transactionIdForStatus: undefined,
39605
+ transactionIdForStatus: depositData.chainflipStatusTrackingId,
39730
39606
  userAddress: sourceUserAddress,
39731
39607
  status: exports.TransactionStatus.INITIAL_LOADING,
39732
39608
  sourceStatus: exports.TransactionStatus.ONGOING,
@@ -39743,13 +39619,39 @@ const useExecuteTransaction = (squidRoute) => {
39743
39619
  });
39744
39620
  return signature;
39745
39621
  }
39746
- catch (error) {
39747
- console.error("Solana transaction failed:", error);
39748
- throw error instanceof Error
39749
- ? error
39750
- : new Error("Failed to execute Solana transaction");
39751
- }
39752
- },
39622
+ const signature = await executeSolanaSwap({
39623
+ route,
39624
+ signer: solanaSigner,
39625
+ connection: solanaConnection,
39626
+ onSigned: (txHash) => {
39627
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39628
+ const txParams = setTransactionState({
39629
+ route,
39630
+ txHash,
39631
+ transactionIdForStatus: undefined,
39632
+ userAddress: sourceUserAddress,
39633
+ status: exports.TransactionStatus.INITIAL_LOADING,
39634
+ sourceStatus: exports.TransactionStatus.ONGOING,
39635
+ id,
39636
+ });
39637
+ if (txParams) {
39638
+ addSwapTransaction({
39639
+ ...txParams,
39640
+ params: route.params,
39641
+ estimate: route.estimate,
39642
+ });
39643
+ }
39644
+ },
39645
+ });
39646
+ return signature;
39647
+ }
39648
+ catch (error) {
39649
+ console.error("Solana transaction failed:", error);
39650
+ throw error instanceof Error
39651
+ ? error
39652
+ : new Error("Failed to execute Solana transaction");
39653
+ }
39654
+ }, {
39753
39655
  onError: (error, variables) => {
39754
39656
  const currentTx = getTransaction(variables.id);
39755
39657
  const errorObject = getTransactionError(error);
@@ -39770,9 +39672,7 @@ const useExecuteTransaction = (squidRoute) => {
39770
39672
  },
39771
39673
  onSuccess: (_data, variables) => {
39772
39674
  const currentTx = getTransaction(variables.id);
39773
- queryClient.invalidateQueries({
39774
- queryKey: getPrefixKey(QueryKeys.Balances),
39775
- });
39675
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balances));
39776
39676
  if (isSameChain && currentTx?.transactionId) {
39777
39677
  replaceSwapTransactionStatus({
39778
39678
  transactionId: currentTx.transactionId,
@@ -39789,207 +39689,197 @@ const useExecuteTransaction = (squidRoute) => {
39789
39689
  });
39790
39690
  },
39791
39691
  });
39792
- const swapMutationBitcoin = reactQuery.useMutation({
39793
- mutationFn: async ({ id, route }) => {
39794
- const { depositAddress, amount: sendAmount, chainflipStatusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
39795
- if (!depositAddress) {
39796
- throw new Error(`Invalid deposit address: ${depositAddress}`);
39797
- }
39798
- if (!sendAmount) {
39799
- throw new Error(`Invalid send amount: ${sendAmount}`);
39800
- }
39801
- const allParamsValid = route && bitcoinSigner && depositAddress && sendAmount;
39802
- await changeNetworkIfNeeded.mutateAsync();
39803
- if (allParamsValid) {
39804
- dispatchSignatureRequestEvent(route);
39805
- const { txHash } = await bitcoinSigner.sendBTC(depositAddress, Number(sendAmount));
39806
- if (txHash) {
39807
- resetQueriesAfterTxSigned();
39808
- }
39809
- // Dispatch event so it can be listened from outside the widget
39810
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39811
- if (route.transactionRequest) {
39812
- const txParams = setTransactionState({
39813
- route,
39814
- txHash,
39815
- // When bridging from Bitcoin we need to send the chainflipId to the status endpoint
39816
- // instead of the Bitcoin transaction hash
39817
- transactionIdForStatus: chainflipStatusTrackingId,
39818
- userAddress: sourceUserAddress,
39819
- status: exports.TransactionStatus.INITIAL_LOADING,
39820
- sourceStatus: exports.TransactionStatus.ONGOING,
39821
- axelarUrl: undefined,
39822
- id,
39823
- });
39824
- if (txParams) {
39825
- addSwapTransaction({
39826
- ...txParams,
39827
- params: route.params,
39828
- estimate: route.estimate,
39829
- });
39830
- }
39831
- }
39832
- }
39833
- else {
39834
- throw new Error("Need all parameters");
39835
- }
39836
- },
39837
- });
39838
- const swapMutationXrpl = reactQuery.useMutation({
39839
- mutationFn: async ({ id, route }) => {
39840
- if (!route?.transactionRequest || !xrplSigner) {
39841
- throw new Error("Need all parameters");
39842
- }
39843
- if (route.transactionRequest.type !== squidTypes.SquidDataType.OnChainExecution) {
39844
- throw new Error("Invalid route type");
39845
- }
39846
- const { data } = route.transactionRequest;
39847
- const paymentTx = parseXrplPaymentTx(data);
39848
- if (!paymentTx)
39849
- throw new Error("Could not parse transaction");
39850
- const fromChainId = route.params.fromChain;
39851
- const xrplNetwork = getXrplNetwork(fromChainId);
39852
- if (xrplNetwork == null) {
39853
- throw new Error(`No XRPL network found for chainId '${fromChainId}'`);
39854
- }
39855
- const txRes = await xrplSigner.signAndSubmit({
39856
- tx: paymentTx,
39857
- network: xrplNetwork,
39858
- });
39859
- const txParams = setTransactionState({
39860
- txHash: txRes.hash,
39861
- id,
39862
- sourceStatus: exports.TransactionStatus.ONGOING,
39863
- status: exports.TransactionStatus.ONGOING,
39864
- route: route,
39865
- userAddress: sourceUserAddress,
39866
- });
39867
- if (txParams && route) {
39868
- addSwapTransaction({
39869
- ...txParams,
39870
- params: route.params,
39871
- estimate: route.estimate,
39872
- });
39873
- }
39874
- if (txRes.status !== XrplTxStatus.SUCCESS) {
39875
- throw new Error(`Transaction failed with status: ${txRes.status}`);
39876
- }
39877
- },
39878
- });
39879
- const swapMutationSui = reactQuery.useMutation({
39880
- mutationFn: async ({ id, route }) => {
39881
- if (!route || !suiSigner || !fromChain) {
39882
- throw new Error("Need all parameters");
39883
- }
39884
- if (route.transactionRequest?.type !== squidTypes.SquidDataType.OnChainExecution) {
39885
- throw new Error("Invalid route type");
39886
- }
39887
- const suiWalletState = connectedWalletsByChainType[squidTypes.ChainType.SUI];
39888
- if (!suiWalletState.account) {
39889
- throw new Error("Sui wallet is missing account data");
39890
- }
39891
- const fromChainId = route.params.fromChain;
39892
- const suiChain = getSuiChain(fromChainId);
39893
- if (!suiChain) {
39894
- throw new Error(`Source chain (${fromChainId}) does not match any Sui chain`);
39895
- }
39896
- const suiClient = await getClient(fromChain);
39897
- const txJson = route.transactionRequest.data;
39898
- const tx = transactions.Transaction.from(txJson);
39899
- const signedTx = await suiSigner.signTransaction({
39900
- transaction: tx,
39901
- account: suiWalletState.account,
39902
- chain: suiChain,
39903
- });
39904
- // execute transaction without waiting for confirmation
39905
- const txResponse = await suiClient.executeTransactionBlock({
39906
- signature: signedTx.signature,
39907
- transactionBlock: signedTx.bytes,
39908
- });
39909
- const txHash = txResponse.digest;
39692
+ const swapMutationBitcoin = reactQuery.useMutation(async ({ id, route }) => {
39693
+ const { depositAddress, amount: sendAmount, chainflipStatusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
39694
+ if (!depositAddress) {
39695
+ throw new Error(`Invalid deposit address: ${depositAddress}`);
39696
+ }
39697
+ if (!sendAmount) {
39698
+ throw new Error(`Invalid send amount: ${sendAmount}`);
39699
+ }
39700
+ const allParamsValid = route && bitcoinSigner && depositAddress && sendAmount;
39701
+ await changeNetworkIfNeeded.mutateAsync();
39702
+ if (allParamsValid) {
39703
+ dispatchSignatureRequestEvent(route);
39704
+ const { txHash } = await bitcoinSigner.sendBTC(depositAddress, Number(sendAmount));
39910
39705
  if (txHash) {
39911
39706
  resetQueriesAfterTxSigned();
39912
39707
  }
39708
+ // Dispatch event so it can be listened from outside the widget
39913
39709
  WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39914
- const txParams = setTransactionState({
39915
- route,
39916
- txHash,
39917
- userAddress: sourceUserAddress,
39918
- status: exports.TransactionStatus.INITIAL_LOADING,
39919
- sourceStatus: exports.TransactionStatus.ONGOING,
39920
- id,
39921
- });
39922
- if (txParams) {
39923
- addSwapTransaction({
39924
- ...txParams,
39925
- params: route.params,
39926
- estimate: route.estimate,
39710
+ if (route.transactionRequest) {
39711
+ const txParams = setTransactionState({
39712
+ route,
39713
+ txHash,
39714
+ // When bridging from Bitcoin we need to send the chainflipId to the status endpoint
39715
+ // instead of the Bitcoin transaction hash
39716
+ transactionIdForStatus: chainflipStatusTrackingId,
39717
+ userAddress: sourceUserAddress,
39718
+ status: exports.TransactionStatus.INITIAL_LOADING,
39719
+ sourceStatus: exports.TransactionStatus.ONGOING,
39720
+ axelarUrl: undefined,
39721
+ id,
39927
39722
  });
39723
+ if (txParams) {
39724
+ addSwapTransaction({
39725
+ ...txParams,
39726
+ params: route.params,
39727
+ estimate: route.estimate,
39728
+ });
39729
+ }
39928
39730
  }
39929
- // wait for transaction confirmation
39930
- await suiClient.waitForTransaction({
39931
- digest: txHash,
39932
- });
39933
- },
39731
+ }
39732
+ else {
39733
+ throw new Error("Need all parameters");
39734
+ }
39934
39735
  });
39935
- const swapMutationStellar = reactQuery.useMutation({
39936
- mutationFn: async ({ id, route }) => {
39937
- if (!stellarSigner || !route || !squid || !fromChain) {
39938
- throw new Error("Need all parameters");
39939
- }
39940
- const fromChainId = route.params.fromChain;
39941
- const stellarNetwork = getStellarNetwork(fromChainId);
39942
- if (stellarNetwork == null) {
39943
- throw new Error(`No Stellar network found for chainId ${fromChainId}`);
39944
- }
39945
- const { data: xdrHex, gasPrice } = route.transactionRequest;
39946
- const { address } = await stellarSigner.getAddress();
39947
- const client = await getClient(fromChain);
39948
- const account = await client.getAccount(address);
39949
- const operation = stellarSdk.xdr.Operation.fromXDR(xdrHex, "hex");
39950
- const builtTransaction = new stellarSdk.TransactionBuilder(account, {
39951
- fee: gasPrice || (BigInt(stellarSdk.BASE_FEE) * BigInt(2)).toString(),
39952
- networkPassphrase: stellarNetwork,
39953
- })
39954
- .addOperation(operation)
39955
- .setTimeout(300)
39956
- .build();
39957
- const preparedTransaction = await client.prepareTransaction(builtTransaction);
39958
- const { signedTxXdr } = await stellarSigner.signTransaction(preparedTransaction.toXDR(), {
39959
- networkPassphrase: stellarNetwork,
39736
+ const swapMutationXrpl = reactQuery.useMutation(async ({ id, route }) => {
39737
+ if (!route?.transactionRequest || !xrplSigner) {
39738
+ throw new Error("Need all parameters");
39739
+ }
39740
+ if (route.transactionRequest.type !== squidTypes.SquidDataType.OnChainExecution) {
39741
+ throw new Error("Invalid route type");
39742
+ }
39743
+ const { data } = route.transactionRequest;
39744
+ const paymentTx = parseXrplPaymentTx(data);
39745
+ if (!paymentTx)
39746
+ throw new Error("Could not parse transaction");
39747
+ const fromChainId = route.params.fromChain;
39748
+ const xrplNetwork = getXrplNetwork(fromChainId);
39749
+ if (xrplNetwork == null) {
39750
+ throw new Error(`No XRPL network found for chainId '${fromChainId}'`);
39751
+ }
39752
+ const txRes = await xrplSigner.signAndSubmit({
39753
+ tx: paymentTx,
39754
+ network: xrplNetwork,
39755
+ });
39756
+ const txParams = setTransactionState({
39757
+ txHash: txRes.hash,
39758
+ id,
39759
+ sourceStatus: exports.TransactionStatus.ONGOING,
39760
+ status: exports.TransactionStatus.ONGOING,
39761
+ route: route,
39762
+ userAddress: sourceUserAddress,
39763
+ });
39764
+ if (txParams && route) {
39765
+ addSwapTransaction({
39766
+ ...txParams,
39767
+ params: route.params,
39768
+ estimate: route.estimate,
39960
39769
  });
39961
- const signedTransaction = new stellarSdk.Transaction(signedTxXdr, stellarNetwork);
39962
- // get hash before submitting
39963
- const hash = signedTransaction.hash().toString("hex");
39964
- if (hash) {
39965
- resetQueriesAfterTxSigned();
39966
- }
39967
- // Dispatch event so it can be listened from outside the widget
39968
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39969
- const txParams = setTransactionState({
39970
- route,
39971
- txHash: hash,
39972
- userAddress: sourceUserAddress,
39973
- status: exports.TransactionStatus.INITIAL_LOADING,
39974
- sourceStatus: exports.TransactionStatus.ONGOING,
39975
- id,
39770
+ }
39771
+ if (txRes.status !== XrplTxStatus.SUCCESS) {
39772
+ throw new Error(`Transaction failed with status: ${txRes.status}`);
39773
+ }
39774
+ }, {});
39775
+ const swapMutationSui = reactQuery.useMutation(async ({ id, route }) => {
39776
+ if (!route || !suiSigner || !fromChain) {
39777
+ throw new Error("Need all parameters");
39778
+ }
39779
+ if (route.transactionRequest?.type !== squidTypes.SquidDataType.OnChainExecution) {
39780
+ throw new Error("Invalid route type");
39781
+ }
39782
+ const suiWalletState = connectedWalletsByChainType[squidTypes.ChainType.SUI];
39783
+ if (!suiWalletState.account) {
39784
+ throw new Error("Sui wallet is missing account data");
39785
+ }
39786
+ const fromChainId = route.params.fromChain;
39787
+ const suiChain = getSuiChain(fromChainId);
39788
+ if (!suiChain) {
39789
+ throw new Error(`Source chain (${fromChainId}) does not match any Sui chain`);
39790
+ }
39791
+ const suiClient = await getClient(fromChain);
39792
+ const txJson = route.transactionRequest.data;
39793
+ const tx = transactions.Transaction.from(txJson);
39794
+ const signedTx = await suiSigner.signTransaction({
39795
+ transaction: tx,
39796
+ account: suiWalletState.account,
39797
+ chain: suiChain,
39798
+ });
39799
+ // execute transaction without waiting for confirmation
39800
+ const txResponse = await suiClient.executeTransactionBlock({
39801
+ signature: signedTx.signature,
39802
+ transactionBlock: signedTx.bytes,
39803
+ });
39804
+ const txHash = txResponse.digest;
39805
+ if (txHash) {
39806
+ resetQueriesAfterTxSigned();
39807
+ }
39808
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
39809
+ const txParams = setTransactionState({
39810
+ route,
39811
+ txHash,
39812
+ userAddress: sourceUserAddress,
39813
+ status: exports.TransactionStatus.INITIAL_LOADING,
39814
+ sourceStatus: exports.TransactionStatus.ONGOING,
39815
+ id,
39816
+ });
39817
+ if (txParams) {
39818
+ addSwapTransaction({
39819
+ ...txParams,
39820
+ params: route.params,
39821
+ estimate: route.estimate,
39976
39822
  });
39977
- if (txParams) {
39978
- addSwapTransaction({
39979
- ...txParams,
39980
- params: route.params,
39981
- estimate: route.estimate,
39982
- });
39983
- }
39984
- const sentTransaction = await client.sendTransaction(signedTransaction);
39985
- await client.waitForTransaction(sentTransaction.hash);
39986
- },
39987
- });
39823
+ }
39824
+ // wait for transaction confirmation
39825
+ await suiClient.waitForTransaction({
39826
+ digest: txHash,
39827
+ });
39828
+ }, {});
39829
+ const swapMutationStellar = reactQuery.useMutation(async ({ id, route }) => {
39830
+ if (!stellarSigner || !route || !squid || !fromChain) {
39831
+ throw new Error("Need all parameters");
39832
+ }
39833
+ const fromChainId = route.params.fromChain;
39834
+ const stellarNetwork = getStellarNetwork(fromChainId);
39835
+ if (stellarNetwork == null) {
39836
+ throw new Error(`No Stellar network found for chainId ${fromChainId}`);
39837
+ }
39838
+ const { data: xdrHex, gasPrice } = route.transactionRequest;
39839
+ const { address } = await stellarSigner.getAddress();
39840
+ const client = await getClient(fromChain);
39841
+ const account = await client.getAccount(address);
39842
+ const operation = stellarSdk.xdr.Operation.fromXDR(xdrHex, "hex");
39843
+ const builtTransaction = new stellarSdk.TransactionBuilder(account, {
39844
+ fee: gasPrice || (BigInt(stellarSdk.BASE_FEE) * BigInt(2)).toString(),
39845
+ networkPassphrase: stellarNetwork,
39846
+ })
39847
+ .addOperation(operation)
39848
+ .setTimeout(300)
39849
+ .build();
39850
+ const preparedTransaction = await client.prepareTransaction(builtTransaction);
39851
+ const { signedTxXdr } = await stellarSigner.signTransaction(preparedTransaction.toXDR(), {
39852
+ networkPassphrase: stellarNetwork,
39853
+ });
39854
+ const signedTransaction = new stellarSdk.Transaction(signedTxXdr, stellarNetwork);
39855
+ // get hash before submitting
39856
+ const hash = signedTransaction.hash().toString("hex");
39857
+ if (hash) {
39858
+ resetQueriesAfterTxSigned();
39859
+ }
39860
+ // Dispatch event so it can be listened from outside the widget
39861
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, hash);
39862
+ const txParams = setTransactionState({
39863
+ route,
39864
+ txHash: hash,
39865
+ userAddress: sourceUserAddress,
39866
+ status: exports.TransactionStatus.INITIAL_LOADING,
39867
+ sourceStatus: exports.TransactionStatus.ONGOING,
39868
+ id,
39869
+ });
39870
+ if (txParams) {
39871
+ addSwapTransaction({
39872
+ ...txParams,
39873
+ params: route.params,
39874
+ estimate: route.estimate,
39875
+ });
39876
+ }
39877
+ const sentTransaction = await client.sendTransaction(signedTransaction);
39878
+ await client.waitForTransaction(sentTransaction.hash);
39879
+ }, {});
39988
39880
  const handleTransactionSuccess = React.useCallback((id) => {
39989
39881
  const currentTx = getTransaction(id);
39990
- queryClient.invalidateQueries({
39991
- queryKey: getPrefixKey(QueryKeys.Balances),
39992
- });
39882
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balances));
39993
39883
  if (isSameChain && currentTx?.transactionId) {
39994
39884
  replaceSwapTransactionStatus({
39995
39885
  transactionId: currentTx.transactionId,
@@ -40041,39 +39931,38 @@ const useExecuteTransaction = (squidRoute) => {
40041
39931
  setTransactionStoreState,
40042
39932
  squidRoute,
40043
39933
  ]);
40044
- const swapMutation = reactQuery.useMutation({
40045
- mutationFn: async (mutationParams) => {
40046
- if (!mutationParams.route)
40047
- throw new Error("route is required");
40048
- const sourceChain = findChain(mutationParams.route.params?.fromChain);
40049
- if (!sourceChain)
40050
- throw new Error("Could not find source chain");
40051
- switch (sourceChain.chainType) {
40052
- case squidTypes.ChainType.COSMOS: {
40053
- return swapMutationCosmos.mutateAsync(mutationParams);
40054
- }
40055
- case squidTypes.ChainType.EVM: {
40056
- return swapMutationEvm.mutateAsync(mutationParams);
40057
- }
40058
- case squidTypes.ChainType.BTC: {
40059
- return swapMutationBitcoin.mutateAsync(mutationParams);
40060
- }
40061
- case squidTypes.ChainType.SOLANA: {
40062
- return swapMutationSolana.mutateAsync(mutationParams);
40063
- }
40064
- case squidTypes.ChainType.SUI: {
40065
- return swapMutationSui.mutateAsync(mutationParams);
40066
- }
40067
- case squidTypes.ChainType.XRPL: {
40068
- return swapMutationXrpl.mutateAsync(mutationParams);
40069
- }
40070
- case squidTypes.ChainType.STELLAR: {
40071
- return swapMutationStellar.mutateAsync(mutationParams);
40072
- }
40073
- default:
40074
- throw new Error(`Swap mutation not implemented for chain type: ${sourceChain.chainType}`);
39934
+ const swapMutation = reactQuery.useMutation(async (mutationParams) => {
39935
+ if (!mutationParams.route)
39936
+ throw new Error("route is required");
39937
+ const sourceChain = findChain(mutationParams.route.params?.fromChain);
39938
+ if (!sourceChain)
39939
+ throw new Error("Could not find source chain");
39940
+ switch (sourceChain.chainType) {
39941
+ case squidTypes.ChainType.COSMOS: {
39942
+ return swapMutationCosmos.mutateAsync(mutationParams);
40075
39943
  }
40076
- },
39944
+ case squidTypes.ChainType.EVM: {
39945
+ return swapMutationEvm.mutateAsync(mutationParams);
39946
+ }
39947
+ case squidTypes.ChainType.BTC: {
39948
+ return swapMutationBitcoin.mutateAsync(mutationParams);
39949
+ }
39950
+ case squidTypes.ChainType.SOLANA: {
39951
+ return swapMutationSolana.mutateAsync(mutationParams);
39952
+ }
39953
+ case squidTypes.ChainType.SUI: {
39954
+ return swapMutationSui.mutateAsync(mutationParams);
39955
+ }
39956
+ case squidTypes.ChainType.XRPL: {
39957
+ return swapMutationXrpl.mutateAsync(mutationParams);
39958
+ }
39959
+ case squidTypes.ChainType.STELLAR: {
39960
+ return swapMutationStellar.mutateAsync(mutationParams);
39961
+ }
39962
+ default:
39963
+ throw new Error(`Swap mutation not implemented for chain type: ${sourceChain.chainType}`);
39964
+ }
39965
+ }, {
40077
39966
  onMutate: (variables) => {
40078
39967
  useTransactionStore.setState({
40079
39968
  txLocalId: variables.id,
@@ -40122,7 +40011,7 @@ const useExecuteTransaction = (squidRoute) => {
40122
40011
  toToken,
40123
40012
  toChain,
40124
40013
  fromChain,
40125
- isPending: swapMutation.isPending,
40014
+ isLoading: swapMutation.isLoading,
40126
40015
  error: swapMutation.error,
40127
40016
  };
40128
40017
  };
@@ -40183,59 +40072,57 @@ const useGetRoute = () => {
40183
40072
  * These data will be used to trigger the transaction
40184
40073
  * @returns {Route} Route data
40185
40074
  */
40186
- return reactQuery.useMutation({
40187
- mutationFn: async ({ fromChain, toChain, fromToken, toToken, sourceUserAddress, destinationAddress, fromPrice, bypassGuardrails, quoteOnly, fromChainType, postHook, preHook, }) => {
40188
- if (!fromChain || !toChain || !fromToken || !toToken || !fromPrice) {
40189
- return undefined;
40190
- }
40191
- // Dispatch requestQuote event
40192
- dispatchRequestQuoteEvent({
40193
- fromChain,
40194
- toChain,
40195
- fromToken: fromToken.address,
40196
- toToken: toToken.address,
40197
- fromAmount: fromPrice,
40198
- fromAddress: sourceUserAddress,
40199
- toAddress: destinationAddress,
40200
- });
40201
- const isEvmSwap = Number(fromChain) > 0 && Number(toChain) > 0;
40202
- const cosmosFallbackAddresses = quoteOnly || isEvmSwap ? undefined : await getCosmosFallbackAddresses();
40203
- const fromTokenAddress = fromToken.address;
40204
- const toTokenAddress = toToken.address;
40205
- const fromAmount = parseToBigInt(fromPrice?.toString() ?? "0", fromToken?.decimals).toString();
40206
- const fromAddress = sourceUserAddress ??
40207
- chainTypeToZeroAddressMap[fromChainType ?? squidTypes.ChainType.EVM];
40208
- const params = {
40209
- fromChain,
40210
- fromToken: fromTokenAddress,
40211
- fromAddress,
40212
- fromAmount,
40213
- toChain,
40214
- toToken: toTokenAddress,
40215
- toAddress: destinationAddress ?? "",
40216
- quoteOnly,
40217
- slippage: config.slippage === 0 ? undefined : config.slippage,
40218
- bypassGuardrails,
40219
- preHook,
40220
- postHook,
40221
- };
40222
- // If the swap is involving cosmos chains, we need to add the fallback addresses (if any)
40223
- if (cosmosFallbackAddresses &&
40224
- cosmosFallbackAddresses.length > 0 &&
40225
- cosmosFallbackAddresses[0].address) {
40226
- params.fallbackAddresses = cosmosFallbackAddresses;
40227
- }
40228
- const { route } = await squid.getRoute({
40229
- ...params,
40230
- });
40231
- // Cache the route data
40232
- // Useful when the getRoute mutation is called from another hook
40233
- 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);
40234
- return route;
40235
- },
40075
+ return reactQuery.useMutation(async ({ fromChain, toChain, fromToken, toToken, sourceUserAddress, destinationAddress, fromPrice, bypassGuardrails, quoteOnly, fromChainType, postHook, preHook, }) => {
40076
+ if (!fromChain || !toChain || !fromToken || !toToken || !fromPrice) {
40077
+ return undefined;
40078
+ }
40079
+ // Dispatch requestQuote event
40080
+ dispatchRequestQuoteEvent({
40081
+ fromChain,
40082
+ toChain,
40083
+ fromToken: fromToken.address,
40084
+ toToken: toToken.address,
40085
+ fromAmount: fromPrice,
40086
+ fromAddress: sourceUserAddress,
40087
+ toAddress: destinationAddress,
40088
+ });
40089
+ const isEvmSwap = Number(fromChain) > 0 && Number(toChain) > 0;
40090
+ const cosmosFallbackAddresses = quoteOnly || isEvmSwap ? undefined : await getCosmosFallbackAddresses();
40091
+ const fromTokenAddress = fromToken.address;
40092
+ const toTokenAddress = toToken.address;
40093
+ const fromAmount = parseToBigInt(fromPrice?.toString() ?? "0", fromToken?.decimals).toString();
40094
+ const fromAddress = sourceUserAddress ??
40095
+ chainTypeToZeroAddressMap[fromChainType ?? squidTypes.ChainType.EVM];
40096
+ const params = {
40097
+ fromChain,
40098
+ fromToken: fromTokenAddress,
40099
+ fromAddress,
40100
+ fromAmount,
40101
+ toChain,
40102
+ toToken: toTokenAddress,
40103
+ toAddress: destinationAddress ?? "",
40104
+ quoteOnly,
40105
+ slippage: config.slippage === 0 ? undefined : config.slippage,
40106
+ bypassGuardrails,
40107
+ preHook,
40108
+ postHook,
40109
+ };
40110
+ // If the swap is involving cosmos chains, we need to add the fallback addresses (if any)
40111
+ if (cosmosFallbackAddresses &&
40112
+ cosmosFallbackAddresses.length > 0 &&
40113
+ cosmosFallbackAddresses[0].address) {
40114
+ params.fallbackAddresses = cosmosFallbackAddresses;
40115
+ }
40116
+ const { route } = await squid.getRoute({
40117
+ ...params,
40118
+ });
40119
+ // Cache the route data
40120
+ // Useful when the getRoute mutation is called from another hook
40121
+ 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);
40122
+ return route;
40236
40123
  });
40237
40124
  };
40238
- const useGetRouteWrapper = ({ enabled, gcTime = 5 * 60 * 1000, // 5 minutes
40125
+ const useGetRouteWrapper = ({ enabled, cacheTime = 5 * 60 * 1000, // 5 minutes
40239
40126
  staleTime = 60 * 1000, // 1 minute
40240
40127
  refetchOnWindowFocus = (query) => Date.now() - query.state.dataUpdatedAt > 30000, // Update if older than 30 seconds, when window is focused
40241
40128
  refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true, }) => {
@@ -40285,27 +40172,25 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
40285
40172
  * These data will be used to trigger the transaction
40286
40173
  * @returns {Route} Route data
40287
40174
  */
40288
- const squidRoute = reactQuery.useQuery({
40289
- queryKey: squidRouteQueryKeys,
40290
- queryFn: async () => {
40291
- const route = await getRouteMutation.mutateAsync({
40292
- fromChain: fromChain?.chainId,
40293
- toChain: toChain?.chainId,
40294
- fromToken,
40295
- toToken,
40296
- sourceUserAddress,
40297
- destinationAddress,
40298
- fromPrice,
40299
- bypassGuardrails: config.degenMode,
40300
- quoteOnly,
40301
- fromChainType: fromChain?.chainType,
40302
- postHook: config.postHook,
40303
- preHook: config.preHook,
40304
- });
40305
- return route;
40306
- },
40175
+ const squidRoute = reactQuery.useQuery(squidRouteQueryKeys, async () => {
40176
+ const route = await getRouteMutation.mutateAsync({
40177
+ fromChain: fromChain?.chainId,
40178
+ toChain: toChain?.chainId,
40179
+ fromToken,
40180
+ toToken,
40181
+ sourceUserAddress,
40182
+ destinationAddress,
40183
+ fromPrice,
40184
+ bypassGuardrails: config.degenMode,
40185
+ quoteOnly,
40186
+ fromChainType: fromChain?.chainType,
40187
+ postHook: config.postHook,
40188
+ preHook: config.preHook,
40189
+ });
40190
+ return route;
40191
+ }, {
40307
40192
  enabled: queryEnabled,
40308
- gcTime,
40193
+ cacheTime,
40309
40194
  staleTime,
40310
40195
  refetchOnWindowFocus,
40311
40196
  refetchIntervalInBackground,
@@ -40314,7 +40199,7 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
40314
40199
  /**
40315
40200
  * If last updated data is older than X seconds and the query is currently loading, show loading indicator
40316
40201
  */
40317
- const showLoading = squidRoute.isFetching || squidRoute.isRefetching;
40202
+ const showLoading = React.useMemo(() => squidRoute.isFetching || squidRoute.isRefetching, [squidRoute.isFetching, squidRoute.isRefetching]);
40318
40203
  return {
40319
40204
  squidRoute,
40320
40205
  showLoading,
@@ -40346,7 +40231,7 @@ function useSendTransactionStatus({ chain, txHash, }) {
40346
40231
  transactionId: txHash,
40347
40232
  txType: exports.HistoryTxType.SEND,
40348
40233
  });
40349
- const { data: status, isSuccess, isError, } = reactQuery.useQuery({
40234
+ const { data: status } = reactQuery.useQuery({
40350
40235
  queryKey: keys().sendTransactionStatus(txHash, chain?.chainId),
40351
40236
  queryFn: async () => {
40352
40237
  if (!chain || !txHash)
@@ -40356,30 +40241,17 @@ function useSendTransactionStatus({ chain, txHash, }) {
40356
40241
  txHash,
40357
40242
  });
40358
40243
  },
40359
- refetchInterval: chain
40360
- ? getSendTxStatusRefetchInterval(chain.chainType)
40361
- : false,
40362
- enabled: !!chain &&
40363
- !!txHash &&
40364
- !isTransactionComplete &&
40365
- !!currentHistoryItem &&
40366
- !isHistoryTransactionEnded({
40367
- data: currentHistoryItem?.data,
40368
- txType: exports.HistoryTxType.SEND,
40369
- }),
40370
- });
40371
- React.useEffect(() => {
40372
- if (isSuccess) {
40373
- setIsTransactionComplete(status !== exports.SendTransactionStatus.ONGOING);
40374
- if (status != null && !!txHash) {
40244
+ onSuccess: (txStatus) => {
40245
+ setIsTransactionComplete(txStatus !== exports.SendTransactionStatus.ONGOING);
40246
+ if (txStatus != null && !!txHash) {
40375
40247
  replaceTransactionStatus({
40376
40248
  txType: exports.HistoryTxType.SEND,
40377
- status: status,
40249
+ status: txStatus,
40378
40250
  hash: txHash,
40379
40251
  });
40380
40252
  }
40381
- }
40382
- if (isError) {
40253
+ },
40254
+ onError() {
40383
40255
  setIsTransactionComplete(true);
40384
40256
  if (txHash) {
40385
40257
  replaceTransactionStatus({
@@ -40388,8 +40260,19 @@ function useSendTransactionStatus({ chain, txHash, }) {
40388
40260
  hash: txHash,
40389
40261
  });
40390
40262
  }
40391
- }
40392
- }, [isError, isSuccess, replaceTransactionStatus, status, txHash]);
40263
+ },
40264
+ refetchInterval: chain
40265
+ ? getSendTxStatusRefetchInterval(chain.chainType)
40266
+ : false,
40267
+ enabled: !!chain &&
40268
+ !!txHash &&
40269
+ !isTransactionComplete &&
40270
+ !!currentHistoryItem &&
40271
+ !isHistoryTransactionEnded({
40272
+ data: currentHistoryItem?.data,
40273
+ txType: exports.HistoryTxType.SEND,
40274
+ }),
40275
+ });
40393
40276
  return {
40394
40277
  status: status ?? currentHistoryItem?.data?.status,
40395
40278
  };
@@ -40423,9 +40306,7 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
40423
40306
  apiUrl: latestConfig.apiUrl,
40424
40307
  });
40425
40308
  }, [transaction]);
40426
- const transactionStatusQuery = reactQuery.useQuery({
40427
- queryKey: keys().swapTransactionStatus(transaction?.transactionId),
40428
- queryFn: fetchTransactionStatusWithLatestConfig,
40309
+ const transactionStatusQuery = reactQuery.useQuery(keys().swapTransactionStatus(transaction?.transactionId), fetchTransactionStatusWithLatestConfig, {
40429
40310
  enabled: enabled &&
40430
40311
  transaction?.transactionId !== "0" &&
40431
40312
  !!transaction?.transactionId &&
@@ -40439,12 +40320,12 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
40439
40320
  data: currentHistoryItem?.data,
40440
40321
  txType: exports.HistoryTxType.SWAP,
40441
40322
  }),
40442
- refetchInterval({ state }) {
40323
+ refetchInterval(statusResponse) {
40443
40324
  // If the status response is something telling that the transaction
40444
40325
  // is finished, then store transaction history state if success
40445
40326
  // And return false to indicate refetcher to stop
40446
- if (state.data &&
40447
- transactionEndStatuses.includes(getTransactionStatus(state.data) ?? "")) {
40327
+ if (statusResponse &&
40328
+ transactionEndStatuses.includes(getTransactionStatus(statusResponse) ?? "")) {
40448
40329
  return false;
40449
40330
  }
40450
40331
  return refetchInterval; // Had to handle a variable here because after onError, we want the interval to stop
@@ -40453,10 +40334,7 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
40453
40334
  retryDelay: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 5000 : 3000,
40454
40335
  retry: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 6 : retry,
40455
40336
  refetchOnWindowFocus,
40456
- });
40457
- React.useEffect(() => {
40458
- if (transactionStatusQuery.isSuccess && transactionStatusQuery.data) {
40459
- const statusResponse = transactionStatusQuery.data;
40337
+ onSuccess: (statusResponse) => {
40460
40338
  // Dispatch event
40461
40339
  WidgetEvents.getInstance().dispatchSwapStatus(statusResponse.squidTransactionStatus ?? "");
40462
40340
  const endStatus = getTransactionEndStatus({ statusResponse });
@@ -40468,9 +40346,8 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
40468
40346
  status: endStatus,
40469
40347
  });
40470
40348
  }
40471
- }
40472
- if (transactionStatusQuery.isError) {
40473
- const error = transactionStatusQuery.error;
40349
+ },
40350
+ onError: (error) => {
40474
40351
  // `fetchTransactionStatus` throws an error with a cause being an AxiosError
40475
40352
  const is404 = is404Error(error.cause);
40476
40353
  if (!transaction?.transactionId)
@@ -40491,15 +40368,8 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
40491
40368
  status: exports.TransactionStatus.ERROR,
40492
40369
  });
40493
40370
  }
40494
- }
40495
- }, [
40496
- transactionStatusQuery.isSuccess,
40497
- transactionStatusQuery.isError,
40498
- transaction?.transactionId,
40499
- transactionStatusQuery.error,
40500
- replaceSwapTransactionStatus,
40501
- transactionStatusQuery.data,
40502
- ]);
40371
+ },
40372
+ });
40503
40373
  return {
40504
40374
  transactionStatusQuery,
40505
40375
  latestStatus: transactionStatusQuery.data
@@ -40542,7 +40412,7 @@ const useAvatar = (seed = zeroAddress) => {
40542
40412
  },
40543
40413
  // data is static, so no need to refetch
40544
40414
  refetchOnWindowFocus: false,
40545
- gcTime: Infinity,
40415
+ cacheTime: Infinity,
40546
40416
  staleTime: Infinity,
40547
40417
  });
40548
40418
  return avatar || "";
@@ -40584,40 +40454,38 @@ const useAddToken = (chainToCompare, tokenToCompare) => {
40584
40454
  /**
40585
40455
  * Add token to wallet
40586
40456
  */
40587
- const addToken = reactQuery.useMutation({
40588
- mutationFn: async ({ chain: _chain, token: _token, }) => {
40589
- const token = _token ?? tokenToCompare;
40590
- const chain = _chain ?? chainToCompare;
40591
- if (token && chain?.chainType === squidTypes.ChainType.EVM) {
40592
- const provider = await connector?.getProvider();
40593
- // Switch network if needed
40594
- if (currentEvmChain?.id.toString() !== token?.chainId) {
40595
- try {
40457
+ const addToken = reactQuery.useMutation(async ({ chain: _chain, token: _token, }) => {
40458
+ const token = _token ?? tokenToCompare;
40459
+ const chain = _chain ?? chainToCompare;
40460
+ if (token && chain?.chainType === squidTypes.ChainType.EVM) {
40461
+ const provider = await connector?.getProvider();
40462
+ // Switch network if needed
40463
+ if (currentEvmChain?.id.toString() !== token?.chainId) {
40464
+ try {
40465
+ await switchChainAsync({
40466
+ chainId: +token.chainId,
40467
+ });
40468
+ }
40469
+ catch (error) {
40470
+ console.debug("Error switching network:", error);
40471
+ if (isEvmChainNotSupportedError(error)) {
40472
+ await addEthereumChain({
40473
+ chain,
40474
+ provider,
40475
+ });
40596
40476
  await switchChainAsync({
40597
40477
  chainId: +token.chainId,
40598
40478
  });
40599
40479
  }
40600
- catch (error) {
40601
- console.debug("Error switching network:", error);
40602
- if (isEvmChainNotSupportedError(error)) {
40603
- await addEthereumChain({
40604
- chain,
40605
- provider,
40606
- });
40607
- await switchChainAsync({
40608
- chainId: +token.chainId,
40609
- });
40610
- }
40611
- }
40612
- // Metamask is not popping the second modal if we don't wait a bit
40613
- // eslint-disable-next-line no-promise-executor-return
40614
- await new Promise((resolve) => setTimeout(resolve, 100));
40615
40480
  }
40616
- await addTokenToWallet({ token, provider });
40481
+ // Metamask is not popping the second modal if we don't wait a bit
40482
+ // eslint-disable-next-line no-promise-executor-return
40483
+ await new Promise((resolve) => setTimeout(resolve, 100));
40617
40484
  }
40618
- // TODO: Implement keplr add token
40619
- return false;
40485
+ await addTokenToWallet({ token, provider });
40620
40486
  }
40487
+ // TODO: Implement keplr add token
40488
+ return false;
40621
40489
  });
40622
40490
  return {
40623
40491
  addToken,
@@ -40822,9 +40690,7 @@ function useXrplTrustLine({ address, chain, token, amount }) {
40822
40690
  }
40823
40691
  },
40824
40692
  async onSuccess() {
40825
- queryClient.invalidateQueries({
40826
- queryKey: getPrefixKey(QueryKeys.XrplTrustLine),
40827
- });
40693
+ queryClient.invalidateQueries(getPrefixKey(QueryKeys.XrplTrustLine));
40828
40694
  },
40829
40695
  });
40830
40696
  /**
@@ -40891,6 +40757,117 @@ function useXrplTrustLine({ address, chain, token, amount }) {
40891
40757
  };
40892
40758
  }
40893
40759
 
40760
+ // Prevent fetching too soon after the first successful request.
40761
+ const DEFAULT_STALE_TIME = 8000;
40762
+ const defaultOptions = {
40763
+ queries: {
40764
+ staleTime: DEFAULT_STALE_TIME,
40765
+ refetchOnWindowFocus: false,
40766
+ retry: false,
40767
+ retryOnMount: false,
40768
+ },
40769
+ };
40770
+
40771
+ const queryClient = new reactQuery.QueryClient({ defaultOptions });
40772
+ const verifyIntegratorIdValidity = (integratorId) => {
40773
+ if (!integratorId) {
40774
+ throw new Error("Integrator ID is required");
40775
+ }
40776
+ };
40777
+ const SquidProvider = ({ children, config, placeholder, }) => {
40778
+ verifyIntegratorIdValidity(config.integratorId);
40779
+ const [wagmiConfig, setWagmiConfig] = React.useState();
40780
+ const sdkInitializedRef = React.useRef(false);
40781
+ const initializeSdk = React.useCallback(async () => {
40782
+ if (sdkInitializedRef.current) {
40783
+ return;
40784
+ }
40785
+ sdkInitializedRef.current = true;
40786
+ try {
40787
+ const squid = new sdk.Squid({
40788
+ integratorId: config.integratorId,
40789
+ baseUrl: config.apiUrl ?? squidApiBaseUrl,
40790
+ });
40791
+ const [sdkInfoResponse, assetsColorsResponse] = await Promise.allSettled([
40792
+ squid.init(),
40793
+ fetchAssetsColors(),
40794
+ ]);
40795
+ if (sdkInfoResponse.status === "rejected") {
40796
+ throw sdkInfoResponse.reason;
40797
+ }
40798
+ if (assetsColorsResponse.status === "fulfilled") {
40799
+ useAssetsColorsStore.setState(assetsColorsResponse.value);
40800
+ initializeSquidWithAssetsColors(squid, assetsColorsResponse.value);
40801
+ }
40802
+ const shouldResetSwapRouteStore =
40803
+ // reset swap route if specified in config
40804
+ !config?.loadPreviousStateFromLocalStorage ||
40805
+ // or if initial assets are provided
40806
+ !isEmptyObject(config.initialAssets?.from) ||
40807
+ !isEmptyObject(config.initialAssets?.to);
40808
+ if (shouldResetSwapRouteStore) {
40809
+ useSwapRoutePersistStore.setState({
40810
+ swapRoute: undefined,
40811
+ });
40812
+ }
40813
+ useSquidStore.setState((_) => ({
40814
+ squid,
40815
+ maintenanceMode: { active: false, message: undefined },
40816
+ }));
40817
+ const newWagmiConfig = createWagmiConfig(squid.chains);
40818
+ setWagmiConfig(newWagmiConfig);
40819
+ useConfigStore.setState({
40820
+ isInitialized: true,
40821
+ config: getConfigWithDefaults(config),
40822
+ });
40823
+ }
40824
+ catch (error) {
40825
+ const isAxios503Error = error.isAxiosError &&
40826
+ error.response?.status === 503;
40827
+ if (isAxios503Error) {
40828
+ const maintenanceMessage = error.response?.data
40829
+ ?.message ?? undefined;
40830
+ // Even with an error, we want wagmi to be defined so that we can display the maintenance mode layout
40831
+ // Create wagmi config with mainnet as fallback in maintenance mode
40832
+ const newWagmiConfig = wagmi.createConfig({
40833
+ chains: [chains$1.mainnet],
40834
+ connectors: [connectors.injected()],
40835
+ transports: {
40836
+ [chains$1.mainnet.id]: wagmi.http(),
40837
+ },
40838
+ });
40839
+ setWagmiConfig(newWagmiConfig);
40840
+ useConfigStore.setState({
40841
+ isInitialized: false,
40842
+ config: getConfigWithDefaults(config),
40843
+ });
40844
+ useSquidStore.setState({
40845
+ squid: undefined,
40846
+ maintenanceMode: {
40847
+ active: true,
40848
+ message: maintenanceMessage,
40849
+ },
40850
+ });
40851
+ }
40852
+ else {
40853
+ console.error("Error initializing SDK:", error);
40854
+ }
40855
+ }
40856
+ }, [config]);
40857
+ React.useEffect(() => {
40858
+ initializeSdk();
40859
+ }, [initializeSdk]);
40860
+ return wagmiConfig ? (React.createElement(wagmi.WagmiProvider, { reconnectOnMount: false, config: wagmiConfig },
40861
+ React.createElement(reactQuery.QueryClientProvider, { client: queryClient },
40862
+ React.createElement(StellarProvider, null,
40863
+ React.createElement(EvmProvider, null,
40864
+ React.createElement(XrplProvider, null,
40865
+ React.createElement(SuiProvider, null,
40866
+ React.createElement(SolanaProvider, null,
40867
+ React.createElement(BitcoinProvider, null,
40868
+ React.createElement(CosmosProvider, null, children)))))))))) : (placeholder);
40869
+ };
40870
+
40894
40871
  exports.CHAIN_IDS = CHAIN_IDS;
40895
40872
  exports.CosmosProvider = CosmosProvider;
40896
40873
  exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
@@ -41029,7 +41006,7 @@ exports.parseEvmAddress = parseEvmAddress;
41029
41006
  exports.parseToBigInt = parseToBigInt;
41030
41007
  exports.parseXrplPaymentTx = parseXrplPaymentTx;
41031
41008
  exports.populateWallets = populateWallets;
41032
- exports.queryClient = queryClient;
41009
+ exports.randomIntFromInterval = randomIntFromInterval;
41033
41010
  exports.redirectToExtensionsStore = redirectToExtensionsStore;
41034
41011
  exports.roundNumericValue = roundNumericValue;
41035
41012
  exports.searchTokens = searchTokens;
@@ -41071,6 +41048,8 @@ exports.useEvmBalance = useEvmBalance;
41071
41048
  exports.useExecuteFiatQuote = useExecuteFiatQuote;
41072
41049
  exports.useExecuteTransaction = useExecuteTransaction;
41073
41050
  exports.useFavoriteTokensStore = useFavoriteTokensStore;
41051
+ exports.useFiatOnRampTxStatus = useFiatOnRampTxStatus;
41052
+ exports.useFiatTransactions = useFiatTransactions;
41074
41053
  exports.useGetFiatQuote = useGetFiatQuote;
41075
41054
  exports.useGetOnRampConfig = useGetOnRampConfig;
41076
41055
  exports.useGetOnrampPaymentTypes = useGetOnrampPaymentTypes;
@@ -41088,6 +41067,7 @@ exports.useMultiChainWallet = useMultiChainWallet;
41088
41067
  exports.useMultipleTokenPrices = useMultipleTokenPrices;
41089
41068
  exports.useNativeBalance = useNativeBalance;
41090
41069
  exports.useNativeTokenForChain = useNativeTokenForChain;
41070
+ exports.useRecommendedQuote = useRecommendedQuote;
41091
41071
  exports.useRouteWarnings = useRouteWarnings;
41092
41072
  exports.useSendTransaction = useSendTransaction;
41093
41073
  exports.useSendTransactionGas = useSendTransactionGas;
@@ -41115,4 +41095,4 @@ exports.useWallets = useWallets;
41115
41095
  exports.useXrplTrustLine = useXrplTrustLine;
41116
41096
  exports.walletIconBaseUrl = walletIconBaseUrl;
41117
41097
  exports.walletSupportsChainType = walletSupportsChainType;
41118
- //# sourceMappingURL=index-CjNxoWnC.js.map
41098
+ //# sourceMappingURL=index-DVmnHUzP.js.map