@0xsquid/react-hooks 8.3.1 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/core/constants.d.ts +1 -0
  2. package/dist/core/index.d.ts +1 -1
  3. package/dist/core/types/transaction.d.ts +19 -1
  4. package/dist/hooks/hedera/useHederaAccountActivation.d.ts +10 -0
  5. package/dist/hooks/index.d.ts +2 -1
  6. package/dist/hooks/tokens/useNativeBalance.d.ts +2 -0
  7. package/dist/hooks/transaction/useGetRoute.d.ts +18 -7
  8. package/dist/{index-qAOvcSon.js → index-BdrSk8Ed.js} +874 -764
  9. package/dist/index-BdrSk8Ed.js.map +1 -0
  10. package/dist/{index-CMrdTYeW.js → index-BxJVsDEs.js} +861 -765
  11. package/dist/index-BxJVsDEs.js.map +1 -0
  12. package/dist/{index.es-DRgOycmm.js → index.es-CFf55ppw.js} +2 -2
  13. package/dist/{index.es-DRgOycmm.js.map → index.es-CFf55ppw.js.map} +1 -1
  14. package/dist/{index.es-Cu_QQTg-.js → index.es-DhiQj1ju.js} +2 -2
  15. package/dist/{index.es-Cu_QQTg-.js.map → index.es-DhiQj1ju.js.map} +1 -1
  16. package/dist/index.esm.js +1 -1
  17. package/dist/index.js +15 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/{secretService-B3sc6ibT.js → secretService-D0xrwhEv.js} +2 -2
  20. package/dist/{secretService-B3sc6ibT.js.map → secretService-D0xrwhEv.js.map} +1 -1
  21. package/dist/{secretService-B_-XWo1F.js → secretService-DRTd4cda.js} +2 -2
  22. package/dist/{secretService-B_-XWo1F.js.map → secretService-DRTd4cda.js.map} +1 -1
  23. package/dist/services/index.d.ts +1 -0
  24. package/dist/services/internal/hederaService.d.ts +2 -0
  25. package/dist/services/internal/routeService.d.ts +8 -0
  26. package/dist/services/internal/transactionService.d.ts +14 -1
  27. package/dist/{stellarService.client-sRzC5VSD.js → stellarService.client-CRFUb2R6.js} +2 -2
  28. package/dist/{stellarService.client-sRzC5VSD.js.map → stellarService.client-CRFUb2R6.js.map} +1 -1
  29. package/dist/{stellarService.client-Ciqw9lmL.js → stellarService.client-xMf7fjCz.js} +2 -2
  30. package/dist/{stellarService.client-Ciqw9lmL.js.map → stellarService.client-xMf7fjCz.js.map} +1 -1
  31. package/package.json +4 -4
  32. package/dist/index-CMrdTYeW.js.map +0 -1
  33. package/dist/index-qAOvcSon.js.map +0 -1
@@ -102,6 +102,7 @@ const gasRefundMultiplier = 25;
102
102
  const internalSquidApiBaseUrl = "https://app.squidrouter.com/api";
103
103
  const XAMAN_API_URL = `${internalSquidApiBaseUrl}/xaman/`;
104
104
  const TOKEN_PRICE_API_URL = `${internalSquidApiBaseUrl}/coingecko`;
105
+ const DEFAULT_ROUTE_REFETCH_INTERVAL = 30_000;
105
106
  const SOLANA_RPC_URL = "https://meredith-ute2ko-fast-mainnet.helius-rpc.com";
106
107
  const INTEGRATOR_ID = "squid-widget-playground-local-cd33cba6-7e12-4fcc-8d5d-35e286f655ea";
107
108
  const DEFAULT_COUNTRY_CODE = "US";
@@ -20855,6 +20856,309 @@ const isBitcoinAddressValid = (address) => {
20855
20856
  }
20856
20857
  };
20857
20858
 
