@0xsquid/react-hooks 8.0.1-tanstack-v5-beta.0 → 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.
- package/dist/core/types/event.d.ts +17 -8
- package/dist/hooks/onramp/useFiatToCrypto.d.ts +28 -6
- package/dist/hooks/squid/useSquid.d.ts +2 -2
- package/dist/hooks/swap/useDepositAddress.d.ts +2 -2
- package/dist/hooks/tokens/useAllConnectedWalletBalances.d.ts +11 -5
- package/dist/hooks/tokens/useAllTokensWithBalanceForChainType.d.ts +1 -1
- package/dist/hooks/tokens/useBalance.d.ts +1 -1
- package/dist/hooks/tokens/useMultipleTokenPrices.d.ts +2 -2
- package/dist/hooks/tokens/useNativeBalance.d.ts +2 -2
- package/dist/hooks/tokens/useTokenHistoricalData.d.ts +4 -4
- package/dist/hooks/transaction/send/useEstimateSendTransactionGas.d.ts +1 -1
- package/dist/hooks/transaction/send/useSendTransactionGas.d.ts +1 -1
- package/dist/hooks/transaction/useAllTransactionsStatus.d.ts +29 -3
- package/dist/hooks/transaction/useApproval.d.ts +2 -2
- package/dist/hooks/transaction/useExecuteTransaction.d.ts +2 -2
- package/dist/hooks/transaction/useGetRoute.d.ts +7 -7
- package/dist/hooks/transaction/useSwapTransactionStatus.d.ts +1 -1
- package/dist/hooks/wallet/useAddToken.d.ts +1 -1
- package/dist/hooks/wallet/useEns.d.ts +2 -2
- package/dist/hooks/wallet/useMultiChainWallet.d.ts +1 -1
- package/dist/hooks/wallet/useWallet.d.ts +1 -1
- package/dist/hooks/xrpl/useXrplTrustLine.d.ts +5 -5
- package/dist/{index-CS74WzWX.js → index-DVmnHUzP.js} +987 -960
- package/dist/index-DVmnHUzP.js.map +1 -0
- package/dist/{index-BA79s7uI.js → index-jI-SulDo.js} +986 -962
- package/dist/index-jI-SulDo.js.map +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/{secretService-U8WiVPay.js → secretService-DBxDcfuA.js} +2 -2
- package/dist/{secretService-U8WiVPay.js.map → secretService-DBxDcfuA.js.map} +1 -1
- package/dist/{secretService-D3MB_TMv.js → secretService-DN5IzV4w.js} +2 -2
- package/dist/{secretService-D3MB_TMv.js.map → secretService-DN5IzV4w.js.map} +1 -1
- package/dist/services/internal/eventService.d.ts +1 -0
- package/dist/{stellarService.client-Dp4tvmUo.js → stellarService.client-7sSrAZi2.js} +2 -2
- package/dist/{stellarService.client-Dp4tvmUo.js.map → stellarService.client-7sSrAZi2.js.map} +1 -1
- package/dist/{stellarService.client-BUdrOP04.js → stellarService.client-DTFEi5m2.js} +2 -2
- package/dist/{stellarService.client-BUdrOP04.js.map → stellarService.client-DTFEi5m2.js.map} +1 -1
- package/package.json +12 -12
- package/dist/index-BA79s7uI.js.map +0 -1
- package/dist/index-CS74WzWX.js.map +0 -1
|
@@ -4002,6 +4002,20 @@ class WidgetEvents extends EventTarget {
|
|
|
4002
4002
|
constructor() {
|
|
4003
4003
|
super();
|
|
4004
4004
|
}
|
|
4005
|
+
getRouteEventPayload = (route, txHash) => {
|
|
4006
|
+
const { fromAddress, toAddress, fromChain, toChain, fromToken, toToken, fromAmount, } = route.params;
|
|
4007
|
+
return {
|
|
4008
|
+
fromAddress,
|
|
4009
|
+
toAddress,
|
|
4010
|
+
fromChain,
|
|
4011
|
+
toChain,
|
|
4012
|
+
fromToken,
|
|
4013
|
+
toToken,
|
|
4014
|
+
fromAmount,
|
|
4015
|
+
quoteId: route.quoteId,
|
|
4016
|
+
txHash,
|
|
4017
|
+
};
|
|
4018
|
+
};
|
|
4005
4019
|
// Singleton, because we need to access this service outside the widget
|
|
4006
4020
|
static getInstance() {
|
|
4007
4021
|
if (!WidgetEvents.instance) {
|
|
@@ -4052,7 +4066,7 @@ class WidgetEvents extends EventTarget {
|
|
|
4052
4066
|
* @param route
|
|
4053
4067
|
*/
|
|
4054
4068
|
dispatchSwapExecuteCall(route, txHash) {
|
|
4055
|
-
this.dispatch("swap",
|
|
4069
|
+
this.dispatch("swap", this.getRouteEventPayload(route, txHash));
|
|
4056
4070
|
}
|
|
4057
4071
|
/**
|
|
4058
4072
|
* Dispatch event when user changes chain/token
|
|
@@ -4131,7 +4145,18 @@ class WidgetEvents extends EventTarget {
|
|
|
4131
4145
|
* @param data Quote execution parameters
|
|
4132
4146
|
*/
|
|
4133
4147
|
dispatchOnrampQuoteExecute(data) {
|
|
4134
|
-
this.dispatch("onrampQuoteExecute",
|
|
4148
|
+
this.dispatch("onrampQuoteExecute", {
|
|
4149
|
+
tokenAddress: data.squidToken?.address,
|
|
4150
|
+
tokenChainId: data.squidToken?.chainId,
|
|
4151
|
+
amount: data.cryptoAmount,
|
|
4152
|
+
paymentMethod: data.paymentMethod,
|
|
4153
|
+
walletAddress: data.walletAddress,
|
|
4154
|
+
orderId: data.orderId,
|
|
4155
|
+
fiatCurrency: data.fiatCurrency,
|
|
4156
|
+
cryptoCurrencyID: data.cryptoCurrencyID,
|
|
4157
|
+
region: data.region,
|
|
4158
|
+
onrampProviderId: data.onrampProviderId,
|
|
4159
|
+
});
|
|
4135
4160
|
}
|
|
4136
4161
|
/**
|
|
4137
4162
|
* Dispatch event when the search query has no results
|
|
@@ -26816,9 +26841,7 @@ const fetchHighestBalanceToken = (fetchCachedBalance, chainId) => {
|
|
|
26816
26841
|
if (fetchCachedBalance) {
|
|
26817
26842
|
const queryCache = fetchCachedBalance?.queryClient?.getQueryCache();
|
|
26818
26843
|
// get cached balance from key
|
|
26819
|
-
const cache = queryCache?.find(
|
|
26820
|
-
queryKey: keys().allTokensBalance(fetchCachedBalance?.address, !isNaN(Number(chainId)) ? squidTypes.ChainType.EVM : squidTypes.ChainType.COSMOS),
|
|
26821
|
-
});
|
|
26844
|
+
const cache = queryCache?.find(keys().allTokensBalance(fetchCachedBalance?.address, !isNaN(Number(chainId)) ? squidTypes.ChainType.EVM : squidTypes.ChainType.COSMOS));
|
|
26822
26845
|
// Parse result to TokenWithBalance[]
|
|
26823
26846
|
const cacheResult = cache?.state.data ?? [];
|
|
26824
26847
|
if (cacheResult.length > 0) {
|
|
@@ -27474,7 +27497,7 @@ const filterViewableTokens = (tokens, config, direction) => {
|
|
|
27474
27497
|
};
|
|
27475
27498
|
const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
|
|
27476
27499
|
const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
|
|
27477
|
-
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-
|
|
27500
|
+
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-DBxDcfuA.js'); });
|
|
27478
27501
|
return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
|
|
27479
27502
|
};
|
|
27480
27503
|
function getTokenAssetsKey(token) {
|
|
@@ -29233,16 +29256,13 @@ const useSquid = () => {
|
|
|
29233
29256
|
* Fetch squid info
|
|
29234
29257
|
* Will refetch every minute
|
|
29235
29258
|
*/
|
|
29236
|
-
const squidInfoQuery = reactQuery.useQuery({
|
|
29237
|
-
|
|
29238
|
-
|
|
29239
|
-
|
|
29240
|
-
|
|
29241
|
-
initializeSquidWithAssetsColors(squid, assetsColors);
|
|
29242
|
-
return squid;
|
|
29243
|
-
}
|
|
29244
|
-
return null;
|
|
29259
|
+
const squidInfoQuery = reactQuery.useQuery(keys().squidInfo(), async () => {
|
|
29260
|
+
if (squid) {
|
|
29261
|
+
await squid?.init();
|
|
29262
|
+
initializeSquidWithAssetsColors(squid, assetsColors);
|
|
29263
|
+
return squid;
|
|
29245
29264
|
}
|
|
29265
|
+
return null;
|
|
29246
29266
|
});
|
|
29247
29267
|
const tokens = React.useMemo(() => {
|
|
29248
29268
|
if ((squidInfoQuery?.data?.tokens ?? []).length > 0) {
|
|
@@ -29358,11 +29378,47 @@ const FINAL_TRANSACTION_STATUSES = [
|
|
|
29358
29378
|
"completed",
|
|
29359
29379
|
"failed",
|
|
29360
29380
|
];
|
|
29381
|
+
/**
|
|
29382
|
+
* Configuration for transaction status tracking
|
|
29383
|
+
*/
|
|
29384
|
+
const createTransactionStatusConfig = ({ transactionId, walletAddress, providerId, replaceTransactionStatus, }) => {
|
|
29385
|
+
return {
|
|
29386
|
+
queryKey: keys().fiatToCryptoStatus(transactionId),
|
|
29387
|
+
queryFn: () => new OnrampService().getTransactionStatus(transactionId, walletAddress, providerId),
|
|
29388
|
+
enabled: !!transactionId && !!walletAddress && !!providerId,
|
|
29389
|
+
retry: TX_STATUS_CONSTANTS.RETRY_COUNT,
|
|
29390
|
+
retryDelay: TX_STATUS_CONSTANTS.RETRY_DELAY,
|
|
29391
|
+
refetchInterval: (data) => {
|
|
29392
|
+
if (data?.status && FINAL_TRANSACTION_STATUSES.includes(data.status)) {
|
|
29393
|
+
return false;
|
|
29394
|
+
}
|
|
29395
|
+
return TX_STATUS_CONSTANTS.REFETCH_INTERVAL;
|
|
29396
|
+
},
|
|
29397
|
+
onSuccess: (data) => {
|
|
29398
|
+
if (data) {
|
|
29399
|
+
replaceTransactionStatus({
|
|
29400
|
+
txType: exports.HistoryTxType.BUY,
|
|
29401
|
+
orderId: transactionId,
|
|
29402
|
+
status: data.status,
|
|
29403
|
+
transactionHash: data.transactionHash,
|
|
29404
|
+
});
|
|
29405
|
+
}
|
|
29406
|
+
},
|
|
29407
|
+
onError: () => {
|
|
29408
|
+
replaceTransactionStatus({
|
|
29409
|
+
txType: exports.HistoryTxType.BUY,
|
|
29410
|
+
orderId: transactionId,
|
|
29411
|
+
status: "failed",
|
|
29412
|
+
transactionHash: undefined,
|
|
29413
|
+
});
|
|
29414
|
+
},
|
|
29415
|
+
};
|
|
29416
|
+
};
|
|
29361
29417
|
/**
|
|
29362
29418
|
* Fetches quotes for fiat to crypto conversion with provider details.
|
|
29363
29419
|
* Returns available rates, fees, and supported payment methods for the conversion.
|
|
29364
29420
|
*/
|
|
29365
|
-
const useGetFiatQuote = ({ fiatCurrency, cryptoCurrencyID, amount, region, paymentMethod, enabled = true, }) => {
|
|
29421
|
+
const useGetFiatQuote = ({ fiatCurrency, cryptoCurrencyID, amount, region, paymentMethod, enabled = true, onSuccess, }) => {
|
|
29366
29422
|
const service = React.useMemo(() => new OnrampService(), []);
|
|
29367
29423
|
const { data: config } = useGetOnRampConfig();
|
|
29368
29424
|
return reactQuery.useQuery({
|
|
@@ -29398,6 +29454,7 @@ const useGetFiatQuote = ({ fiatCurrency, cryptoCurrencyID, amount, region, payme
|
|
|
29398
29454
|
return quoteResponse;
|
|
29399
29455
|
},
|
|
29400
29456
|
enabled: enabled && !!fiatCurrency && !!cryptoCurrencyID && amount > 0,
|
|
29457
|
+
onSuccess,
|
|
29401
29458
|
});
|
|
29402
29459
|
};
|
|
29403
29460
|
/**
|
|
@@ -29414,7 +29471,7 @@ const useGetOnRampConfig = () => {
|
|
|
29414
29471
|
chains,
|
|
29415
29472
|
tokens,
|
|
29416
29473
|
}),
|
|
29417
|
-
|
|
29474
|
+
cacheTime: 1000 * 60 * 60,
|
|
29418
29475
|
staleTime: 1000 * 60 * 30, // 30 minutes
|
|
29419
29476
|
});
|
|
29420
29477
|
};
|
|
@@ -29472,11 +29529,49 @@ const useExecuteFiatQuote = () => {
|
|
|
29472
29529
|
},
|
|
29473
29530
|
});
|
|
29474
29531
|
};
|
|
29532
|
+
/**
|
|
29533
|
+
* Tracks the status of a single fiat to crypto transaction.
|
|
29534
|
+
*/
|
|
29535
|
+
const useFiatOnRampTxStatus = (transactionId, walletAddress, providerId) => {
|
|
29536
|
+
const replaceTransactionStatus = useHistoryStore((state) => state.replaceTransactionStatus);
|
|
29537
|
+
return reactQuery.useQuery({
|
|
29538
|
+
...createTransactionStatusConfig({
|
|
29539
|
+
transactionId,
|
|
29540
|
+
walletAddress,
|
|
29541
|
+
providerId,
|
|
29542
|
+
replaceTransactionStatus,
|
|
29543
|
+
}),
|
|
29544
|
+
});
|
|
29545
|
+
};
|
|
29546
|
+
/**
|
|
29547
|
+
* Tracks all pending fiat transactions.
|
|
29548
|
+
*/
|
|
29549
|
+
const useFiatTransactions = () => {
|
|
29550
|
+
const transactions = useHistoryStore((state) => state.transactions.filter((tx) => tx.txType === exports.HistoryTxType.BUY));
|
|
29551
|
+
const replaceTransactionStatus = useHistoryStore((state) => state.replaceTransactionStatus);
|
|
29552
|
+
const pendingTransactions = React.useMemo(() => transactions?.filter((tx) => !FINAL_TRANSACTION_STATUSES.includes(tx.data.status)) ?? [], [transactions]);
|
|
29553
|
+
const queries = reactQuery.useQueries({
|
|
29554
|
+
queries: pendingTransactions.map((tx) => ({
|
|
29555
|
+
...createTransactionStatusConfig({
|
|
29556
|
+
transactionId: tx.data.orderId,
|
|
29557
|
+
walletAddress: tx.data.toAddress,
|
|
29558
|
+
providerId: tx.data.providerId,
|
|
29559
|
+
replaceTransactionStatus,
|
|
29560
|
+
}),
|
|
29561
|
+
})),
|
|
29562
|
+
});
|
|
29563
|
+
return {
|
|
29564
|
+
transactions: transactions.map((tx) => tx.data),
|
|
29565
|
+
isLoading: queries.some((q) => q.isLoading),
|
|
29566
|
+
isError: queries.some((q) => q.isError),
|
|
29567
|
+
};
|
|
29568
|
+
};
|
|
29475
29569
|
/**
|
|
29476
29570
|
* Gets currency details including symbol and limits.
|
|
29477
29571
|
* Example: USD → { symbol: "$", name: "US Dollar", ... }
|
|
29478
29572
|
*/
|
|
29479
29573
|
const useCurrencyDetails = (currencyCode) => {
|
|
29574
|
+
const { data: config } = useGetOnRampConfig();
|
|
29480
29575
|
return React.useMemo(() => {
|
|
29481
29576
|
if (!currencyCode)
|
|
29482
29577
|
return undefined;
|
|
@@ -29489,7 +29584,7 @@ const useCurrencyDetails = (currencyCode) => {
|
|
|
29489
29584
|
};
|
|
29490
29585
|
}
|
|
29491
29586
|
return undefined;
|
|
29492
|
-
}, [currencyCode]);
|
|
29587
|
+
}, [currencyCode, config?.supportedFiats]);
|
|
29493
29588
|
};
|
|
29494
29589
|
/**
|
|
29495
29590
|
* Gets country details with flag URL and localized name.
|
|
@@ -29516,6 +29611,23 @@ const useAvailableQuotes = (quotes) => {
|
|
|
29516
29611
|
return uniqueQuotes;
|
|
29517
29612
|
}, [quotes]);
|
|
29518
29613
|
};
|
|
29614
|
+
/**
|
|
29615
|
+
* Gets the recommended quote based on best rates or provider preferences.
|
|
29616
|
+
* Falls back to first available quote if no specific recommendation.
|
|
29617
|
+
*/
|
|
29618
|
+
const useRecommendedQuote = (quotes, recommendedQuote) => {
|
|
29619
|
+
const availableQuotes = useAvailableQuotes(quotes);
|
|
29620
|
+
return React.useMemo(() => {
|
|
29621
|
+
if (!availableQuotes.length)
|
|
29622
|
+
return undefined;
|
|
29623
|
+
if (!recommendedQuote)
|
|
29624
|
+
return availableQuotes[0];
|
|
29625
|
+
// Try to find the recommended quote among available quotes
|
|
29626
|
+
const recommendedAvailableQuote = availableQuotes.find((quote) => quote.onrampProviderId === recommendedQuote.onrampProviderId);
|
|
29627
|
+
// If recommended quote is not available, return first available quote
|
|
29628
|
+
return recommendedAvailableQuote ?? availableQuotes[0];
|
|
29629
|
+
}, [availableQuotes, recommendedQuote]);
|
|
29630
|
+
};
|
|
29519
29631
|
/**
|
|
29520
29632
|
* Fetches the available payment methods for a given fiat and crypto currency pair.
|
|
29521
29633
|
* The first item in the returned array is the most recommended.
|
|
@@ -29618,7 +29730,7 @@ const middleStepChecker = (statusResponse) => {
|
|
|
29618
29730
|
}
|
|
29619
29731
|
return exports.TransactionStatus.ERROR;
|
|
29620
29732
|
}
|
|
29621
|
-
if (statusResponse?.
|
|
29733
|
+
if (statusResponse?.isInitialLoading) {
|
|
29622
29734
|
return exports.TransactionStatus.INITIAL_LOADING;
|
|
29623
29735
|
}
|
|
29624
29736
|
return exports.TransactionStatus.ONGOING;
|
|
@@ -30063,7 +30175,7 @@ const useClient = () => {
|
|
|
30063
30175
|
queryFn: getUserCountry,
|
|
30064
30176
|
enabled: isClient,
|
|
30065
30177
|
retry: false,
|
|
30066
|
-
|
|
30178
|
+
cacheTime: CACHE_TIME,
|
|
30067
30179
|
staleTime: STALE_TIME,
|
|
30068
30180
|
});
|
|
30069
30181
|
const userCountry = countryData?.countryCode || DEFAULT_COUNTRY_CODE;
|
|
@@ -30164,13 +30276,11 @@ function useDebouncedValue(value, delay) {
|
|
|
30164
30276
|
* @returns the ENS data of the given address
|
|
30165
30277
|
*/
|
|
30166
30278
|
function useEnsDataForAddress({ address, options, }) {
|
|
30167
|
-
const ensQuery = reactQuery.useQuery({
|
|
30168
|
-
queryKey: keys().ensData(address?.toLowerCase()),
|
|
30169
|
-
queryFn: () => EnsService.getEnsDataFromAddress(address),
|
|
30279
|
+
const ensQuery = reactQuery.useQuery(keys().ensData(address?.toLowerCase()), () => EnsService.getEnsDataFromAddress(address), {
|
|
30170
30280
|
...options,
|
|
30171
30281
|
enabled: Boolean(address?.trim()) &&
|
|
30172
30282
|
(options?.enabled === undefined ? true : options.enabled),
|
|
30173
|
-
|
|
30283
|
+
cacheTime: Infinity,
|
|
30174
30284
|
});
|
|
30175
30285
|
return ensQuery;
|
|
30176
30286
|
}
|
|
@@ -30186,16 +30296,14 @@ function useEnsDataForAddress({ address, options, }) {
|
|
|
30186
30296
|
*/
|
|
30187
30297
|
function useEnsSearch({ name, enabled = true, delayMs = 500, }) {
|
|
30188
30298
|
const debouncedName = useDebouncedValue(enabled ? name : undefined, delayMs);
|
|
30189
|
-
const ensSearchQuery = reactQuery.useQuery({
|
|
30190
|
-
|
|
30191
|
-
|
|
30192
|
-
|
|
30193
|
-
|
|
30194
|
-
|
|
30195
|
-
: EnsService.searchEnsNames(debouncedName);
|
|
30196
|
-
},
|
|
30299
|
+
const ensSearchQuery = reactQuery.useQuery(keys().ensSearch(debouncedName), () => {
|
|
30300
|
+
const isExactEnsSearch = checkIsExactEns(debouncedName);
|
|
30301
|
+
return isExactEnsSearch
|
|
30302
|
+
? EnsService.getExactEns(debouncedName)
|
|
30303
|
+
: EnsService.searchEnsNames(debouncedName);
|
|
30304
|
+
}, {
|
|
30197
30305
|
enabled: Boolean(debouncedName?.trim()) && enabled,
|
|
30198
|
-
|
|
30306
|
+
cacheTime: Infinity,
|
|
30199
30307
|
});
|
|
30200
30308
|
return ensSearchQuery;
|
|
30201
30309
|
}
|
|
@@ -30216,25 +30324,23 @@ function checkIsExactEns(name = "") {
|
|
|
30216
30324
|
|
|
30217
30325
|
const useCosmosForChain = (chain) => {
|
|
30218
30326
|
const { keplrTypeWallet } = useCosmosSigner({ chain });
|
|
30219
|
-
const cosmosAddressQuery = reactQuery.useQuery({
|
|
30220
|
-
|
|
30221
|
-
|
|
30222
|
-
|
|
30223
|
-
|
|
30224
|
-
|
|
30225
|
-
|
|
30226
|
-
|
|
30227
|
-
|
|
30228
|
-
|
|
30229
|
-
|
|
30230
|
-
|
|
30231
|
-
|
|
30232
|
-
|
|
30233
|
-
|
|
30234
|
-
|
|
30235
|
-
|
|
30236
|
-
}
|
|
30237
|
-
},
|
|
30327
|
+
const cosmosAddressQuery = reactQuery.useQuery(keys().cosmosAddress(chain?.chainId), async () => {
|
|
30328
|
+
if (!chain || !keplrTypeWallet)
|
|
30329
|
+
return "";
|
|
30330
|
+
try {
|
|
30331
|
+
const address = await getCosmosKey(chain.chainId, keplrTypeWallet);
|
|
30332
|
+
return address ?? "";
|
|
30333
|
+
}
|
|
30334
|
+
catch (error) {
|
|
30335
|
+
await suggestChainOrThrow({
|
|
30336
|
+
chain: chain,
|
|
30337
|
+
error,
|
|
30338
|
+
keplrTypeWallet,
|
|
30339
|
+
});
|
|
30340
|
+
const address = await getCosmosKey(chain.chainId, keplrTypeWallet);
|
|
30341
|
+
return address ?? "";
|
|
30342
|
+
}
|
|
30343
|
+
}, {
|
|
30238
30344
|
enabled: !!keplrTypeWallet && chain?.chainType === squidTypes.ChainType.COSMOS,
|
|
30239
30345
|
});
|
|
30240
30346
|
return cosmosAddressQuery;
|
|
@@ -30311,14 +30417,12 @@ const useIsSameAddressAndGnosisContext = () => {
|
|
|
30311
30417
|
|
|
30312
30418
|
function useBitcoin() {
|
|
30313
30419
|
const connectedBitcoinWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.BTC]);
|
|
30314
|
-
const connectBitcoin = reactQuery.useMutation({
|
|
30315
|
-
|
|
30316
|
-
|
|
30317
|
-
|
|
30318
|
-
|
|
30319
|
-
|
|
30320
|
-
};
|
|
30321
|
-
}
|
|
30420
|
+
const connectBitcoin = reactQuery.useMutation(async ({ wallet, }) => {
|
|
30421
|
+
const { address } = await wallet.connector.requestAccount();
|
|
30422
|
+
return {
|
|
30423
|
+
wallet,
|
|
30424
|
+
address,
|
|
30425
|
+
};
|
|
30322
30426
|
});
|
|
30323
30427
|
return {
|
|
30324
30428
|
connectBitcoin,
|
|
@@ -30358,17 +30462,15 @@ function useEvm() {
|
|
|
30358
30462
|
const { wallets } = useEvmWallets();
|
|
30359
30463
|
const connectedEvmWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.EVM]);
|
|
30360
30464
|
const recentEvmWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.EVM]);
|
|
30361
|
-
const connectEvm = reactQuery.useMutation({
|
|
30362
|
-
|
|
30363
|
-
|
|
30364
|
-
|
|
30365
|
-
|
|
30366
|
-
|
|
30367
|
-
|
|
30368
|
-
|
|
30369
|
-
|
|
30370
|
-
};
|
|
30371
|
-
}
|
|
30465
|
+
const connectEvm = reactQuery.useMutation(async ({ wallet, }) => {
|
|
30466
|
+
const result = await connectAsync({
|
|
30467
|
+
connector: wallet.connector,
|
|
30468
|
+
});
|
|
30469
|
+
const [firstAddress] = result.accounts;
|
|
30470
|
+
return {
|
|
30471
|
+
wallet,
|
|
30472
|
+
address: firstAddress,
|
|
30473
|
+
};
|
|
30372
30474
|
});
|
|
30373
30475
|
const disconnectEvm = React.useCallback(async () => {
|
|
30374
30476
|
disconnect({ connector: connectedEvmWallet.wallet?.connector });
|
|
@@ -30462,23 +30564,21 @@ function useSolana() {
|
|
|
30462
30564
|
const { wallets } = useSolanaWallets();
|
|
30463
30565
|
const connectedSolanaWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.SOLANA]);
|
|
30464
30566
|
const recentSolanaWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.SOLANA]);
|
|
30465
|
-
const connectSolana = reactQuery.useMutation({
|
|
30466
|
-
|
|
30467
|
-
try
|
|
30468
|
-
|
|
30469
|
-
await wallet.connector.autoConnect();
|
|
30470
|
-
}
|
|
30471
|
-
catch {
|
|
30472
|
-
// if auto-connect fails (e.g. not authorized yet)
|
|
30473
|
-
// fallback to connect via popup
|
|
30474
|
-
await wallet.connector.connect();
|
|
30475
|
-
}
|
|
30476
|
-
const address = wallet.connector.wallet.accounts[0].address;
|
|
30477
|
-
return {
|
|
30478
|
-
wallet,
|
|
30479
|
-
address,
|
|
30480
|
-
};
|
|
30567
|
+
const connectSolana = reactQuery.useMutation(async ({ wallet, }) => {
|
|
30568
|
+
try {
|
|
30569
|
+
// try to connect silently first
|
|
30570
|
+
await wallet.connector.autoConnect();
|
|
30481
30571
|
}
|
|
30572
|
+
catch {
|
|
30573
|
+
// if auto-connect fails (e.g. not authorized yet)
|
|
30574
|
+
// fallback to connect via popup
|
|
30575
|
+
await wallet.connector.connect();
|
|
30576
|
+
}
|
|
30577
|
+
const address = wallet.connector.wallet.accounts[0].address;
|
|
30578
|
+
return {
|
|
30579
|
+
wallet,
|
|
30580
|
+
address,
|
|
30581
|
+
};
|
|
30482
30582
|
});
|
|
30483
30583
|
const disconnectSolana = React.useCallback(async () => {
|
|
30484
30584
|
await connectedSolanaWallet.wallet?.connector.disconnect();
|
|
@@ -30553,7 +30653,7 @@ function useStellarWallets() {
|
|
|
30553
30653
|
return;
|
|
30554
30654
|
try {
|
|
30555
30655
|
const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
|
|
30556
|
-
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-
|
|
30656
|
+
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-DTFEi5m2.js'); });
|
|
30557
30657
|
const modules = initializeAllModules();
|
|
30558
30658
|
const promises = modules.map(async (module) => {
|
|
30559
30659
|
const isAvailable = await module.isAvailable();
|
|
@@ -30581,14 +30681,12 @@ function useStellarWallets() {
|
|
|
30581
30681
|
function useStellar() {
|
|
30582
30682
|
const { wallets } = useStellarWallets();
|
|
30583
30683
|
const connectedStellarWallet = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.STELLAR]);
|
|
30584
|
-
const connectStellar = reactQuery.useMutation({
|
|
30585
|
-
|
|
30586
|
-
|
|
30587
|
-
|
|
30588
|
-
|
|
30589
|
-
|
|
30590
|
-
};
|
|
30591
|
-
}
|
|
30684
|
+
const connectStellar = reactQuery.useMutation(async ({ wallet, }) => {
|
|
30685
|
+
const { address } = await wallet.connector.getAddress();
|
|
30686
|
+
return {
|
|
30687
|
+
wallet,
|
|
30688
|
+
address,
|
|
30689
|
+
};
|
|
30592
30690
|
});
|
|
30593
30691
|
const disconnectStellar = React.useCallback(async () => {
|
|
30594
30692
|
await connectedStellarWallet.wallet?.connector.disconnect?.();
|
|
@@ -30640,24 +30738,22 @@ function useSui() {
|
|
|
30640
30738
|
const recentSuiWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.SUI]);
|
|
30641
30739
|
const setConnectedWallet = useWalletStore((store) => store.setConnectedWallet);
|
|
30642
30740
|
const disconnectWallet = useWalletStore((store) => store.disconnectWallet);
|
|
30643
|
-
const connectSui = reactQuery.useMutation({
|
|
30644
|
-
|
|
30645
|
-
|
|
30646
|
-
try
|
|
30647
|
-
|
|
30648
|
-
account = await wallet.connector.connect({ silent: true });
|
|
30649
|
-
}
|
|
30650
|
-
catch {
|
|
30651
|
-
// if auto-connect fails (e.g. not authorized yet)
|
|
30652
|
-
// fallback to connect via popup
|
|
30653
|
-
account = await wallet.connector.connect();
|
|
30654
|
-
}
|
|
30655
|
-
return {
|
|
30656
|
-
wallet,
|
|
30657
|
-
address: account.account.address,
|
|
30658
|
-
account: account.account,
|
|
30659
|
-
};
|
|
30741
|
+
const connectSui = reactQuery.useMutation(async ({ wallet, }) => {
|
|
30742
|
+
let account;
|
|
30743
|
+
try {
|
|
30744
|
+
// try to connect silently first
|
|
30745
|
+
account = await wallet.connector.connect({ silent: true });
|
|
30660
30746
|
}
|
|
30747
|
+
catch {
|
|
30748
|
+
// if auto-connect fails (e.g. not authorized yet)
|
|
30749
|
+
// fallback to connect via popup
|
|
30750
|
+
account = await wallet.connector.connect();
|
|
30751
|
+
}
|
|
30752
|
+
return {
|
|
30753
|
+
wallet,
|
|
30754
|
+
address: account.account.address,
|
|
30755
|
+
account: account.account,
|
|
30756
|
+
};
|
|
30661
30757
|
});
|
|
30662
30758
|
const disconnectSui = React.useCallback(async () => {
|
|
30663
30759
|
await connectedSuiWallet.wallet?.connector.disconnect();
|
|
@@ -30966,14 +31062,12 @@ function useXrpl() {
|
|
|
30966
31062
|
const recentXrplWalletId = useWalletStore((store) => store.recentConnectorIds[squidTypes.ChainType.XRPL]);
|
|
30967
31063
|
const setConnectedWallet = useWalletStore((store) => store.setConnectedWallet);
|
|
30968
31064
|
const disconnectWallet = useWalletStore((store) => store.disconnectWallet);
|
|
30969
|
-
const connectXrpl = reactQuery.useMutation({
|
|
30970
|
-
|
|
30971
|
-
|
|
30972
|
-
|
|
30973
|
-
|
|
30974
|
-
|
|
30975
|
-
};
|
|
30976
|
-
}
|
|
31065
|
+
const connectXrpl = reactQuery.useMutation(async ({ wallet, }) => {
|
|
31066
|
+
const xrplConnectedAddress = await wallet.connector.connect();
|
|
31067
|
+
return {
|
|
31068
|
+
wallet,
|
|
31069
|
+
address: xrplConnectedAddress,
|
|
31070
|
+
};
|
|
30977
31071
|
});
|
|
30978
31072
|
const disconnectXrpl = React.useCallback(async () => {
|
|
30979
31073
|
await connectedXrplWallet?.wallet?.connector.disconnect?.();
|
|
@@ -31360,19 +31454,18 @@ const useMultiChainWallet = (chain) => {
|
|
|
31360
31454
|
/**
|
|
31361
31455
|
* Change current network for desired chain
|
|
31362
31456
|
*/
|
|
31363
|
-
const changeNetworkIfNeeded = reactQuery.useMutation({
|
|
31364
|
-
|
|
31365
|
-
|
|
31366
|
-
|
|
31367
|
-
|
|
31368
|
-
|
|
31369
|
-
|
|
31370
|
-
|
|
31371
|
-
|
|
31372
|
-
|
|
31373
|
-
|
|
31374
|
-
|
|
31375
|
-
},
|
|
31457
|
+
const changeNetworkIfNeeded = reactQuery.useMutation(async () => {
|
|
31458
|
+
const isNotOnDesiredChain = chain?.chainType === squidTypes.ChainType.EVM &&
|
|
31459
|
+
currentEvmChain?.id !== Number(chain.chainId);
|
|
31460
|
+
if (isNotOnDesiredChain) {
|
|
31461
|
+
await switchChainAsync({
|
|
31462
|
+
chainId: Number(chain.chainId),
|
|
31463
|
+
});
|
|
31464
|
+
}
|
|
31465
|
+
// Implement keplr change network
|
|
31466
|
+
// Looks like there are no method to do that at the moment
|
|
31467
|
+
return false;
|
|
31468
|
+
}, {
|
|
31376
31469
|
onError: async (error) => {
|
|
31377
31470
|
if (error instanceof viem.UserRejectedRequestError) {
|
|
31378
31471
|
return;
|
|
@@ -31384,7 +31477,7 @@ const useMultiChainWallet = (chain) => {
|
|
|
31384
31477
|
provider,
|
|
31385
31478
|
});
|
|
31386
31479
|
}
|
|
31387
|
-
}
|
|
31480
|
+
},
|
|
31388
31481
|
});
|
|
31389
31482
|
const isChainTypeConnected = React.useCallback((chainType) => {
|
|
31390
31483
|
if (isGnosisConnected && chainType === squidTypes.ChainType.EVM) {
|
|
@@ -31732,53 +31825,51 @@ const useCosmos = () => {
|
|
|
31732
31825
|
clientWindow?.removeEventListener("keplr_keystorechange", () => handleKeplrAccountChanged());
|
|
31733
31826
|
};
|
|
31734
31827
|
}, [handleKeplrAccountChanged, clientWindow]);
|
|
31735
|
-
const connectCosmos = reactQuery.useMutation({
|
|
31736
|
-
|
|
31737
|
-
|
|
31738
|
-
|
|
31739
|
-
|
|
31740
|
-
|
|
31741
|
-
|
|
31742
|
-
|
|
31743
|
-
|
|
31744
|
-
|
|
31745
|
-
|
|
31746
|
-
|
|
31747
|
-
|
|
31748
|
-
|
|
31749
|
-
|
|
31750
|
-
|
|
31751
|
-
await cosmosWalletObject.enable(chainsToEnable);
|
|
31752
|
-
}
|
|
31753
|
-
catch (error) {
|
|
31754
|
-
console.warn("Failed to get chain infos, falling back to single chain enable", error);
|
|
31755
|
-
await cosmosWalletObject.enable(chainInfos.chainId);
|
|
31756
|
-
}
|
|
31828
|
+
const connectCosmos = reactQuery.useMutation(async ({ chain, wallet, approveAllChains = true, }) => {
|
|
31829
|
+
const chainInfos = getCosmosChainInfosObject(chain);
|
|
31830
|
+
const cosmosWalletObject = wallet.connector().provider;
|
|
31831
|
+
if (cosmosWalletObject) {
|
|
31832
|
+
setCosmosChainId(chainInfos.chainId.toString());
|
|
31833
|
+
try {
|
|
31834
|
+
if (approveAllChains &&
|
|
31835
|
+
typeof cosmosWalletObject.getChainInfosWithoutEndpoints ===
|
|
31836
|
+
"function") {
|
|
31837
|
+
try {
|
|
31838
|
+
const addedChains = await cosmosWalletObject.getChainInfosWithoutEndpoints();
|
|
31839
|
+
const addedChainIds = addedChains?.map((addedChain) => addedChain.chainId);
|
|
31840
|
+
const chainsToEnable = cosmosChains
|
|
31841
|
+
.filter((c) => addedChainIds?.includes(c.chainId.toString()))
|
|
31842
|
+
.map((c) => c.chainId.toString());
|
|
31843
|
+
await cosmosWalletObject.enable(chainsToEnable);
|
|
31757
31844
|
}
|
|
31758
|
-
|
|
31845
|
+
catch (error) {
|
|
31846
|
+
console.warn("Failed to get chain infos, falling back to single chain enable", error);
|
|
31759
31847
|
await cosmosWalletObject.enable(chainInfos.chainId);
|
|
31760
31848
|
}
|
|
31761
|
-
const address = await getAddress({
|
|
31762
|
-
chainId: chain.chainId.toString(),
|
|
31763
|
-
cosmosWalletObject,
|
|
31764
|
-
wallet,
|
|
31765
|
-
});
|
|
31766
|
-
if (address) {
|
|
31767
|
-
updateWalletStore(wallet, cosmosWalletObject, address);
|
|
31768
|
-
return address;
|
|
31769
|
-
}
|
|
31770
31849
|
}
|
|
31771
|
-
|
|
31772
|
-
await
|
|
31773
|
-
|
|
31774
|
-
|
|
31775
|
-
|
|
31776
|
-
|
|
31777
|
-
|
|
31850
|
+
else {
|
|
31851
|
+
await cosmosWalletObject.enable(chainInfos.chainId);
|
|
31852
|
+
}
|
|
31853
|
+
const address = await getAddress({
|
|
31854
|
+
chainId: chain.chainId.toString(),
|
|
31855
|
+
cosmosWalletObject,
|
|
31856
|
+
wallet,
|
|
31857
|
+
});
|
|
31858
|
+
if (address) {
|
|
31859
|
+
updateWalletStore(wallet, cosmosWalletObject, address);
|
|
31860
|
+
return address;
|
|
31778
31861
|
}
|
|
31779
31862
|
}
|
|
31780
|
-
|
|
31863
|
+
catch (error) {
|
|
31864
|
+
await suggestChainOrThrow({
|
|
31865
|
+
chain,
|
|
31866
|
+
error,
|
|
31867
|
+
keplrTypeWallet: cosmosWalletObject,
|
|
31868
|
+
});
|
|
31869
|
+
return connectCosmos.mutateAsync({ chain, wallet });
|
|
31870
|
+
}
|
|
31781
31871
|
}
|
|
31872
|
+
return undefined;
|
|
31782
31873
|
});
|
|
31783
31874
|
const clearData = () => {
|
|
31784
31875
|
disconnectWallet(squidTypes.ChainType.COSMOS);
|
|
@@ -31932,11 +32023,11 @@ const useSquidQueryClient = () => {
|
|
|
31932
32023
|
const queryClient = reactQuery.useQueryClient();
|
|
31933
32024
|
const invalidateQueries = (key) => {
|
|
31934
32025
|
const prefixKey = getPrefixKey(key);
|
|
31935
|
-
queryClient.invalidateQueries(
|
|
32026
|
+
queryClient.invalidateQueries(prefixKey);
|
|
31936
32027
|
};
|
|
31937
32028
|
const refetchQueries = (key) => {
|
|
31938
32029
|
const prefixKey = getPrefixKey(key);
|
|
31939
|
-
queryClient.refetchQueries(
|
|
32030
|
+
queryClient.refetchQueries(prefixKey);
|
|
31940
32031
|
};
|
|
31941
32032
|
const invalidateAndRefetchQueries = (key) => {
|
|
31942
32033
|
invalidateQueries(key);
|
|
@@ -33443,19 +33534,17 @@ function useDepositAddress(squidRoute) {
|
|
|
33443
33534
|
toggleDepositFlow(false);
|
|
33444
33535
|
setDeposit(null);
|
|
33445
33536
|
}, [toggleDepositFlow, setDeposit]);
|
|
33446
|
-
const getRouteWithDeposit = reactQuery.useMutation({
|
|
33447
|
-
|
|
33448
|
-
|
|
33449
|
-
|
|
33450
|
-
|
|
33451
|
-
|
|
33452
|
-
|
|
33453
|
-
|
|
33454
|
-
|
|
33455
|
-
|
|
33456
|
-
|
|
33457
|
-
};
|
|
33458
|
-
}
|
|
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
|
+
};
|
|
33459
33548
|
});
|
|
33460
33549
|
return {
|
|
33461
33550
|
isEnabled,
|
|
@@ -33539,55 +33628,53 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
33539
33628
|
xrplTokens.length,
|
|
33540
33629
|
stellarTokens.length,
|
|
33541
33630
|
]);
|
|
33542
|
-
const query = reactQuery.useQuery({
|
|
33543
|
-
|
|
33544
|
-
|
|
33545
|
-
|
|
33546
|
-
if (!address) {
|
|
33547
|
-
const defaultTokens = placeholderData.tokens;
|
|
33548
|
-
return {
|
|
33549
|
-
tokens: defaultTokens,
|
|
33550
|
-
totalUsdBalance: calculateTotalUsdBalanceUSD(defaultTokens),
|
|
33551
|
-
};
|
|
33552
|
-
}
|
|
33553
|
-
let fetchedTokens = [];
|
|
33554
|
-
// Fetch tokens based on chain type
|
|
33555
|
-
switch (chainType) {
|
|
33556
|
-
case squidTypes.ChainType.EVM:
|
|
33557
|
-
fetchedTokens = await getAllEvmTokensBalance(evmTokens, address, evmChains);
|
|
33558
|
-
break;
|
|
33559
|
-
case squidTypes.ChainType.COSMOS:
|
|
33560
|
-
const addresses = await getAllKeysForSupportedCosmosChains(cosmosChains.map((c) => c.chainId), keplrTypeWallet);
|
|
33561
|
-
fetchedTokens = await getAllCosmosBalances({
|
|
33562
|
-
addresses,
|
|
33563
|
-
cosmosChains,
|
|
33564
|
-
cosmosTokens,
|
|
33565
|
-
});
|
|
33566
|
-
break;
|
|
33567
|
-
case squidTypes.ChainType.SOLANA:
|
|
33568
|
-
fetchedTokens = await getAllSolanaTokensBalance(solanaTokens, address);
|
|
33569
|
-
break;
|
|
33570
|
-
case squidTypes.ChainType.BTC:
|
|
33571
|
-
fetchedTokens = await getAllBitcoinTokensBalance(address, bitcoinTokens);
|
|
33572
|
-
break;
|
|
33573
|
-
case squidTypes.ChainType.SUI:
|
|
33574
|
-
fetchedTokens = await getAllSuiTokensBalance(address, suiTokens, suiChains);
|
|
33575
|
-
break;
|
|
33576
|
-
case squidTypes.ChainType.XRPL:
|
|
33577
|
-
fetchedTokens = await getAllXrplTokensBalance(address, xrplTokens, xrplChains);
|
|
33578
|
-
break;
|
|
33579
|
-
case squidTypes.ChainType.STELLAR:
|
|
33580
|
-
fetchedTokens = await getAllStellarTokensBalance(address, stellarTokens, stellarChains);
|
|
33581
|
-
break;
|
|
33582
|
-
default:
|
|
33583
|
-
fetchedTokens = placeholderData.tokens;
|
|
33584
|
-
break;
|
|
33585
|
-
}
|
|
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;
|
|
33586
33635
|
return {
|
|
33587
|
-
tokens:
|
|
33588
|
-
totalUsdBalance: calculateTotalUsdBalanceUSD(
|
|
33636
|
+
tokens: defaultTokens,
|
|
33637
|
+
totalUsdBalance: calculateTotalUsdBalanceUSD(defaultTokens),
|
|
33589
33638
|
};
|
|
33590
|
-
}
|
|
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
|
+
}, {
|
|
33591
33678
|
...queryOptions,
|
|
33592
33679
|
enabled: isQueryEnabled,
|
|
33593
33680
|
});
|
|
@@ -33602,7 +33689,7 @@ const BALANCE_STALE_TIME = 60000; // 1 minute
|
|
|
33602
33689
|
const BALANCE_CACHE_TIME = 300000; // 5 minutes
|
|
33603
33690
|
const useAllConnectedWalletBalances = ({ direction, queryOptions = {
|
|
33604
33691
|
staleTime: BALANCE_STALE_TIME,
|
|
33605
|
-
|
|
33692
|
+
cacheTime: BALANCE_CACHE_TIME,
|
|
33606
33693
|
refetchOnWindowFocus: true,
|
|
33607
33694
|
refetchOnMount: true,
|
|
33608
33695
|
}, } = {}) => {
|
|
@@ -33683,9 +33770,9 @@ const useAllConnectedWalletBalances = ({ direction, queryOptions = {
|
|
|
33683
33770
|
}, [balanceQueries]);
|
|
33684
33771
|
// Aggregate loading states
|
|
33685
33772
|
const queryStates = React.useMemo(() => ({
|
|
33686
|
-
|
|
33773
|
+
isInitialLoading: Object.values(balanceQueries).some((q) => q.isInitialLoading),
|
|
33687
33774
|
isFetching: Object.values(balanceQueries).some((q) => q.isFetching),
|
|
33688
|
-
|
|
33775
|
+
isLoading: Object.values(balanceQueries).some((q) => q.isLoading),
|
|
33689
33776
|
isRefetching: Object.values(balanceQueries).some((q) => q.isRefetching),
|
|
33690
33777
|
isError: Object.values(balanceQueries).some((q) => q.isError),
|
|
33691
33778
|
isSuccess: Object.values(balanceQueries).every((q) => q.isSuccess),
|
|
@@ -33727,7 +33814,7 @@ function useNativeTokenForChain(chain) {
|
|
|
33727
33814
|
|
|
33728
33815
|
const useEvmNativeBalance = ({ address, chain, }) => {
|
|
33729
33816
|
const { isChainTypeConnected } = useWallet();
|
|
33730
|
-
const { data: nativeEvmBalance,
|
|
33817
|
+
const { data: nativeEvmBalance, isLoading } = wagmi.useBalance({
|
|
33731
33818
|
address: address,
|
|
33732
33819
|
chainId: Number(chain?.chainId),
|
|
33733
33820
|
query: {
|
|
@@ -33749,13 +33836,13 @@ const useEvmNativeBalance = ({ address, chain, }) => {
|
|
|
33749
33836
|
}, [nativeEvmBalance?.decimals, nativeEvmBalance?.value]);
|
|
33750
33837
|
return {
|
|
33751
33838
|
balance,
|
|
33752
|
-
|
|
33839
|
+
isLoading,
|
|
33753
33840
|
};
|
|
33754
33841
|
};
|
|
33755
33842
|
const useCosmosNativeBalance = ({ address, chain, }) => {
|
|
33756
33843
|
const { isConnected: isCosmosConnected } = useCosmosContext();
|
|
33757
33844
|
const { nativeToken: nativeCosmosToken } = useNativeTokenForChain(chain);
|
|
33758
|
-
const { balance: rawBalance,
|
|
33845
|
+
const { balance: rawBalance, isLoading } = useCosmosBalance({
|
|
33759
33846
|
chain,
|
|
33760
33847
|
token: nativeCosmosToken,
|
|
33761
33848
|
userAddress: address,
|
|
@@ -33770,18 +33857,16 @@ const useCosmosNativeBalance = ({ address, chain, }) => {
|
|
|
33770
33857
|
};
|
|
33771
33858
|
}
|
|
33772
33859
|
}, [nativeCosmosToken?.decimals, rawBalance]);
|
|
33773
|
-
return { balance,
|
|
33860
|
+
return { balance, isLoading };
|
|
33774
33861
|
};
|
|
33775
33862
|
const useBitcoinNativeBalance = ({ chain, address, }) => {
|
|
33776
33863
|
const { nativeToken } = useNativeTokenForChain(chain);
|
|
33777
|
-
const { data: rawBalance = "0",
|
|
33778
|
-
|
|
33779
|
-
|
|
33780
|
-
|
|
33781
|
-
|
|
33782
|
-
|
|
33783
|
-
return formatBNToReadable(balance, nativeToken.decimals);
|
|
33784
|
-
},
|
|
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
|
+
}, {
|
|
33785
33870
|
enabled: chain?.chainType === squidTypes.ChainType.BTC &&
|
|
33786
33871
|
nativeToken?.decimals != null &&
|
|
33787
33872
|
isWalletAddressValid(chain, address),
|
|
@@ -33800,17 +33885,15 @@ const useBitcoinNativeBalance = ({ chain, address, }) => {
|
|
|
33800
33885
|
}, [nativeToken?.decimals, rawBalance]);
|
|
33801
33886
|
return {
|
|
33802
33887
|
balance,
|
|
33803
|
-
|
|
33888
|
+
isLoading,
|
|
33804
33889
|
};
|
|
33805
33890
|
};
|
|
33806
33891
|
const useSolanaNativeBalance = ({ chain, address, }) => {
|
|
33807
33892
|
const { nativeToken } = useNativeTokenForChain(chain);
|
|
33808
|
-
const { data: rawBalance,
|
|
33809
|
-
|
|
33810
|
-
|
|
33811
|
-
|
|
33812
|
-
return formatBNToReadable(balance, nativeToken.decimals);
|
|
33813
|
-
},
|
|
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
|
+
}, {
|
|
33814
33897
|
enabled: !!address &&
|
|
33815
33898
|
nativeToken?.decimals != null &&
|
|
33816
33899
|
chain?.chainType === squidTypes.ChainType.SOLANA,
|
|
@@ -33829,12 +33912,12 @@ const useSolanaNativeBalance = ({ chain, address, }) => {
|
|
|
33829
33912
|
}, [nativeToken?.decimals, rawBalance]);
|
|
33830
33913
|
return {
|
|
33831
33914
|
balance,
|
|
33832
|
-
|
|
33915
|
+
isLoading,
|
|
33833
33916
|
};
|
|
33834
33917
|
};
|
|
33835
33918
|
const useSuiNativeBalance = ({ address, chain, }) => {
|
|
33836
33919
|
const { nativeToken } = useNativeTokenForChain(chain);
|
|
33837
|
-
const { balance: rawBalance,
|
|
33920
|
+
const { balance: rawBalance, isLoading } = useSuiBalance({
|
|
33838
33921
|
chain,
|
|
33839
33922
|
token: nativeToken,
|
|
33840
33923
|
userAddress: address,
|
|
@@ -33849,12 +33932,12 @@ const useSuiNativeBalance = ({ address, chain, }) => {
|
|
|
33849
33932
|
}, [nativeToken?.decimals, rawBalance]);
|
|
33850
33933
|
return {
|
|
33851
33934
|
balance,
|
|
33852
|
-
|
|
33935
|
+
isLoading,
|
|
33853
33936
|
};
|
|
33854
33937
|
};
|
|
33855
33938
|
const useXrplNativeBalance = ({ address, chain, }) => {
|
|
33856
33939
|
const { nativeToken } = useNativeTokenForChain(chain);
|
|
33857
|
-
const { balance: rawBalance,
|
|
33940
|
+
const { balance: rawBalance, isLoading } = useXrplBalance({
|
|
33858
33941
|
chain,
|
|
33859
33942
|
token: nativeToken,
|
|
33860
33943
|
userAddress: address,
|
|
@@ -33870,12 +33953,12 @@ const useXrplNativeBalance = ({ address, chain, }) => {
|
|
|
33870
33953
|
}, [nativeToken?.decimals, rawBalance]);
|
|
33871
33954
|
return {
|
|
33872
33955
|
balance,
|
|
33873
|
-
|
|
33956
|
+
isLoading,
|
|
33874
33957
|
};
|
|
33875
33958
|
};
|
|
33876
33959
|
const useStellarNativeBalance = ({ address, chain, }) => {
|
|
33877
33960
|
const { nativeToken } = useNativeTokenForChain(chain);
|
|
33878
|
-
const { balance: rawBalance,
|
|
33961
|
+
const { balance: rawBalance, isLoading } = useStellarBalance({
|
|
33879
33962
|
chain,
|
|
33880
33963
|
token: nativeToken,
|
|
33881
33964
|
userAddress: address,
|
|
@@ -33891,7 +33974,7 @@ const useStellarNativeBalance = ({ address, chain, }) => {
|
|
|
33891
33974
|
}, [nativeToken?.decimals, rawBalance]);
|
|
33892
33975
|
return {
|
|
33893
33976
|
balance,
|
|
33894
|
-
|
|
33977
|
+
isLoading,
|
|
33895
33978
|
};
|
|
33896
33979
|
};
|
|
33897
33980
|
const useNativeBalance = (chain) => {
|
|
@@ -33899,28 +33982,28 @@ const useNativeBalance = (chain) => {
|
|
|
33899
33982
|
const { data: cosmosAddressForChain } = useCosmosForChain(chain);
|
|
33900
33983
|
// Cosmos is a special case because the address changes on every chain
|
|
33901
33984
|
// so we can't use the default cosmos connected address
|
|
33902
|
-
const { balance: nativeCosmosBalance,
|
|
33985
|
+
const { balance: nativeCosmosBalance, isLoading: isCosmosLoading } = useCosmosNativeBalance({
|
|
33903
33986
|
address: cosmosAddressForChain,
|
|
33904
33987
|
chain,
|
|
33905
33988
|
});
|
|
33906
|
-
const { balance: nativeEvmBalance,
|
|
33907
|
-
const { balance: nativeBitcoinBalance,
|
|
33989
|
+
const { balance: nativeEvmBalance, isLoading: isEvmLoading } = useEvmNativeBalance({ address: connectedAddresses[squidTypes.ChainType.EVM], chain });
|
|
33990
|
+
const { balance: nativeBitcoinBalance, isLoading: isBitcoinLoading } = useBitcoinNativeBalance({
|
|
33908
33991
|
address: connectedAddresses[squidTypes.ChainType.BTC],
|
|
33909
33992
|
chain,
|
|
33910
33993
|
});
|
|
33911
|
-
const { balance: nativeSolanaBalance,
|
|
33994
|
+
const { balance: nativeSolanaBalance, isLoading: isSolanaLoading } = useSolanaNativeBalance({
|
|
33912
33995
|
address: connectedAddresses[squidTypes.ChainType.SOLANA],
|
|
33913
33996
|
chain,
|
|
33914
33997
|
});
|
|
33915
|
-
const { balance: nativeSuiBalance,
|
|
33998
|
+
const { balance: nativeSuiBalance, isLoading: isSuiLoading } = useSuiNativeBalance({
|
|
33916
33999
|
address: connectedAddresses[squidTypes.ChainType.SUI],
|
|
33917
34000
|
chain,
|
|
33918
34001
|
});
|
|
33919
|
-
const { balance: nativeXrplBalance,
|
|
34002
|
+
const { balance: nativeXrplBalance, isLoading: isXrpLoading } = useXrplNativeBalance({
|
|
33920
34003
|
address: connectedAddresses[squidTypes.ChainType.XRPL],
|
|
33921
34004
|
chain,
|
|
33922
34005
|
});
|
|
33923
|
-
const { balance: nativeStellarBalance,
|
|
34006
|
+
const { balance: nativeStellarBalance, isLoading: isStellarLoading } = useStellarNativeBalance({
|
|
33924
34007
|
address: connectedAddresses[squidTypes.ChainType.STELLAR],
|
|
33925
34008
|
chain,
|
|
33926
34009
|
});
|
|
@@ -33965,36 +34048,36 @@ const useNativeBalance = (chain) => {
|
|
|
33965
34048
|
nativeXrplBalance,
|
|
33966
34049
|
nativeStellarBalance,
|
|
33967
34050
|
]);
|
|
33968
|
-
const
|
|
34051
|
+
const isLoading = React.useMemo(() => {
|
|
33969
34052
|
if (!chain?.chainType)
|
|
33970
34053
|
return false;
|
|
33971
34054
|
switch (chain.chainType) {
|
|
33972
34055
|
case squidTypes.ChainType.EVM:
|
|
33973
|
-
return
|
|
34056
|
+
return isEvmLoading;
|
|
33974
34057
|
case squidTypes.ChainType.COSMOS:
|
|
33975
|
-
return
|
|
34058
|
+
return isCosmosLoading;
|
|
33976
34059
|
case squidTypes.ChainType.BTC:
|
|
33977
|
-
return
|
|
34060
|
+
return isBitcoinLoading;
|
|
33978
34061
|
case squidTypes.ChainType.SOLANA:
|
|
33979
|
-
return
|
|
34062
|
+
return isSolanaLoading;
|
|
33980
34063
|
case squidTypes.ChainType.SUI:
|
|
33981
|
-
return
|
|
34064
|
+
return isSuiLoading;
|
|
33982
34065
|
case squidTypes.ChainType.XRPL:
|
|
33983
|
-
return
|
|
34066
|
+
return isXrpLoading;
|
|
33984
34067
|
case squidTypes.ChainType.STELLAR:
|
|
33985
|
-
return
|
|
34068
|
+
return isStellarLoading;
|
|
33986
34069
|
}
|
|
33987
34070
|
}, [
|
|
33988
34071
|
chain?.chainType,
|
|
33989
|
-
|
|
33990
|
-
|
|
33991
|
-
|
|
33992
|
-
|
|
33993
|
-
|
|
33994
|
-
|
|
33995
|
-
|
|
34072
|
+
isEvmLoading,
|
|
34073
|
+
isCosmosLoading,
|
|
34074
|
+
isBitcoinLoading,
|
|
34075
|
+
isSolanaLoading,
|
|
34076
|
+
isSuiLoading,
|
|
34077
|
+
isXrpLoading,
|
|
34078
|
+
isStellarLoading,
|
|
33996
34079
|
]);
|
|
33997
|
-
return { nativeBalance, nativeBalanceFormatted,
|
|
34080
|
+
return { nativeBalance, nativeBalanceFormatted, isLoading };
|
|
33998
34081
|
};
|
|
33999
34082
|
|
|
34000
34083
|
const DEFAULT_REFRESH_INTERVAL_MS = 15000;
|
|
@@ -34003,7 +34086,7 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
|
|
|
34003
34086
|
const isNativeToken = token?.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
|
|
34004
34087
|
const userAddressParsed = userAddress;
|
|
34005
34088
|
// Only fetch using useBalance if it's a native token
|
|
34006
|
-
const { data: nativeBalance,
|
|
34089
|
+
const { data: nativeBalance, isLoading: isNativeTokenLoading } = wagmi.useBalance({
|
|
34007
34090
|
address: userAddressParsed,
|
|
34008
34091
|
chainId: Number(chain?.chainId),
|
|
34009
34092
|
query: {
|
|
@@ -34019,7 +34102,7 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
|
|
|
34019
34102
|
});
|
|
34020
34103
|
// Only fetch using useReadContract if it's not a native token
|
|
34021
34104
|
// This is temporary, because of wagmi error: https://github.com/wevm/wagmi/issues/4353
|
|
34022
|
-
const { data: erc20Balance,
|
|
34105
|
+
const { data: erc20Balance, isLoading: isErc20Loading } = wagmi.useReadContract({
|
|
34023
34106
|
address: token?.address,
|
|
34024
34107
|
abi: viem.erc20Abi,
|
|
34025
34108
|
functionName: "balanceOf",
|
|
@@ -34035,15 +34118,15 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
|
|
|
34035
34118
|
},
|
|
34036
34119
|
});
|
|
34037
34120
|
const balance = isNativeToken ? nativeBalance?.value : erc20Balance;
|
|
34038
|
-
const
|
|
34121
|
+
const isLoading = isNativeToken ? isNativeTokenLoading : isErc20Loading;
|
|
34039
34122
|
const formattedBalance = balance != null && token?.decimals != null
|
|
34040
34123
|
? formatBNToReadable(balance, token.decimals)
|
|
34041
34124
|
: "0";
|
|
34042
|
-
return { balance: formattedBalance,
|
|
34125
|
+
return { balance: formattedBalance, isLoading };
|
|
34043
34126
|
};
|
|
34044
34127
|
const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
|
|
34045
34128
|
const { isConnected } = useCosmosContext();
|
|
34046
|
-
const { data: balance = "0",
|
|
34129
|
+
const { data: balance = "0", isLoading } = reactQuery.useQuery({
|
|
34047
34130
|
queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
|
|
34048
34131
|
queryFn: async () => {
|
|
34049
34132
|
if (!userAddress || !token || chain?.chainType !== squidTypes.ChainType.COSMOS) {
|
|
@@ -34063,10 +34146,10 @@ const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIn
|
|
|
34063
34146
|
refetchInterval: refreshIntervalMs,
|
|
34064
34147
|
retry: 2,
|
|
34065
34148
|
});
|
|
34066
|
-
return { balance,
|
|
34149
|
+
return { balance, isLoading };
|
|
34067
34150
|
};
|
|
34068
34151
|
const useSolanaBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
|
|
34069
|
-
const { data: balance = "0",
|
|
34152
|
+
const { data: balance = "0", isLoading } = reactQuery.useQuery({
|
|
34070
34153
|
queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
|
|
34071
34154
|
queryFn: async () => {
|
|
34072
34155
|
if (!userAddress || !token)
|
|
@@ -34081,11 +34164,11 @@ const useSolanaBalance = ({ chain, token, userAddress, enabled = true, refreshIn
|
|
|
34081
34164
|
refetchInterval: refreshIntervalMs,
|
|
34082
34165
|
retry: 2,
|
|
34083
34166
|
});
|
|
34084
|
-
return { balance,
|
|
34167
|
+
return { balance, isLoading };
|
|
34085
34168
|
};
|
|
34086
34169
|
// TODO: implement fetching balances for all bitcoin tokens
|
|
34087
34170
|
const useBitcoinBalance = ({ userAddress, chain, }) => {
|
|
34088
|
-
const { balance: balanceBn,
|
|
34171
|
+
const { balance: balanceBn, isLoading } = useBitcoinNativeBalance({
|
|
34089
34172
|
address: userAddress,
|
|
34090
34173
|
chain,
|
|
34091
34174
|
});
|
|
@@ -34094,10 +34177,10 @@ const useBitcoinBalance = ({ userAddress, chain, }) => {
|
|
|
34094
34177
|
return "0";
|
|
34095
34178
|
return formatBNToReadable(balanceBn?.value, balanceBn?.decimals);
|
|
34096
34179
|
}, [balanceBn]);
|
|
34097
|
-
return { balance,
|
|
34180
|
+
return { balance, isLoading };
|
|
34098
34181
|
};
|
|
34099
34182
|
const useSuiBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
|
|
34100
|
-
const { data: balance = "0",
|
|
34183
|
+
const { data: balance = "0", isLoading } = reactQuery.useQuery({
|
|
34101
34184
|
queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
|
|
34102
34185
|
queryFn: async () => {
|
|
34103
34186
|
if (!userAddress ||
|
|
@@ -34117,10 +34200,10 @@ const useSuiBalance = ({ chain, token, userAddress, enabled = true, refreshInter
|
|
|
34117
34200
|
refetchInterval: refreshIntervalMs,
|
|
34118
34201
|
retry: 2,
|
|
34119
34202
|
});
|
|
34120
|
-
return { balance,
|
|
34203
|
+
return { balance, isLoading };
|
|
34121
34204
|
};
|
|
34122
34205
|
const useXrplBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
|
|
34123
|
-
const { data: balance = "0",
|
|
34206
|
+
const { data: balance = "0", isLoading } = reactQuery.useQuery({
|
|
34124
34207
|
queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
|
|
34125
34208
|
queryFn: async () => {
|
|
34126
34209
|
if (!userAddress || !token || !chain)
|
|
@@ -34137,10 +34220,10 @@ const useXrplBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs
|
|
|
34137
34220
|
refetchInterval: refreshIntervalMs,
|
|
34138
34221
|
retry: 2,
|
|
34139
34222
|
});
|
|
34140
|
-
return { balance,
|
|
34223
|
+
return { balance, isLoading };
|
|
34141
34224
|
};
|
|
34142
34225
|
const useStellarBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
|
|
34143
|
-
const { data: balance = "0",
|
|
34226
|
+
const { data: balance = "0", isLoading } = reactQuery.useQuery({
|
|
34144
34227
|
queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
|
|
34145
34228
|
queryFn: async () => {
|
|
34146
34229
|
if (!userAddress || !token || !chain)
|
|
@@ -34157,7 +34240,7 @@ const useStellarBalance = ({ userAddress, chain, enabled, token, refreshInterval
|
|
|
34157
34240
|
refetchInterval: refreshIntervalMs,
|
|
34158
34241
|
retry: 2,
|
|
34159
34242
|
});
|
|
34160
|
-
return { balance,
|
|
34243
|
+
return { balance, isLoading };
|
|
34161
34244
|
};
|
|
34162
34245
|
|
|
34163
34246
|
/**
|
|
@@ -34278,7 +34361,7 @@ const useMultipleTokenPrices = (tokens) => {
|
|
|
34278
34361
|
return {
|
|
34279
34362
|
tokenPrices,
|
|
34280
34363
|
getTokenPrice,
|
|
34281
|
-
|
|
34364
|
+
isLoading: coinGeckoQuery.isLoading,
|
|
34282
34365
|
isError: coinGeckoQuery.isError,
|
|
34283
34366
|
error: coinGeckoQuery.error,
|
|
34284
34367
|
refetch: coinGeckoQuery.refetch,
|
|
@@ -34427,17 +34510,13 @@ const fetchTokensData = async (tokens) => {
|
|
|
34427
34510
|
|
|
34428
34511
|
// Coingecko has a limit for some queries for multiple tokens, not sure what it is, but let's use 100 for now
|
|
34429
34512
|
const useHistoricalData = (coingeckoId, timeFrame) => {
|
|
34430
|
-
return reactQuery.useQuery({
|
|
34431
|
-
queryKey: keys().historicalData(coingeckoId, timeFrame),
|
|
34432
|
-
queryFn: () => fetchHistoricalData(coingeckoId, timeFrame),
|
|
34513
|
+
return reactQuery.useQuery(keys().historicalData(coingeckoId, timeFrame), () => fetchHistoricalData(coingeckoId, timeFrame), {
|
|
34433
34514
|
staleTime: 5 * 60 * 1000,
|
|
34434
34515
|
enabled: !!coingeckoId,
|
|
34435
34516
|
});
|
|
34436
34517
|
};
|
|
34437
34518
|
const useTokensData = (tokens) => {
|
|
34438
|
-
return reactQuery.useQuery({
|
|
34439
|
-
queryKey: keys().tokensData(tokens),
|
|
34440
|
-
queryFn: () => fetchTokensData(tokens),
|
|
34519
|
+
return reactQuery.useQuery(keys().tokensData(tokens), () => fetchTokensData(tokens), {
|
|
34441
34520
|
staleTime: 60 * 1000,
|
|
34442
34521
|
enabled: !!tokens && tokens.length > 0,
|
|
34443
34522
|
});
|
|
@@ -34742,7 +34821,7 @@ function useSendTransactionGas({ chain, token, from, }) {
|
|
|
34742
34821
|
}
|
|
34743
34822
|
|
|
34744
34823
|
function useEstimateSendTransaction({ chain, token, amount, balance, from, }) {
|
|
34745
|
-
const { data: estimatedGas = BigInt(0),
|
|
34824
|
+
const { data: estimatedGas = BigInt(0), isLoading } = useSendTransactionGas({
|
|
34746
34825
|
chain,
|
|
34747
34826
|
token,
|
|
34748
34827
|
from,
|
|
@@ -34787,7 +34866,7 @@ function useEstimateSendTransaction({ chain, token, amount, balance, from, }) {
|
|
|
34787
34866
|
return {
|
|
34788
34867
|
estimatedGas,
|
|
34789
34868
|
isBalanceEnough,
|
|
34790
|
-
|
|
34869
|
+
isLoading,
|
|
34791
34870
|
isNativeBalanceEnoughToPayGasFees,
|
|
34792
34871
|
minAmountValueWarnMsg,
|
|
34793
34872
|
};
|
|
@@ -35194,12 +35273,10 @@ function useSendTransaction({ to, amount, token, chain, }) {
|
|
|
35194
35273
|
// amount is already formatted with the token decimals
|
|
35195
35274
|
amount,
|
|
35196
35275
|
toAddress: to,
|
|
35197
|
-
|
|
35198
|
-
|
|
35199
|
-
|
|
35200
|
-
|
|
35201
|
-
type: token.type,
|
|
35202
|
-
},
|
|
35276
|
+
tokenAddress: token.address,
|
|
35277
|
+
tokenChainId: token.chainId,
|
|
35278
|
+
tokenSymbol: token.symbol,
|
|
35279
|
+
tokenType: token.type,
|
|
35203
35280
|
});
|
|
35204
35281
|
}, [
|
|
35205
35282
|
allEventParamsDefined,
|
|
@@ -35219,12 +35296,10 @@ function useSendTransaction({ to, amount, token, chain, }) {
|
|
|
35219
35296
|
// amount is already formatted with the token decimals
|
|
35220
35297
|
amount,
|
|
35221
35298
|
toAddress: to,
|
|
35222
|
-
|
|
35223
|
-
|
|
35224
|
-
|
|
35225
|
-
|
|
35226
|
-
type: token.type,
|
|
35227
|
-
},
|
|
35299
|
+
tokenAddress: token.address,
|
|
35300
|
+
tokenChainId: token.chainId,
|
|
35301
|
+
tokenSymbol: token.symbol,
|
|
35302
|
+
tokenType: token.type,
|
|
35228
35303
|
txHash,
|
|
35229
35304
|
});
|
|
35230
35305
|
}, [
|
|
@@ -35370,9 +35445,7 @@ function useSendTransaction({ to, amount, token, chain, }) {
|
|
|
35370
35445
|
});
|
|
35371
35446
|
},
|
|
35372
35447
|
onSuccess: (tx, variables) => {
|
|
35373
|
-
queryClient.invalidateQueries(
|
|
35374
|
-
queryKey: getPrefixKey(QueryKeys.Balance),
|
|
35375
|
-
});
|
|
35448
|
+
queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balance));
|
|
35376
35449
|
setTransactionState(variables.id, tx);
|
|
35377
35450
|
persistTransaction({
|
|
35378
35451
|
txType: exports.HistoryTxType.SEND,
|
|
@@ -35699,10 +35772,9 @@ const useAllTransactionsStatus = ({ enabled }) => {
|
|
|
35699
35772
|
queryKey: keys().fiatToCryptoStatus(data.orderId),
|
|
35700
35773
|
retry: TX_STATUS_CONSTANTS.RETRY_COUNT,
|
|
35701
35774
|
retryDelay: TX_STATUS_CONSTANTS.RETRY_DELAY,
|
|
35702
|
-
refetchInterval: (
|
|
35703
|
-
|
|
35704
|
-
|
|
35705
|
-
FINAL_TRANSACTION_STATUSES.includes(state.data.status)) {
|
|
35775
|
+
refetchInterval: (data) => {
|
|
35776
|
+
if (data?.status &&
|
|
35777
|
+
FINAL_TRANSACTION_STATUSES.includes(data.status)) {
|
|
35706
35778
|
return false;
|
|
35707
35779
|
}
|
|
35708
35780
|
return TX_STATUS_CONSTANTS.REFETCH_INTERVAL;
|
|
@@ -35762,7 +35834,7 @@ const useAllTransactionsStatus = ({ enabled }) => {
|
|
|
35762
35834
|
queries: enabled && config.apiUrl ? statusQueries : [],
|
|
35763
35835
|
});
|
|
35764
35836
|
return {
|
|
35765
|
-
|
|
35837
|
+
isLoading: queries.some((q) => q.isLoading),
|
|
35766
35838
|
isError: queries.some((q) => q.isError),
|
|
35767
35839
|
data: queries.map((q) => q.data).filter(Boolean),
|
|
35768
35840
|
};
|
|
@@ -36021,18 +36093,16 @@ const useApproval = ({ squidRoute, }) => {
|
|
|
36021
36093
|
* On Error: Showing the error message if any
|
|
36022
36094
|
* @returns {boolean} approved
|
|
36023
36095
|
*/
|
|
36024
|
-
const routeApproved = reactQuery.useQuery({
|
|
36025
|
-
|
|
36026
|
-
|
|
36027
|
-
|
|
36028
|
-
|
|
36029
|
-
|
|
36030
|
-
|
|
36031
|
-
return true;
|
|
36032
|
-
},
|
|
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
|
+
}, {
|
|
36033
36103
|
enabled: !!squidRoute &&
|
|
36034
36104
|
!!sourceUserAddress &&
|
|
36035
|
-
!allowanceQuery?.
|
|
36105
|
+
!allowanceQuery?.isLoading &&
|
|
36036
36106
|
allowanceQuery?.isFetched,
|
|
36037
36107
|
});
|
|
36038
36108
|
// USDT has a very specific way of handling approvals
|
|
@@ -36121,84 +36191,81 @@ const useApproval = ({ squidRoute, }) => {
|
|
|
36121
36191
|
/**
|
|
36122
36192
|
* Manually approve route if necessary
|
|
36123
36193
|
*/
|
|
36124
|
-
const approveRoute = reactQuery.useMutation({
|
|
36125
|
-
|
|
36126
|
-
|
|
36127
|
-
|
|
36128
|
-
|
|
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) });
|
|
36129
36205
|
}
|
|
36130
|
-
|
|
36131
|
-
|
|
36132
|
-
|
|
36133
|
-
|
|
36134
|
-
|
|
36135
|
-
|
|
36136
|
-
|
|
36137
|
-
|
|
36138
|
-
|
|
36139
|
-
|
|
36140
|
-
|
|
36141
|
-
|
|
36142
|
-
|
|
36143
|
-
|
|
36144
|
-
|
|
36145
|
-
|
|
36146
|
-
|
|
36147
|
-
|
|
36148
|
-
|
|
36149
|
-
|
|
36150
|
-
|
|
36151
|
-
|
|
36152
|
-
|
|
36153
|
-
denom: squidRoute.estimate.actions[0].fromToken
|
|
36154
|
-
.originalAddress,
|
|
36155
|
-
amount: squidRoute.params.fromAmount,
|
|
36156
|
-
},
|
|
36157
|
-
],
|
|
36158
|
-
allowList: [],
|
|
36159
|
-
allowedPacketData: ["*"],
|
|
36160
|
-
},
|
|
36161
|
-
],
|
|
36162
|
-
]);
|
|
36163
|
-
approveTx = await evmSigner.sendTransaction({
|
|
36164
|
-
to: squidRoute.transactionRequest.target,
|
|
36165
|
-
data: approveData,
|
|
36166
|
-
value: "0",
|
|
36167
|
-
gasLimit: squidRoute.transactionRequest
|
|
36168
|
-
.gasLimit,
|
|
36169
|
-
gasPrice: squidRoute.transactionRequest
|
|
36170
|
-
.gasPrice,
|
|
36171
|
-
});
|
|
36172
|
-
}
|
|
36173
|
-
else {
|
|
36174
|
-
approveTx = await squid.approveRoute({
|
|
36175
|
-
route: squidRoute,
|
|
36176
|
-
signer: evmSigner,
|
|
36177
|
-
// For security reasons, we don't want to allow infinite approvals in our frontends
|
|
36178
|
-
executionSettings: {
|
|
36179
|
-
infiniteApproval: false,
|
|
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: ["*"],
|
|
36180
36229
|
},
|
|
36181
|
-
|
|
36182
|
-
|
|
36183
|
-
|
|
36184
|
-
|
|
36185
|
-
|
|
36186
|
-
|
|
36187
|
-
|
|
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
|
+
});
|
|
36188
36241
|
}
|
|
36189
|
-
|
|
36190
|
-
|
|
36191
|
-
|
|
36192
|
-
|
|
36193
|
-
|
|
36194
|
-
|
|
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;
|
|
36195
36257
|
}
|
|
36196
|
-
|
|
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
|
+
}, {
|
|
36197
36266
|
onSuccess: async () => {
|
|
36198
36267
|
await allowanceQuery?.refetch();
|
|
36199
|
-
queryClient.invalidateQueries(
|
|
36200
|
-
queryKey: getPrefixKey(QueryKeys.RouteApproved),
|
|
36201
|
-
});
|
|
36268
|
+
queryClient.invalidateQueries(getPrefixKey(QueryKeys.RouteApproved));
|
|
36202
36269
|
// After an approval, we refetch the transaction query with all required parameters
|
|
36203
36270
|
// This is to ensure we're using the latest expiry timestamp
|
|
36204
36271
|
if (squidRoute) {
|
|
@@ -39318,10 +39385,8 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
39318
39385
|
}
|
|
39319
39386
|
}, [cosmosSigner, fromChain]);
|
|
39320
39387
|
const resetQueriesAfterTxSigned = () => {
|
|
39321
|
-
queryClient.refetchQueries(
|
|
39322
|
-
queryClient.invalidateQueries(
|
|
39323
|
-
queryKey: getPrefixKey(QueryKeys.Transaction),
|
|
39324
|
-
});
|
|
39388
|
+
queryClient.refetchQueries(getPrefixKey(QueryKeys.Balance));
|
|
39389
|
+
queryClient.invalidateQueries(getPrefixKey(QueryKeys.Transaction));
|
|
39325
39390
|
};
|
|
39326
39391
|
const dispatchSignatureRequestEvent = React.useCallback((route) => {
|
|
39327
39392
|
WidgetEvents.getInstance().dispatchSwapTxSignatureRequested({
|
|
@@ -39339,64 +39404,62 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
39339
39404
|
txHash,
|
|
39340
39405
|
}, findToken);
|
|
39341
39406
|
}, [findToken]);
|
|
39342
|
-
const swapMutationCosmos = reactQuery.useMutation({
|
|
39343
|
-
|
|
39344
|
-
|
|
39345
|
-
|
|
39346
|
-
|
|
39347
|
-
|
|
39348
|
-
|
|
39349
|
-
|
|
39350
|
-
|
|
39351
|
-
|
|
39352
|
-
|
|
39353
|
-
|
|
39354
|
-
|
|
39355
|
-
|
|
39356
|
-
|
|
39357
|
-
|
|
39358
|
-
|
|
39359
|
-
|
|
39360
|
-
|
|
39361
|
-
|
|
39362
|
-
|
|
39363
|
-
|
|
39364
|
-
|
|
39365
|
-
|
|
39366
|
-
|
|
39367
|
-
|
|
39368
|
-
|
|
39369
|
-
|
|
39370
|
-
|
|
39371
|
-
|
|
39372
|
-
|
|
39373
|
-
|
|
39374
|
-
|
|
39375
|
-
|
|
39376
|
-
|
|
39377
|
-
|
|
39378
|
-
|
|
39379
|
-
|
|
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,
|
|
39380
39450
|
});
|
|
39381
|
-
if (txParams) {
|
|
39382
|
-
addSwapTransaction({
|
|
39383
|
-
...txParams,
|
|
39384
|
-
params: route.params,
|
|
39385
|
-
estimate: route.estimate,
|
|
39386
|
-
});
|
|
39387
|
-
}
|
|
39388
|
-
return response.code === 0;
|
|
39389
39451
|
}
|
|
39452
|
+
return response.code === 0;
|
|
39390
39453
|
}
|
|
39391
|
-
|
|
39392
|
-
|
|
39393
|
-
|
|
39394
|
-
|
|
39395
|
-
|
|
39454
|
+
}
|
|
39455
|
+
catch (error) {
|
|
39456
|
+
console.error("Error executing Cosmos transaction", error);
|
|
39457
|
+
if (isUserRejectionError(normalizeError(error))) {
|
|
39458
|
+
throw new Error("Request rejected");
|
|
39396
39459
|
}
|
|
39397
39460
|
}
|
|
39398
|
-
|
|
39399
|
-
|
|
39461
|
+
}
|
|
39462
|
+
throw new Error("Need all parameters");
|
|
39400
39463
|
});
|
|
39401
39464
|
// If the transaction is replaced, we need to update the transaction hash
|
|
39402
39465
|
// Transaction replaced can mean that the user has speed up the transaction for example
|
|
@@ -39449,126 +39512,97 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
39449
39512
|
throw error;
|
|
39450
39513
|
}
|
|
39451
39514
|
}, [replaceSwapTransactionNonce, setTransactionState, sourceUserAddress]);
|
|
39452
|
-
const swapMutationEvm = reactQuery.useMutation({
|
|
39453
|
-
|
|
39454
|
-
|
|
39455
|
-
|
|
39456
|
-
|
|
39457
|
-
|
|
39458
|
-
|
|
39459
|
-
|
|
39460
|
-
|
|
39461
|
-
|
|
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({
|
|
39462
39537
|
route,
|
|
39463
|
-
|
|
39464
|
-
|
|
39465
|
-
|
|
39466
|
-
|
|
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
|
+
});
|
|
39467
39552
|
}
|
|
39468
|
-
|
|
39469
|
-
|
|
39553
|
+
}
|
|
39554
|
+
try {
|
|
39555
|
+
if (isProblematicConnector(activeConnector)) {
|
|
39556
|
+
await sleep(3_000);
|
|
39470
39557
|
}
|
|
39471
|
-
|
|
39472
|
-
|
|
39473
|
-
|
|
39474
|
-
|
|
39475
|
-
|
|
39476
|
-
|
|
39477
|
-
|
|
39478
|
-
|
|
39479
|
-
|
|
39480
|
-
|
|
39481
|
-
|
|
39482
|
-
|
|
39483
|
-
|
|
39484
|
-
|
|
39485
|
-
|
|
39486
|
-
|
|
39487
|
-
|
|
39488
|
-
|
|
39489
|
-
|
|
39490
|
-
}
|
|
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");
|
|
39491
39577
|
}
|
|
39492
|
-
|
|
39493
|
-
|
|
39494
|
-
await sleep(3_000);
|
|
39495
|
-
}
|
|
39496
|
-
const response = await txResponse.wait();
|
|
39497
|
-
return response;
|
|
39578
|
+
if (!solanaSigner) {
|
|
39579
|
+
throw new Error("Solana signer is required");
|
|
39498
39580
|
}
|
|
39499
|
-
|
|
39500
|
-
|
|
39501
|
-
error,
|
|
39502
|
-
route,
|
|
39503
|
-
status: exports.TransactionStatus.INITIAL_LOADING,
|
|
39504
|
-
sourceStatus: exports.TransactionStatus.ONGOING,
|
|
39505
|
-
userAddress: sourceUserAddress,
|
|
39506
|
-
axelarUrl: undefined,
|
|
39507
|
-
id,
|
|
39508
|
-
});
|
|
39581
|
+
if (!route.params.fromAddress || !route.params.toAddress) {
|
|
39582
|
+
throw new Error("From or to address is required");
|
|
39509
39583
|
}
|
|
39510
|
-
|
|
39511
|
-
|
|
39512
|
-
|
|
39513
|
-
|
|
39514
|
-
|
|
39515
|
-
|
|
39516
|
-
|
|
39517
|
-
|
|
39518
|
-
|
|
39519
|
-
throw new Error("Solana signer is required");
|
|
39520
|
-
}
|
|
39521
|
-
if (!route.params.fromAddress || !route.params.toAddress) {
|
|
39522
|
-
throw new Error("From or to address is required");
|
|
39523
|
-
}
|
|
39524
|
-
const isDirectTransfer = isDepositRoute(route);
|
|
39525
|
-
// Means it's a transfer to a deposit address
|
|
39526
|
-
// Instead of a Swap/Contract call using a DEX like Jupiter
|
|
39527
|
-
if (isDirectTransfer) {
|
|
39528
|
-
// Get the deposit address from the squidRoute
|
|
39529
|
-
const depositData = useDepositAddressStore.getState().deposit;
|
|
39530
|
-
// Validate params
|
|
39531
|
-
if (!depositData?.depositAddress) {
|
|
39532
|
-
throw new Error("Deposit address is required");
|
|
39533
|
-
}
|
|
39534
|
-
const signature = await executeSolanaTransfer({
|
|
39535
|
-
amount: BigInt(route.params.fromAmount),
|
|
39536
|
-
target: depositData.depositAddress,
|
|
39537
|
-
signer: solanaSigner,
|
|
39538
|
-
connection: solanaConnection,
|
|
39539
|
-
sourceToken: findToken(route.params.fromToken, route?.params?.fromChain),
|
|
39540
|
-
onSigned: (txHash) => {
|
|
39541
|
-
WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
|
|
39542
|
-
const txParams = setTransactionState({
|
|
39543
|
-
route,
|
|
39544
|
-
txHash,
|
|
39545
|
-
transactionIdForStatus: depositData.chainflipStatusTrackingId,
|
|
39546
|
-
userAddress: sourceUserAddress,
|
|
39547
|
-
status: exports.TransactionStatus.INITIAL_LOADING,
|
|
39548
|
-
sourceStatus: exports.TransactionStatus.ONGOING,
|
|
39549
|
-
id,
|
|
39550
|
-
});
|
|
39551
|
-
if (txParams) {
|
|
39552
|
-
addSwapTransaction({
|
|
39553
|
-
...txParams,
|
|
39554
|
-
params: route.params,
|
|
39555
|
-
estimate: route.estimate,
|
|
39556
|
-
});
|
|
39557
|
-
}
|
|
39558
|
-
},
|
|
39559
|
-
});
|
|
39560
|
-
return signature;
|
|
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");
|
|
39561
39593
|
}
|
|
39562
|
-
const signature = await
|
|
39563
|
-
route,
|
|
39594
|
+
const signature = await executeSolanaTransfer({
|
|
39595
|
+
amount: BigInt(route.params.fromAmount),
|
|
39596
|
+
target: depositData.depositAddress,
|
|
39564
39597
|
signer: solanaSigner,
|
|
39565
39598
|
connection: solanaConnection,
|
|
39599
|
+
sourceToken: findToken(route.params.fromToken, route?.params?.fromChain),
|
|
39566
39600
|
onSigned: (txHash) => {
|
|
39567
39601
|
WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
|
|
39568
39602
|
const txParams = setTransactionState({
|
|
39569
39603
|
route,
|
|
39570
39604
|
txHash,
|
|
39571
|
-
transactionIdForStatus:
|
|
39605
|
+
transactionIdForStatus: depositData.chainflipStatusTrackingId,
|
|
39572
39606
|
userAddress: sourceUserAddress,
|
|
39573
39607
|
status: exports.TransactionStatus.INITIAL_LOADING,
|
|
39574
39608
|
sourceStatus: exports.TransactionStatus.ONGOING,
|
|
@@ -39585,13 +39619,39 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
39585
39619
|
});
|
|
39586
39620
|
return signature;
|
|
39587
39621
|
}
|
|
39588
|
-
|
|
39589
|
-
|
|
39590
|
-
|
|
39591
|
-
|
|
39592
|
-
|
|
39593
|
-
|
|
39594
|
-
|
|
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
|
+
}, {
|
|
39595
39655
|
onError: (error, variables) => {
|
|
39596
39656
|
const currentTx = getTransaction(variables.id);
|
|
39597
39657
|
const errorObject = getTransactionError(error);
|
|
@@ -39612,9 +39672,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
39612
39672
|
},
|
|
39613
39673
|
onSuccess: (_data, variables) => {
|
|
39614
39674
|
const currentTx = getTransaction(variables.id);
|
|
39615
|
-
queryClient.invalidateQueries(
|
|
39616
|
-
queryKey: getPrefixKey(QueryKeys.Balances),
|
|
39617
|
-
});
|
|
39675
|
+
queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balances));
|
|
39618
39676
|
if (isSameChain && currentTx?.transactionId) {
|
|
39619
39677
|
replaceSwapTransactionStatus({
|
|
39620
39678
|
transactionId: currentTx.transactionId,
|
|
@@ -39631,207 +39689,197 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
39631
39689
|
});
|
|
39632
39690
|
},
|
|
39633
39691
|
});
|
|
39634
|
-
const swapMutationBitcoin = reactQuery.useMutation({
|
|
39635
|
-
|
|
39636
|
-
|
|
39637
|
-
|
|
39638
|
-
|
|
39639
|
-
|
|
39640
|
-
|
|
39641
|
-
|
|
39642
|
-
|
|
39643
|
-
|
|
39644
|
-
|
|
39645
|
-
|
|
39646
|
-
|
|
39647
|
-
const { txHash } = await bitcoinSigner.sendBTC(depositAddress, Number(sendAmount));
|
|
39648
|
-
if (txHash) {
|
|
39649
|
-
resetQueriesAfterTxSigned();
|
|
39650
|
-
}
|
|
39651
|
-
// Dispatch event so it can be listened from outside the widget
|
|
39652
|
-
WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
|
|
39653
|
-
if (route.transactionRequest) {
|
|
39654
|
-
const txParams = setTransactionState({
|
|
39655
|
-
route,
|
|
39656
|
-
txHash,
|
|
39657
|
-
// When bridging from Bitcoin we need to send the chainflipId to the status endpoint
|
|
39658
|
-
// instead of the Bitcoin transaction hash
|
|
39659
|
-
transactionIdForStatus: chainflipStatusTrackingId,
|
|
39660
|
-
userAddress: sourceUserAddress,
|
|
39661
|
-
status: exports.TransactionStatus.INITIAL_LOADING,
|
|
39662
|
-
sourceStatus: exports.TransactionStatus.ONGOING,
|
|
39663
|
-
axelarUrl: undefined,
|
|
39664
|
-
id,
|
|
39665
|
-
});
|
|
39666
|
-
if (txParams) {
|
|
39667
|
-
addSwapTransaction({
|
|
39668
|
-
...txParams,
|
|
39669
|
-
params: route.params,
|
|
39670
|
-
estimate: route.estimate,
|
|
39671
|
-
});
|
|
39672
|
-
}
|
|
39673
|
-
}
|
|
39674
|
-
}
|
|
39675
|
-
else {
|
|
39676
|
-
throw new Error("Need all parameters");
|
|
39677
|
-
}
|
|
39678
|
-
},
|
|
39679
|
-
});
|
|
39680
|
-
const swapMutationXrpl = reactQuery.useMutation({
|
|
39681
|
-
mutationFn: async ({ id, route }) => {
|
|
39682
|
-
if (!route?.transactionRequest || !xrplSigner) {
|
|
39683
|
-
throw new Error("Need all parameters");
|
|
39684
|
-
}
|
|
39685
|
-
if (route.transactionRequest.type !== squidTypes.SquidDataType.OnChainExecution) {
|
|
39686
|
-
throw new Error("Invalid route type");
|
|
39687
|
-
}
|
|
39688
|
-
const { data } = route.transactionRequest;
|
|
39689
|
-
const paymentTx = parseXrplPaymentTx(data);
|
|
39690
|
-
if (!paymentTx)
|
|
39691
|
-
throw new Error("Could not parse transaction");
|
|
39692
|
-
const fromChainId = route.params.fromChain;
|
|
39693
|
-
const xrplNetwork = getXrplNetwork(fromChainId);
|
|
39694
|
-
if (xrplNetwork == null) {
|
|
39695
|
-
throw new Error(`No XRPL network found for chainId '${fromChainId}'`);
|
|
39696
|
-
}
|
|
39697
|
-
const txRes = await xrplSigner.signAndSubmit({
|
|
39698
|
-
tx: paymentTx,
|
|
39699
|
-
network: xrplNetwork,
|
|
39700
|
-
});
|
|
39701
|
-
const txParams = setTransactionState({
|
|
39702
|
-
txHash: txRes.hash,
|
|
39703
|
-
id,
|
|
39704
|
-
sourceStatus: exports.TransactionStatus.ONGOING,
|
|
39705
|
-
status: exports.TransactionStatus.ONGOING,
|
|
39706
|
-
route: route,
|
|
39707
|
-
userAddress: sourceUserAddress,
|
|
39708
|
-
});
|
|
39709
|
-
if (txParams && route) {
|
|
39710
|
-
addSwapTransaction({
|
|
39711
|
-
...txParams,
|
|
39712
|
-
params: route.params,
|
|
39713
|
-
estimate: route.estimate,
|
|
39714
|
-
});
|
|
39715
|
-
}
|
|
39716
|
-
if (txRes.status !== XrplTxStatus.SUCCESS) {
|
|
39717
|
-
throw new Error(`Transaction failed with status: ${txRes.status}`);
|
|
39718
|
-
}
|
|
39719
|
-
},
|
|
39720
|
-
});
|
|
39721
|
-
const swapMutationSui = reactQuery.useMutation({
|
|
39722
|
-
mutationFn: async ({ id, route }) => {
|
|
39723
|
-
if (!route || !suiSigner || !fromChain) {
|
|
39724
|
-
throw new Error("Need all parameters");
|
|
39725
|
-
}
|
|
39726
|
-
if (route.transactionRequest?.type !== squidTypes.SquidDataType.OnChainExecution) {
|
|
39727
|
-
throw new Error("Invalid route type");
|
|
39728
|
-
}
|
|
39729
|
-
const suiWalletState = connectedWalletsByChainType[squidTypes.ChainType.SUI];
|
|
39730
|
-
if (!suiWalletState.account) {
|
|
39731
|
-
throw new Error("Sui wallet is missing account data");
|
|
39732
|
-
}
|
|
39733
|
-
const fromChainId = route.params.fromChain;
|
|
39734
|
-
const suiChain = getSuiChain(fromChainId);
|
|
39735
|
-
if (!suiChain) {
|
|
39736
|
-
throw new Error(`Source chain (${fromChainId}) does not match any Sui chain`);
|
|
39737
|
-
}
|
|
39738
|
-
const suiClient = await getClient(fromChain);
|
|
39739
|
-
const txJson = route.transactionRequest.data;
|
|
39740
|
-
const tx = transactions.Transaction.from(txJson);
|
|
39741
|
-
const signedTx = await suiSigner.signTransaction({
|
|
39742
|
-
transaction: tx,
|
|
39743
|
-
account: suiWalletState.account,
|
|
39744
|
-
chain: suiChain,
|
|
39745
|
-
});
|
|
39746
|
-
// execute transaction without waiting for confirmation
|
|
39747
|
-
const txResponse = await suiClient.executeTransactionBlock({
|
|
39748
|
-
signature: signedTx.signature,
|
|
39749
|
-
transactionBlock: signedTx.bytes,
|
|
39750
|
-
});
|
|
39751
|
-
const txHash = txResponse.digest;
|
|
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));
|
|
39752
39705
|
if (txHash) {
|
|
39753
39706
|
resetQueriesAfterTxSigned();
|
|
39754
39707
|
}
|
|
39708
|
+
// Dispatch event so it can be listened from outside the widget
|
|
39755
39709
|
WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
|
|
39756
|
-
|
|
39757
|
-
|
|
39758
|
-
|
|
39759
|
-
|
|
39760
|
-
|
|
39761
|
-
|
|
39762
|
-
|
|
39763
|
-
|
|
39764
|
-
|
|
39765
|
-
|
|
39766
|
-
|
|
39767
|
-
|
|
39768
|
-
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,
|
|
39769
39722
|
});
|
|
39723
|
+
if (txParams) {
|
|
39724
|
+
addSwapTransaction({
|
|
39725
|
+
...txParams,
|
|
39726
|
+
params: route.params,
|
|
39727
|
+
estimate: route.estimate,
|
|
39728
|
+
});
|
|
39729
|
+
}
|
|
39770
39730
|
}
|
|
39771
|
-
|
|
39772
|
-
|
|
39773
|
-
|
|
39774
|
-
|
|
39775
|
-
},
|
|
39731
|
+
}
|
|
39732
|
+
else {
|
|
39733
|
+
throw new Error("Need all parameters");
|
|
39734
|
+
}
|
|
39776
39735
|
});
|
|
39777
|
-
const
|
|
39778
|
-
|
|
39779
|
-
|
|
39780
|
-
|
|
39781
|
-
|
|
39782
|
-
|
|
39783
|
-
|
|
39784
|
-
|
|
39785
|
-
|
|
39786
|
-
|
|
39787
|
-
|
|
39788
|
-
|
|
39789
|
-
|
|
39790
|
-
|
|
39791
|
-
|
|
39792
|
-
|
|
39793
|
-
|
|
39794
|
-
|
|
39795
|
-
|
|
39796
|
-
|
|
39797
|
-
|
|
39798
|
-
|
|
39799
|
-
|
|
39800
|
-
|
|
39801
|
-
|
|
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,
|
|
39802
39769
|
});
|
|
39803
|
-
|
|
39804
|
-
|
|
39805
|
-
|
|
39806
|
-
|
|
39807
|
-
|
|
39808
|
-
|
|
39809
|
-
|
|
39810
|
-
|
|
39811
|
-
|
|
39812
|
-
|
|
39813
|
-
|
|
39814
|
-
|
|
39815
|
-
|
|
39816
|
-
|
|
39817
|
-
|
|
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,
|
|
39818
39822
|
});
|
|
39819
|
-
|
|
39820
|
-
|
|
39821
|
-
|
|
39822
|
-
|
|
39823
|
-
|
|
39824
|
-
|
|
39825
|
-
|
|
39826
|
-
|
|
39827
|
-
|
|
39828
|
-
}
|
|
39829
|
-
|
|
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
|
+
}, {});
|
|
39830
39880
|
const handleTransactionSuccess = React.useCallback((id) => {
|
|
39831
39881
|
const currentTx = getTransaction(id);
|
|
39832
|
-
queryClient.invalidateQueries(
|
|
39833
|
-
queryKey: getPrefixKey(QueryKeys.Balances),
|
|
39834
|
-
});
|
|
39882
|
+
queryClient.invalidateQueries(getPrefixKey(QueryKeys.Balances));
|
|
39835
39883
|
if (isSameChain && currentTx?.transactionId) {
|
|
39836
39884
|
replaceSwapTransactionStatus({
|
|
39837
39885
|
transactionId: currentTx.transactionId,
|
|
@@ -39883,39 +39931,38 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
39883
39931
|
setTransactionStoreState,
|
|
39884
39932
|
squidRoute,
|
|
39885
39933
|
]);
|
|
39886
|
-
const swapMutation = reactQuery.useMutation({
|
|
39887
|
-
|
|
39888
|
-
|
|
39889
|
-
|
|
39890
|
-
|
|
39891
|
-
|
|
39892
|
-
|
|
39893
|
-
|
|
39894
|
-
|
|
39895
|
-
return swapMutationCosmos.mutateAsync(mutationParams);
|
|
39896
|
-
}
|
|
39897
|
-
case squidTypes.ChainType.EVM: {
|
|
39898
|
-
return swapMutationEvm.mutateAsync(mutationParams);
|
|
39899
|
-
}
|
|
39900
|
-
case squidTypes.ChainType.BTC: {
|
|
39901
|
-
return swapMutationBitcoin.mutateAsync(mutationParams);
|
|
39902
|
-
}
|
|
39903
|
-
case squidTypes.ChainType.SOLANA: {
|
|
39904
|
-
return swapMutationSolana.mutateAsync(mutationParams);
|
|
39905
|
-
}
|
|
39906
|
-
case squidTypes.ChainType.SUI: {
|
|
39907
|
-
return swapMutationSui.mutateAsync(mutationParams);
|
|
39908
|
-
}
|
|
39909
|
-
case squidTypes.ChainType.XRPL: {
|
|
39910
|
-
return swapMutationXrpl.mutateAsync(mutationParams);
|
|
39911
|
-
}
|
|
39912
|
-
case squidTypes.ChainType.STELLAR: {
|
|
39913
|
-
return swapMutationStellar.mutateAsync(mutationParams);
|
|
39914
|
-
}
|
|
39915
|
-
default:
|
|
39916
|
-
throw new Error(`Swap mutation not implemented for chain type: ${sourceChain.chainType}`);
|
|
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);
|
|
39917
39943
|
}
|
|
39918
|
-
|
|
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
|
+
}, {
|
|
39919
39966
|
onMutate: (variables) => {
|
|
39920
39967
|
useTransactionStore.setState({
|
|
39921
39968
|
txLocalId: variables.id,
|
|
@@ -39964,7 +40011,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
39964
40011
|
toToken,
|
|
39965
40012
|
toChain,
|
|
39966
40013
|
fromChain,
|
|
39967
|
-
|
|
40014
|
+
isLoading: swapMutation.isLoading,
|
|
39968
40015
|
error: swapMutation.error,
|
|
39969
40016
|
};
|
|
39970
40017
|
};
|
|
@@ -40025,59 +40072,57 @@ const useGetRoute = () => {
|
|
|
40025
40072
|
* These data will be used to trigger the transaction
|
|
40026
40073
|
* @returns {Route} Route data
|
|
40027
40074
|
*/
|
|
40028
|
-
return reactQuery.useMutation({
|
|
40029
|
-
|
|
40030
|
-
|
|
40031
|
-
|
|
40032
|
-
|
|
40033
|
-
|
|
40034
|
-
|
|
40035
|
-
|
|
40036
|
-
|
|
40037
|
-
|
|
40038
|
-
|
|
40039
|
-
|
|
40040
|
-
|
|
40041
|
-
|
|
40042
|
-
|
|
40043
|
-
|
|
40044
|
-
|
|
40045
|
-
|
|
40046
|
-
|
|
40047
|
-
|
|
40048
|
-
|
|
40049
|
-
|
|
40050
|
-
|
|
40051
|
-
|
|
40052
|
-
|
|
40053
|
-
|
|
40054
|
-
|
|
40055
|
-
|
|
40056
|
-
|
|
40057
|
-
|
|
40058
|
-
|
|
40059
|
-
|
|
40060
|
-
|
|
40061
|
-
|
|
40062
|
-
|
|
40063
|
-
|
|
40064
|
-
|
|
40065
|
-
|
|
40066
|
-
|
|
40067
|
-
|
|
40068
|
-
|
|
40069
|
-
|
|
40070
|
-
|
|
40071
|
-
|
|
40072
|
-
|
|
40073
|
-
|
|
40074
|
-
|
|
40075
|
-
|
|
40076
|
-
return route;
|
|
40077
|
-
},
|
|
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;
|
|
40078
40123
|
});
|
|
40079
40124
|
};
|
|
40080
|
-
const useGetRouteWrapper = ({ enabled,
|
|
40125
|
+
const useGetRouteWrapper = ({ enabled, cacheTime = 5 * 60 * 1000, // 5 minutes
|
|
40081
40126
|
staleTime = 60 * 1000, // 1 minute
|
|
40082
40127
|
refetchOnWindowFocus = (query) => Date.now() - query.state.dataUpdatedAt > 30000, // Update if older than 30 seconds, when window is focused
|
|
40083
40128
|
refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true, }) => {
|
|
@@ -40127,27 +40172,25 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
|
|
|
40127
40172
|
* These data will be used to trigger the transaction
|
|
40128
40173
|
* @returns {Route} Route data
|
|
40129
40174
|
*/
|
|
40130
|
-
const squidRoute = reactQuery.useQuery({
|
|
40131
|
-
|
|
40132
|
-
|
|
40133
|
-
|
|
40134
|
-
|
|
40135
|
-
|
|
40136
|
-
|
|
40137
|
-
|
|
40138
|
-
|
|
40139
|
-
|
|
40140
|
-
|
|
40141
|
-
|
|
40142
|
-
|
|
40143
|
-
|
|
40144
|
-
|
|
40145
|
-
|
|
40146
|
-
|
|
40147
|
-
return route;
|
|
40148
|
-
},
|
|
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
|
+
}, {
|
|
40149
40192
|
enabled: queryEnabled,
|
|
40150
|
-
|
|
40193
|
+
cacheTime,
|
|
40151
40194
|
staleTime,
|
|
40152
40195
|
refetchOnWindowFocus,
|
|
40153
40196
|
refetchIntervalInBackground,
|
|
@@ -40156,7 +40199,7 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
|
|
|
40156
40199
|
/**
|
|
40157
40200
|
* If last updated data is older than X seconds and the query is currently loading, show loading indicator
|
|
40158
40201
|
*/
|
|
40159
|
-
const showLoading = squidRoute.isFetching || squidRoute.isRefetching;
|
|
40202
|
+
const showLoading = React.useMemo(() => squidRoute.isFetching || squidRoute.isRefetching, [squidRoute.isFetching, squidRoute.isRefetching]);
|
|
40160
40203
|
return {
|
|
40161
40204
|
squidRoute,
|
|
40162
40205
|
showLoading,
|
|
@@ -40188,7 +40231,7 @@ function useSendTransactionStatus({ chain, txHash, }) {
|
|
|
40188
40231
|
transactionId: txHash,
|
|
40189
40232
|
txType: exports.HistoryTxType.SEND,
|
|
40190
40233
|
});
|
|
40191
|
-
const { data: status
|
|
40234
|
+
const { data: status } = reactQuery.useQuery({
|
|
40192
40235
|
queryKey: keys().sendTransactionStatus(txHash, chain?.chainId),
|
|
40193
40236
|
queryFn: async () => {
|
|
40194
40237
|
if (!chain || !txHash)
|
|
@@ -40198,30 +40241,17 @@ function useSendTransactionStatus({ chain, txHash, }) {
|
|
|
40198
40241
|
txHash,
|
|
40199
40242
|
});
|
|
40200
40243
|
},
|
|
40201
|
-
|
|
40202
|
-
|
|
40203
|
-
|
|
40204
|
-
enabled: !!chain &&
|
|
40205
|
-
!!txHash &&
|
|
40206
|
-
!isTransactionComplete &&
|
|
40207
|
-
!!currentHistoryItem &&
|
|
40208
|
-
!isHistoryTransactionEnded({
|
|
40209
|
-
data: currentHistoryItem?.data,
|
|
40210
|
-
txType: exports.HistoryTxType.SEND,
|
|
40211
|
-
}),
|
|
40212
|
-
});
|
|
40213
|
-
React.useEffect(() => {
|
|
40214
|
-
if (isSuccess) {
|
|
40215
|
-
setIsTransactionComplete(status !== exports.SendTransactionStatus.ONGOING);
|
|
40216
|
-
if (status != null && !!txHash) {
|
|
40244
|
+
onSuccess: (txStatus) => {
|
|
40245
|
+
setIsTransactionComplete(txStatus !== exports.SendTransactionStatus.ONGOING);
|
|
40246
|
+
if (txStatus != null && !!txHash) {
|
|
40217
40247
|
replaceTransactionStatus({
|
|
40218
40248
|
txType: exports.HistoryTxType.SEND,
|
|
40219
|
-
status:
|
|
40249
|
+
status: txStatus,
|
|
40220
40250
|
hash: txHash,
|
|
40221
40251
|
});
|
|
40222
40252
|
}
|
|
40223
|
-
}
|
|
40224
|
-
|
|
40253
|
+
},
|
|
40254
|
+
onError() {
|
|
40225
40255
|
setIsTransactionComplete(true);
|
|
40226
40256
|
if (txHash) {
|
|
40227
40257
|
replaceTransactionStatus({
|
|
@@ -40230,8 +40260,19 @@ function useSendTransactionStatus({ chain, txHash, }) {
|
|
|
40230
40260
|
hash: txHash,
|
|
40231
40261
|
});
|
|
40232
40262
|
}
|
|
40233
|
-
}
|
|
40234
|
-
|
|
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
|
+
});
|
|
40235
40276
|
return {
|
|
40236
40277
|
status: status ?? currentHistoryItem?.data?.status,
|
|
40237
40278
|
};
|
|
@@ -40265,9 +40306,7 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
|
|
|
40265
40306
|
apiUrl: latestConfig.apiUrl,
|
|
40266
40307
|
});
|
|
40267
40308
|
}, [transaction]);
|
|
40268
|
-
const transactionStatusQuery = reactQuery.useQuery({
|
|
40269
|
-
queryKey: keys().swapTransactionStatus(transaction?.transactionId),
|
|
40270
|
-
queryFn: fetchTransactionStatusWithLatestConfig,
|
|
40309
|
+
const transactionStatusQuery = reactQuery.useQuery(keys().swapTransactionStatus(transaction?.transactionId), fetchTransactionStatusWithLatestConfig, {
|
|
40271
40310
|
enabled: enabled &&
|
|
40272
40311
|
transaction?.transactionId !== "0" &&
|
|
40273
40312
|
!!transaction?.transactionId &&
|
|
@@ -40281,12 +40320,12 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
|
|
|
40281
40320
|
data: currentHistoryItem?.data,
|
|
40282
40321
|
txType: exports.HistoryTxType.SWAP,
|
|
40283
40322
|
}),
|
|
40284
|
-
refetchInterval(
|
|
40323
|
+
refetchInterval(statusResponse) {
|
|
40285
40324
|
// If the status response is something telling that the transaction
|
|
40286
40325
|
// is finished, then store transaction history state if success
|
|
40287
40326
|
// And return false to indicate refetcher to stop
|
|
40288
|
-
if (
|
|
40289
|
-
transactionEndStatuses.includes(getTransactionStatus(
|
|
40327
|
+
if (statusResponse &&
|
|
40328
|
+
transactionEndStatuses.includes(getTransactionStatus(statusResponse) ?? "")) {
|
|
40290
40329
|
return false;
|
|
40291
40330
|
}
|
|
40292
40331
|
return refetchInterval; // Had to handle a variable here because after onError, we want the interval to stop
|
|
@@ -40295,10 +40334,7 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
|
|
|
40295
40334
|
retryDelay: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 5000 : 3000,
|
|
40296
40335
|
retry: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 6 : retry,
|
|
40297
40336
|
refetchOnWindowFocus,
|
|
40298
|
-
|
|
40299
|
-
React.useEffect(() => {
|
|
40300
|
-
if (transactionStatusQuery.isSuccess && transactionStatusQuery.data) {
|
|
40301
|
-
const statusResponse = transactionStatusQuery.data;
|
|
40337
|
+
onSuccess: (statusResponse) => {
|
|
40302
40338
|
// Dispatch event
|
|
40303
40339
|
WidgetEvents.getInstance().dispatchSwapStatus(statusResponse.squidTransactionStatus ?? "");
|
|
40304
40340
|
const endStatus = getTransactionEndStatus({ statusResponse });
|
|
@@ -40310,9 +40346,8 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
|
|
|
40310
40346
|
status: endStatus,
|
|
40311
40347
|
});
|
|
40312
40348
|
}
|
|
40313
|
-
}
|
|
40314
|
-
|
|
40315
|
-
const error = transactionStatusQuery.error;
|
|
40349
|
+
},
|
|
40350
|
+
onError: (error) => {
|
|
40316
40351
|
// `fetchTransactionStatus` throws an error with a cause being an AxiosError
|
|
40317
40352
|
const is404 = is404Error(error.cause);
|
|
40318
40353
|
if (!transaction?.transactionId)
|
|
@@ -40333,15 +40368,8 @@ const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocu
|
|
|
40333
40368
|
status: exports.TransactionStatus.ERROR,
|
|
40334
40369
|
});
|
|
40335
40370
|
}
|
|
40336
|
-
}
|
|
40337
|
-
}
|
|
40338
|
-
transactionStatusQuery.isSuccess,
|
|
40339
|
-
transactionStatusQuery.isError,
|
|
40340
|
-
transaction?.transactionId,
|
|
40341
|
-
transactionStatusQuery.error,
|
|
40342
|
-
replaceSwapTransactionStatus,
|
|
40343
|
-
transactionStatusQuery.data,
|
|
40344
|
-
]);
|
|
40371
|
+
},
|
|
40372
|
+
});
|
|
40345
40373
|
return {
|
|
40346
40374
|
transactionStatusQuery,
|
|
40347
40375
|
latestStatus: transactionStatusQuery.data
|
|
@@ -40384,7 +40412,7 @@ const useAvatar = (seed = zeroAddress) => {
|
|
|
40384
40412
|
},
|
|
40385
40413
|
// data is static, so no need to refetch
|
|
40386
40414
|
refetchOnWindowFocus: false,
|
|
40387
|
-
|
|
40415
|
+
cacheTime: Infinity,
|
|
40388
40416
|
staleTime: Infinity,
|
|
40389
40417
|
});
|
|
40390
40418
|
return avatar || "";
|
|
@@ -40426,40 +40454,38 @@ const useAddToken = (chainToCompare, tokenToCompare) => {
|
|
|
40426
40454
|
/**
|
|
40427
40455
|
* Add token to wallet
|
|
40428
40456
|
*/
|
|
40429
|
-
const addToken = reactQuery.useMutation({
|
|
40430
|
-
|
|
40431
|
-
|
|
40432
|
-
|
|
40433
|
-
|
|
40434
|
-
|
|
40435
|
-
|
|
40436
|
-
|
|
40437
|
-
|
|
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
|
+
});
|
|
40438
40476
|
await switchChainAsync({
|
|
40439
40477
|
chainId: +token.chainId,
|
|
40440
40478
|
});
|
|
40441
40479
|
}
|
|
40442
|
-
catch (error) {
|
|
40443
|
-
console.debug("Error switching network:", error);
|
|
40444
|
-
if (isEvmChainNotSupportedError(error)) {
|
|
40445
|
-
await addEthereumChain({
|
|
40446
|
-
chain,
|
|
40447
|
-
provider,
|
|
40448
|
-
});
|
|
40449
|
-
await switchChainAsync({
|
|
40450
|
-
chainId: +token.chainId,
|
|
40451
|
-
});
|
|
40452
|
-
}
|
|
40453
|
-
}
|
|
40454
|
-
// Metamask is not popping the second modal if we don't wait a bit
|
|
40455
|
-
// eslint-disable-next-line no-promise-executor-return
|
|
40456
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
40457
40480
|
}
|
|
40458
|
-
|
|
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));
|
|
40459
40484
|
}
|
|
40460
|
-
|
|
40461
|
-
return false;
|
|
40485
|
+
await addTokenToWallet({ token, provider });
|
|
40462
40486
|
}
|
|
40487
|
+
// TODO: Implement keplr add token
|
|
40488
|
+
return false;
|
|
40463
40489
|
});
|
|
40464
40490
|
return {
|
|
40465
40491
|
addToken,
|
|
@@ -40664,9 +40690,7 @@ function useXrplTrustLine({ address, chain, token, amount }) {
|
|
|
40664
40690
|
}
|
|
40665
40691
|
},
|
|
40666
40692
|
async onSuccess() {
|
|
40667
|
-
queryClient.invalidateQueries(
|
|
40668
|
-
queryKey: getPrefixKey(QueryKeys.XrplTrustLine),
|
|
40669
|
-
});
|
|
40693
|
+
queryClient.invalidateQueries(getPrefixKey(QueryKeys.XrplTrustLine));
|
|
40670
40694
|
},
|
|
40671
40695
|
});
|
|
40672
40696
|
/**
|
|
@@ -41024,6 +41048,8 @@ exports.useEvmBalance = useEvmBalance;
|
|
|
41024
41048
|
exports.useExecuteFiatQuote = useExecuteFiatQuote;
|
|
41025
41049
|
exports.useExecuteTransaction = useExecuteTransaction;
|
|
41026
41050
|
exports.useFavoriteTokensStore = useFavoriteTokensStore;
|
|
41051
|
+
exports.useFiatOnRampTxStatus = useFiatOnRampTxStatus;
|
|
41052
|
+
exports.useFiatTransactions = useFiatTransactions;
|
|
41027
41053
|
exports.useGetFiatQuote = useGetFiatQuote;
|
|
41028
41054
|
exports.useGetOnRampConfig = useGetOnRampConfig;
|
|
41029
41055
|
exports.useGetOnrampPaymentTypes = useGetOnrampPaymentTypes;
|
|
@@ -41041,6 +41067,7 @@ exports.useMultiChainWallet = useMultiChainWallet;
|
|
|
41041
41067
|
exports.useMultipleTokenPrices = useMultipleTokenPrices;
|
|
41042
41068
|
exports.useNativeBalance = useNativeBalance;
|
|
41043
41069
|
exports.useNativeTokenForChain = useNativeTokenForChain;
|
|
41070
|
+
exports.useRecommendedQuote = useRecommendedQuote;
|
|
41044
41071
|
exports.useRouteWarnings = useRouteWarnings;
|
|
41045
41072
|
exports.useSendTransaction = useSendTransaction;
|
|
41046
41073
|
exports.useSendTransactionGas = useSendTransactionGas;
|
|
@@ -41068,4 +41095,4 @@ exports.useWallets = useWallets;
|
|
|
41068
41095
|
exports.useXrplTrustLine = useXrplTrustLine;
|
|
41069
41096
|
exports.walletIconBaseUrl = walletIconBaseUrl;
|
|
41070
41097
|
exports.walletSupportsChainType = walletSupportsChainType;
|
|
41071
|
-
//# sourceMappingURL=index-
|
|
41098
|
+
//# sourceMappingURL=index-DVmnHUzP.js.map
|