@ensofinance/checkout-widget 0.0.16 → 0.0.18

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 (195) hide show
  1. package/dist/checkout-widget.es.js +22025 -33937
  2. package/dist/checkout-widget.es.js.map +1 -1
  3. package/dist/checkout-widget.umd.js +61 -46
  4. package/dist/checkout-widget.umd.js.map +1 -1
  5. package/dist/index.d.ts +3 -1
  6. package/orval.config.ts +14 -9
  7. package/package.json +2 -2
  8. package/src/components/Checkout.tsx +3 -2
  9. package/src/components/steps/ExchangeFlow.tsx +526 -157
  10. package/src/enso-api/api.ts +19 -42
  11. package/src/enso-api/index.ts +1114 -1070
  12. package/src/enso-api/model/action.ts +1 -1
  13. package/src/enso-api/model/actionAction.ts +3 -1
  14. package/src/enso-api/model/actionInputs.ts +1 -1
  15. package/src/enso-api/model/actionToBundle.ts +1 -1
  16. package/src/enso-api/model/actionToBundleAction.ts +3 -1
  17. package/src/enso-api/model/actionToBundleArgs.ts +1 -1
  18. package/src/enso-api/model/approveActionDto.ts +1 -1
  19. package/src/enso-api/model/approveArgsDto.ts +1 -1
  20. package/src/enso-api/model/approveArgsDtoAmount.ts +1 -1
  21. package/src/enso-api/model/balanceActionDto.ts +1 -1
  22. package/src/enso-api/model/balanceArgsDto.ts +1 -1
  23. package/src/enso-api/model/borrowActionDto.ts +1 -1
  24. package/src/enso-api/model/borrowArgsDto.ts +1 -1
  25. package/src/enso-api/model/borrowArgsDtoAmountOut.ts +1 -1
  26. package/src/enso-api/model/bridgeActionDto.ts +1 -1
  27. package/src/enso-api/model/bridgeArgsDto.ts +1 -1
  28. package/src/enso-api/model/bridgeArgsDtoAmountIn.ts +1 -1
  29. package/src/enso-api/model/bridgeArgsDtoCallbackItem.ts +1 -1
  30. package/src/enso-api/model/bridgeLatencyEstimate.ts +33 -0
  31. package/src/enso-api/model/bridgeTransactionResponse.ts +37 -0
  32. package/src/enso-api/model/bridgeTransactionResponseStatus.ts +25 -0
  33. package/src/enso-api/model/bundleControllerBundleShortcutTransactionBodyItem.ts +1 -1
  34. package/src/enso-api/model/bundleControllerBundleShortcutTransactionParams.ts +1 -1
  35. package/src/enso-api/model/bundleControllerBundleShortcutTransactionRoutingStrategy.ts +2 -2
  36. package/src/enso-api/model/bundleShortcutTransaction.ts +13 -4
  37. package/src/enso-api/model/bundleShortcutTransactionAmountsOut.ts +1 -1
  38. package/src/enso-api/model/bundleShortcutTransactionFeeAmount.ts +1 -1
  39. package/src/enso-api/model/bundleShortcutTransactionMinAmountsOut.ts +15 -0
  40. package/src/enso-api/model/callActionDto.ts +1 -1
  41. package/src/enso-api/model/callArgsDto.ts +1 -1
  42. package/src/enso-api/model/callArgsDtoArgsItem.ts +1 -1
  43. package/src/enso-api/model/callArgsDtoArgsItemAnyOf.ts +1 -1
  44. package/src/enso-api/model/callArgsDtoValue.ts +1 -1
  45. package/src/enso-api/model/callOutput.ts +1 -1
  46. package/src/enso-api/model/connectedNetwork.ts +1 -1
  47. package/src/enso-api/model/depositActionDto.ts +1 -1
  48. package/src/enso-api/model/depositArgsDto.ts +1 -1
  49. package/src/enso-api/model/depositArgsDtoAmountIn.ts +1 -1
  50. package/src/enso-api/model/depositArgsDtoAmountInOneOfItem.ts +1 -1
  51. package/src/enso-api/model/depositArgsDtoTokenIn.ts +1 -1
  52. package/src/enso-api/model/depositArgsDtoTokenOut.ts +1 -1
  53. package/src/enso-api/model/depositCLMMActionDto.ts +1 -1
  54. package/src/enso-api/model/depositCLMMArgsDto.ts +1 -1
  55. package/src/enso-api/model/depositCLMMArgsDtoAmountInItem.ts +1 -1
  56. package/src/enso-api/model/depositCLMMArgsDtoAmountInItemAnyOf.ts +1 -1
  57. package/src/enso-api/model/ensoEvent.ts +30 -0
  58. package/src/enso-api/model/ensoFeeActionDto.ts +1 -1
  59. package/src/enso-api/model/ensoFeeArgsDto.ts +1 -1
  60. package/src/enso-api/model/ensoFeeArgsDtoAmount.ts +1 -1
  61. package/src/enso-api/model/ensoMetadata.ts +23 -0
  62. package/src/enso-api/model/feeActionDto.ts +1 -1
  63. package/src/enso-api/model/feeArgsDto.ts +1 -1
  64. package/src/enso-api/model/feeArgsDtoAmount.ts +1 -1
  65. package/src/enso-api/model/harvestActionDto.ts +1 -1
  66. package/src/enso-api/model/harvestArgsDto.ts +1 -1
  67. package/src/enso-api/model/hop.ts +1 -1
  68. package/src/enso-api/model/hopArgs.ts +1 -1
  69. package/src/enso-api/model/index.ts +63 -54
  70. package/src/enso-api/model/iporControllerIporShortcutTransactionParams.ts +1 -1
  71. package/src/enso-api/model/iporShortcutInput.ts +1 -1
  72. package/src/enso-api/model/iporShortcutTransaction.ts +1 -1
  73. package/src/enso-api/model/lZDestinationTokenData.ts +1 -1
  74. package/src/enso-api/model/lZPoolLookupResponse.ts +1 -1
  75. package/src/enso-api/model/layerZeroControllerCheckBridgeTransactionParams.ts +21 -0
  76. package/src/enso-api/model/layerZeroControllerGetPoolAddressParams.ts +1 -1
  77. package/src/enso-api/model/layerZeroMessageStatus.ts +39 -0
  78. package/src/enso-api/model/mergeActionDto.ts +1 -1
  79. package/src/enso-api/model/mergeArgsDto.ts +1 -1
  80. package/src/enso-api/model/mergeArgsDtoAmountInItem.ts +1 -1
  81. package/src/enso-api/model/minAmountOutActionDto.ts +1 -1
  82. package/src/enso-api/model/minAmountOutArgsDto.ts +1 -1
  83. package/src/enso-api/model/minAmountOutArgsDtoAmountOut.ts +1 -1
  84. package/src/enso-api/model/minAmountOutArgsDtoMinAmountOut.ts +1 -1
  85. package/src/enso-api/model/multiDepositActionDto.ts +1 -1
  86. package/src/enso-api/model/multiDepositArgsDto.ts +1 -1
  87. package/src/enso-api/model/multiDepositArgsDtoAmountInItem.ts +1 -1
  88. package/src/enso-api/model/multiDepositArgsDtoAmountInItemAnyOf.ts +1 -1
  89. package/src/enso-api/model/multiOutSingleDepositActionDto.ts +1 -1
  90. package/src/enso-api/model/multiOutSingleDepositArgsDto.ts +1 -1
  91. package/src/enso-api/model/multiOutSingleDepositArgsDtoAmountIn.ts +1 -1
  92. package/src/enso-api/model/multiRedeemActionDto.ts +1 -1
  93. package/src/enso-api/model/multiRedeemArgs2Dto.ts +1 -1
  94. package/src/enso-api/model/multiRedeemArgs2DtoAmountIn.ts +1 -1
  95. package/src/enso-api/model/network.ts +1 -1
  96. package/src/enso-api/model/networksControllerNetworksParams.ts +1 -1
  97. package/src/enso-api/model/nonTokenizedControllerTokens200.ts +1 -1
  98. package/src/enso-api/model/nonTokenizedControllerTokens200AllOf.ts +1 -1
  99. package/src/enso-api/model/nonTokenizedControllerTokensParams.ts +6 -2
  100. package/src/enso-api/model/nonTokenizedModel.ts +1 -1
  101. package/src/enso-api/model/nontokenizedControllerRouteNontokenizedShorcutTransactionParams.ts +2 -2
  102. package/src/enso-api/model/nontokenizedControllerRouteNontokenizedShorcutTransactionRoutingStrategy.ts +1 -1
  103. package/src/enso-api/model/nontokenizedRouteShortcutTransaction.ts +4 -1
  104. package/src/enso-api/model/paginatedResult.ts +1 -1
  105. package/src/enso-api/model/paginationMeta.ts +1 -1
  106. package/src/enso-api/model/paymasterFeeActionDto.ts +1 -1
  107. package/src/enso-api/model/paymasterFeeArgsDto.ts +1 -1
  108. package/src/enso-api/model/paymasterFeeArgsDtoAmount.ts +1 -1
  109. package/src/enso-api/model/permitTransferFromActionDto.ts +1 -1
  110. package/src/enso-api/model/permitTransferFromArgsDto.ts +1 -1
  111. package/src/enso-api/model/permitTransferFromArgsDtoAmount.ts +1 -1
  112. package/src/enso-api/model/permitTransferFromArgsDtoAmountOneOfItem.ts +1 -1
  113. package/src/enso-api/model/permitTransferFromArgsDtoToken.ts +1 -1
  114. package/src/enso-api/model/positionModel.ts +1 -1
  115. package/src/enso-api/model/price.ts +1 -1
  116. package/src/enso-api/model/pricesControllerGetPricesParams.ts +1 -1
  117. package/src/enso-api/model/project.ts +1 -1
  118. package/src/enso-api/model/protocol.ts +1 -1
  119. package/src/enso-api/model/protocolModel.ts +1 -1
  120. package/src/enso-api/model/protocolsControllerFindAllParams.ts +1 -1
  121. package/src/enso-api/model/redeemActionDto.ts +1 -1
  122. package/src/enso-api/model/redeemArgsDto.ts +1 -1
  123. package/src/enso-api/model/redeemArgsDtoAmountIn.ts +1 -1
  124. package/src/enso-api/model/redeemArgsDtoTokenOut.ts +1 -1
  125. package/src/enso-api/model/redeemCLMMActionDto.ts +1 -1
  126. package/src/enso-api/model/redeemCLMMArgsDto.ts +1 -1
  127. package/src/enso-api/model/redeemCLMMArgsDtoLiquidity.ts +1 -1
  128. package/src/enso-api/model/refundDetails.ts +21 -0
  129. package/src/enso-api/model/repayActionDto.ts +1 -1
  130. package/src/enso-api/model/repayArgsDto.ts +1 -1
  131. package/src/enso-api/model/repayArgsDtoAmountIn.ts +1 -1
  132. package/src/enso-api/model/routeActionDto.ts +1 -1
  133. package/src/enso-api/model/routeArgsDto.ts +1 -1
  134. package/src/enso-api/model/routeArgsDtoAmountIn.ts +1 -1
  135. package/src/enso-api/model/routeShortcutTransaction.ts +7 -4
  136. package/src/enso-api/model/routeShortcutVariableInputs.ts +2 -2
  137. package/src/enso-api/model/routeShortcutVariableInputsRoutingStrategy.ts +2 -2
  138. package/src/enso-api/model/routeShortcutVariableInputsVariableEstimates.ts +1 -1
  139. package/src/enso-api/model/routerControllerRouteShortcutTransactionParams.ts +1 -1
  140. package/src/enso-api/model/routerControllerRouteShortcutTransactionRoutingStrategy.ts +2 -2
  141. package/src/enso-api/model/singleDepositActionDto.ts +1 -1
  142. package/src/enso-api/model/singleDepositArgsDto.ts +1 -1
  143. package/src/enso-api/model/singleDepositArgsDtoAmountIn.ts +1 -1
  144. package/src/enso-api/model/singleRedeemActionDto.ts +1 -1
  145. package/src/enso-api/model/singleRedeemArgs2Dto.ts +1 -1
  146. package/src/enso-api/model/singleRedeemArgs2DtoAmountIn.ts +1 -1
  147. package/src/enso-api/model/slippageActionDto.ts +1 -1
  148. package/src/enso-api/model/slippageArgsDto.ts +1 -1
  149. package/src/enso-api/model/slippageArgsDtoAmountOut.ts +1 -1
  150. package/src/enso-api/model/splitActionDto.ts +1 -1
  151. package/src/enso-api/model/splitArgsDto.ts +1 -1
  152. package/src/enso-api/model/splitArgsDtoAmountIn.ts +1 -1
  153. package/src/enso-api/model/standard.ts +1 -1
  154. package/src/enso-api/model/standardAction.ts +1 -1
  155. package/src/enso-api/model/standardActionAction.ts +3 -1
  156. package/src/enso-api/model/swapActionDto.ts +1 -1
  157. package/src/enso-api/model/swapArgsDto.ts +1 -1
  158. package/src/enso-api/model/swapArgsDtoAmountIn.ts +1 -1
  159. package/src/enso-api/model/tokenModel.ts +1 -1
  160. package/src/enso-api/model/tokenizedMultiDepositActionDto.ts +1 -1
  161. package/src/enso-api/model/tokenizedMultiDepositArgsDto.ts +1 -1
  162. package/src/enso-api/model/tokenizedMultiDepositArgsDtoAmountInItem.ts +1 -1
  163. package/src/enso-api/model/tokenizedMultiDepositArgsDtoAmountInItemAnyOf.ts +1 -1
  164. package/src/enso-api/model/tokenizedMultiRedeemActionDto.ts +1 -1
  165. package/src/enso-api/model/tokenizedMultiRedeemArgsDto.ts +1 -1
  166. package/src/enso-api/model/tokenizedMultiRedeemArgsDtoAmountIn.ts +1 -1
  167. package/src/enso-api/model/tokenizedSingleDepositActionDto.ts +1 -1
  168. package/src/enso-api/model/tokenizedSingleDepositArgsDto.ts +1 -1
  169. package/src/enso-api/model/tokenizedSingleDepositArgsDtoAmountIn.ts +1 -1
  170. package/src/enso-api/model/tokenizedSingleRedeemActionDto.ts +1 -1
  171. package/src/enso-api/model/tokenizedSingleRedeemArgsDto.ts +1 -1
  172. package/src/enso-api/model/tokenizedSingleRedeemArgsDtoAmountIn.ts +1 -1
  173. package/src/enso-api/model/tokensControllerTokens200.ts +1 -1
  174. package/src/enso-api/model/tokensControllerTokens200AllOf.ts +1 -1
  175. package/src/enso-api/model/tokensControllerTokensLiquidityType.ts +1 -1
  176. package/src/enso-api/model/tokensControllerTokensParams.ts +1 -1
  177. package/src/enso-api/model/tokensControllerTokensType.ts +1 -1
  178. package/src/enso-api/model/transaction.ts +1 -1
  179. package/src/enso-api/model/transferActionDto.ts +1 -1
  180. package/src/enso-api/model/transferArgsDto.ts +1 -1
  181. package/src/enso-api/model/transferArgsDtoAmount.ts +1 -1
  182. package/src/enso-api/model/transferFromActionDto.ts +1 -1
  183. package/src/enso-api/model/transferFromArgsDto.ts +1 -1
  184. package/src/enso-api/model/transferFromArgsDtoAmount.ts +1 -1
  185. package/src/enso-api/model/userOperation.ts +7 -7
  186. package/src/enso-api/model/walletApproveTransaction.ts +1 -1
  187. package/src/enso-api/model/walletApproveTransactionTx.ts +1 -1
  188. package/src/enso-api/model/walletBalance.ts +21 -9
  189. package/src/enso-api/model/walletControllerCreateApproveTransactionParams.ts +1 -1
  190. package/src/enso-api/model/walletControllerCreateApproveTransactionRoutingStrategy.ts +2 -2
  191. package/src/enso-api/model/walletControllerWalletBalancesParams.ts +4 -4
  192. package/src/index.ts +3 -0
  193. package/src/types/index.ts +2 -0
  194. package/src/util/constants.tsx +19 -0
  195. package/src/util/tx-tracker.tsx +162 -1