20859
+ exports.HistoryTxType = void 0;
20860
+ (function (HistoryTxType) {
20861
+ HistoryTxType[HistoryTxType["SWAP"] = 0] = "SWAP";
20862
+ HistoryTxType[HistoryTxType["BUY"] = 1] = "BUY";
20863
+ HistoryTxType[HistoryTxType["SEND"] = 2] = "SEND";
20864
+ })(exports.HistoryTxType || (exports.HistoryTxType = {}));
20865
+
20866
+ var TransactionType;
20867
+ (function (TransactionType) {
20868
+ TransactionType["BRIDGE"] = "BRIDGE";
20869
+ TransactionType["BRIDGE_CALL"] = "BRIDGE_CALL";
20870
+ TransactionType["CALL_BRIDGE"] = "CALL_BRIDGE";
20871
+ TransactionType["CALL_BRIDGE_CALL"] = "CALL_BRIDGE_CALL";
20872
+ })(TransactionType || (TransactionType = {}));
20873
+ exports.AxelarStatusResponseType = void 0;
20874
+ (function (AxelarStatusResponseType) {
20875
+ AxelarStatusResponseType["GAS_PAID_NOT_ENOUGH_GAS"] = "gas_paid_not_enough_gas";
20876
+ AxelarStatusResponseType["DESTINATION_EXECUTED"] = "destination_executed";
20877
+ AxelarStatusResponseType["EXPRESS_EXECUTED"] = "express_executed";
20878
+ AxelarStatusResponseType["CROSS_MULTICALL_EXECUTED"] = "CrossMulticallExecuted";
20879
+ AxelarStatusResponseType["CROSS_MULTICALL_FAILED"] = "CrossMulticallFailed";
20880
+ AxelarStatusResponseType["SRC_GATEWAY_CALLED"] = "source_gateway_called";
20881
+ AxelarStatusResponseType["DEST_GATEWAY_APPROVED"] = "destination_gateway_approved";
20882
+ AxelarStatusResponseType["DESTINATION_EXECUTE_ERROR"] = "destination_execute_error";
20883
+ AxelarStatusResponseType["DESTINATION_EXECUTING"] = "executing";
20884
+ AxelarStatusResponseType["UNKNOWN_ERROR"] = "unknown_error";
20885
+ AxelarStatusResponseType["CANNOT_FETCH_STATUS"] = "cannot_fetch_status";
20886
+ AxelarStatusResponseType["ERROR"] = "error";
20887
+ })(exports.AxelarStatusResponseType || (exports.AxelarStatusResponseType = {}));
20888
+ exports.TransactionStatus = void 0;
20889
+ (function (TransactionStatus) {
20890
+ // Submitted transaction, returned by squid axelar
20891
+ TransactionStatus["SUCCESS"] = "success";
20892
+ TransactionStatus["NEEDS_GAS"] = "needs_gas";
20893
+ TransactionStatus["ONGOING"] = "ongoing";
20894
+ TransactionStatus["PARTIAL_SUCCESS"] = "partial_success";
20895
+ TransactionStatus["NOT_FOUND"] = "not_found";
20896
+ // Unsubmitted Transaction, can be status from wallet
20897
+ TransactionStatus["INITIAL_LOADING"] = "initialLoading";
20898
+ TransactionStatus["GENERATING_DEPOSIT"] = "generating_deposit";
20899
+ TransactionStatus["ERROR"] = "error";
20900
+ TransactionStatus["WARNING"] = "warning";
20901
+ TransactionStatus["PENDING"] = "pending";
20902
+ TransactionStatus["REJECTED"] = "rejected";
20903
+ // Coral refund
20904
+ TransactionStatus["REFUNDED"] = "refunded";
20905
+ })(exports.TransactionStatus || (exports.TransactionStatus = {}));
20906
+ exports.SendTransactionStatus = void 0;
20907
+ (function (SendTransactionStatus) {
20908
+ SendTransactionStatus[SendTransactionStatus["ONGOING"] = 0] = "ONGOING";
20909
+ SendTransactionStatus[SendTransactionStatus["SUCCESS"] = 1] = "SUCCESS";
20910
+ SendTransactionStatus[SendTransactionStatus["ERROR"] = 2] = "ERROR";
20911
+ })(exports.SendTransactionStatus || (exports.SendTransactionStatus = {}));
20912
+
20913
+ const getQueryHeaders = (integratorId, requestId) => {
20914
+ return {
20915
+ ...(integratorId ? { "X-Integrator-Id": integratorId } : {}),
20916
+ ...(requestId ? { "X-Request-Id": requestId } : {}),
20917
+ };
20918
+ };
20919
+ const getStatusCode = (error) => {
20920
+ if (axios.isAxiosError(error)) {
20921
+ return error.response?.status;
20922
+ }
20923
+ return undefined;
20924
+ };
20925
+ const is404Error = (error) => {
20926
+ const statusCode = getStatusCode(error);
20927
+ if (statusCode === 404) {
20928
+ return true;
20929
+ }
20930
+ return false;
20931
+ };
20932
+
20933
+ const formatTransactionHistoryDate = (transaction) => {
20934
+ if (!transaction?.timestamp)
20935
+ return undefined;
20936
+ try {
20937
+ const date = new Date(Number(transaction.timestamp));
20938
+ // Format date to: MMM DD. Examples:
20939
+ // Jan 01
20940
+ // May 12
20941
+ const month = new Intl.DateTimeFormat(DEFAULT_LOCALE, {
20942
+ month: "short",
20943
+ }).format(date);
20944
+ const day = date.toLocaleString(DEFAULT_LOCALE, { day: "2-digit" });
20945
+ return { month, day };
20946
+ }
20947
+ catch (error) {
20948
+ console.error("Error formatting date:", error);
20949
+ return undefined;
20950
+ }
20951
+ };
20952
+ const getAxelarExplorerTxUrl = (urlPrefix, routeType, txID) => {
20953
+ if (!urlPrefix) {
20954
+ return undefined;
20955
+ }
20956
+ const txType = routeType ?? TransactionType.BRIDGE;
20957
+ if (txType === TransactionType.CALL_BRIDGE ||
20958
+ txType === TransactionType.BRIDGE) {
20959
+ return `${urlPrefix}transfer/${txID}`;
20960
+ }
20961
+ return `${urlPrefix}gmp/${txID}`;
20962
+ };
20963
+ const getSourceExplorerTxUrl = (chain, txID) => {
20964
+ if (!chain || !chain.blockExplorerUrls[0] || !txID) {
20965
+ return undefined;
20966
+ }
20967
+ let txSuffix;
20968
+ switch (chain.chainId) {
20969
+ case CHAIN_IDS.AGORIC:
20970
+ case CHAIN_IDS.XRPL:
20971
+ case CHAIN_IDS.XRPL_TESTNET:
20972
+ txSuffix = "/transactions/";
20973
+ break;
20974
+ case CHAIN_IDS.HEDERA:
20975
+ txSuffix = "/transaction/";
20976
+ break;
20977
+ default:
20978
+ txSuffix = "/tx/";
20979
+ }
20980
+ if (chain.blockExplorerUrls[0].endsWith("/")) {
20981
+ txSuffix = txSuffix.slice(1);
20982
+ }
20983
+ return `${chain.blockExplorerUrls[0]}${txSuffix}${txID}`;
20984
+ };
20985
+ const getMainExplorerUrl = (transaction) => {
20986
+ // The most accurate one is coming from squid /status api
20987
+ if (transaction?.statusResponse?.axelarTransactionUrl) {
20988
+ return transaction?.statusResponse.axelarTransactionUrl;
20989
+ }
20990
+ // If not, we can try to get it from the source chain
20991
+ if (transaction?.sourceTxExplorerUrl) {
20992
+ return transaction?.sourceTxExplorerUrl;
20993
+ }
20994
+ // If not, we can try to guess it from the transaction type
20995
+ if (transaction && transaction?.transactionId) {
20996
+ return getAxelarExplorerTxUrl(transaction.statusResponse?.axelarTransactionUrl, transaction.routeType, transaction.transactionId);
20997
+ }
20998
+ return undefined;
20999
+ };
21000
+ const formatDistance = (date, baseDate, options) => {
21001
+ const { includeSeconds = false, addSuffix = false, locale = { locale: DEFAULT_LOCALE }, } = options || {};
21002
+ const elapsedMilliseconds = Math.abs(new Date(date).getTime() - new Date(baseDate).getTime());
21003
+ const seconds = Math.round(elapsedMilliseconds / 1000);
21004
+ const minutes = Math.round(seconds / 60);
21005
+ const hours = Math.round(minutes / 60);
21006
+ const days = Math.round(hours / 24);
21007
+ const months = Math.round(days / 30.44);
21008
+ const years = Math.round(days / 365.25);
21009
+ const rtf = new Intl.RelativeTimeFormat(locale.locale, { numeric: "auto" });
21010
+ let formatted = "";
21011
+ if (includeSeconds && seconds < 45) {
21012
+ const unit = addSuffix ? "second" : "seconds";
21013
+ formatted = rtf.format(-seconds, unit);
21014
+ }
21015
+ else if (minutes < 60) {
21016
+ formatted = rtf.format(-minutes, "minutes");
21017
+ }
21018
+ else if (hours < 24) {
21019
+ formatted = rtf.format(-hours, "hours");
21020
+ }
21021
+ else if (days < 30) {
21022
+ formatted = rtf.format(-days, "days");
21023
+ }
21024
+ else if (months < 12) {
21025
+ formatted = rtf.format(-months, "months");
21026
+ }
21027
+ else {
21028
+ formatted = rtf.format(-years, "years");
21029
+ }
21030
+ // remove "ago" from the string
21031
+ // before: "2 minutes ago"
21032
+ // after: "2 minutes"
21033
+ return addSuffix ? formatted : formatted.replace(/\b(?:ago)\b/, "").trim();
21034
+ };
21035
+ const formatSeconds = (seconds, secondsTemplate = "s", minutesTemplate = "m", hoursTemplate = "h") => {
21036
+ let duration = "";
21037
+ if (seconds < 60) {
21038
+ duration = `${seconds.toString()}${secondsTemplate}`;
21039
+ }
21040
+ else {
21041
+ duration = formatDistance(0, seconds * 1000, { includeSeconds: true });
21042
+ }
21043
+ const result = duration.startsWith("1 ")
21044
+ ? duration
21045
+ .replace(" minute", minutesTemplate)
21046
+ .replace(" hour", hoursTemplate)
21047
+ : duration
21048
+ .replace(" minutes", minutesTemplate)
21049
+ .replace(" hours", hoursTemplate);
21050
+ return result;
21051
+ };
21052
+ /**
21053
+ * Remove the chainData from statusResponse to gain some storage space
21054
+ */
21055
+ const formatSwapTxStatusResponseForStorage = (sr) => {
21056
+ if (!sr) {
21057
+ return sr;
21058
+ }
21059
+ return {
21060
+ axelarTransactionUrl: sr.axelarTransactionUrl,
21061
+ toChain: sr.toChain?.transactionUrl
21062
+ ? {
21063
+ transactionUrl: sr.toChain?.transactionUrl,
21064
+ }
21065
+ : undefined,
21066
+ };
21067
+ };
21068
+ const simplifyRouteAction = (action) => {
21069
+ return {
21070
+ type: action.type,
21071
+ provider: action.provider,
21072
+ data: {
21073
+ type: action.data?.type,
21074
+ },
21075
+ ...(action.coralV2Order ? { isCoralV2: true } : undefined),
21076
+ };
21077
+ };
21078
+ const fetchSwapTransactionStatus = async ({ transaction, integratorId, apiUrl, }) => {
21079
+ const statusEndpoint = `${apiUrl}/v2/status`;
21080
+ try {
21081
+ const response = await axios.get(statusEndpoint, {
21082
+ params: {
21083
+ transactionId: transaction?.transactionIdForStatus ?? transaction?.transactionId,
21084
+ fromChainId: transaction?.fromChain,
21085
+ toChainId: transaction?.toChain,
21086
+ bridgeType: transaction?.bridgeType,
21087
+ quoteId: transaction?.quoteId,
21088
+ depositTxVerificationSignature: transaction?.depositTxVerificationSignature,
21089
+ },
21090
+ headers: getQueryHeaders(integratorId, transaction?.quoteId),
21091
+ });
21092
+ return response.data;
21093
+ }
21094
+ catch (error) {
21095
+ if (error) {
21096
+ throw new Error("Fetch transaction status failed", { cause: error });
21097
+ }
21098
+ throw new Error("Fetch transaction status failed", { cause: undefined });
21099
+ }
21100
+ };
21101
+ const compareTransactionIds = (idA, idB) => {
21102
+ if (!idA || !idB) {
21103
+ return false;
21104
+ }
21105
+ const normalizedA = idA.toLowerCase();
21106
+ const normalizedB = idB.toLowerCase();
21107
+ return normalizedA.includes(normalizedB) || normalizedB.includes(normalizedA);
21108
+ };
21109
+ /**
21110
+ * Checks if the provided action is Coral bridge action
21111
+ */
21112
+ function isCoralBridgeAction(action) {
21113
+ return (action.type === squidTypes.ActionType.RFQ &&
21114
+ // TODO: update types
21115
+ action.provider?.toLowerCase() === "coral");
21116
+ }
21117
+ function sleep(ms) {
21118
+ return new Promise((resolve) => setTimeout(resolve, ms));
21119
+ }
21120
+ const isDepositRoute = (route) => {
21121
+ return (!!route &&
21122
+ route.transactionRequest?.type === squidTypes.SquidDataType.ChainflipDepositAddress);
21123
+ };
21124
+ /**
21125
+ * Checks if the route contains a Chainflip bridge action
21126
+ */
21127
+ function isChainflipBridgeTransaction(actions = []) {
21128
+ return actions.some((action) => action.type === squidTypes.ActionType.BRIDGE &&
21129
+ action.data?.type === squidTypes.BridgeType.CHAINFLIP);
21130
+ }
21131
+ /**
21132
+ * Checks if a route is of type {@link OnChainExecutionData}
21133
+ *
21134
+ * On-chain routes require calling a smart contract to execute
21135
+ */
21136
+ function isOnChainTxData(squidData) {
21137
+ return [
21138
+ squidTypes.SquidDataType.OnChainExecution,
21139
+ squidTypes.SquidDataType.DepositAddressWithSignature,
21140
+ ].includes(squidData.type);
21141
+ }
21142
+ /**
21143
+ * Checks if a route is of type deposit-with-signature
21144
+ *
21145
+ * deposit-with-signature routes are on-chain routes
21146
+ * that require a signature from the user to execute
21147
+ */
21148
+ function isDepositWithSignatureTxData(squidData) {
21149
+ return squidData.type === squidTypes.SquidDataType.DepositAddressWithSignature;
21150
+ }
21151
+ function getHistoryTransactionId(tx) {
21152
+ switch (tx.txType) {
21153
+ case exports.HistoryTxType.SWAP:
21154
+ return tx.data.transactionId;
21155
+ case exports.HistoryTxType.BUY:
21156
+ return tx.data.orderId;
21157
+ case exports.HistoryTxType.SEND:
21158
+ return tx.data.hash;
21159
+ }
21160
+ }
21161
+
20858
21162
  const STANDARD_FEATURES = [
20859
21163
  "standard:connect",
20860
21164
  "standard:events",
@@ -21031,7 +21335,7 @@ const isSolanaAddressValid = (address) => {
21031
21335
  * This will be used for the swap flow - Using Jupiter Dex under the hood
21032
21336
  */
21033
21337
  const executeSolanaSwap = async ({ route, signer, connection, onSigned, }) => {
21034
- if (!route?.transactionRequest?.data) {
21338
+ if (!route.transactionRequest || !isOnChainTxData(route.transactionRequest)) {
21035
21339
  throw new Error("Invalid parameters");
21036
21340
  }
21037
21341
  const swapRequest = route.transactionRequest.data;
@@ -21906,285 +22210,6 @@ async function getXummClient() {
21906
22210
  return xummClient;
21907
22211
  }
21908
22212
 
21909
- const getQueryHeaders = (integratorId, requestId) => {
21910
- return {
21911
- ...(integratorId ? { "X-Integrator-Id": integratorId } : {}),
21912
- ...(requestId ? { "X-Request-Id": requestId } : {}),
21913
- };
21914
- };
21915
- const getStatusCode = (error) => {
21916
- if (axios.isAxiosError(error)) {
21917
- return error.response?.status;
21918
- }
21919
- return undefined;
21920
- };
21921
- const is404Error = (error) => {
21922
- const statusCode = getStatusCode(error);
21923
- if (statusCode === 404) {
21924
- return true;
21925
- }
21926
- return false;
21927
- };
21928
-
21929
- exports.HistoryTxType = void 0;
21930
- (function (HistoryTxType) {
21931
- HistoryTxType[HistoryTxType["SWAP"] = 0] = "SWAP";
21932
- HistoryTxType[HistoryTxType["BUY"] = 1] = "BUY";
21933
- HistoryTxType[HistoryTxType["SEND"] = 2] = "SEND";
21934
- })(exports.HistoryTxType || (exports.HistoryTxType = {}));
21935
-
21936
- var TransactionType;
21937
- (function (TransactionType) {
21938
- TransactionType["BRIDGE"] = "BRIDGE";
21939
- TransactionType["BRIDGE_CALL"] = "BRIDGE_CALL";
21940
- TransactionType["CALL_BRIDGE"] = "CALL_BRIDGE";
21941
- TransactionType["CALL_BRIDGE_CALL"] = "CALL_BRIDGE_CALL";
21942
- })(TransactionType || (TransactionType = {}));
21943
- exports.AxelarStatusResponseType = void 0;
21944
- (function (AxelarStatusResponseType) {
21945
- AxelarStatusResponseType["GAS_PAID_NOT_ENOUGH_GAS"] = "gas_paid_not_enough_gas";
21946
- AxelarStatusResponseType["DESTINATION_EXECUTED"] = "destination_executed";
21947
- AxelarStatusResponseType["EXPRESS_EXECUTED"] = "express_executed";
21948
- AxelarStatusResponseType["CROSS_MULTICALL_EXECUTED"] = "CrossMulticallExecuted";
21949
- AxelarStatusResponseType["CROSS_MULTICALL_FAILED"] = "CrossMulticallFailed";
21950
- AxelarStatusResponseType["SRC_GATEWAY_CALLED"] = "source_gateway_called";
21951
- AxelarStatusResponseType["DEST_GATEWAY_APPROVED"] = "destination_gateway_approved";
21952
- AxelarStatusResponseType["DESTINATION_EXECUTE_ERROR"] = "destination_execute_error";
21953
- AxelarStatusResponseType["DESTINATION_EXECUTING"] = "executing";
21954
- AxelarStatusResponseType["UNKNOWN_ERROR"] = "unknown_error";
21955
- AxelarStatusResponseType["CANNOT_FETCH_STATUS"] = "cannot_fetch_status";
21956
- AxelarStatusResponseType["ERROR"] = "error";
21957
- })(exports.AxelarStatusResponseType || (exports.AxelarStatusResponseType = {}));
21958
- exports.TransactionStatus = void 0;
21959
- (function (TransactionStatus) {
21960
- // Submitted transaction, returned by squid axelar
21961
- TransactionStatus["SUCCESS"] = "success";
21962
- TransactionStatus["NEEDS_GAS"] = "needs_gas";
21963
- TransactionStatus["ONGOING"] = "ongoing";
21964
- TransactionStatus["PARTIAL_SUCCESS"] = "partial_success";
21965
- TransactionStatus["NOT_FOUND"] = "not_found";
21966
- // Unsubmitted Transaction, can be status from wallet
21967
- TransactionStatus["INITIAL_LOADING"] = "initialLoading";
21968
- TransactionStatus["GENERATING_DEPOSIT"] = "generating_deposit";
21969
- TransactionStatus["ERROR"] = "error";
21970
- TransactionStatus["WARNING"] = "warning";
21971
- TransactionStatus["PENDING"] = "pending";
21972
- TransactionStatus["REJECTED"] = "rejected";
21973
- // Coral refund
21974
- TransactionStatus["REFUNDED"] = "refunded";
21975
- })(exports.TransactionStatus || (exports.TransactionStatus = {}));
21976
- exports.SendTransactionStatus = void 0;
21977
- (function (SendTransactionStatus) {
21978
- SendTransactionStatus[SendTransactionStatus["ONGOING"] = 0] = "ONGOING";
21979
- SendTransactionStatus[SendTransactionStatus["SUCCESS"] = 1] = "SUCCESS";
21980
- SendTransactionStatus[SendTransactionStatus["ERROR"] = 2] = "ERROR";
21981
- })(exports.SendTransactionStatus || (exports.SendTransactionStatus = {}));
21982
-
21983
- const formatTransactionHistoryDate = (transaction) => {
21984
- if (!transaction?.timestamp)
21985
- return undefined;
21986
- try {
21987
- const date = new Date(Number(transaction.timestamp));
21988
- // Format date to: MMM DD. Examples:
21989
- // Jan 01
21990
- // May 12
21991
- const month = new Intl.DateTimeFormat(DEFAULT_LOCALE, {
21992
- month: "short",
21993
- }).format(date);
21994
- const day = date.toLocaleString(DEFAULT_LOCALE, { day: "2-digit" });
21995
- return { month, day };
21996
- }
21997
- catch (error) {
21998
- console.error("Error formatting date:", error);
21999
- return undefined;
22000
- }
22001
- };
22002
- const getAxelarExplorerTxUrl = (urlPrefix, routeType, txID) => {
22003
- if (!urlPrefix) {
22004
- return undefined;
22005
- }
22006
- const txType = routeType ?? TransactionType.BRIDGE;
22007
- if (txType === TransactionType.CALL_BRIDGE ||
22008
- txType === TransactionType.BRIDGE) {
22009
- return `${urlPrefix}transfer/${txID}`;
22010
- }
22011
- return `${urlPrefix}gmp/${txID}`;
22012
- };
22013
- const getSourceExplorerTxUrl = (chain, txID) => {
22014
- if (!chain || !chain.blockExplorerUrls[0] || !txID) {
22015
- return undefined;
22016
- }
22017
- let txSuffix;
22018
- switch (chain.chainId) {
22019
- case CHAIN_IDS.AGORIC:
22020
- case CHAIN_IDS.XRPL:
22021
- case CHAIN_IDS.XRPL_TESTNET:
22022
- txSuffix = "/transactions/";
22023
- break;
22024
- default:
22025
- txSuffix = "/tx/";
22026
- }
22027
- if (chain.blockExplorerUrls[0].endsWith("/")) {
22028
- txSuffix = txSuffix.slice(1);
22029
- }
22030
- return `${chain.blockExplorerUrls[0]}${txSuffix}${txID}`;
22031
- };
22032
- const getMainExplorerUrl = (transaction) => {
22033
- // The most accurate one is coming from squid /status api
22034
- if (transaction?.statusResponse?.axelarTransactionUrl) {
22035
- return transaction?.statusResponse.axelarTransactionUrl;
22036
- }
22037
- // If not, we can try to get it from the source chain
22038
- if (transaction?.sourceTxExplorerUrl) {
22039
- return transaction?.sourceTxExplorerUrl;
22040
- }
22041
- // If not, we can try to guess it from the transaction type
22042
- if (transaction && transaction?.transactionId) {
22043
- return getAxelarExplorerTxUrl(transaction.statusResponse?.axelarTransactionUrl, transaction.routeType, transaction.transactionId);
22044
- }
22045
- return undefined;
22046
- };
22047
- const formatDistance = (date, baseDate, options) => {
22048
- const { includeSeconds = false, addSuffix = false, locale = { locale: DEFAULT_LOCALE }, } = options || {};
22049
- const elapsedMilliseconds = Math.abs(new Date(date).getTime() - new Date(baseDate).getTime());
22050
- const seconds = Math.round(elapsedMilliseconds / 1000);
22051
- const minutes = Math.round(seconds / 60);
22052
- const hours = Math.round(minutes / 60);
22053
- const days = Math.round(hours / 24);
22054
- const months = Math.round(days / 30.44);
22055
- const years = Math.round(days / 365.25);
22056
- const rtf = new Intl.RelativeTimeFormat(locale.locale, { numeric: "auto" });
22057
- let formatted = "";
22058
- if (includeSeconds && seconds < 45) {
22059
- const unit = addSuffix ? "second" : "seconds";
22060
- formatted = rtf.format(-seconds, unit);
22061
- }
22062
- else if (minutes < 60) {
22063
- formatted = rtf.format(-minutes, "minutes");
22064
- }
22065
- else if (hours < 24) {
22066
- formatted = rtf.format(-hours, "hours");
22067
- }
22068
- else if (days < 30) {
22069
- formatted = rtf.format(-days, "days");
22070
- }
22071
- else if (months < 12) {
22072
- formatted = rtf.format(-months, "months");
22073
- }
22074
- else {
22075
- formatted = rtf.format(-years, "years");
22076
- }
22077
- // remove "ago" from the string
22078
- // before: "2 minutes ago"
22079
- // after: "2 minutes"
22080
- return addSuffix ? formatted : formatted.replace(/\b(?:ago)\b/, "").trim();
22081
- };
22082
- const formatSeconds = (seconds, secondsTemplate = "s", minutesTemplate = "m", hoursTemplate = "h") => {
22083
- let duration = "";
22084
- if (seconds < 60) {
22085
- duration = `${seconds.toString()}${secondsTemplate}`;
22086
- }
22087
- else {
22088
- duration = formatDistance(0, seconds * 1000, { includeSeconds: true });
22089
- }
22090
- const result = duration.startsWith("1 ")
22091
- ? duration
22092
- .replace(" minute", minutesTemplate)
22093
- .replace(" hour", hoursTemplate)
22094
- : duration
22095
- .replace(" minutes", minutesTemplate)
22096
- .replace(" hours", hoursTemplate);
22097
- return result;
22098
- };
22099
- /**
22100
- * Remove the chainData from statusResponse to gain some storage space
22101
- */
22102
- const formatSwapTxStatusResponseForStorage = (sr) => {
22103
- if (!sr) {
22104
- return sr;
22105
- }
22106
- return {
22107
- axelarTransactionUrl: sr.axelarTransactionUrl,
22108
- toChain: sr.toChain?.transactionUrl
22109
- ? {
22110
- transactionUrl: sr.toChain?.transactionUrl,
22111
- }
22112
- : undefined,
22113
- };
22114
- };
22115
- const simplifyRouteAction = (action) => {
22116
- return {
22117
- type: action.type,
22118
- provider: action.provider,
22119
- data: {
22120
- type: action.data?.type,
22121
- },
22122
- ...(action.coralV2Order ? { isCoralV2: true } : undefined),
22123
- };
22124
- };
22125
- const fetchSwapTransactionStatus = async ({ transaction, integratorId, apiUrl, }) => {
22126
- const statusEndpoint = `${apiUrl}/v2/status`;
22127
- try {
22128
- const response = await axios.get(statusEndpoint, {
22129
- params: {
22130
- transactionId: transaction?.transactionIdForStatus ?? transaction?.transactionId,
22131
- fromChainId: transaction?.fromChain,
22132
- toChainId: transaction?.toChain,
22133
- bridgeType: transaction?.bridgeType,
22134
- quoteId: transaction?.quoteId,
22135
- },
22136
- headers: getQueryHeaders(integratorId, transaction?.quoteId),
22137
- });
22138
- return response.data;
22139
- }
22140
- catch (error) {
22141
- if (error) {
22142
- throw new Error("Fetch transaction status failed", { cause: error });
22143
- }
22144
- throw new Error("Fetch transaction status failed", { cause: undefined });
22145
- }
22146
- };
22147
- const compareTransactionIds = (idA, idB) => {
22148
- if (!idA || !idB) {
22149
- return false;
22150
- }
22151
- const normalizedA = idA.toLowerCase();
22152
- const normalizedB = idB.toLowerCase();
22153
- return normalizedA.includes(normalizedB) || normalizedB.includes(normalizedA);
22154
- };
22155
- /**
22156
- * Checks if the provided action is Coral bridge action
22157
- */
22158
- function isCoralBridgeAction(action) {
22159
- return (action.type === squidTypes.ActionType.RFQ &&
22160
- // TODO: update types
22161
- action.provider?.toLowerCase() === "coral");
22162
- }
22163
- function sleep(ms) {
22164
- return new Promise((resolve) => setTimeout(resolve, ms));
22165
- }
22166
- const isDepositRoute = (route) => {
22167
- return (!!route &&
22168
- route.transactionRequest?.type === squidTypes.SquidDataType.ChainflipDepositAddress);
22169
- };
22170
- /**
22171
- * Checks if the route contains a Chainflip bridge action
22172
- */
22173
- function isChainflipBridgeTransaction(actions = []) {
22174
- return actions.some((action) => action.type === squidTypes.ActionType.BRIDGE &&
22175
- action.data?.type === squidTypes.BridgeType.CHAINFLIP);
22176
- }
22177
- function getHistoryTransactionId(tx) {
22178
- switch (tx.txType) {
22179
- case exports.HistoryTxType.SWAP:
22180
- return tx.data.transactionId;
22181
- case exports.HistoryTxType.BUY:
22182
- return tx.data.orderId;
22183
- case exports.HistoryTxType.SEND:
22184
- return tx.data.hash;
22185
- }
22186
- }
22187
-
22188
22213
  exports.QueryKeys = void 0;
22189
22214
  (function (QueryKeys) {
22190
22215
  QueryKeys["All"] = "all";
@@ -23153,7 +23178,7 @@ const filterViewableTokens = (tokens, config, direction) => {
23153
23178
  };
23154
23179
  const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
23155
23180
  const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
23156
- const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-B_-XWo1F.js'); });
23181
+ const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-DRTd4cda.js'); });
23157
23182
  return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
23158
23183
  };
23159
23184
  function getTokenAssetsKey(token) {
@@ -24625,6 +24650,37 @@ function convertHederaAccountIdToEvmAddress(accId) {
24625
24650
  function convertEvmAddressToHederaAccountId(address) {
24626
24651
  return "0.0." + Number(address);
24627
24652
  }
24653
+ /**
24654
+ * In Hedera, native HBAR has 8 decimals, but when handling `value` or gas in the EVM we need to use 18 decimals.
24655
+ * To handle this we need to multiply/divide the 1e8 HBAR by 10^10 to get the scaled 1e18/1e8 HBAR value.
24656
+ * @see https://docs.hedera.com/hedera/core-concepts/smart-contracts/understanding-hederas-evm-differences-and-compatibility/for-evm-developers-migrating-to-hedera/decimal-handling-8-vs.-18-decimals
24657
+ */
24658
+ const HBAR_SCALING_FACTOR = BigInt(10 ** 10);
24659
+ function scaleHbarToWei(hbar) {
24660
+ return hbar * HBAR_SCALING_FACTOR;
24661
+ }
24662
+ function scaleWeiToHbar(wei) {
24663
+ return wei / HBAR_SCALING_FACTOR;
24664
+ }
24665
+
24666
+ /**
24667
+ * Return the expiry of a route in milliseconds
24668
+ *
24669
+ * @param route - Squid route
24670
+ * @returns expiry in milliseconds
24671
+ */
24672
+ function getRouteExpiry(route) {
24673
+ if (!route?.transactionRequest)
24674
+ return DEFAULT_ROUTE_REFETCH_INTERVAL;
24675
+ if (!isOnChainTxData(route.transactionRequest)) {
24676
+ return DEFAULT_ROUTE_REFETCH_INTERVAL;
24677
+ }
24678
+ const { expiryOffset } = route.transactionRequest;
24679
+ if (expiryOffset != null && Number(expiryOffset) >= 0) {
24680
+ return Number(expiryOffset) * 1_000;
24681
+ }
24682
+ return DEFAULT_ROUTE_REFETCH_INTERVAL;
24683
+ }
24628
24684
 
24629
24685
  /**
24630
24686
  * Minimum length of a search query to search by address
@@ -26438,7 +26494,7 @@ function useStellarWallets() {
26438
26494
  try {
26439
26495
  const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
26440
26496
  const { LedgerModule } = await import('@creit.tech/stellar-wallets-kit/modules/ledger.module');
26441
- const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-sRzC5VSD.js'); });
26497
+ const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-CRFUb2R6.js'); });
26442
26498
  const modules = [...initializeAllModules(), new LedgerModule()];
26443
26499
  const promises = modules.map(async (module) => {
26444
26500
  const isAvailable = await module.isAvailable();
@@ -27938,7 +27994,7 @@ function hederaWalletConnect(parameters) {
27938
27994
  const optionalChains = config.chains.map((x) => x.id);
27939
27995
  if (!optionalChains.length)
27940
27996
  return;
27941
- const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-Cu_QQTg-.js'); });
27997
+ const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-DhiQj1ju.js'); });
27942
27998
  const rawProvider = await EthereumProvider.init({
27943
27999
  ...restParameters,
27944
28000
  disableProviderPing: true,
@@ -29699,6 +29755,490 @@ function useStellarAccountActivation({ address, chain, token, }) {
29699
29755
  };
29700
29756
  }
29701
29757
 
29758
+ const DEFAULT_REFRESH_INTERVAL_MS = 15000;
29759
+ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
29760
+ const { isChainTypeConnected } = useWallet();
29761
+ const isNativeToken = token?.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
29762
+ const userAddressParsed = userAddress;
29763
+ // Only fetch using useBalance if it's a native token
29764
+ const { data: nativeBalance, isLoading: isNativeTokenLoading } = wagmi.useBalance({
29765
+ address: userAddressParsed,
29766
+ chainId: Number(chain?.chainId),
29767
+ query: {
29768
+ enabled: enabled &&
29769
+ !!userAddress &&
29770
+ isNativeToken &&
29771
+ !!chain &&
29772
+ chain.chainType === squidTypes.ChainType.EVM &&
29773
+ isChainTypeConnected(chain.chainType),
29774
+ refetchInterval: refreshIntervalMs,
29775
+ retry: 2,
29776
+ },
29777
+ });
29778
+ // Only fetch using useReadContract if it's not a native token
29779
+ // This is temporary, because of wagmi error: https://github.com/wevm/wagmi/issues/4353
29780
+ const { data: erc20Balance, isLoading: isErc20Loading } = wagmi.useReadContract({
29781
+ address: token?.address,
29782
+ abi: viem.erc20Abi,
29783
+ functionName: "balanceOf",
29784
+ args: [userAddressParsed],
29785
+ chainId: Number(chain?.chainId),
29786
+ query: {
29787
+ enabled: isChainTypeConnected(squidTypes.ChainType.EVM) &&
29788
+ enabled &&
29789
+ !!userAddress &&
29790
+ !isNativeToken,
29791
+ refetchInterval: refreshIntervalMs,
29792
+ retry: 2,
29793
+ },
29794
+ });
29795
+ if (isNativeToken) {
29796
+ return {
29797
+ isLoading: isNativeTokenLoading,
29798
+ balance: nativeBalance
29799
+ ? formatBNToReadable(nativeBalance.value, nativeBalance.decimals)
29800
+ : "0",
29801
+ };
29802
+ }
29803
+ return {
29804
+ balance: erc20Balance && token
29805
+ ? formatBNToReadable(erc20Balance, token.decimals)
29806
+ : "0",
29807
+ isLoading: isErc20Loading,
29808
+ };
29809
+ };
29810
+ const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
29811
+ const { isConnected } = useCosmosContext();
29812
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
29813
+ queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
29814
+ queryFn: async () => {
29815
+ if (!userAddress || !token || chain?.chainType !== squidTypes.ChainType.COSMOS) {
29816
+ return "0";
29817
+ }
29818
+ const isAddressValid = isCosmosAddressValid(chain.bech32Config.bech32PrefixAccAddr, userAddress);
29819
+ if (!isAddressValid)
29820
+ return "0";
29821
+ const balanceBn = await getCosmosTokenBalance(chain, userAddress, token.address);
29822
+ return formatBNToReadable(balanceBn, token.decimals);
29823
+ },
29824
+ enabled: isConnected &&
29825
+ enabled &&
29826
+ !!userAddress &&
29827
+ !!token &&
29828
+ chain?.chainType === squidTypes.ChainType.COSMOS,
29829
+ refetchInterval: refreshIntervalMs,
29830
+ retry: 2,
29831
+ });
29832
+ return { balance, isLoading };
29833
+ };
29834
+ const useSolanaBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
29835
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
29836
+ queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
29837
+ queryFn: async () => {
29838
+ if (!userAddress || !token)
29839
+ return "0";
29840
+ const balanceBn = await getSolanaTokenBalance(userAddress, token.address);
29841
+ return formatBNToReadable(balanceBn, token.decimals);
29842
+ },
29843
+ enabled: enabled &&
29844
+ !!userAddress &&
29845
+ !!token &&
29846
+ chain?.chainType === squidTypes.ChainType.SOLANA,
29847
+ refetchInterval: refreshIntervalMs,
29848
+ retry: 2,
29849
+ });
29850
+ return { balance, isLoading };
29851
+ };
29852
+ // TODO: implement fetching balances for all bitcoin tokens
29853
+ const useBitcoinBalance = ({ userAddress, chain, }) => {
29854
+ const { balance: balanceBn, isLoading } = useBitcoinNativeBalance({
29855
+ address: userAddress,
29856
+ chain,
29857
+ });
29858
+ const balance = React.useMemo(() => {
29859
+ if (!balanceBn)
29860
+ return "0";
29861
+ return formatBNToReadable(balanceBn?.value, balanceBn?.decimals);
29862
+ }, [balanceBn]);
29863
+ return { balance, isLoading };
29864
+ };
29865
+ const useSuiBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
29866
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
29867
+ queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
29868
+ queryFn: async () => {
29869
+ if (!userAddress ||
29870
+ token?.type !== squidTypes.ChainType.SUI ||
29871
+ chain?.chainType !== squidTypes.ChainType.SUI) {
29872
+ throw new Error("Invalid SUI balance query parameters");
29873
+ }
29874
+ const balanceBn = await getSuiTokenBalance(userAddress, token.address, chain.rpc);
29875
+ return formatBNToReadable(balanceBn, token.decimals) ?? "0";
29876
+ },
29877
+ enabled: enabled &&
29878
+ !!userAddress &&
29879
+ !!chain?.rpc &&
29880
+ token?.type === squidTypes.ChainType.SUI &&
29881
+ chain?.chainType === squidTypes.ChainType.SUI &&
29882
+ isSuiAddressValid(userAddress),
29883
+ refetchInterval: refreshIntervalMs,
29884
+ retry: 2,
29885
+ });
29886
+ return { balance, isLoading };
29887
+ };
29888
+ const useXrplBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
29889
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
29890
+ queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
29891
+ queryFn: async () => {
29892
+ if (!userAddress || !token || !chain)
29893
+ return "0";
29894
+ const balanceBn = await getXrplTokenBalance(userAddress, token, chain);
29895
+ return formatBNToReadable(balanceBn, token.decimals) ?? "0";
29896
+ },
29897
+ enabled: enabled &&
29898
+ !!userAddress &&
29899
+ !!token &&
29900
+ !!chain?.rpc &&
29901
+ chain?.chainType === squidTypes.ChainType.XRPL &&
29902
+ isXrplAddressValid(userAddress),
29903
+ refetchInterval: refreshIntervalMs,
29904
+ retry: 2,
29905
+ });
29906
+ return { balance, isLoading };
29907
+ };
29908
+ const useStellarBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
29909
+ const { data: balance = "0", isLoading } = reactQuery.useQuery({
29910
+ queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
29911
+ queryFn: async () => {
29912
+ if (!userAddress || !token || !chain)
29913
+ return "0";
29914
+ const balanceBn = await getStellarTokenBalance(userAddress, token, chain);
29915
+ return formatBNToReadable(balanceBn, token.decimals) ?? "0";
29916
+ },
29917
+ enabled: enabled &&
29918
+ !!userAddress &&
29919
+ !!token &&
29920
+ !!chain?.rpc &&
29921
+ chain?.chainType === squidTypes.ChainType.STELLAR &&
29922
+ isStellarAddressValid(userAddress),
29923
+ refetchInterval: refreshIntervalMs,
29924
+ retry: 2,
29925
+ });
29926
+ return { balance, isLoading };
29927
+ };
29928
+
29929
+ function useNativeTokenForChain(chain) {
29930
+ const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, } = useSquidTokens();
29931
+ const getTokensForChainType = () => {
29932
+ if (!chain?.chainType)
29933
+ return [];
29934
+ switch (chain.chainType) {
29935
+ case squidTypes.ChainType.EVM:
29936
+ return evmTokens;
29937
+ case squidTypes.ChainType.COSMOS:
29938
+ return cosmosTokens;
29939
+ case squidTypes.ChainType.SOLANA:
29940
+ return solanaTokens;
29941
+ case squidTypes.ChainType.BTC:
29942
+ return bitcoinTokens;
29943
+ case squidTypes.ChainType.SUI:
29944
+ return suiTokens;
29945
+ case squidTypes.ChainType.XRPL:
29946
+ return xrplTokens;
29947
+ case squidTypes.ChainType.STELLAR:
29948
+ return stellarTokens;
29949
+ }
29950
+ };
29951
+ const nativeTokenForChainType = React.useMemo(() => {
29952
+ return findNativeToken(getTokensForChainType(), chain);
29953
+ }, [chain]);
29954
+ return { nativeToken: nativeTokenForChainType };
29955
+ }
29956
+
29957
+ const useEvmNativeBalance = ({ address, chain, }) => {
29958
+ const { isChainTypeConnected } = useWallet();
29959
+ const { data: nativeEvmBalance, isLoading } = wagmi.useBalance({
29960
+ address: address,
29961
+ chainId: Number(chain?.chainId),
29962
+ query: {
29963
+ enabled: isChainTypeConnected(squidTypes.ChainType.EVM) && !!address,
29964
+ refetchInterval: 10000,
29965
+ staleTime: 5000,
29966
+ refetchOnWindowFocus: true,
29967
+ refetchOnMount: true,
29968
+ },
29969
+ });
29970
+ const balance = React.useMemo(() => {
29971
+ if (nativeEvmBalance?.decimals && nativeEvmBalance?.value) {
29972
+ return {
29973
+ decimals: nativeEvmBalance.decimals,
29974
+ value: nativeEvmBalance.value,
29975
+ };
29976
+ }
29977
+ return;
29978
+ }, [nativeEvmBalance?.decimals, nativeEvmBalance?.value]);
29979
+ return {
29980
+ balance,
29981
+ isLoading,
29982
+ };
29983
+ };
29984
+ const useCosmosNativeBalance = ({ address, chain, }) => {
29985
+ const { isConnected: isCosmosConnected } = useCosmosContext();
29986
+ const { nativeToken: nativeCosmosToken } = useNativeTokenForChain(chain);
29987
+ const { balance: rawBalance, isLoading } = useCosmosBalance({
29988
+ chain,
29989
+ token: nativeCosmosToken,
29990
+ userAddress: address,
29991
+ enabled: isCosmosConnected && chain?.chainType === squidTypes.ChainType.COSMOS,
29992
+ refreshIntervalMs: 10000,
29993
+ });
29994
+ const balance = React.useMemo(() => {
29995
+ if (nativeCosmosToken?.decimals && rawBalance) {
29996
+ return {
29997
+ decimals: nativeCosmosToken.decimals,
29998
+ value: parseToBigInt(rawBalance, nativeCosmosToken.decimals),
29999
+ };
30000
+ }
30001
+ }, [nativeCosmosToken?.decimals, rawBalance]);
30002
+ return { balance, isLoading };
30003
+ };
30004
+ const useBitcoinNativeBalance = ({ chain, address, }) => {
30005
+ const { nativeToken } = useNativeTokenForChain(chain);
30006
+ const { data: rawBalance = "0", isLoading } = reactQuery.useQuery(keys().balance(chain?.chainId, nativeToken?.address, address), async () => {
30007
+ if (!address || !nativeToken)
30008
+ return "0";
30009
+ const balance = await getBitcoinNativeBalance(address);
30010
+ return formatBNToReadable(balance, nativeToken.decimals);
30011
+ }, {
30012
+ enabled: chain?.chainType === squidTypes.ChainType.BTC &&
30013
+ nativeToken?.decimals != null &&
30014
+ isWalletAddressValid(chain, address),
30015
+ refetchInterval: 40000,
30016
+ staleTime: 20000,
30017
+ refetchOnWindowFocus: true,
30018
+ refetchOnMount: true,
30019
+ });
30020
+ const balance = React.useMemo(() => {
30021
+ if (nativeToken?.decimals && rawBalance) {
30022
+ return {
30023
+ decimals: nativeToken.decimals,
30024
+ value: parseToBigInt(rawBalance, nativeToken.decimals),
30025
+ };
30026
+ }
30027
+ }, [nativeToken?.decimals, rawBalance]);
30028
+ return {
30029
+ balance,
30030
+ isLoading,
30031
+ };
30032
+ };
30033
+ const useSolanaNativeBalance = ({ chain, address, }) => {
30034
+ const { nativeToken } = useNativeTokenForChain(chain);
30035
+ const { data: rawBalance, isLoading } = reactQuery.useQuery(keys().balance(chain?.chainId, nativeToken?.address, address), async () => {
30036
+ const balance = await getSolanaNativeBalance(address);
30037
+ return formatBNToReadable(balance, nativeToken.decimals);
30038
+ }, {
30039
+ enabled: !!address &&
30040
+ nativeToken?.decimals != null &&
30041
+ chain?.chainType === squidTypes.ChainType.SOLANA,
30042
+ refetchInterval: 40000,
30043
+ staleTime: 20000,
30044
+ refetchOnWindowFocus: true,
30045
+ refetchOnMount: true,
30046
+ });
30047
+ const balance = React.useMemo(() => {
30048
+ if (nativeToken?.decimals && rawBalance) {
30049
+ return {
30050
+ decimals: nativeToken.decimals,
30051
+ value: parseToBigInt(rawBalance, nativeToken.decimals),
30052
+ };
30053
+ }
30054
+ }, [nativeToken?.decimals, rawBalance]);
30055
+ return {
30056
+ balance,
30057
+ isLoading,
30058
+ };
30059
+ };
30060
+ const useSuiNativeBalance = ({ address, chain, }) => {
30061
+ const { nativeToken } = useNativeTokenForChain(chain);
30062
+ const { balance: rawBalance, isLoading } = useSuiBalance({
30063
+ chain,
30064
+ token: nativeToken,
30065
+ userAddress: address,
30066
+ });
30067
+ const balance = React.useMemo(() => {
30068
+ if (nativeToken?.decimals && rawBalance) {
30069
+ return {
30070
+ decimals: nativeToken.decimals,
30071
+ value: parseToBigInt(rawBalance, nativeToken.decimals),
30072
+ };
30073
+ }
30074
+ }, [nativeToken?.decimals, rawBalance]);
30075
+ return {
30076
+ balance,
30077
+ isLoading,
30078
+ };
30079
+ };
30080
+ const useXrplNativeBalance = ({ address, chain, }) => {
30081
+ const { nativeToken } = useNativeTokenForChain(chain);
30082
+ const { balance: rawBalance, isLoading } = useXrplBalance({
30083
+ chain,
30084
+ token: nativeToken,
30085
+ userAddress: address,
30086
+ enabled: chain?.chainType === squidTypes.ChainType.XRPL,
30087
+ });
30088
+ const balance = React.useMemo(() => {
30089
+ if (nativeToken?.decimals && rawBalance) {
30090
+ return {
30091
+ decimals: nativeToken.decimals,
30092
+ value: parseToBigInt(rawBalance, nativeToken.decimals),
30093
+ };
30094
+ }
30095
+ }, [nativeToken?.decimals, rawBalance]);
30096
+ return {
30097
+ balance,
30098
+ isLoading,
30099
+ };
30100
+ };
30101
+ const useStellarNativeBalance = ({ address, chain, }) => {
30102
+ const { nativeToken } = useNativeTokenForChain(chain);
30103
+ const { balance: rawBalance, isLoading } = useStellarBalance({
30104
+ chain,
30105
+ token: nativeToken,
30106
+ userAddress: address,
30107
+ enabled: chain?.chainType === squidTypes.ChainType.STELLAR,
30108
+ });
30109
+ const balance = React.useMemo(() => {
30110
+ if (nativeToken?.decimals && rawBalance) {
30111
+ return {
30112
+ decimals: nativeToken.decimals,
30113
+ value: parseToBigInt(rawBalance, nativeToken.decimals),
30114
+ };
30115
+ }
30116
+ }, [nativeToken?.decimals, rawBalance]);
30117
+ return {
30118
+ balance,
30119
+ isLoading,
30120
+ };
30121
+ };
30122
+ const useNativeBalance = (chain) => {
30123
+ const { connectedAddresses } = useWallet();
30124
+ const { data: cosmosAddressForChain } = useCosmosForChain(chain);
30125
+ // Cosmos is a special case because the address changes on every chain
30126
+ // so we can't use the default cosmos connected address
30127
+ const { balance: nativeCosmosBalance, isLoading: isCosmosLoading } = useCosmosNativeBalance({
30128
+ address: cosmosAddressForChain,
30129
+ chain,
30130
+ });
30131
+ const { balance: nativeEvmBalance, isLoading: isEvmLoading } = useEvmNativeBalance({ address: connectedAddresses[squidTypes.ChainType.EVM], chain });
30132
+ const { balance: nativeBitcoinBalance, isLoading: isBitcoinLoading } = useBitcoinNativeBalance({
30133
+ address: connectedAddresses[squidTypes.ChainType.BTC],
30134
+ chain,
30135
+ });
30136
+ const { balance: nativeSolanaBalance, isLoading: isSolanaLoading } = useSolanaNativeBalance({
30137
+ address: connectedAddresses[squidTypes.ChainType.SOLANA],
30138
+ chain,
30139
+ });
30140
+ const { balance: nativeSuiBalance, isLoading: isSuiLoading } = useSuiNativeBalance({
30141
+ address: connectedAddresses[squidTypes.ChainType.SUI],
30142
+ chain,
30143
+ });
30144
+ const { balance: nativeXrplBalance, isLoading: isXrpLoading } = useXrplNativeBalance({
30145
+ address: connectedAddresses[squidTypes.ChainType.XRPL],
30146
+ chain,
30147
+ });
30148
+ const { balance: nativeStellarBalance, isLoading: isStellarLoading } = useStellarNativeBalance({
30149
+ address: connectedAddresses[squidTypes.ChainType.STELLAR],
30150
+ chain,
30151
+ });
30152
+ const { nativeBalance, nativeBalanceFormatted } = React.useMemo(() => {
30153
+ let balance;
30154
+ switch (chain?.chainType) {
30155
+ case squidTypes.ChainType.EVM:
30156
+ balance = nativeEvmBalance;
30157
+ break;
30158
+ case squidTypes.ChainType.COSMOS:
30159
+ balance = nativeCosmosBalance;
30160
+ break;
30161
+ case squidTypes.ChainType.BTC:
30162
+ balance = nativeBitcoinBalance;
30163
+ break;
30164
+ case squidTypes.ChainType.SOLANA:
30165
+ balance = nativeSolanaBalance;
30166
+ break;
30167
+ case squidTypes.ChainType.SUI:
30168
+ balance = nativeSuiBalance;
30169
+ break;
30170
+ case squidTypes.ChainType.XRPL:
30171
+ balance = nativeXrplBalance;
30172
+ break;
30173
+ case squidTypes.ChainType.STELLAR:
30174
+ balance = nativeStellarBalance;
30175
+ }
30176
+ const balanceFormatted = !!balance
30177
+ ? formatBNToReadable(balance.value, balance.decimals)
30178
+ : undefined;
30179
+ return {
30180
+ nativeBalance: balance,
30181
+ nativeBalanceFormatted: balanceFormatted,
30182
+ };
30183
+ }, [
30184
+ chain?.chainType,
30185
+ nativeEvmBalance,
30186
+ nativeCosmosBalance,
30187
+ nativeBitcoinBalance,
30188
+ nativeSolanaBalance,
30189
+ nativeSuiBalance,
30190
+ nativeXrplBalance,
30191
+ nativeStellarBalance,
30192
+ ]);
30193
+ const isLoading = React.useMemo(() => {
30194
+ if (!chain?.chainType)
30195
+ return false;
30196
+ switch (chain.chainType) {
30197
+ case squidTypes.ChainType.EVM:
30198
+ return isEvmLoading;
30199
+ case squidTypes.ChainType.COSMOS:
30200
+ return isCosmosLoading;
30201
+ case squidTypes.ChainType.BTC:
30202
+ return isBitcoinLoading;
30203
+ case squidTypes.ChainType.SOLANA:
30204
+ return isSolanaLoading;
30205
+ case squidTypes.ChainType.SUI:
30206
+ return isSuiLoading;
30207
+ case squidTypes.ChainType.XRPL:
30208
+ return isXrpLoading;
30209
+ case squidTypes.ChainType.STELLAR:
30210
+ return isStellarLoading;
30211
+ }
30212
+ }, [
30213
+ chain?.chainType,
30214
+ isEvmLoading,
30215
+ isCosmosLoading,
30216
+ isBitcoinLoading,
30217
+ isSolanaLoading,
30218
+ isSuiLoading,
30219
+ isXrpLoading,
30220
+ isStellarLoading,
30221
+ ]);
30222
+ return { nativeBalance, nativeBalanceFormatted, isLoading };
30223
+ };
30224
+
30225
+ function useHederaAccountActivation({ address, chain, token }) {
30226
+ const { balance: destNativeEvmBalance } = useEvmNativeBalance({
30227
+ chain,
30228
+ address,
30229
+ });
30230
+ const isHederaAccountActivated = React.useMemo(() => {
30231
+ if (token?.chainId !== CHAIN_IDS.HEDERA)
30232
+ return true;
30233
+ if (token.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase())
30234
+ return true;
30235
+ return (!!destNativeEvmBalance?.value && destNativeEvmBalance.value > BigInt(0));
30236
+ }, [token?.chainId, token?.address, destNativeEvmBalance?.value]);
30237
+ return {
30238
+ isHederaAccountActivated,
30239
+ };
30240
+ }
30241
+
29702
30242
  const useAddressBookStore = zustand.create(middleware.persist((set) => ({
29703
30243
  addressBook: [],
29704
30244
  add: (newAddressData) => {
@@ -30064,473 +30604,6 @@ const useAllConnectedWalletBalances = ({ direction, queryOptions = {
30064
30604
  };
30065
30605
  };
30066
30606
 
30067
- function useNativeTokenForChain(chain) {
30068
- const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, } = useSquidTokens();
30069
- const getTokensForChainType = () => {
30070
- if (!chain?.chainType)
30071
- return [];
30072
- switch (chain.chainType) {
30073
- case squidTypes.ChainType.EVM:
30074
- return evmTokens;
30075
- case squidTypes.ChainType.COSMOS:
30076
- return cosmosTokens;
30077
- case squidTypes.ChainType.SOLANA:
30078
- return solanaTokens;
30079
- case squidTypes.ChainType.BTC:
30080
- return bitcoinTokens;
30081
- case squidTypes.ChainType.SUI:
30082
- return suiTokens;
30083
- case squidTypes.ChainType.XRPL:
30084
- return xrplTokens;
30085
- case squidTypes.ChainType.STELLAR:
30086
- return stellarTokens;
30087
- }
30088
- };
30089
- const nativeTokenForChainType = React.useMemo(() => {
30090
- return findNativeToken(getTokensForChainType(), chain);
30091
- }, [chain]);
30092
- return { nativeToken: nativeTokenForChainType };
30093
- }
30094
-
30095
- const useEvmNativeBalance = ({ address, chain, }) => {
30096
- const { isChainTypeConnected } = useWallet();
30097
- const { data: nativeEvmBalance, isLoading } = wagmi.useBalance({
30098
- address: address,
30099
- chainId: Number(chain?.chainId),
30100
- query: {
30101
- enabled: isChainTypeConnected(squidTypes.ChainType.EVM) && !!address,
30102
- refetchInterval: 10000,
30103
- staleTime: 5000,
30104
- refetchOnWindowFocus: true,
30105
- refetchOnMount: true,
30106
- },
30107
- });
30108
- const balance = React.useMemo(() => {
30109
- if (nativeEvmBalance?.decimals && nativeEvmBalance?.value) {
30110
- return {
30111
- decimals: nativeEvmBalance.decimals,
30112
- value: nativeEvmBalance.value,
30113
- };
30114
- }
30115
- return;
30116
- }, [nativeEvmBalance?.decimals, nativeEvmBalance?.value]);
30117
- return {
30118
- balance,
30119
- isLoading,
30120
- };
30121
- };
30122
- const useCosmosNativeBalance = ({ address, chain, }) => {
30123
- const { isConnected: isCosmosConnected } = useCosmosContext();
30124
- const { nativeToken: nativeCosmosToken } = useNativeTokenForChain(chain);
30125
- const { balance: rawBalance, isLoading } = useCosmosBalance({
30126
- chain,
30127
- token: nativeCosmosToken,
30128
- userAddress: address,
30129
- enabled: isCosmosConnected && chain?.chainType === squidTypes.ChainType.COSMOS,
30130
- refreshIntervalMs: 10000,
30131
- });
30132
- const balance = React.useMemo(() => {
30133
- if (nativeCosmosToken?.decimals && rawBalance) {
30134
- return {
30135
- decimals: nativeCosmosToken.decimals,
30136
- value: parseToBigInt(rawBalance, nativeCosmosToken.decimals),
30137
- };
30138
- }
30139
- }, [nativeCosmosToken?.decimals, rawBalance]);
30140
- return { balance, isLoading };
30141
- };
30142
- const useBitcoinNativeBalance = ({ chain, address, }) => {
30143
- const { nativeToken } = useNativeTokenForChain(chain);
30144
- const { data: rawBalance = "0", isLoading } = reactQuery.useQuery(keys().balance(chain?.chainId, nativeToken?.address, address), async () => {
30145
- if (!address || !nativeToken)
30146
- return "0";
30147
- const balance = await getBitcoinNativeBalance(address);
30148
- return formatBNToReadable(balance, nativeToken.decimals);
30149
- }, {
30150
- enabled: chain?.chainType === squidTypes.ChainType.BTC &&
30151
- nativeToken?.decimals != null &&
30152
- isWalletAddressValid(chain, address),
30153
- refetchInterval: 40000,
30154
- staleTime: 20000,
30155
- refetchOnWindowFocus: true,
30156
- refetchOnMount: true,
30157
- });
30158
- const balance = React.useMemo(() => {
30159
- if (nativeToken?.decimals && rawBalance) {
30160
- return {
30161
- decimals: nativeToken.decimals,
30162
- value: parseToBigInt(rawBalance, nativeToken.decimals),
30163
- };
30164
- }
30165
- }, [nativeToken?.decimals, rawBalance]);
30166
- return {
30167
- balance,
30168
- isLoading,
30169
- };
30170
- };
30171
- const useSolanaNativeBalance = ({ chain, address, }) => {
30172
- const { nativeToken } = useNativeTokenForChain(chain);
30173
- const { data: rawBalance, isLoading } = reactQuery.useQuery(keys().balance(chain?.chainId, nativeToken?.address, address), async () => {
30174
- const balance = await getSolanaNativeBalance(address);
30175
- return formatBNToReadable(balance, nativeToken.decimals);
30176
- }, {
30177
- enabled: !!address &&
30178
- nativeToken?.decimals != null &&
30179
- chain?.chainType === squidTypes.ChainType.SOLANA,
30180
- refetchInterval: 40000,
30181
- staleTime: 20000,
30182
- refetchOnWindowFocus: true,
30183
- refetchOnMount: true,
30184
- });
30185
- const balance = React.useMemo(() => {
30186
- if (nativeToken?.decimals && rawBalance) {
30187
- return {
30188
- decimals: nativeToken.decimals,
30189
- value: parseToBigInt(rawBalance, nativeToken.decimals),
30190
- };
30191
- }
30192
- }, [nativeToken?.decimals, rawBalance]);
30193
- return {
30194
- balance,
30195
- isLoading,
30196
- };
30197
- };
30198
- const useSuiNativeBalance = ({ address, chain, }) => {
30199
- const { nativeToken } = useNativeTokenForChain(chain);
30200
- const { balance: rawBalance, isLoading } = useSuiBalance({
30201
- chain,
30202
- token: nativeToken,
30203
- userAddress: address,
30204
- });
30205
- const balance = React.useMemo(() => {
30206
- if (nativeToken?.decimals && rawBalance) {
30207
- return {
30208
- decimals: nativeToken.decimals,
30209
- value: parseToBigInt(rawBalance, nativeToken.decimals),
30210
- };
30211
- }
30212
- }, [nativeToken?.decimals, rawBalance]);
30213
- return {
30214
- balance,
30215
- isLoading,
30216
- };
30217
- };
30218
- const useXrplNativeBalance = ({ address, chain, }) => {
30219
- const { nativeToken } = useNativeTokenForChain(chain);
30220
- const { balance: rawBalance, isLoading } = useXrplBalance({
30221
- chain,
30222
- token: nativeToken,
30223
- userAddress: address,
30224
- enabled: chain?.chainType === squidTypes.ChainType.XRPL,
30225
- });
30226
- const balance = React.useMemo(() => {
30227
- if (nativeToken?.decimals && rawBalance) {
30228
- return {
30229
- decimals: nativeToken.decimals,
30230
- value: parseToBigInt(rawBalance, nativeToken.decimals),
30231
- };
30232
- }
30233
- }, [nativeToken?.decimals, rawBalance]);
30234
- return {
30235
- balance,
30236
- isLoading,
30237
- };
30238
- };
30239
- const useStellarNativeBalance = ({ address, chain, }) => {
30240
- const { nativeToken } = useNativeTokenForChain(chain);
30241
- const { balance: rawBalance, isLoading } = useStellarBalance({
30242
- chain,
30243
- token: nativeToken,
30244
- userAddress: address,
30245
- enabled: chain?.chainType === squidTypes.ChainType.STELLAR,
30246
- });
30247
- const balance = React.useMemo(() => {
30248
- if (nativeToken?.decimals && rawBalance) {
30249
- return {
30250
- decimals: nativeToken.decimals,
30251
- value: parseToBigInt(rawBalance, nativeToken.decimals),
30252
- };
30253
- }
30254
- }, [nativeToken?.decimals, rawBalance]);
30255
- return {
30256
- balance,
30257
- isLoading,
30258
- };
30259
- };
30260
- const useNativeBalance = (chain) => {
30261
- const { connectedAddresses } = useWallet();
30262
- const { data: cosmosAddressForChain } = useCosmosForChain(chain);
30263
- // Cosmos is a special case because the address changes on every chain
30264
- // so we can't use the default cosmos connected address
30265
- const { balance: nativeCosmosBalance, isLoading: isCosmosLoading } = useCosmosNativeBalance({
30266
- address: cosmosAddressForChain,
30267
- chain,
30268
- });
30269
- const { balance: nativeEvmBalance, isLoading: isEvmLoading } = useEvmNativeBalance({ address: connectedAddresses[squidTypes.ChainType.EVM], chain });
30270
- const { balance: nativeBitcoinBalance, isLoading: isBitcoinLoading } = useBitcoinNativeBalance({
30271
- address: connectedAddresses[squidTypes.ChainType.BTC],
30272
- chain,
30273
- });
30274
- const { balance: nativeSolanaBalance, isLoading: isSolanaLoading } = useSolanaNativeBalance({
30275
- address: connectedAddresses[squidTypes.ChainType.SOLANA],
30276
- chain,
30277
- });
30278
- const { balance: nativeSuiBalance, isLoading: isSuiLoading } = useSuiNativeBalance({
30279
- address: connectedAddresses[squidTypes.ChainType.SUI],
30280
- chain,
30281
- });
30282
- const { balance: nativeXrplBalance, isLoading: isXrpLoading } = useXrplNativeBalance({
30283
- address: connectedAddresses[squidTypes.ChainType.XRPL],
30284
- chain,
30285
- });
30286
- const { balance: nativeStellarBalance, isLoading: isStellarLoading } = useStellarNativeBalance({
30287
- address: connectedAddresses[squidTypes.ChainType.STELLAR],
30288
- chain,
30289
- });
30290
- const { nativeBalance, nativeBalanceFormatted } = React.useMemo(() => {
30291
- let balance;
30292
- switch (chain?.chainType) {
30293
- case squidTypes.ChainType.EVM:
30294
- balance = nativeEvmBalance;
30295
- break;
30296
- case squidTypes.ChainType.COSMOS:
30297
- balance = nativeCosmosBalance;
30298
- break;
30299
- case squidTypes.ChainType.BTC:
30300
- balance = nativeBitcoinBalance;
30301
- break;
30302
- case squidTypes.ChainType.SOLANA:
30303
- balance = nativeSolanaBalance;
30304
- break;
30305
- case squidTypes.ChainType.SUI:
30306
- balance = nativeSuiBalance;
30307
- break;
30308
- case squidTypes.ChainType.XRPL:
30309
- balance = nativeXrplBalance;
30310
- break;
30311
- case squidTypes.ChainType.STELLAR:
30312
- balance = nativeStellarBalance;
30313
- }
30314
- const balanceFormatted = !!balance
30315
- ? formatBNToReadable(balance.value, balance.decimals)
30316
- : undefined;
30317
- return {
30318
- nativeBalance: balance,
30319
- nativeBalanceFormatted: balanceFormatted,
30320
- };
30321
- }, [
30322
- chain?.chainType,
30323
- nativeEvmBalance,
30324
- nativeCosmosBalance,
30325
- nativeBitcoinBalance,
30326
- nativeSolanaBalance,
30327
- nativeSuiBalance,
30328
- nativeXrplBalance,
30329
- nativeStellarBalance,
30330
- ]);
30331
- const isLoading = React.useMemo(() => {
30332
- if (!chain?.chainType)
30333
- return false;
30334
- switch (chain.chainType) {
30335
- case squidTypes.ChainType.EVM:
30336
- return isEvmLoading;
30337
- case squidTypes.ChainType.COSMOS:
30338
- return isCosmosLoading;
30339
- case squidTypes.ChainType.BTC:
30340
- return isBitcoinLoading;
30341
- case squidTypes.ChainType.SOLANA:
30342
- return isSolanaLoading;
30343
- case squidTypes.ChainType.SUI:
30344
- return isSuiLoading;
30345
- case squidTypes.ChainType.XRPL:
30346
- return isXrpLoading;
30347
- case squidTypes.ChainType.STELLAR:
30348
- return isStellarLoading;
30349
- }
30350
- }, [
30351
- chain?.chainType,
30352
- isEvmLoading,
30353
- isCosmosLoading,
30354
- isBitcoinLoading,
30355
- isSolanaLoading,
30356
- isSuiLoading,
30357
- isXrpLoading,
30358
- isStellarLoading,
30359
- ]);
30360
- return { nativeBalance, nativeBalanceFormatted, isLoading };
30361
- };
30362
-
30363
- const DEFAULT_REFRESH_INTERVAL_MS = 15000;
30364
- const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
30365
- const { isChainTypeConnected } = useWallet();
30366
- const isNativeToken = token?.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
30367
- const userAddressParsed = userAddress;
30368
- // Only fetch using useBalance if it's a native token
30369
- const { data: nativeBalance, isLoading: isNativeTokenLoading } = wagmi.useBalance({
30370
- address: userAddressParsed,
30371
- chainId: Number(chain?.chainId),
30372
- query: {
30373
- enabled: enabled &&
30374
- !!userAddress &&
30375
- isNativeToken &&
30376
- !!chain &&
30377
- chain.chainType === squidTypes.ChainType.EVM &&
30378
- isChainTypeConnected(chain.chainType),
30379
- refetchInterval: refreshIntervalMs,
30380
- retry: 2,
30381
- },
30382
- });
30383
- // Only fetch using useReadContract if it's not a native token
30384
- // This is temporary, because of wagmi error: https://github.com/wevm/wagmi/issues/4353
30385
- const { data: erc20Balance, isLoading: isErc20Loading } = wagmi.useReadContract({
30386
- address: token?.address,
30387
- abi: viem.erc20Abi,
30388
- functionName: "balanceOf",
30389
- args: [userAddressParsed],
30390
- chainId: Number(chain?.chainId),
30391
- query: {
30392
- enabled: isChainTypeConnected(squidTypes.ChainType.EVM) &&
30393
- enabled &&
30394
- !!userAddress &&
30395
- !isNativeToken,
30396
- refetchInterval: refreshIntervalMs,
30397
- retry: 2,
30398
- },
30399
- });
30400
- if (isNativeToken) {
30401
- return {
30402
- isLoading: isNativeTokenLoading,
30403
- balance: nativeBalance
30404
- ? formatBNToReadable(nativeBalance.value, nativeBalance.decimals)
30405
- : "0",
30406
- };
30407
- }
30408
- return {
30409
- balance: erc20Balance && token
30410
- ? formatBNToReadable(erc20Balance, token.decimals)
30411
- : "0",
30412
- isLoading: isErc20Loading,
30413
- };
30414
- };
30415
- const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
30416
- const { isConnected } = useCosmosContext();
30417
- const { data: balance = "0", isLoading } = reactQuery.useQuery({
30418
- queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
30419
- queryFn: async () => {
30420
- if (!userAddress || !token || chain?.chainType !== squidTypes.ChainType.COSMOS) {
30421
- return "0";
30422
- }
30423
- const isAddressValid = isCosmosAddressValid(chain.bech32Config.bech32PrefixAccAddr, userAddress);
30424
- if (!isAddressValid)
30425
- return "0";
30426
- const balanceBn = await getCosmosTokenBalance(chain, userAddress, token.address);
30427
- return formatBNToReadable(balanceBn, token.decimals);
30428
- },
30429
- enabled: isConnected &&
30430
- enabled &&
30431
- !!userAddress &&
30432
- !!token &&
30433
- chain?.chainType === squidTypes.ChainType.COSMOS,
30434
- refetchInterval: refreshIntervalMs,
30435
- retry: 2,
30436
- });
30437
- return { balance, isLoading };
30438
- };
30439
- const useSolanaBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
30440
- const { data: balance = "0", isLoading } = reactQuery.useQuery({
30441
- queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
30442
- queryFn: async () => {
30443
- if (!userAddress || !token)
30444
- return "0";
30445
- const balanceBn = await getSolanaTokenBalance(userAddress, token.address);
30446
- return formatBNToReadable(balanceBn, token.decimals);
30447
- },
30448
- enabled: enabled &&
30449
- !!userAddress &&
30450
- !!token &&
30451
- chain?.chainType === squidTypes.ChainType.SOLANA,
30452
- refetchInterval: refreshIntervalMs,
30453
- retry: 2,
30454
- });
30455
- return { balance, isLoading };
30456
- };
30457
- // TODO: implement fetching balances for all bitcoin tokens
30458
- const useBitcoinBalance = ({ userAddress, chain, }) => {
30459
- const { balance: balanceBn, isLoading } = useBitcoinNativeBalance({
30460
- address: userAddress,
30461
- chain,
30462
- });
30463
- const balance = React.useMemo(() => {
30464
- if (!balanceBn)
30465
- return "0";
30466
- return formatBNToReadable(balanceBn?.value, balanceBn?.decimals);
30467
- }, [balanceBn]);
30468
- return { balance, isLoading };
30469
- };
30470
- const useSuiBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
30471
- const { data: balance = "0", isLoading } = reactQuery.useQuery({
30472
- queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
30473
- queryFn: async () => {
30474
- if (!userAddress ||
30475
- token?.type !== squidTypes.ChainType.SUI ||
30476
- chain?.chainType !== squidTypes.ChainType.SUI) {
30477
- throw new Error("Invalid SUI balance query parameters");
30478
- }
30479
- const balanceBn = await getSuiTokenBalance(userAddress, token.address, chain.rpc);
30480
- return formatBNToReadable(balanceBn, token.decimals) ?? "0";
30481
- },
30482
- enabled: enabled &&
30483
- !!userAddress &&
30484
- !!chain?.rpc &&
30485
- token?.type === squidTypes.ChainType.SUI &&
30486
- chain?.chainType === squidTypes.ChainType.SUI &&
30487
- isSuiAddressValid(userAddress),
30488
- refetchInterval: refreshIntervalMs,
30489
- retry: 2,
30490
- });
30491
- return { balance, isLoading };
30492
- };
30493
- const useXrplBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
30494
- const { data: balance = "0", isLoading } = reactQuery.useQuery({
30495
- queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
30496
- queryFn: async () => {
30497
- if (!userAddress || !token || !chain)
30498
- return "0";
30499
- const balanceBn = await getXrplTokenBalance(userAddress, token, chain);
30500
- return formatBNToReadable(balanceBn, token.decimals) ?? "0";
30501
- },
30502
- enabled: enabled &&
30503
- !!userAddress &&
30504
- !!token &&
30505
- !!chain?.rpc &&
30506
- chain?.chainType === squidTypes.ChainType.XRPL &&
30507
- isXrplAddressValid(userAddress),
30508
- refetchInterval: refreshIntervalMs,
30509
- retry: 2,
30510
- });
30511
- return { balance, isLoading };
30512
- };
30513
- const useStellarBalance = ({ userAddress, chain, enabled, token, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
30514
- const { data: balance = "0", isLoading } = reactQuery.useQuery({
30515
- queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
30516
- queryFn: async () => {
30517
- if (!userAddress || !token || !chain)
30518
- return "0";
30519
- const balanceBn = await getStellarTokenBalance(userAddress, token, chain);
30520
- return formatBNToReadable(balanceBn, token.decimals) ?? "0";
30521
- },
30522
- enabled: enabled &&
30523
- !!userAddress &&
30524
- !!token &&
30525
- !!chain?.rpc &&
30526
- chain?.chainType === squidTypes.ChainType.STELLAR &&
30527
- isStellarAddressValid(userAddress),
30528
- refetchInterval: refreshIntervalMs,
30529
- retry: 2,
30530
- });
30531
- return { balance, isLoading };
30532
- };
30533
-
30534
30607
  /**
30535
30608
  * Hook to get balance depending on the chain type
30536
30609
  * @param {ChainData} chain
@@ -31043,6 +31116,10 @@ function useSendTransactionGas({ chain, token, from, }) {
31043
31116
  const feeData = await client.getFeeData();
31044
31117
  if (!feeData.maxFeePerGas)
31045
31118
  return BigInt(0);
31119
+ let maxFeePerGas = feeData.maxFeePerGas;
31120
+ if (token.chainId === CHAIN_IDS.HEDERA) {
31121
+ maxFeePerGas = scaleWeiToHbar(BigInt(feeData.maxFeePerGas));
31122
+ }
31046
31123
  const dummyAddress = "0x1111111111111111111111111111111111111111";
31047
31124
  // Some RPC providers require the sender to have enough balance, otherwise estimation reverts
31048
31125
  // so we'll try to use the user provided address when possible
@@ -31054,7 +31131,7 @@ function useSendTransactionGas({ chain, token, from, }) {
31054
31131
  value: 1,
31055
31132
  chainId: chain.chainId,
31056
31133
  });
31057
- return gas * feeData.maxFeePerGas;
31134
+ return gas * maxFeePerGas;
31058
31135
  }
31059
31136
  const erc20Interface = new ethers.Interface(viem.erc20Abi);
31060
31137
  const data = erc20Interface.encodeFunctionData("transfer", [
@@ -31067,7 +31144,7 @@ function useSendTransactionGas({ chain, token, from, }) {
31067
31144
  data,
31068
31145
  chainId: chain.chainId,
31069
31146
  });
31070
- return gas * feeData.maxFeePerGas;
31147
+ return gas * maxFeePerGas;
31071
31148
  }
31072
31149
  case squidTypes.ChainType.COSMOS: {
31073
31150
  // TODO: get gas estimation from backend
@@ -31163,9 +31240,13 @@ function useEstimateSendTransaction({ chain, token, amount, balance, from, }) {
31163
31240
  async function sendTransactionEvm({ to, amount, token, signer, rpcUrl, }) {
31164
31241
  const isNativeToken = token.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
31165
31242
  if (isNativeToken) {
31243
+ let value = amount;
31244
+ if (token.chainId === CHAIN_IDS.HEDERA) {
31245
+ value = scaleHbarToWei(BigInt(amount)).toString();
31246
+ }
31166
31247
  const tx = await signer.sendTransaction({
31167
31248
  to,
31168
- value: amount,
31249
+ value,
31169
31250
  chainId: Number(token.chainId),
31170
31251
  });
31171
31252
  return {
@@ -31993,7 +32074,12 @@ const useErc20Allowance = ({ tokenAddress, ownerAddress, spenderAddress, amount
31993
32074
  const parsedOwnerAddress = parseEvmAddress(ownerAddress);
31994
32075
  const parsedSpenderAddress = parseEvmAddress(spenderAddress);
31995
32076
  const isNativeToken = parsedTokenAddress?.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
31996
- const isDepositAddressTx = transactionType === squidTypes.SquidDataType.DepositAddressCalldata;
32077
+ const isDepositAddressTx = !!transactionType &&
32078
+ [
32079
+ squidTypes.SquidDataType.DepositAddressCalldata,
32080
+ squidTypes.SquidDataType.DepositAddressWithSignature,
32081
+ squidTypes.SquidDataType.DepositAddressWithMemo,
32082
+ ].includes(transactionType);
31997
32083
  const result = wagmi.useReadContract({
31998
32084
  abi: viem.erc20Abi,
31999
32085
  address: parsedTokenAddress ?? undefined,
@@ -35279,7 +35365,7 @@ const useExecuteTransaction = (squidRoute) => {
35279
35365
  * Set the transaction state in the store
35280
35366
  * This is useful to access the latest transaction from any hook
35281
35367
  */
35282
- const setTransactionState = React.useCallback(({ route, txHash, transactionIdForStatus, nonce, status, sourceStatus, userAddress, axelarUrl, id, }) => {
35368
+ const setTransactionState = React.useCallback(({ route, txHash, transactionIdForStatus, nonce, status, sourceStatus, userAddress, axelarUrl, id, depositTxVerificationSignature, }) => {
35283
35369
  if (!route?.transactionRequest)
35284
35370
  return undefined;
35285
35371
  const { quoteId } = route;
@@ -35298,10 +35384,11 @@ const useExecuteTransaction = (squidRoute) => {
35298
35384
  sourceTxExplorerUrl: getSourceExplorerTxUrl(fromChain, txHash),
35299
35385
  sourceExplorerImgUrl: fromChain?.chainIconURI,
35300
35386
  axelarUrl,
35387
+ depositTxVerificationSignature,
35301
35388
  };
35302
35389
  setTransactionStoreState(id, tx);
35303
35390
  return tx;
35304
- }, [fromChain, setTransactionStoreState, toChain]);
35391
+ }, [fromChain, toChain, setTransactionStoreState]);
35305
35392
  const getCosmosSignerClient = React.useCallback(async () => {
35306
35393
  if (!fromChain)
35307
35394
  return null;
@@ -35479,6 +35566,7 @@ const useExecuteTransaction = (squidRoute) => {
35479
35566
  sourceStatus: exports.TransactionStatus.ONGOING,
35480
35567
  axelarUrl: undefined,
35481
35568
  id,
35569
+ depositTxVerificationSignature: txResponse.depositTxVerificationSignature,
35482
35570
  });
35483
35571
  if (txParams) {
35484
35572
  addSwapTransaction({
@@ -35673,7 +35761,7 @@ const useExecuteTransaction = (squidRoute) => {
35673
35761
  if (!route?.transactionRequest || !xrplSigner) {
35674
35762
  throw new Error("Need all parameters");
35675
35763
  }
35676
- if (route.transactionRequest.type !== squidTypes.SquidDataType.OnChainExecution) {
35764
+ if (!isOnChainTxData(route.transactionRequest)) {
35677
35765
  throw new Error("Invalid route type");
35678
35766
  }
35679
35767
  const { data } = route.transactionRequest;
@@ -35709,10 +35797,10 @@ const useExecuteTransaction = (squidRoute) => {
35709
35797
  }
35710
35798
  }, {});
35711
35799
  const swapMutationSui = reactQuery.useMutation(async ({ id, route }) => {
35712
- if (!route || !suiSigner || !fromChain) {
35800
+ if (!route?.transactionRequest || !suiSigner || !fromChain) {
35713
35801
  throw new Error("Need all parameters");
35714
35802
  }
35715
- if (route.transactionRequest?.type !== squidTypes.SquidDataType.OnChainExecution) {
35803
+ if (!isOnChainTxData(route.transactionRequest)) {
35716
35804
  throw new Error("Invalid route type");
35717
35805
  }
35718
35806
  const suiWalletState = connectedWalletsByChainType[squidTypes.ChainType.SUI];
@@ -35763,9 +35851,15 @@ const useExecuteTransaction = (squidRoute) => {
35763
35851
  });
35764
35852
  }, {});
35765
35853
  const swapMutationStellar = reactQuery.useMutation(async ({ id, route }) => {
35766
- if (!stellarSigner || !route || !squid || !fromChain) {
35854
+ if (!stellarSigner ||
35855
+ !route?.transactionRequest ||
35856
+ !squid ||
35857
+ !fromChain) {
35767
35858
  throw new Error("Need all parameters");
35768
35859
  }
35860
+ if (!isOnChainTxData(route.transactionRequest)) {
35861
+ throw new Error("Invalid route type");
35862
+ }
35769
35863
  const fromChainId = route.params.fromChain;
35770
35864
  const stellarNetwork = getStellarNetwork(fromChainId);
35771
35865
  if (stellarNetwork == null) {
@@ -35868,11 +35962,13 @@ const useExecuteTransaction = (squidRoute) => {
35868
35962
  squidRoute,
35869
35963
  ]);
35870
35964
  const swapMutation = reactQuery.useMutation(async (mutationParams) => {
35871
- if (!mutationParams.route)
35872
- throw new Error("route is required");
35965
+ if (!mutationParams.route?.transactionRequest) {
35966
+ throw new Error("Route is required");
35967
+ }
35873
35968
  const sourceChain = findChain(mutationParams.route.params?.fromChain);
35874
35969
  if (!sourceChain)
35875
35970
  throw new Error("Could not find source chain");
35971
+ // After getting signature (if needed), continue with the swap flow
35876
35972
  switch (sourceChain.chainType) {
35877
35973
  case squidTypes.ChainType.COSMOS: {
35878
35974
  return swapMutationCosmos.mutateAsync(mutationParams);
@@ -36061,7 +36157,7 @@ const useGetRoute = () => {
36061
36157
  };
36062
36158
  const useGetRouteWrapper = ({ enabled, cacheTime = 5 * 60 * 1000, // 5 minutes
36063
36159
  staleTime = 60 * 1000, // 1 minute
36064
- refetchOnWindowFocus = (query) => Date.now() - query.state.dataUpdatedAt > 30000, // Update if older than 30 seconds, when window is focused
36160
+ refetchOnWindowFocus = (query) => Date.now() - query.state.dataUpdatedAt > DEFAULT_ROUTE_REFETCH_INTERVAL, // Update if older than default refetch interval, when window is focused
36065
36161
  refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true, }) => {
36066
36162
  const config = useConfigStore((state) => state.config);
36067
36163
  const squid = useSquidStore((state) => state.squid);
@@ -36816,6 +36912,7 @@ const SquidProvider = ({ children, config, placeholder, }) => {
36816
36912
  exports.CHAIN_IDS = CHAIN_IDS;
36817
36913
  exports.CosmosProvider = CosmosProvider;
36818
36914
  exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
36915
+ exports.DEFAULT_ROUTE_REFETCH_INTERVAL = DEFAULT_ROUTE_REFETCH_INTERVAL;
36819
36916
  exports.EnsService = EnsService;
36820
36917
  exports.EvmNetworkNotSupportedErrorCode = EvmNetworkNotSupportedErrorCode;
36821
36918
  exports.FINAL_TRANSACTION_STATUSES = FINAL_TRANSACTION_STATUSES;
@@ -36897,6 +36994,7 @@ exports.getMainExplorerUrl = getMainExplorerUrl;
36897
36994
  exports.getNewSwapParamsFromInput = getNewSwapParamsFromInput;
36898
36995
  exports.getNumericValue = getNumericValue;
36899
36996
  exports.getQueryHeaders = getQueryHeaders;
36997
+ exports.getRouteExpiry = getRouteExpiry;
36900
36998
  exports.getSecretNetworkBalances = getSecretNetworkBalances;
36901
36999
  exports.getSendTxStatusRefetchInterval = getSendTxStatusRefetchInterval;
36902
37000
  exports.getSourceExplorerTxUrl = getSourceExplorerTxUrl;
@@ -36925,6 +37023,7 @@ exports.isChainflipBridgeTransaction = isChainflipBridgeTransaction;
36925
37023
  exports.isCoralBridgeAction = isCoralBridgeAction;
36926
37024
  exports.isCosmosAddressValid = isCosmosAddressValid;
36927
37025
  exports.isDepositRoute = isDepositRoute;
37026
+ exports.isDepositWithSignatureTxData = isDepositWithSignatureTxData;
36928
37027
  exports.isEmptyObject = isEmptyObject;
36929
37028
  exports.isEvmChainNotSupportedError = isEvmChainNotSupportedError;
36930
37029
  exports.isEvmosChain = isEvmosChain;
@@ -36933,6 +37032,7 @@ exports.isHistoryTransactionEnded = isHistoryTransactionEnded;
36933
37032
  exports.isHistoryTransactionFailed = isHistoryTransactionFailed;
36934
37033
  exports.isHistoryTransactionPending = isHistoryTransactionPending;
36935
37034
  exports.isHistoryTransactionWarning = isHistoryTransactionWarning;
37035
+ exports.isOnChainTxData = isOnChainTxData;
36936
37036
  exports.isProblematicConnector = isProblematicConnector;
36937
37037
  exports.isSolanaAddressValid = isSolanaAddressValid;
36938
37038
  exports.isStatusError = isStatusError;
@@ -36960,6 +37060,8 @@ exports.populateWallets = populateWallets;
36960
37060
  exports.randomIntFromInterval = randomIntFromInterval;
36961
37061
  exports.redirectToExtensionsStore = redirectToExtensionsStore;
36962
37062
  exports.roundNumericValue = roundNumericValue;
37063
+ exports.scaleHbarToWei = scaleHbarToWei;
37064
+ exports.scaleWeiToHbar = scaleWeiToHbar;
36963
37065
  exports.searchTokens = searchTokens;
36964
37066
  exports.shareSubgraphId = shareSubgraphId;
36965
37067
  exports.simplifyRouteAction = simplifyRouteAction;
@@ -36981,11 +37083,13 @@ exports.useAssetsColorsStore = useAssetsColorsStore;
36981
37083
  exports.useAutoConnect = useAutoConnect;
36982
37084
  exports.useAvailableQuotes = useAvailableQuotes;
36983
37085
  exports.useAvatar = useAvatar;
37086
+ exports.useBitcoinNativeBalance = useBitcoinNativeBalance;
36984
37087
  exports.useClient = useClient;
36985
37088
  exports.useConfigStore = useConfigStore;
36986
37089
  exports.useCosmosBalance = useCosmosBalance;
36987
37090
  exports.useCosmosContext = useCosmosContext;
36988
37091
  exports.useCosmosForChain = useCosmosForChain;
37092
+ exports.useCosmosNativeBalance = useCosmosNativeBalance;
36989
37093
  exports.useCountryDetails = useCountryDetails;
36990
37094
  exports.useCurrencyDetails = useCurrencyDetails;
36991
37095
  exports.useDebouncedValue = useDebouncedValue;
@@ -36996,6 +37100,7 @@ exports.useEstimate = useEstimate;
36996
37100
  exports.useEstimatePriceImpact = useEstimatePriceImpact;
36997
37101
  exports.useEstimateSendTransaction = useEstimateSendTransaction;
36998
37102
  exports.useEvmBalance = useEvmBalance;
37103
+ exports.useEvmNativeBalance = useEvmNativeBalance;
36999
37104
  exports.useExecuteFiatQuote = useExecuteFiatQuote;
37000
37105
  exports.useExecuteTransaction = useExecuteTransaction;
37001
37106
  exports.useFavoriteTokensStore = useFavoriteTokensStore;
@@ -37007,6 +37112,7 @@ exports.useGetOnrampPaymentTypes = useGetOnrampPaymentTypes;
37007
37112
  exports.useGetRoute = useGetRoute;
37008
37113
  exports.useGetRouteWrapper = useGetRouteWrapper;
37009
37114
  exports.useGnosisContext = useGnosisContext;
37115
+ exports.useHederaAccountActivation = useHederaAccountActivation;
37010
37116
  exports.useHederaTokenAssociations = useHederaTokenAssociations;
37011
37117
  exports.useHistoricalData = useHistoricalData;
37012
37118
  exports.useHistory = useHistory;
@@ -37027,13 +37133,16 @@ exports.useSendTransactionStatus = useSendTransactionStatus;
37027
37133
  exports.useSendTransactionStore = useSendTransactionStore;
37028
37134
  exports.useSigner = useSigner;
37029
37135
  exports.useSingleTokenPrice = useSingleTokenPrice;
37136
+ exports.useSolanaNativeBalance = useSolanaNativeBalance;
37030
37137
  exports.useSquid = useSquid;
37031
37138
  exports.useSquidChains = useSquidChains;
37032
37139
  exports.useSquidQueryClient = useSquidQueryClient;
37033
37140
  exports.useSquidStore = useSquidStore;
37034
37141
  exports.useSquidTokens = useSquidTokens;
37035
37142
  exports.useStellarAccountActivation = useStellarAccountActivation;
37143
+ exports.useStellarNativeBalance = useStellarNativeBalance;
37036
37144
  exports.useSuggestedFiatAmounts = useSuggestedFiatAmounts;
37145
+ exports.useSuiNativeBalance = useSuiNativeBalance;
37037
37146
  exports.useSwap = useSwap;
37038
37147
  exports.useSwapRoutePersistStore = useSwapRoutePersistStore;
37039
37148
  exports.useSwapTransactionStatus = useSwapTransactionStatus;
@@ -37044,8 +37153,9 @@ exports.useUserParams = useUserParams;
37044
37153
  exports.useWallet = useWallet;
37045
37154
  exports.useWalletStore = useWalletStore;
37046
37155
  exports.useWallets = useWallets;
37156
+ exports.useXrplNativeBalance = useXrplNativeBalance;
37047
37157
  exports.useXrplTrustLine = useXrplTrustLine;
37048
37158
  exports.waitForReceiptWithRetry = waitForReceiptWithRetry;
37049
37159
  exports.walletIconBaseUrl = walletIconBaseUrl;
37050
37160
  exports.walletSupportsChainType = walletSupportsChainType;
37051
- //# sourceMappingURL=index-qAOvcSon.js.map
37161
+ //# sourceMappingURL=index-BdrSk8Ed.js.map