@sodax/dapp-kit 2.4.0-rc.2 → 2.4.0-rc.3

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 (283) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +279 -2428
  3. package/dist/index.mjs +15 -24
  4. package/package.json +2 -2
  5. package/src/hooks/_apiKeyWire.test.ts +4 -29
  6. package/src/hooks/_mutationContract.test.ts +1 -8
  7. package/src/hooks/backend/index.ts +0 -13
  8. package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +0 -6
  9. package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +0 -10
  10. package/src/hooks/backend/useBackendIntentByHash.ts +0 -6
  11. package/src/hooks/backend/useBackendIntentByTxHash.ts +1 -10
  12. package/src/hooks/backend/useBackendMoneyMarketAsset.ts +0 -6
  13. package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +0 -8
  14. package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +0 -8
  15. package/src/hooks/backend/useBackendMoneyMarketPosition.ts +0 -6
  16. package/src/hooks/backend/useBackendOracleCandles.ts +1 -9
  17. package/src/hooks/backend/useBackendOracleMarkets.ts +1 -7
  18. package/src/hooks/backend/useBackendOrderbook.ts +0 -6
  19. package/src/hooks/backend/useBackendUserIntents.ts +0 -8
  20. package/src/hooks/bitcoin/resolveBtcReadAddress.test.ts +1 -3
  21. package/src/hooks/bitcoin/resolveBtcReadAddress.ts +2 -12
  22. package/src/hooks/bitcoin/useBitcoinBalance.ts +1 -7
  23. package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +2 -4
  24. package/src/hooks/bitcoin/useEnsureRadfiAccessToken.ts +2 -13
  25. package/src/hooks/bitcoin/useFundTradingWallet.ts +0 -6
  26. package/src/hooks/bitcoin/useRadfiAuth.ts +1 -6
  27. package/src/hooks/bitcoin/useRadfiSession.ts +0 -1
  28. package/src/hooks/bitcoin/useRadfiWithdraw.ts +0 -6
  29. package/src/hooks/bitcoin/useRenewUtxos.ts +0 -5
  30. package/src/hooks/bitcoin/useTradingWallet.ts +1 -4
  31. package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.test.ts +1 -7
  32. package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.ts +7 -21
  33. package/src/hooks/bridge/useBridge.test.ts +1 -11
  34. package/src/hooks/bridge/useBridge.ts +2 -12
  35. package/src/hooks/bridge/useBridgeAllowance.ts +1 -2
  36. package/src/hooks/bridge/useBridgeApprovalStrategy.ts +2 -6
  37. package/src/hooks/bridge/useBridgeApprove.ts +2 -14
  38. package/src/hooks/bridge/useBridgeDetailedStatus.test.ts +2 -11
  39. package/src/hooks/bridge/useBridgeDetailedStatus.ts +3 -23
  40. package/src/hooks/bridge/useBridgeWithApproval.ts +2 -11
  41. package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.test.ts +2 -7
  42. package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.ts +2 -13
  43. package/src/hooks/bridgeApi/index.ts +11 -14
  44. package/src/hooks/bridgeApi/useBridgeApiAllowance.ts +1 -9
  45. package/src/hooks/bridgeApi/useBridgeApiApprove.ts +2 -17
  46. package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.test.ts +2 -13
  47. package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.ts +3 -20
  48. package/src/hooks/bridgeApi/useBridgeApiBridgeableAmount.ts +1 -12
  49. package/src/hooks/bridgeApi/useBridgeApiCreateBridgeIntent.ts +1 -14
  50. package/src/hooks/bridgeApi/useBridgeApiFee.ts +2 -11
  51. package/src/hooks/bridgeApi/useBridgeApiIsBridgeable.ts +1 -12
  52. package/src/hooks/bridgeApi/useBridgeApiSubmitTx.ts +2 -23
  53. package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.test.ts +1 -9
  54. package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.ts +1 -19
  55. package/src/hooks/bridgeApi/useBridgeApiTokens.ts +0 -8
  56. package/src/hooks/bridgeApi/useBridgeApiTokensByChain.ts +0 -7
  57. package/src/hooks/dex/useClaimRewards.ts +1 -12
  58. package/src/hooks/dex/useCreateDecreaseLiquidityParams.ts +1 -5
  59. package/src/hooks/dex/useCreateDepositParams.ts +1 -5
  60. package/src/hooks/dex/useCreateSupplyLiquidityParams.ts +1 -10
  61. package/src/hooks/dex/useCreateWithdrawParams.ts +1 -5
  62. package/src/hooks/dex/useDecreaseLiquidity.ts +2 -15
  63. package/src/hooks/dex/useDexAllowance.ts +1 -5
  64. package/src/hooks/dex/useDexApprove.ts +1 -12
  65. package/src/hooks/dex/useDexDeposit.ts +1 -23
  66. package/src/hooks/dex/useDexWithdraw.ts +1 -13
  67. package/src/hooks/dex/useLiquidityAmounts.ts +1 -4
  68. package/src/hooks/dex/usePoolBalances.ts +0 -4
  69. package/src/hooks/dex/usePoolData.ts +1 -4
  70. package/src/hooks/dex/usePools.ts +1 -4
  71. package/src/hooks/dex/usePositionInfo.ts +1 -4
  72. package/src/hooks/dex/useSupplyLiquidity.ts +3 -20
  73. package/src/hooks/leverageYield/useApproveLeveragePositionFunding.ts +2 -8
  74. package/src/hooks/leverageYield/useLeveragePositionAccount.ts +2 -13
  75. package/src/hooks/leverageYield/useLeveragePositionCollateral.ts +2 -14
  76. package/src/hooks/leverageYield/useLeveragePositionFundingAllowance.ts +2 -9
  77. package/src/hooks/leverageYield/useLeveragePositionInfo.ts +1 -13
  78. package/src/hooks/leverageYield/useLeveragePositionPayoutAddress.ts +3 -15
  79. package/src/hooks/leverageYield/useLeveragePositionPending.ts +2 -16
  80. package/src/hooks/leverageYield/useLeveragePositions.ts +1 -15
  81. package/src/hooks/leverageYield/useLeveragePositionsForUser.ts +1 -15
  82. package/src/hooks/leverageYield/useLeverageYieldApprovalStrategy.ts +1 -6
  83. package/src/hooks/leverageYield/useLeverageYieldDeposit.ts +1 -17
  84. package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.test.ts +3 -14
  85. package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.ts +2 -19
  86. package/src/hooks/leverageYield/useLeverageYieldEffectiveApr.ts +1 -12
  87. package/src/hooks/leverageYield/useLeverageYieldNotifySolver.ts +1 -11
  88. package/src/hooks/leverageYield/useLeverageYieldPosition.ts +1 -13
  89. package/src/hooks/leverageYield/useLeverageYieldPreviewRedeem.ts +1 -12
  90. package/src/hooks/leverageYield/useLeverageYieldQuote.test.ts +3 -13
  91. package/src/hooks/leverageYield/useLeverageYieldQuote.ts +5 -54
  92. package/src/hooks/leverageYield/useLeverageYieldShareBalances.ts +2 -29
  93. package/src/hooks/leverageYield/useLeverageYieldTotalAssets.ts +1 -9
  94. package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +2 -25
  95. package/src/hooks/leverageYield/useLeverageYieldVaultSwapWithApproval.ts +1 -11
  96. package/src/hooks/leverageYield/useLeverageYieldWithdraw.ts +1 -17
  97. package/src/hooks/leverageYield/useOpenLeveragePosition.ts +5 -18
  98. package/src/hooks/leverageYield/useRunLeveragePositionOperation.ts +4 -20
  99. package/src/hooks/leverageYield/useSubmitLeveragePositionIntent.ts +3 -15
  100. package/src/hooks/leverageYieldApi/index.ts +0 -15
  101. package/src/hooks/leverageYieldApi/useLeverageYieldApiAllowance.ts +1 -8
  102. package/src/hooks/leverageYieldApi/useLeverageYieldApiApprove.ts +3 -6
  103. package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.test.ts +4 -14
  104. package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts +4 -26
  105. package/src/hooks/leverageYieldApi/useLeverageYieldApiApr.ts +1 -7
  106. package/src/hooks/leverageYieldApi/useLeverageYieldApiAsset.ts +0 -7
  107. package/src/hooks/leverageYieldApi/useLeverageYieldApiCancelIntent.ts +2 -8
  108. package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateDepositIntent.ts +2 -8
  109. package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateWithdrawIntent.ts +2 -8
  110. package/src/hooks/leverageYieldApi/useLeverageYieldApiDeadline.ts +1 -7
  111. package/src/hooks/leverageYieldApi/useLeverageYieldApiDepositQuote.ts +1 -15
  112. package/src/hooks/leverageYieldApi/useLeverageYieldApiEffectiveApr.ts +1 -7
  113. package/src/hooks/leverageYieldApi/useLeverageYieldApiEstimateGas.ts +1 -7
  114. package/src/hooks/leverageYieldApi/useLeverageYieldApiFilledIntent.ts +1 -6
  115. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntent.ts +1 -6
  116. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentExtraData.ts +1 -8
  117. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentHash.ts +0 -7
  118. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentPacket.ts +1 -7
  119. package/src/hooks/leverageYieldApi/useLeverageYieldApiLsdApr.ts +1 -7
  120. package/src/hooks/leverageYieldApi/useLeverageYieldApiMaxWithdraw.ts +1 -7
  121. package/src/hooks/leverageYieldApi/useLeverageYieldApiPartnerFee.ts +1 -7
  122. package/src/hooks/leverageYieldApi/useLeverageYieldApiPosition.ts +0 -7
  123. package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewDeposit.ts +1 -7
  124. package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewRedeem.ts +1 -7
  125. package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewWithdraw.ts +1 -7
  126. package/src/hooks/leverageYieldApi/useLeverageYieldApiShareBalance.ts +0 -7
  127. package/src/hooks/leverageYieldApi/useLeverageYieldApiSolverFee.ts +1 -7
  128. package/src/hooks/leverageYieldApi/useLeverageYieldApiStatus.ts +2 -12
  129. package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitIntent.ts +2 -8
  130. package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTx.ts +2 -8
  131. package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTxStatus.ts +2 -17
  132. package/src/hooks/leverageYieldApi/useLeverageYieldApiTotalAssets.ts +0 -7
  133. package/src/hooks/leverageYieldApi/useLeverageYieldApiVault.ts +1 -7
  134. package/src/hooks/leverageYieldApi/useLeverageYieldApiVaults.ts +0 -7
  135. package/src/hooks/leverageYieldApi/useLeverageYieldApiWithdrawQuote.ts +1 -15
  136. package/src/hooks/migrate/useMigrateBaln.ts +1 -8
  137. package/src/hooks/migrate/useMigrateIcxToSoda.ts +1 -12
  138. package/src/hooks/migrate/useMigratebnUSD.ts +1 -12
  139. package/src/hooks/migrate/useMigrationAllowance.ts +3 -19
  140. package/src/hooks/migrate/useMigrationApprove.ts +2 -20
  141. package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +0 -7
  142. package/src/hooks/mm/useAToken.ts +1 -6
  143. package/src/hooks/mm/useATokensBalances.ts +0 -5
  144. package/src/hooks/mm/useBorrow.ts +1 -13
  145. package/src/hooks/mm/useEModes.ts +2 -13
  146. package/src/hooks/mm/useMMAllowance.test.ts +55 -0
  147. package/src/hooks/mm/useMMAllowance.ts +6 -16
  148. package/src/hooks/mm/useMMApprove.ts +1 -14
  149. package/src/hooks/mm/useRepay.ts +1 -12
  150. package/src/hooks/mm/useReservesData.ts +0 -4
  151. package/src/hooks/mm/useReservesHumanized.ts +0 -4
  152. package/src/hooks/mm/useReservesList.ts +0 -4
  153. package/src/hooks/mm/useReservesUsdFormat.ts +0 -4
  154. package/src/hooks/mm/useSupply.ts +1 -24
  155. package/src/hooks/mm/useUserFormattedSummary.ts +0 -7
  156. package/src/hooks/mm/useUserReservesData.ts +0 -4
  157. package/src/hooks/mm/useWithdraw.ts +1 -13
  158. package/src/hooks/partner/useApproveToken.ts +1 -7
  159. package/src/hooks/partner/useFeeClaimSwap.ts +1 -7
  160. package/src/hooks/partner/useFeeClaimWithdraw.ts +3 -20
  161. package/src/hooks/partner/useFetchAssetsBalances.ts +0 -4
  162. package/src/hooks/partner/useGetAutoSwapPreferences.ts +0 -4
  163. package/src/hooks/partner/useGetIntentDetails.ts +1 -8
  164. package/src/hooks/partner/useGetUserIntent.ts +1 -8
  165. package/src/hooks/partner/useIsTokenApproved.ts +0 -4
  166. package/src/hooks/partner/usePartnerCancelIntent.ts +2 -9
  167. package/src/hooks/partner/useSetSwapPreference.ts +1 -14
  168. package/src/hooks/recovery/useHubAssetBalances.ts +1 -6
  169. package/src/hooks/recovery/useWithdrawHubAsset.ts +1 -13
  170. package/src/hooks/shared/invalidateBalances.ts +2 -10
  171. package/src/hooks/shared/isUserRejectedError.test.ts +0 -3
  172. package/src/hooks/shared/isUserRejectedError.ts +2 -23
  173. package/src/hooks/shared/notFoundStreak.ts +5 -22
  174. package/src/hooks/shared/retryUnlessAuthFailure.test.ts +1 -2
  175. package/src/hooks/shared/retryUnlessAuthFailure.ts +1 -12
  176. package/src/hooks/shared/solverStatusPolicy.test.ts +0 -5
  177. package/src/hooks/shared/solverStatusPolicy.ts +8 -58
  178. package/src/hooks/shared/types.ts +4 -55
  179. package/src/hooks/shared/unwrapResult.ts +1 -8
  180. package/src/hooks/shared/useBalances.ts +6 -39
  181. package/src/hooks/shared/useEstablishTrustline.test.ts +1 -5
  182. package/src/hooks/shared/useEstablishTrustline.ts +3 -13
  183. package/src/hooks/shared/useEstablishXrpTrustline.test.ts +1 -2
  184. package/src/hooks/shared/useEstablishXrpTrustline.ts +3 -5
  185. package/src/hooks/shared/useEstimateGas.ts +0 -1
  186. package/src/hooks/shared/useGetUserHubWalletAddress.ts +1 -18
  187. package/src/hooks/shared/useNearStorageCheck.ts +2 -9
  188. package/src/hooks/shared/useNearStorageGate.ts +5 -15
  189. package/src/hooks/shared/useRegisterNearStorage.ts +2 -10
  190. package/src/hooks/shared/useRequestTrustline.test.ts +1 -7
  191. package/src/hooks/shared/useRequestTrustline.ts +4 -14
  192. package/src/hooks/shared/useSafeMutation.test.ts +0 -3
  193. package/src/hooks/shared/useSafeMutation.ts +2 -26
  194. package/src/hooks/shared/useSodaxContext.ts +0 -6
  195. package/src/hooks/shared/useStellarGate.test.ts +2 -9
  196. package/src/hooks/shared/useStellarGate.ts +3 -9
  197. package/src/hooks/shared/useStellarTrustlineCheck.test.ts +0 -2
  198. package/src/hooks/shared/useStellarTrustlineCheck.ts +1 -4
  199. package/src/hooks/shared/useXBalances.ts +2 -20
  200. package/src/hooks/shared/useXrpDestinationCheck.ts +1 -5
  201. package/src/hooks/shared/useXrpGate.test.ts +1 -3
  202. package/src/hooks/shared/useXrpGate.ts +2 -3
  203. package/src/hooks/shared/waitForApiAllowance.test.ts +0 -1
  204. package/src/hooks/shared/waitForApiAllowance.ts +2 -6
  205. package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +1 -2
  206. package/src/hooks/sponsoring/useActivateStellarAccount.ts +1 -5
  207. package/src/hooks/sponsoring/useActivateStellarAccount.wire.test.ts +2 -13
  208. package/src/hooks/sponsoring/useSponsorConfig.ts +0 -1
  209. package/src/hooks/sponsoring/useStellarAccountActive.ts +0 -1
  210. package/src/hooks/sponsoring/useStellarAccountStatus.ts +1 -4
  211. package/src/hooks/staking/index.ts +0 -1
  212. package/src/hooks/staking/useCancelUnstake.ts +1 -7
  213. package/src/hooks/staking/useClaim.ts +1 -7
  214. package/src/hooks/staking/useConvertedAssets.ts +1 -4
  215. package/src/hooks/staking/useInstantUnstake.ts +1 -7
  216. package/src/hooks/staking/useInstantUnstakeAllowance.ts +1 -5
  217. package/src/hooks/staking/useInstantUnstakeApprove.ts +1 -11
  218. package/src/hooks/staking/useInstantUnstakeRatio.ts +1 -4
  219. package/src/hooks/staking/useStake.ts +1 -12
  220. package/src/hooks/staking/useStakeAllowance.ts +1 -5
  221. package/src/hooks/staking/useStakeApprove.ts +1 -11
  222. package/src/hooks/staking/useStakeRatio.ts +1 -4
  223. package/src/hooks/staking/useStakingConfig.ts +1 -4
  224. package/src/hooks/staking/useStakingInfo.ts +1 -5
  225. package/src/hooks/staking/useUnstake.ts +2 -9
  226. package/src/hooks/staking/useUnstakeAllowance.ts +1 -5
  227. package/src/hooks/staking/useUnstakeApprove.ts +1 -10
  228. package/src/hooks/staking/useUnstakingInfo.ts +1 -4
  229. package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +1 -4
  230. package/src/hooks/swap/useCancelLimitOrder.ts +1 -7
  231. package/src/hooks/swap/useCancelSwap.ts +1 -7
  232. package/src/hooks/swap/useCreateLimitOrder.ts +2 -12
  233. package/src/hooks/swap/useDetailedStatus.test.ts +6 -18
  234. package/src/hooks/swap/useDetailedStatus.ts +2 -19
  235. package/src/hooks/swap/useQuote.test.ts +2 -8
  236. package/src/hooks/swap/useQuote.ts +5 -32
  237. package/src/hooks/swap/useStatus.ts +2 -10
  238. package/src/hooks/swap/useSwap.test.ts +1 -11
  239. package/src/hooks/swap/useSwap.ts +2 -12
  240. package/src/hooks/swap/useSwapAllowance.ts +1 -2
  241. package/src/hooks/swap/useSwapApprovalStrategy.ts +2 -7
  242. package/src/hooks/swap/useSwapApprove.ts +2 -14
  243. package/src/hooks/swap/useSwapLifecycle.test.ts +1 -2
  244. package/src/hooks/swap/useSwapLifecycle.ts +9 -27
  245. package/src/hooks/swap/useSwapWithApproval.ts +2 -11
  246. package/src/hooks/swapsApi/index.ts +2 -14
  247. package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +1 -5
  248. package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +1 -7
  249. package/src/hooks/swapsApi/useSwapsApiAllowance.ts +0 -7
  250. package/src/hooks/swapsApi/useSwapsApiApprove.ts +1 -14
  251. package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.test.ts +5 -20
  252. package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.ts +3 -24
  253. package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.test.ts +2 -8
  254. package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.ts +6 -41
  255. package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +0 -13
  256. package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +0 -13
  257. package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +1 -13
  258. package/src/hooks/swapsApi/useSwapsApiDeadline.ts +1 -7
  259. package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +0 -7
  260. package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +0 -8
  261. package/src/hooks/swapsApi/useSwapsApiIntent.ts +1 -7
  262. package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +1 -8
  263. package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +0 -7
  264. package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +1 -10
  265. package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +0 -7
  266. package/src/hooks/swapsApi/useSwapsApiQuote.ts +2 -24
  267. package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +0 -7
  268. package/src/hooks/swapsApi/useSwapsApiStatus.ts +1 -11
  269. package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +1 -15
  270. package/src/hooks/swapsApi/useSwapsApiSubmitTx.ts +0 -21
  271. package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +2 -19
  272. package/src/hooks/swapsApi/useSwapsApiTokens.ts +0 -7
  273. package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +0 -7
  274. package/src/index.ts +1 -1
  275. package/src/providers/SodaxProvider.test.ts +2 -9
  276. package/src/providers/SodaxProvider.tsx +1 -12
  277. package/src/providers/createSodaxQueryClient.ts +4 -56
  278. package/src/utils/approvalPlan.ts +9 -32
  279. package/src/utils/dex-utils.ts +5 -20
  280. package/src/utils/nearStorageGate.ts +3 -14
  281. package/src/utils/stellarGate.ts +3 -16
  282. package/src/utils/swapLifecycle.ts +7 -26
  283. package/src/utils/xrpGate.ts +1 -4