@@ -5,7 +5,7 @@
5
5
  - Find detailed documentation on [docs.enso.finance](https://docs.enso.finance).
6
6
  - To use the API, **you must include your API Key in the Authorization header** (Bearer format).
7
7
  - For testing, Swagger pre-authorizes you using the key: `1e02632d-6feb-4a75-a157-documentation` (1rps).
8
- - Get your own API Key at [enso.finance/developers](https://enso.finance/developers).
8
+ - Get your own API Key at [enso.finance/developers](https://developers.enso.build/).
9
9
  * OpenAPI spec version: 1.0
10
10
  */
11
11
 
@@ -15,7 +15,7 @@ export type WalletControllerCreateApproveTransactionRoutingStrategy =
15
15
 
16
16
  // eslint-disable-next-line @typescript-eslint/no-redeclare
17
17
  export const WalletControllerCreateApproveTransactionRoutingStrategy = {
18
- ensowallet: "ensowallet",
18
+ "ensowallet-v2": "ensowallet-v2",
19
19
  router: "router",
20
20
  delegate: "delegate",
21
21
  "router-legacy": "router-legacy",
@@ -5,7 +5,7 @@
5
5
  - Find detailed documentation on [docs.enso.finance](https://docs.enso.finance).
6
6
  - To use the API, **you must include your API Key in the Authorization header** (Bearer format).
7
7
  - For testing, Swagger pre-authorizes you using the key: `1e02632d-6feb-4a75-a157-documentation` (1rps).
8
- - Get your own API Key at [enso.finance/developers](https://enso.finance/developers).
8
+ - Get your own API Key at [enso.finance/developers](https://developers.enso.build/).
9
9
  * OpenAPI spec version: 1.0
10
10
  */
11
11
 
@@ -15,11 +15,11 @@ export type WalletControllerWalletBalancesParams = {
15
15
  */
16
16
  chainId: number;
17
17
  /**
18
- * Address of the eoa with which to associate the ensoWallet for balances
18
+ * Address of the eoa with which to associate the ensoWallet-v2 for balances
19
19
  */
20
20
  eoaAddress?: string;
21
21
  /**
22
- * If true returns balances for the provided address, instead of the associated ensoWallet
22
+ * If true returns balances for the provided address, instead of the associated ensoWallet-v2
23
23
  */
24
- useEoa?: boolean;
24
+ useEoa: boolean;
25
25
  };
package/src/index.ts CHANGED
@@ -18,3 +18,6 @@ export {
18
18
  // Export theme type for TypeScript users
19
19
  export type { WidgetTheme } from "./types";
20
20
  export { SupportedExchanges } from "./types";
21
+
22
+ // Export default CEX bridge chain mapping for users to extend
23
+ export { DEFAULT_CEX_BRIDGE_CHAIN_MAPPING } from "./util/constants";
@@ -14,6 +14,8 @@ export type CheckoutConfig = {
14
14
  apiKey: string;
15
15
  theme?: WidgetTheme;
16
16
  enableExchange?: SupportedExchanges[];
17
+ /** Override the default CEX bridge chain mapping (maps target chains to intermediate chains for withdrawal + bridge) */
18
+ cexBridgeChainMapping?: Record<number, number>;
17
19
  };
18
20
 
19
21
  export type CheckoutModalProps = {
@@ -191,6 +191,25 @@ export const CHAINS_NATIVE_TOKENS: Record<SupportedChainId, Token> = {
191
191
  [SupportedChainId.KATANA]: ETH_TOKEN,
192
192
  };
193
193
 
194
+ // CEX Bridge Chain Mapping
195
+ // Maps target chains not directly supported by CEXs to intermediate chains for withdrawal + bridge
196
+ export const DEFAULT_CEX_BRIDGE_CHAIN_MAPPING: Record<number, number> = {
197
+ [SupportedChainId.HYPERLIQUID]: SupportedChainId.ARBITRUM_ONE, // 999 → 42161
198
+ };
199
+
200
+ /** @deprecated Use the context-aware version with custom mapping parameter */
201
+ export const CEX_BRIDGE_CHAIN_MAPPING = DEFAULT_CEX_BRIDGE_CHAIN_MAPPING;
202
+
203
+ export const isCexBridgeRequired = (
204
+ chainId: number,
205
+ mapping: Record<number, number> = DEFAULT_CEX_BRIDGE_CHAIN_MAPPING,
206
+ ): boolean => chainId in mapping;
207
+
208
+ export const getCexIntermediateChain = (
209
+ chainId: number,
210
+ mapping: Record<number, number> = DEFAULT_CEX_BRIDGE_CHAIN_MAPPING,
211
+ ): number | null => mapping[chainId] ?? null;
212
+
194
213
  export const CHAINS_ETHERSCAN: Record<SupportedChainId, string> = {
195
214
  [SupportedChainId.OPTIMISM]: "https://optimistic.etherscan.io",
196
215
  [SupportedChainId.MAINNET]: "https://etherscan.io",
@@ -52,7 +52,7 @@ export const useTrackTx = () => {
52
52
  return { track };
53
53
  };
54
54
 
55
- enum LayerZeroStatus {
55
+ export enum LayerZeroStatus {
56
56
  Pending = "PENDING",
57
57
  Success = "SUCCEEDED",
58
58
  Failed = "FAILED",
@@ -61,6 +61,167 @@ enum LayerZeroStatus {
61
61
  Delivered = "DELIVERED",
62
62
  }
63
63
 
64
+ // Types for Enso bridge check API response
65
+ export interface BridgeCheckResponse {
66
+ sourceChainId: number;
67
+ sourceTxHash: string;
68
+ status: "pending" | "success" | "failed";
69
+ layerZeroMessage?: {
70
+ srcEid: number;
71
+ dstEid: number;
72
+ srcChainId: number;
73
+ dstChainId: number;
74
+ status: LayerZeroStatus;
75
+ srcTxHash: string;
76
+ dstTxHash: string;
77
+ srcBlockNumber: string;
78
+ dstBlockNumber: number;
79
+ sender: string;
80
+ receiver: string;
81
+ };
82
+ destinationChainId?: number;
83
+ destinationTxHash?: string;
84
+ ensoSourceEvent?: {
85
+ accountId: string;
86
+ requestId: string;
87
+ blockNumber: number;
88
+ transactionHash: string;
89
+ chainId: number;
90
+ success: boolean;
91
+ };
92
+ ensoDestinationEvent?: {
93
+ blockNumber: number;
94
+ transactionHash: string;
95
+ chainId: number;
96
+ success: boolean;
97
+ error?: string;
98
+ refundDetails?: {
99
+ token: string;
100
+ amount: string;
101
+ recipient: string;
102
+ isNative: boolean;
103
+ };
104
+ };
105
+ }
106
+
107
+ // Hook for bridge status using Enso API (includes destination execution verification)
108
+ export const useBridgeStatus = (
109
+ hash?: `0x${string}`,
110
+ chainId?: number,
111
+ enabled = true,
112
+ ) => {
113
+ const { data, isLoading } = useQuery({
114
+ queryKey: ["bridgeStatus", hash || "none", chainId],
115
+ queryFn: async (): Promise<BridgeCheckResponse | null> => {
116
+ if (!hash || !chainId) return null;
117
+ const res = await fetch(
118
+ `https://api.enso.finance/api/v1/layerzero/bridge/check?chainId=${chainId}&txHash=${hash}`,
119
+ );
120
+ if (!res.ok) return null;
121
+ return res.json();
122
+ },
123
+ refetchInterval: 3000,
124
+ enabled: enabled && !!hash && !!chainId,
125
+ });
126
+
127
+ const lzStatus = data?.layerZeroMessage?.status;
128
+ const overallStatus = data?.status;
129
+ const destinationSuccess = data?.ensoDestinationEvent?.success;
130
+ const refundDetails = data?.ensoDestinationEvent?.refundDetails;
131
+
132
+ let step = 0;
133
+ let message = "Waiting for bridge transaction...";
134
+
135
+ if (!data) {
136
+ step = 0;
137
+ message = "Waiting for bridge transaction...";
138
+ } else if (lzStatus === LayerZeroStatus.Inflight) {
139
+ step = 1;
140
+ message = "Funds in transit to destination...";
141
+ } else if (lzStatus === LayerZeroStatus.Confirming) {
142
+ step = 2;
143
+ message = "Confirming on destination chain...";
144
+ } else if (lzStatus === LayerZeroStatus.Delivered) {
145
+ if (overallStatus === "success" || destinationSuccess === true) {
146
+ step = 4;
147
+ message = "Bridge completed successfully!";
148
+ } else if (overallStatus === "failed" || destinationSuccess === false) {
149
+ step = 4;
150
+ message = refundDetails
151
+ ? "Destination execution failed. Funds refunded."
152
+ : "Destination execution failed.";
153
+ } else {
154
+ step = 3;
155
+ message = "Verifying destination execution...";
156
+ }
157
+ } else if (lzStatus === LayerZeroStatus.Failed) {
158
+ step = 4;
159
+ message = "Bridge transaction failed.";
160
+ }
161
+
162
+ return {
163
+ data,
164
+ isLoading,
165
+ lzStatus,
166
+ overallStatus,
167
+ destinationSuccess,
168
+ refundDetails,
169
+ step,
170
+ message,
171
+ isComplete: overallStatus === "success",
172
+ isFailed: overallStatus === "failed" || lzStatus === LayerZeroStatus.Failed,
173
+ destinationTxHash: data?.destinationTxHash,
174
+ };
175
+ };
176
+
177
+ // Legacy hook for LayerZero status polling (kept for backward compatibility)
178
+ export const useLayerZeroStatus = (hash?: `0x${string}`, enabled = true) => {
179
+ const { data, isLoading } = useQuery({
180
+ queryKey: ["layerZeroStatus", hash || "none"],
181
+ queryFn: async () => {
182
+ if (!hash) return null;
183
+ return fetch(
184
+ `https://scan.layerzero-api.com/v1/messages/tx/${hash}`,
185
+ )
186
+ .then((res) => res.json())
187
+ .then((res) => res.data?.[0] ?? null);
188
+ },
189
+ refetchInterval: 2000,
190
+ enabled: enabled && !!hash,
191
+ });
192
+
193
+ const statusName = data?.status?.name as LayerZeroStatus | undefined;
194
+ const sourceStatus = data?.source?.status as LayerZeroStatus | undefined;
195
+
196
+ let step = 0;
197
+ let message = "Waiting for bridge transaction...";
198
+
199
+ if (sourceStatus && sourceStatus !== LayerZeroStatus.Success) {
200
+ step = 1;
201
+ message = "Waiting for funds to be sent on destination";
202
+ } else if (statusName === LayerZeroStatus.Inflight) {
203
+ step = 2;
204
+ message = "Waiting for funds to be delivered on destination";
205
+ } else if (statusName === LayerZeroStatus.Confirming) {
206
+ step = 3;
207
+ message = "Waiting for destination execution";
208
+ } else if (statusName === LayerZeroStatus.Delivered) {
209
+ step = 4;
210
+ message = "Bridging is complete";
211
+ }
212
+
213
+ return {
214
+ data,
215
+ isLoading,
216
+ status: statusName,
217
+ sourceStatus,
218
+ step,
219
+ message,
220
+ isComplete: statusName === LayerZeroStatus.Delivered,
221
+ isFailed: statusName === LayerZeroStatus.Failed,
222
+ };
223
+ }
224
+
64
225
  const useLayerZeroUrl = (hash?: `0x${string}`, reset?: () => void) => {
65
226
  // const [loadingToastId, setLoadingToastId] = useState<string>();
66
227
  const updateTx = useTrackingStore((state) => state.updateTx);