@@ -1,20 +1,5 @@
1
- /**
2
- * The polling policy shared by every solver-backed status read.
3
- *
4
- * Two features now resolve a source tx to a solver answer — swap and leverage yield — and their
5
- * status unions are structurally the same, so the terminality rules and the ambiguous-miss mapping
6
- * are identical. They live here rather than in one feature's folder: `hooks/` has no cross-feature
7
- * imports anywhere else, and a second verbatim copy is what this extraction exists to prevent.
8
- * Bridge keeps its own policy beside its hook, because its second arm is a relay packet that is
9
- * terminal on arrival and has no solver vocabulary at all.
10
- *
11
- * The read types are declared structurally rather than imported from either feature: this module
12
- * must not own another hook's public contract, and both `DetailedSwapStatus` and
13
- * `DetailedLeverageYieldStatus` satisfy the shape below.
14
- *
15
- * Kept free of React and context imports so it is unit-testable in dapp-kit's `node` test
16
- * environment — importing a hook pulls in `useSodaxContext`.
17
- */
1
+ // Read types are structural so this module does not own a feature hook's public contract.
2
+ // Kept free of React/context imports so it is unit-testable in the `node` test env.
18
3
  import {
19
4
  DETAILED_STATUS_NOT_DELIVERED,
20
5
  isAuthFailure,
@@ -27,15 +12,9 @@ import {
27
12
 
28
13
  import { MAX_NOT_FOUND_POLLS, STATUS_POLL_MS } from './notFoundStreak.js';
29
14
 
30
- /** A solver status read, as `useStatus` holds it. */
31
15
  export type SolverStatusRead = Result<SolverIntentStatusResponse, SolverErrorResponse> | undefined;
32
16
 
33
- /**
34
- * The structural minimum a detailed-status read must satisfy to use this policy: a backend arm
35
- * reporting terminality in the submit-tx vocabulary, and a solver arm carrying the solver's own
36
- * response. A feature's arm may carry more (leverage yield and swap both hoist `dstTxHash`); only
37
- * what is read here is required.
38
- */
17
+ /** Structural minimum of a detailed-status read; feature arms may carry more fields. */
39
18
  export type SolverDetailedStatusRead =
40
19
  | Result<
41
20
  { source: 'backend'; data: { status: string } } | { source: 'solver'; data: SolverIntentStatusResponse },
@@ -43,11 +22,7 @@ export type SolverDetailedStatusRead =
43
22
  >
44
23
  | undefined;
45
24
 
46
- /**
47
- * Polling interval for a plain solver status read (`useStatus`). Stops on SOLVED/FAILED immediately;
48
- * stops on NOT_FOUND only after `MAX_NOT_FOUND_POLLS` consecutive successful fetches (solver forgot /
49
- * never saw the intent). In-flight statuses keep polling with no global cap.
50
- */
25
+ /** Stops on SOLVED/FAILED, or after `MAX_NOT_FOUND_POLLS` consecutive NOT_FOUNDs; in-flight polls uncapped. */
51
26
  export function getSolverStatusRefetchInterval(data: SolverStatusRead, consecutiveNotFound: number): number | false {
52
27
  const status = data?.ok ? data.value.status : undefined;
53
28
  if (status === SolverIntentStatusCode.SOLVED || status === SolverIntentStatusCode.FAILED) {
@@ -59,24 +34,13 @@ export function getSolverStatusRefetchInterval(data: SolverStatusRead, consecuti
59
34
  return STATUS_POLL_MS;
60
35
  }
61
36
 
62
- /** The read shape the budget counts: a solver that has not seen this intent. */
63
37
  export function isSolverNotFound(data: SolverStatusRead): boolean {
64
38
  return (data?.ok ? data.value.status : undefined) === SolverIntentStatusCode.NOT_FOUND;
65
39
  }
66
40
 
67
41
  /**
68
- * Maps a detailed-status read onto the shape the shared NOT_FOUND policy consumes, three ways:
69
- *
70
- * - solver arm → passes through, so its status drives the budget as it does for `useStatus`;
71
- * - backend arm → `undefined`, which resets the budget; the solver is not the one being asked;
72
- * - failed read → counts as `NOT_FOUND` **only** when the relay has no packet for this source tx
73
- * (`DETAILED_STATUS_NOT_DELIVERED`). That miss is ambiguous — a transfer still in flight and one
74
- * whose tx never relayed look the same — so a budget is the only way to stop the second case.
75
- *
76
- * Every other `LOOKUP_FAILED` is a dependency failing right now: the relay unreachable, a malformed
77
- * response, the solver down. Those reset the budget and keep polling, because that is how the read
78
- * recovers when the outage ends. Counting them would stop polling a healthy transfer after ~2 min of
79
- * downtime and never resume.
42
+ * Only `DETAILED_STATUS_NOT_DELIVERED` failures count as NOT_FOUND; other lookup failures are outages
43
+ * and reset the budget so polling resumes when they end.
80
44
  */
81
45
  export function toNotFoundBudgetRead(data: SolverDetailedStatusRead): SolverStatusRead {
82
46
  if (data === undefined) return undefined;
@@ -88,28 +52,14 @@ export function toNotFoundBudgetRead(data: SolverDetailedStatusRead): SolverStat
88
52
  : undefined;
89
53
  }
90
54
 
91
- /**
92
- * Polling interval for a detailed-status read. Backend records report terminality in their own
93
- * vocabulary; everything else reuses the solver policy verbatim, so `MAX_NOT_FOUND_POLLS` stays the
94
- * single cutoff — for a forgotten intent and for a transfer no source can resolve.
95
- *
96
- * A rejected API key is the one stop that sits outside both: `retryUnlessAuthFailure` cannot catch
97
- * it, because the SDK returns the 401/403 as a `Result` rather than throwing, so React Query never
98
- * sees an error to withhold a retry from. Without this branch a bad key polls forever whenever the
99
- * relay has also not delivered — the miss is unprovable behind an unanswered backend, so it never
100
- * consumes the not-delivered budget either.
101
- */
102
55
  export function getSolverDetailedStatusRefetchInterval(
103
56
  data: SolverDetailedStatusRead,
104
57
  consecutiveNotFound: number,
105
58
  ): number | false {
106
- // A rejected key is terminal — only a corrected key changes the answer, so stop asking.
59
+ // The SDK returns 401/403 as a Result, so `retryUnlessAuthFailure` never sees it; stop here instead.
107
60
  if (data && !data.ok && isAuthFailure(data.error)) return false;
108
61
  if (data?.ok && data.value.source === 'backend') {
109
- // Both terminal states of the submit-tx status vocabulary. Today the SDK routes `'failed'`
110
- // records to the solver so only `'solved'` reaches us, but that is its routing rule, not this
111
- // hook's contract — encoding the wire contract keeps a terminal record from being polled forever
112
- // if it changes.
62
+ // SDK currently routes 'failed' to the solver; still treat it as terminal in case routing changes.
113
63
  const { status } = data.value.data;
114
64
  return status === 'solved' || status === 'failed' ? false : STATUS_POLL_MS;
115
65
  }
@@ -1,77 +1,26 @@
1
- // packages/dapp-kit/src/hooks/shared/types.ts
2
1
  import type { UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
3
2
 
4
- /**
5
- * Subset of `UseQueryOptions` consumers may override on dapp-kit read hooks.
6
- *
7
- * `queryKey`, `queryFn`, and `enabled` are owned by the hook (the latter is derived
8
- * from required-input presence) and are intentionally stripped here.
9
- */
3
+ /** `enabled` is hook-owned: derived from required-input presence. */
10
4
  export type ReadQueryOptions<TData, TError = Error> = Omit<
11
5
  UseQueryOptions<TData, TError>,
12
6
  'queryKey' | 'queryFn' | 'enabled'
13
7
  >;
14
8
 
15
- /**
16
- * Canonical params shape for read-only `useQuery`-backed hooks in dapp-kit.
17
- *
18
- * Two top-level keys, always:
19
- * - `params`: SDK-feature-domain inputs (the "what" being fetched)
20
- * - `queryOptions`: React Query behavior knobs (the "how" the query behaves)
21
- *
22
- * For hooks with no required inputs, leave `TParams` at its default and accept the
23
- * whole params object as optional at the call site.
24
- */
25
9
  export type ReadHookParams<TData, TParams = Record<string, never>, TError = Error> = {
26
10
  params?: TParams;
27
11
  queryOptions?: ReadQueryOptions<TData, TError>;
28
12
  };
29
13
 
30
14
  /**
31
- * Subset of `UseMutationOptions` consumers may override on dapp-kit mutation hooks.
32
- *
33
- * `mutationFn` is owned by the hook (it's the SDK integration point) and is
34
- * intentionally stripped here. Everything else — `mutationKey`, `retry`, `gcTime`,
35
- * `networkMode`, `onMutate`, `onSuccess`, `onError`, `onSettled`, `meta`, etc. —
36
- * is consumer-overridable.
37
- *
38
- * Conventions enforced by every dapp-kit mutation hook:
39
- *
40
- * 1. **`mutationFn` throws on SDK failure.** The SDK returns `Result<T>`; the hook
41
- * unwraps `result.value` on `ok` and throws `result.error` on `!ok`. So `TData`
42
- * here is the unwrapped success type, not `Result<T>`. React Query's native
43
- * error model — `isError`, `error`, `onError`, `retry`, `throwOnError`, devtools —
44
- * works exactly as documented.
45
- *
46
- * 2. **`onSuccess` is composed.** Hook-owned invalidations always run first; then
47
- * the hook awaits `mutationOptions?.onSuccess?.(data, vars, ctx)`. Per-call
48
- * `mutate(vars, { onSuccess })` runs after both, per TanStack Query's native
49
- * ordering. Because invalidations now live inside `onSuccess` (not `onSettled`),
50
- * they only fire on confirmed success — failed mutations never trigger them.
51
- *
52
- * 3. **A default `mutationKey` is set per hook** (e.g. `['mm', 'supply']`,
53
- * `['swap']`) so consumers can use `useIsMutating(['mm'])` and
54
- * `useMutationState` without guessing the key shape. The default is set
55
- * *before* `...mutationOptions` is spread, so consumers can override it.
15
+ * `TData` is the unwrapped success type (hooks throw on SDK failure). A consumer `onSuccess` runs after
16
+ * the hook's own invalidations; the default `mutationKey` is overridable.
56
17
  */
57
18
  export type MutationHookOptions<TData, TVars, TError = Error, TContext = unknown> = Omit<
58
19
  UseMutationOptions<TData, TError, TVars, TContext>,
59
20
  'mutationFn'
60
21
  >;
61
22
 
62
- /**
63
- * Canonical params shape for `useMutation`-backed hooks in dapp-kit.
64
- *
65
- * One top-level key:
66
- * - `mutationOptions`: React Query behavior knobs (the "how" the mutation behaves)
67
- *
68
- * Domain inputs (params, walletProvider, etc.) are NOT here — they belong in
69
- * `TVars` and flow through `mutate(vars)` so the call site can vary them per
70
- * invocation without re-rendering the hook.
71
- *
72
- * Always accept the whole params object as optional at the call site:
73
- * `useFoo({ mutationOptions } = {})`.
74
- */
23
+ /** Domain inputs belong in `TVars` and flow through `mutate(vars)`, not here. */
75
24
  export type MutationHookParams<TData, TVars, TError = Error, TContext = unknown> = {
76
25
  mutationOptions?: MutationHookOptions<TData, TVars, TError, TContext>;
77
26
  };
@@ -1,13 +1,6 @@
1
1
  import type { Result } from '@sodax/sdk';
2
2
 
3
- /**
4
- * Translates the SDK's `Result<T>` contract into the React Query contract: returns `value` on
5
- * success, throws `error` on failure. Non-`Error` throwables are wrapped so consumers always get
6
- * an `Error` in `mutation.error` / catch blocks.
7
- *
8
- * Used by every dapp-kit mutation hook so the React Query error model (`isError`, `error`,
9
- * `onError`, `retry`, `throwOnError`, devtools) engages uniformly.
10
- */
3
+ /** Returns `value` or throws `error`; non-`Error` failures are wrapped so consumers always get an `Error`. */
11
4
  export function unwrapResult<T>(result: Result<T>): T {
12
5
  if (!result.ok) {
13
6
  if (result.error instanceof Error) throw result.error;
@@ -4,13 +4,7 @@ import { useSodaxContext } from './useSodaxContext.js';
4
4
  import { unwrapResult } from './unwrapResult.js';
5
5
  import type { ReadHookParams } from './types.js';
6
6
 
7
- /**
8
- * Domain inputs for {@link useBalances}. `chainKey` is optional so the hook can be mounted before a
9
- * chain is selected; `enabled` gates execution on every required field being present.
10
- *
11
- * The SDK reads the chain named by `chainKey` and ignores `token.chainKey`, so a token that does
12
- * not live on that chain reads as `0n` rather than erroring — keep the two in step.
13
- */
7
+ /** The SDK ignores `token.chainKey`: a token not on `chainKey` reads as `0n` rather than erroring. */
14
8
  export interface BalancesInputs {
15
9
  chainKey: SpokeChainKey | undefined;
16
10
  tokens: readonly XToken[];
@@ -23,16 +17,10 @@ export type UseBalancesParams = ReadHookParams<Record<string, bigint>, BalancesI
23
17
 
24
18
  const REFETCH_INTERVAL_MS = 5_000;
25
19
 
26
- /**
27
- * Pure builder for {@link useBalances} query options. Exported for unit tests and for advanced
28
- * callers that compose their own `useQuery` wrapper. Takes the SDK instance explicitly (the hook
29
- * supplies it from context).
30
- */
31
20
  export function getBalancesQueryOptions(sodax: Sodax, { chainKey, tokens, address, accountAddress }: BalancesInputs) {
32
21
  const tonAccount = chainKey === ChainKeys.TON_MAINNET && accountAddress ? { accountAddress } : undefined;
33
22
  return {
34
- // Pair symbol + address: readable in devtools, unique on-chain (symbol alone can collide —
35
- // e.g. scam tokens copying a legitimate ticker).
23
+ // Symbol alone can collide (scam tokens copy tickers), so pair it with the address.
36
24
  queryKey: [
37
25
  'shared',
38
26
  'balances',
@@ -49,35 +37,14 @@ export function getBalancesQueryOptions(sodax: Sodax, { chainKey, tokens, addres
49
37
  },
50
38
  enabled: !!chainKey && !!address && tokens.length > 0,
51
39
  refetchInterval: REFETCH_INTERVAL_MS,
52
- // Deliberately NOT `placeholderData: keepPreviousData`: the query key carries the chain, so a
53
- // chain switch would surface the previous chain's map — and every EVM chain shares the native
54
- // token address, so its native balance would render as the new chain's until the fetch lands.
40
+ // No `keepPreviousData`: EVM chains share the native token address, so a chain switch would
41
+ // show the previous chain's native balance until the fetch lands.
55
42
  };
56
43
  }
57
44
 
58
45
  /**
59
- * Fetch a user's own wallet balances for multiple tokens on a specific chain, straight from the
60
- * core SDK (`sodax.spoke.getWalletBalances`) — no wallet SDK / `xService` required. Returns an
61
- * object mapping each token's address to its balance in smallest units.
62
- *
63
- * This is the SDK-backed successor to {@link useXBalances} (which wraps a wallet-layer `xService`).
64
- * Prefer this when the app already has a `SodaxProvider`.
65
- *
66
- * Failure model: a token that could not be read is logged by the SDK and reported as `0n`, so a
67
- * flaky RPC is indistinguishable from an empty wallet — always the conservative direction, since
68
- * under-reporting blocks a spend rather than permitting one. The query only errors when the whole
69
- * batch is unusable: a shared round-trip every token depends on, or a batch in which no token
70
- * could be read at all.
71
- *
72
- * Chain-specific notes: Stellar XLM reports the *spendable* amount (total minus the minimum reserve
73
- * and selling liabilities); Bitcoin returns `0n` for Rune tokens, whose amounts are not exposed by
74
- * the UTXO endpoint.
75
- *
76
- * @example
77
- * ```tsx
78
- * const { data: balances } = useBalances({ params: { chainKey, address, tokens } });
79
- * const usdcBalance = balances?.[usdc.address] ?? 0n;
80
- * ```
46
+ * Balances keyed by token address. An unreadable token reports `0n`; the query errors only when the
47
+ * whole batch fails. Stellar XLM is the spendable amount; Bitcoin Runes read `0n`.
81
48
  */
82
49
  export function useBalances({ params, queryOptions }: UseBalancesParams = {}): UseQueryResult<Record<string, bigint>> {
83
50
  const { sodax } = useSodaxContext();
@@ -4,8 +4,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
4
4
  const invalidateQueries = vi.fn();
5
5
  const requestTrustline = vi.fn();
6
6
 
7
- // The hook is a pure options builder around useSafeMutation, so stubbing the three
8
- // React-side imports lets the real onSuccess run without a DOM.
7
+ // Stubbing the React-side imports lets the real onSuccess run without a DOM.
9
8
  vi.mock('@tanstack/react-query', () => ({ useQueryClient: () => ({ invalidateQueries }) }));
10
9
  vi.mock('./useSodaxContext.js', () => ({
11
10
  useSodaxContext: () => ({ sodax: { spoke: { stellar: { requestTrustline } } } }),
@@ -53,15 +52,12 @@ describe('useEstablishTrustline — invalidation after a broadcast trustline', (
53
52
  });
54
53
 
55
54
  it('SURVIVES a wallet that fails right after signing, and still invalidates', async () => {
56
- // The trustline is already on-chain here: throwing would report success as an
57
- // error and leave the gate showing "needs a trustline" until a manual refetch.
58
55
  const rejecting = vars(async () => {
59
56
  throw new Error('wallet is locked');
60
57
  });
61
58
 
62
59
  await expect(optionsOf().onSuccess('hash', rejecting, undefined)).resolves.toBeUndefined();
63
60
 
64
- // Falls back to the whole prefix, because the account is no longer identifiable.
65
61
  expect(invalidatedKeys()).toEqual([
66
62
  ['shared', 'stellarTrustlineCheck'],
67
63
  ['sponsoring', 'stellarAccountStatus'],
@@ -13,13 +13,7 @@ export type UseEstablishTrustlineVars = {
13
13
  walletProvider: IStellarWalletProvider;
14
14
  };
15
15
 
16
- /**
17
- * Establish a Stellar trustline. The account pays its fee and reserve; use
18
- * {@link useStellarGate} to verify it can afford them.
19
- *
20
- * Supersedes the deprecated `useRequestTrustline`, which keeps the hand-rolled
21
- * shape released in 2.0.0.
22
- */
16
+ /** The account pays the fee and reserve; use {@link useStellarGate} to verify it can afford them. */
23
17
  export function useEstablishTrustline({
24
18
  mutationOptions,
25
19
  }: MutationHookParams<string, UseEstablishTrustlineVars> = {}): SafeUseMutationResult<
@@ -34,8 +28,7 @@ export function useEstablishTrustline({
34
28
  mutationKey: ['shared', 'establishTrustline'],
35
29
  ...mutationOptions,
36
30
  mutationFn: async ({ token, amount, srcChainKey, walletProvider }): Promise<string> => {
37
- // Rejecting `0n` preserves the behaviour of the hook this replaced: an amount
38
- // sizes the trustline check, so zero is a caller bug rather than a request.
31
+ // The amount sizes the trustline check, so `0n` is a caller bug.
39
32
  if (!token || !amount) {
40
33
  throw new Error('Token and amount are required');
41
34
  }
@@ -50,11 +43,8 @@ export function useEstablishTrustline({
50
43
  });
51
44
  },
52
45
  onSuccess: async (data, vars, ctx) => {
53
- // The trustline is already broadcast here, so a wallet that locks or switches
54
- // accounts mid-flow must not turn success into an error — nor skip the
55
- // invalidations below, which is what an unguarded throw would do.
46
+ // Already broadcast: a locked/switched wallet must not turn success into an error or skip invalidation.
56
47
  const srcAddress = await vars.walletProvider.getWalletAddress().catch(() => undefined);
57
- // Without the address, invalidate the whole prefix rather than nothing.
58
48
  queryClient.invalidateQueries({
59
49
  queryKey: srcAddress
60
50
  ? ['shared', 'stellarTrustlineCheck', vars.srcChainKey, vars.token, srcAddress]
@@ -4,8 +4,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
4
4
  const invalidateQueries = vi.fn();
5
5
  const requestTrustline = vi.fn();
6
6
 
7
- // The hook is a pure options builder around useSafeMutation, so stubbing the React-side imports
8
- // lets the real mutationFn and onSuccess run without a DOM.
7
+ // Stubbing the React-side imports lets the real mutationFn and onSuccess run without a DOM.
9
8
  vi.mock('@tanstack/react-query', () => ({ useQueryClient: () => ({ invalidateQueries }) }));
10
9
  vi.mock('./useSodaxContext.js', () => ({
11
10
  useSodaxContext: () => ({ sodax: { spoke: { xrp: { requestTrustline } } } }),
@@ -8,17 +8,15 @@ import { useSodaxContext } from './useSodaxContext.js';
8
8
  import { unwrapResult } from './unwrapResult.js';
9
9
 
10
10
  export type UseEstablishXrpTrustlineVars = {
11
- /** The XRPL issued token to hold. */
12
11
  token: string;
13
- /** The account that needs the trustline. When set, the mutation refuses a wallet connected to another account. */
12
+ /** When set, the mutation refuses a wallet connected to another account. */
14
13
  address?: string;
15
14
  walletProvider: IXrpWalletProvider;
16
15
  };
17
16
 
18
17
  /**
19
- * Create the XRPL trustline the connected account needs to hold `token`, or raise its limit. Resolves to the
20
- * TrustSet hash once it validates. The account pays its fee and, unless the ledger waives it, an owner reserve: check with
21
- * {@link useXrpTrustlineReserveCheck}, or use {@link useXrpGate}, before asking the user to sign.
18
+ * Creates or raises the XRPL trustline; resolves to the validated TrustSet hash. The account pays the fee
19
+ * and possibly an owner reserve: check with {@link useXrpGate} before asking the user to sign.
22
20
  */
23
21
  export function useEstablishXrpTrustline({
24
22
  mutationOptions,
@@ -1,4 +1,3 @@
1
- // packages/dapp-kit/src/hooks/shared/useEstimateGas.ts
2
1
  import type { EstimateGasParams, GetEstimateGasReturnType, SpokeChainKey } from '@sodax/sdk';
3
2
  import { useSodaxContext } from './useSodaxContext.js';
4
3
  import type { MutationHookParams } from './types.js';
@@ -13,24 +13,7 @@ export type UseGetUserHubWalletAddressParams = ReadHookParams<
13
13
  }
14
14
  >;
15
15
 
16
- /**
17
- * Hook for deriving user wallet address for hub abstraction.
18
- *
19
- * This hook derives the user's abstracted wallet address for the hub chain based on the spoke chain ID and address.
20
- * If the spoke chain is the same as the hub chain, it returns the encoded spoke address.
21
- * Otherwise, it derives and returns the abstracted wallet address for cross-chain operations.
22
- * NOTE: This hook is different from useDeriveUserWalletAddress because it uses wallet router address instead of CREATE3 address for Sonic (hub).
23
- *
24
- * The query is automatically enabled when both `spokeChainId` and `spokeAddress` are provided.
25
- * This is a deterministic operation, so the result is cached and not refetched automatically.
26
- *
27
- * @example
28
- * ```typescript
29
- * const { data: derivedAddress, isLoading, error } = useGetUserHubWalletAddress({
30
- * params: { spokeChainId, spokeAddress: userAddress },
31
- * });
32
- * ```
33
- */
16
+ /** Unlike `useDeriveUserWalletAddress`, uses the wallet router address (not CREATE3) for the hub chain. */
34
17
  export function useGetUserHubWalletAddress({
35
18
  params,
36
19
  queryOptions,
@@ -13,15 +13,8 @@ export type UseNearStorageCheckParams = ReadHookParams<
13
13
  >;
14
14
 
15
15
  /**
16
- * Whether `accountId` is NEP-141 storage-registered for `token` on NEAR — the receive-side
17
- * prerequisite for any leg that delivers a token to the user on NEAR (swap output on NEAR, bridge
18
- * into NEAR, money-market borrow/withdraw to NEAR). NEAR's analogue of a Stellar trustline.
19
- *
20
- * Returns `true` (no gate) when `chainId` is not NEAR, mirroring how the Stellar trustline check
21
- * short-circuits off-chain. Native NEAR is not a NEP-141 token, so the SDK reports it as registered.
22
- *
23
- * Pair with {@link useRegisterNearStorage} to perform the one-time `storage_deposit` when this
24
- * resolves to `false`.
16
+ * Whether `accountId` is NEP-141 storage-registered to receive `token` on NEAR. Resolves `true` when
17
+ * `chainId` is not NEAR; native NEAR always reads as registered.
25
18
  */
26
19
  export function useNearStorageCheck({
27
20
  params,
@@ -4,38 +4,28 @@ import { useNearStorageCheck } from './useNearStorageCheck.js';
4
4
  import { useRegisterNearStorage } from './useRegisterNearStorage.js';
5
5
 
6
6
  export interface UseNearStorageGateParams {
7
- /** Destination chain the token is delivered on; `undefined` (not chosen yet) leaves the gate inert. */
7
+ /** `undefined` (not chosen yet) leaves the gate inert. */
8
8
  dstChainKey: SpokeChainKey | undefined;
9
- /** Destination token address the recipient must be registered for. */
10
9
  token: string | undefined;
11
- /** Recipient NEAR account id. */
12
10
  accountId: string | undefined;
13
- /** Destination wallet provider; only consumed when it is the NEAR provider. */
11
+ /** Only consumed when it is the NEAR provider. */
14
12
  walletProvider: GetWalletProviderType<SpokeChainKey> | undefined;
15
13
  }
16
14
 
17
15
  export interface NearStorageGate {
18
- /** Destination is NEAR. */
19
16
  isNear: boolean;
20
- /** Destination is NEAR and the recipient is not yet storage-registered for `token`. */
21
17
  needsRegistration: boolean;
22
- /** The downstream action must stay disabled while the gate is unresolved or unmet. */
18
+ /** True while the gate is unresolved or unmet. */
23
19
  blocksAction: boolean;
24
- /** The registration-status query is actively fetching. */
25
20
  isChecking: boolean;
26
- /** Destination is NEAR and the registration check failed, so whether the recipient can receive is unknown. */
27
21
  checkFailed: boolean;
28
- /** Re-run the registration check. */
29
22
  retry: () => void;
30
- /** A `storage_deposit` tx is in flight. */
31
23
  isRegistering: boolean;
32
- /** Submit the `storage_deposit`; resolves to the SDK `Result` or `undefined` if inputs are missing. */
24
+ /** Resolves to `undefined` if inputs are missing. */
33
25
  registerStorage: () => Promise<Result<string> | undefined>;
34
26
  }
35
27
 
36
- /**
37
- * NEP-141 storage-registration gate for flows that deliver a token to a user on NEAR.
38
- */
28
+ /** NEP-141 storage-registration gate for flows that deliver a token to a user on NEAR. */
39
29
  export function useNearStorageGate({
40
30
  dstChainKey,
41
31
  token,
@@ -12,16 +12,7 @@ export type UseRegisterNearStorageVars = {
12
12
  deposit?: bigint;
13
13
  };
14
14
 
15
- /**
16
- * Submit a NEP-141 `storage_deposit` so `accountId` can receive `token` on NEAR. NEAR's analogue of
17
- * requesting a Stellar trustline; pair with {@link useNearStorageCheck} and call this when the check
18
- * resolves to `false`. The recipient's NEAR wallet signs the registration tx.
19
- *
20
- * Pure mutation: pass `{ token, accountId, walletProvider }` to `mutate(...)`. The hook itself only
21
- * takes the structural `mutationOptions` slot. `registerStorage` throws natively (no `Result<T>`),
22
- * so this hook is registered as `nativeThrow` in the mutation contract. On success it invalidates
23
- * the matching {@link useNearStorageCheck} query.
24
- */
15
+ /** NEP-141 `storage_deposit` so `accountId` can receive `token` on NEAR; the recipient's wallet signs. */
25
16
  export function useRegisterNearStorage({
26
17
  mutationOptions,
27
18
  }: MutationHookParams<string, UseRegisterNearStorageVars> = {}): SafeUseMutationResult<
@@ -34,6 +25,7 @@ export function useRegisterNearStorage({
34
25
  return useSafeMutation<string, Error, UseRegisterNearStorageVars>({
35
26
  mutationKey: ['shared', 'registerNearStorage'],
36
27
  ...mutationOptions,
28
+ // `registerStorage` throws natively (no Result), hence `nativeThrow` in the mutation contract.
37
29
  mutationFn: async ({ token, accountId, walletProvider, deposit }) =>
38
30
  sodax.spoke.near.registerStorage({ token, accountId, walletProvider, deposit, raw: false }),
39
31
  onSuccess: async (data, vars, ctx) => {
@@ -14,8 +14,7 @@ let mutation: MutationState;
14
14
  const refSlots: Array<{ current: unknown }> = [];
15
15
  let refCursor = 0;
16
16
 
17
- // Only useRef and useCallback are needed, and call order is stable, so this replays React's
18
- // slot semantics well enough to observe the deprecated hook across renders — no DOM, no renderer.
17
+ // Replays React's ref slots by call order, enough to observe the hook across renders without a DOM.
19
18
  vi.mock('react', () => ({
20
19
  useRef: (initial: unknown) => {
21
20
  const slot = refSlots[refCursor] ?? { current: initial };
@@ -39,12 +38,9 @@ const idle: MutationState = {
39
38
  data: undefined,
40
39
  };
41
40
 
42
- /** One render of the hook, with the mutation in `state`. */
43
41
  const render = (state: Partial<MutationState> = {}) => {
44
42
  mutation = { ...idle, ...state };
45
43
  refCursor = 0;
46
- // The positional argument was ignored in 2.0.0 and still is; passed here because keeping it
47
- // callable is the point of this wrapper.
48
44
  return useRequestTrustline(TOKEN);
49
45
  };
50
46
 
@@ -79,8 +75,6 @@ describe('useRequestTrustline — 2.0.0 compatibility wrapper', () => {
79
75
  expect(first.isRequested).toBe(true);
80
76
  expect(first.data).toBe('hash');
81
77
 
82
- // React Query clears data and isSuccess once the next attempt starts; 2.0.0 held both
83
- // in component state and never cleared them.
84
78
  const retrying = render({ isPending: true });
85
79
  expect(retrying.isRequested).toBe(true);
86
80
  expect(retrying.data).toBe('hash');
@@ -1,10 +1,7 @@
1
1
  import { useCallback, useRef } from 'react';
2
2
  import { useEstablishTrustline, type UseEstablishTrustlineVars } from './useEstablishTrustline.js';
3
3
 
4
- /**
5
- * The shape released in 2.0.0. Declared explicitly so a change to it fails
6
- * `checkTs` here rather than silently breaking consumers.
7
- */
4
+ // The 2.0.0 shape, declared explicitly so a change fails `checkTs` here instead of breaking consumers.
8
5
  type ReleasedRequestTrustline = {
9
6
  requestTrustline: (params: UseEstablishTrustlineVars) => Promise<string>;
10
7
  isLoading: boolean;
@@ -14,20 +11,13 @@ type ReleasedRequestTrustline = {
14
11
  };
15
12
 
16
13
  /**
17
- * Establish a Stellar trustline.
18
- *
19
- * @deprecated Use {@link useEstablishTrustline}, the canonical mutation hook, which exposes
20
- * `mutate` / `mutateAsync` / `mutateAsyncSafe` and accepts `mutationOptions`. This wrapper
21
- * preserves the shape released in 2.0.0 and will be removed in the next major.
22
- *
23
- * @param token - Ignored, as it was in 2.0.0. Accepted only so existing call sites compile.
14
+ * @deprecated Use {@link useEstablishTrustline}; removed in the next major. `token` is ignored, as in 2.0.0.
24
15
  */
25
16
  export function useRequestTrustline(token?: string | undefined): ReleasedRequestTrustline {
26
17
  const { mutateAsync, isPending, isSuccess, error, data } = useEstablishTrustline();
27
18
 
28
- // 2.0.0 held `isRequested` and `data` in component state and never cleared them, whereas
29
- // React Query resets its equivalents when the next attempt starts. Latch to keep the
30
- // released semantics: a retry that fails must not un-report the trustline that succeeded.
19
+ // Latch like 2.0.0 did: React Query resets these on the next attempt, but a failed retry
20
+ // must not un-report a trustline that succeeded.
31
21
  const requested = useRef(false);
32
22
  const lastData = useRef<string | null>(null);
33
23
  if (isSuccess) requested.current = true;
@@ -26,8 +26,6 @@ describe('toResult', () => {
26
26
  });
27
27
 
28
28
  it('does not catch synchronous throws above the await — caller must produce a Promise', async () => {
29
- // Documents the contract: toResult only neutralizes Promise rejections, not sync throws
30
- // before the Promise is constructed. Hooks always pass `mutateAsync(vars)` which is async.
31
29
  const wrapped = (): Promise<Result<number>> =>
32
30
  toResult(
33
31
  (async () => {
@@ -39,5 +37,4 @@ describe('toResult', () => {
39
37
  });
40
38
  });
41
39
 
42
- // Local type alias to keep the file self-contained — mirrors @sodax/sdk's Result<T>.
43
40
  type Result<T> = { ok: true; value: T } | { ok: false; error: unknown };