@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.
- package/README.md +1 -1
- package/dist/index.d.ts +279 -2428
- package/dist/index.mjs +15 -24
- package/package.json +2 -2
- package/src/hooks/_apiKeyWire.test.ts +4 -29
- package/src/hooks/_mutationContract.test.ts +1 -8
- package/src/hooks/backend/index.ts +0 -13
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +0 -6
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +0 -10
- package/src/hooks/backend/useBackendIntentByHash.ts +0 -6
- package/src/hooks/backend/useBackendIntentByTxHash.ts +1 -10
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +0 -6
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +0 -8
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +0 -8
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +0 -6
- package/src/hooks/backend/useBackendOracleCandles.ts +1 -9
- package/src/hooks/backend/useBackendOracleMarkets.ts +1 -7
- package/src/hooks/backend/useBackendOrderbook.ts +0 -6
- package/src/hooks/backend/useBackendUserIntents.ts +0 -8
- package/src/hooks/bitcoin/resolveBtcReadAddress.test.ts +1 -3
- package/src/hooks/bitcoin/resolveBtcReadAddress.ts +2 -12
- package/src/hooks/bitcoin/useBitcoinBalance.ts +1 -7
- package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +2 -4
- package/src/hooks/bitcoin/useEnsureRadfiAccessToken.ts +2 -13
- package/src/hooks/bitcoin/useFundTradingWallet.ts +0 -6
- package/src/hooks/bitcoin/useRadfiAuth.ts +1 -6
- package/src/hooks/bitcoin/useRadfiSession.ts +0 -1
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +0 -6
- package/src/hooks/bitcoin/useRenewUtxos.ts +0 -5
- package/src/hooks/bitcoin/useTradingWallet.ts +1 -4
- package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.test.ts +1 -7
- package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.ts +7 -21
- package/src/hooks/bridge/useBridge.test.ts +1 -11
- package/src/hooks/bridge/useBridge.ts +2 -12
- package/src/hooks/bridge/useBridgeAllowance.ts +1 -2
- package/src/hooks/bridge/useBridgeApprovalStrategy.ts +2 -6
- package/src/hooks/bridge/useBridgeApprove.ts +2 -14
- package/src/hooks/bridge/useBridgeDetailedStatus.test.ts +2 -11
- package/src/hooks/bridge/useBridgeDetailedStatus.ts +3 -23
- package/src/hooks/bridge/useBridgeWithApproval.ts +2 -11
- package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.test.ts +2 -7
- package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.ts +2 -13
- package/src/hooks/bridgeApi/index.ts +11 -14
- package/src/hooks/bridgeApi/useBridgeApiAllowance.ts +1 -9
- package/src/hooks/bridgeApi/useBridgeApiApprove.ts +2 -17
- package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.test.ts +2 -13
- package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.ts +3 -20
- package/src/hooks/bridgeApi/useBridgeApiBridgeableAmount.ts +1 -12
- package/src/hooks/bridgeApi/useBridgeApiCreateBridgeIntent.ts +1 -14
- package/src/hooks/bridgeApi/useBridgeApiFee.ts +2 -11
- package/src/hooks/bridgeApi/useBridgeApiIsBridgeable.ts +1 -12
- package/src/hooks/bridgeApi/useBridgeApiSubmitTx.ts +2 -23
- package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.test.ts +1 -9
- package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.ts +1 -19
- package/src/hooks/bridgeApi/useBridgeApiTokens.ts +0 -8
- package/src/hooks/bridgeApi/useBridgeApiTokensByChain.ts +0 -7
- package/src/hooks/dex/useClaimRewards.ts +1 -12
- package/src/hooks/dex/useCreateDecreaseLiquidityParams.ts +1 -5
- package/src/hooks/dex/useCreateDepositParams.ts +1 -5
- package/src/hooks/dex/useCreateSupplyLiquidityParams.ts +1 -10
- package/src/hooks/dex/useCreateWithdrawParams.ts +1 -5
- package/src/hooks/dex/useDecreaseLiquidity.ts +2 -15
- package/src/hooks/dex/useDexAllowance.ts +1 -5
- package/src/hooks/dex/useDexApprove.ts +1 -12
- package/src/hooks/dex/useDexDeposit.ts +1 -23
- package/src/hooks/dex/useDexWithdraw.ts +1 -13
- package/src/hooks/dex/useLiquidityAmounts.ts +1 -4
- package/src/hooks/dex/usePoolBalances.ts +0 -4
- package/src/hooks/dex/usePoolData.ts +1 -4
- package/src/hooks/dex/usePools.ts +1 -4
- package/src/hooks/dex/usePositionInfo.ts +1 -4
- package/src/hooks/dex/useSupplyLiquidity.ts +3 -20
- package/src/hooks/leverageYield/useApproveLeveragePositionFunding.ts +2 -8
- package/src/hooks/leverageYield/useLeveragePositionAccount.ts +2 -13
- package/src/hooks/leverageYield/useLeveragePositionCollateral.ts +2 -14
- package/src/hooks/leverageYield/useLeveragePositionFundingAllowance.ts +2 -9
- package/src/hooks/leverageYield/useLeveragePositionInfo.ts +1 -13
- package/src/hooks/leverageYield/useLeveragePositionPayoutAddress.ts +3 -15
- package/src/hooks/leverageYield/useLeveragePositionPending.ts +2 -16
- package/src/hooks/leverageYield/useLeveragePositions.ts +1 -15
- package/src/hooks/leverageYield/useLeveragePositionsForUser.ts +1 -15
- package/src/hooks/leverageYield/useLeverageYieldApprovalStrategy.ts +1 -6
- package/src/hooks/leverageYield/useLeverageYieldDeposit.ts +1 -17
- package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.test.ts +3 -14
- package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.ts +2 -19
- package/src/hooks/leverageYield/useLeverageYieldEffectiveApr.ts +1 -12
- package/src/hooks/leverageYield/useLeverageYieldNotifySolver.ts +1 -11
- package/src/hooks/leverageYield/useLeverageYieldPosition.ts +1 -13
- package/src/hooks/leverageYield/useLeverageYieldPreviewRedeem.ts +1 -12
- package/src/hooks/leverageYield/useLeverageYieldQuote.test.ts +3 -13
- package/src/hooks/leverageYield/useLeverageYieldQuote.ts +5 -54
- package/src/hooks/leverageYield/useLeverageYieldShareBalances.ts +2 -29
- package/src/hooks/leverageYield/useLeverageYieldTotalAssets.ts +1 -9
- package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +2 -25
- package/src/hooks/leverageYield/useLeverageYieldVaultSwapWithApproval.ts +1 -11
- package/src/hooks/leverageYield/useLeverageYieldWithdraw.ts +1 -17
- package/src/hooks/leverageYield/useOpenLeveragePosition.ts +5 -18
- package/src/hooks/leverageYield/useRunLeveragePositionOperation.ts +4 -20
- package/src/hooks/leverageYield/useSubmitLeveragePositionIntent.ts +3 -15
- package/src/hooks/leverageYieldApi/index.ts +0 -15
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAllowance.ts +1 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApprove.ts +3 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.test.ts +4 -14
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts +4 -26
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAsset.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCancelIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateDepositIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateWithdrawIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDeadline.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDepositQuote.ts +1 -15
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEffectiveApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEstimateGas.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiFilledIntent.ts +1 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntent.ts +1 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentExtraData.ts +1 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentHash.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentPacket.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiLsdApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiMaxWithdraw.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPartnerFee.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPosition.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewDeposit.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewRedeem.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewWithdraw.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiShareBalance.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSolverFee.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiStatus.ts +2 -12
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTx.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTxStatus.ts +2 -17
- package/src/hooks/leverageYieldApi/useLeverageYieldApiTotalAssets.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVault.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVaults.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiWithdrawQuote.ts +1 -15
- package/src/hooks/migrate/useMigrateBaln.ts +1 -8
- package/src/hooks/migrate/useMigrateIcxToSoda.ts +1 -12
- package/src/hooks/migrate/useMigratebnUSD.ts +1 -12
- package/src/hooks/migrate/useMigrationAllowance.ts +3 -19
- package/src/hooks/migrate/useMigrationApprove.ts +2 -20
- package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +0 -7
- package/src/hooks/mm/useAToken.ts +1 -6
- package/src/hooks/mm/useATokensBalances.ts +0 -5
- package/src/hooks/mm/useBorrow.ts +1 -13
- package/src/hooks/mm/useEModes.ts +2 -13
- package/src/hooks/mm/useMMAllowance.test.ts +55 -0
- package/src/hooks/mm/useMMAllowance.ts +6 -16
- package/src/hooks/mm/useMMApprove.ts +1 -14
- package/src/hooks/mm/useRepay.ts +1 -12
- package/src/hooks/mm/useReservesData.ts +0 -4
- package/src/hooks/mm/useReservesHumanized.ts +0 -4
- package/src/hooks/mm/useReservesList.ts +0 -4
- package/src/hooks/mm/useReservesUsdFormat.ts +0 -4
- package/src/hooks/mm/useSupply.ts +1 -24
- package/src/hooks/mm/useUserFormattedSummary.ts +0 -7
- package/src/hooks/mm/useUserReservesData.ts +0 -4
- package/src/hooks/mm/useWithdraw.ts +1 -13
- package/src/hooks/partner/useApproveToken.ts +1 -7
- package/src/hooks/partner/useFeeClaimSwap.ts +1 -7
- package/src/hooks/partner/useFeeClaimWithdraw.ts +3 -20
- package/src/hooks/partner/useFetchAssetsBalances.ts +0 -4
- package/src/hooks/partner/useGetAutoSwapPreferences.ts +0 -4
- package/src/hooks/partner/useGetIntentDetails.ts +1 -8
- package/src/hooks/partner/useGetUserIntent.ts +1 -8
- package/src/hooks/partner/useIsTokenApproved.ts +0 -4
- package/src/hooks/partner/usePartnerCancelIntent.ts +2 -9
- package/src/hooks/partner/useSetSwapPreference.ts +1 -14
- package/src/hooks/recovery/useHubAssetBalances.ts +1 -6
- package/src/hooks/recovery/useWithdrawHubAsset.ts +1 -13
- package/src/hooks/shared/invalidateBalances.ts +2 -10
- package/src/hooks/shared/isUserRejectedError.test.ts +0 -3
- package/src/hooks/shared/isUserRejectedError.ts +2 -23
- package/src/hooks/shared/notFoundStreak.ts +5 -22
- package/src/hooks/shared/retryUnlessAuthFailure.test.ts +1 -2
- package/src/hooks/shared/retryUnlessAuthFailure.ts +1 -12
- package/src/hooks/shared/solverStatusPolicy.test.ts +0 -5
- package/src/hooks/shared/solverStatusPolicy.ts +8 -58
- package/src/hooks/shared/types.ts +4 -55
- package/src/hooks/shared/unwrapResult.ts +1 -8
- package/src/hooks/shared/useBalances.ts +6 -39
- package/src/hooks/shared/useEstablishTrustline.test.ts +1 -5
- package/src/hooks/shared/useEstablishTrustline.ts +3 -13
- package/src/hooks/shared/useEstablishXrpTrustline.test.ts +1 -2
- package/src/hooks/shared/useEstablishXrpTrustline.ts +3 -5
- package/src/hooks/shared/useEstimateGas.ts +0 -1
- package/src/hooks/shared/useGetUserHubWalletAddress.ts +1 -18
- package/src/hooks/shared/useNearStorageCheck.ts +2 -9
- package/src/hooks/shared/useNearStorageGate.ts +5 -15
- package/src/hooks/shared/useRegisterNearStorage.ts +2 -10
- package/src/hooks/shared/useRequestTrustline.test.ts +1 -7
- package/src/hooks/shared/useRequestTrustline.ts +4 -14
- package/src/hooks/shared/useSafeMutation.test.ts +0 -3
- package/src/hooks/shared/useSafeMutation.ts +2 -26
- package/src/hooks/shared/useSodaxContext.ts +0 -6
- package/src/hooks/shared/useStellarGate.test.ts +2 -9
- package/src/hooks/shared/useStellarGate.ts +3 -9
- package/src/hooks/shared/useStellarTrustlineCheck.test.ts +0 -2
- package/src/hooks/shared/useStellarTrustlineCheck.ts +1 -4
- package/src/hooks/shared/useXBalances.ts +2 -20
- package/src/hooks/shared/useXrpDestinationCheck.ts +1 -5
- package/src/hooks/shared/useXrpGate.test.ts +1 -3
- package/src/hooks/shared/useXrpGate.ts +2 -3
- package/src/hooks/shared/waitForApiAllowance.test.ts +0 -1
- package/src/hooks/shared/waitForApiAllowance.ts +2 -6
- package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +1 -2
- package/src/hooks/sponsoring/useActivateStellarAccount.ts +1 -5
- package/src/hooks/sponsoring/useActivateStellarAccount.wire.test.ts +2 -13
- package/src/hooks/sponsoring/useSponsorConfig.ts +0 -1
- package/src/hooks/sponsoring/useStellarAccountActive.ts +0 -1
- package/src/hooks/sponsoring/useStellarAccountStatus.ts +1 -4
- package/src/hooks/staking/index.ts +0 -1
- package/src/hooks/staking/useCancelUnstake.ts +1 -7
- package/src/hooks/staking/useClaim.ts +1 -7
- package/src/hooks/staking/useConvertedAssets.ts +1 -4
- package/src/hooks/staking/useInstantUnstake.ts +1 -7
- package/src/hooks/staking/useInstantUnstakeAllowance.ts +1 -5
- package/src/hooks/staking/useInstantUnstakeApprove.ts +1 -11
- package/src/hooks/staking/useInstantUnstakeRatio.ts +1 -4
- package/src/hooks/staking/useStake.ts +1 -12
- package/src/hooks/staking/useStakeAllowance.ts +1 -5
- package/src/hooks/staking/useStakeApprove.ts +1 -11
- package/src/hooks/staking/useStakeRatio.ts +1 -4
- package/src/hooks/staking/useStakingConfig.ts +1 -4
- package/src/hooks/staking/useStakingInfo.ts +1 -5
- package/src/hooks/staking/useUnstake.ts +2 -9
- package/src/hooks/staking/useUnstakeAllowance.ts +1 -5
- package/src/hooks/staking/useUnstakeApprove.ts +1 -10
- package/src/hooks/staking/useUnstakingInfo.ts +1 -4
- package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +1 -4
- package/src/hooks/swap/useCancelLimitOrder.ts +1 -7
- package/src/hooks/swap/useCancelSwap.ts +1 -7
- package/src/hooks/swap/useCreateLimitOrder.ts +2 -12
- package/src/hooks/swap/useDetailedStatus.test.ts +6 -18
- package/src/hooks/swap/useDetailedStatus.ts +2 -19
- package/src/hooks/swap/useQuote.test.ts +2 -8
- package/src/hooks/swap/useQuote.ts +5 -32
- package/src/hooks/swap/useStatus.ts +2 -10
- package/src/hooks/swap/useSwap.test.ts +1 -11
- package/src/hooks/swap/useSwap.ts +2 -12
- package/src/hooks/swap/useSwapAllowance.ts +1 -2
- package/src/hooks/swap/useSwapApprovalStrategy.ts +2 -7
- package/src/hooks/swap/useSwapApprove.ts +2 -14
- package/src/hooks/swap/useSwapLifecycle.test.ts +1 -2
- package/src/hooks/swap/useSwapLifecycle.ts +9 -27
- package/src/hooks/swap/useSwapWithApproval.ts +2 -11
- package/src/hooks/swapsApi/index.ts +2 -14
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +1 -5
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiAllowance.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiApprove.ts +1 -14
- package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.test.ts +5 -20
- package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.ts +3 -24
- package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.test.ts +2 -8
- package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.ts +6 -41
- package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +0 -13
- package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +0 -13
- package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +1 -13
- package/src/hooks/swapsApi/useSwapsApiDeadline.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +0 -8
- package/src/hooks/swapsApi/useSwapsApiIntent.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +1 -8
- package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +1 -10
- package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiQuote.ts +2 -24
- package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiStatus.ts +1 -11
- package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +1 -15
- package/src/hooks/swapsApi/useSwapsApiSubmitTx.ts +0 -21
- package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +2 -19
- package/src/hooks/swapsApi/useSwapsApiTokens.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +0 -7
- package/src/index.ts +1 -1
- package/src/providers/SodaxProvider.test.ts +2 -9
- package/src/providers/SodaxProvider.tsx +1 -12
- package/src/providers/createSodaxQueryClient.ts +4 -56
- package/src/utils/approvalPlan.ts +9 -32
- package/src/utils/dex-utils.ts +5 -20
- package/src/utils/nearStorageGate.ts +3 -14
- package/src/utils/stellarGate.ts +3 -16
- package/src/utils/swapLifecycle.ts +7 -26
- package/src/utils/xrpGate.ts +1 -4
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/shared/useSafeMutation.ts
|
|
2
1
|
import type { Result } from '@sodax/sdk';
|
|
3
2
|
import {
|
|
4
3
|
useMutation,
|
|
@@ -10,35 +9,16 @@ import {
|
|
|
10
9
|
import { useCallback } from 'react';
|
|
11
10
|
import { retryBeforeSubmission } from './retryBeforeSubmission.js';
|
|
12
11
|
|
|
13
|
-
/**
|
|
14
|
-
* Return shape of every dapp-kit mutation hook. Extends `UseMutationResult` with one extra
|
|
15
|
-
* method, `mutateAsyncSafe`, that never rejects — it returns the SDK's `Result<T>` shape so
|
|
16
|
-
* callers can branch on `.ok` without `try/catch`.
|
|
17
|
-
*
|
|
18
|
-
* The underlying `mutationFn` still throws on SDK failure, so React Query's native error model
|
|
19
|
-
* (`isError`, `error`, `onError`, `retry`, `throwOnError`, devtools) keeps working as documented.
|
|
20
|
-
*/
|
|
21
12
|
export type SafeUseMutationResult<TData, TError, TVars, TContext = unknown> = UseMutationResult<
|
|
22
13
|
TData,
|
|
23
14
|
TError,
|
|
24
15
|
TVars,
|
|
25
16
|
TContext
|
|
26
17
|
> & {
|
|
27
|
-
/**
|
|
28
|
-
* Like `mutateAsync` but never rejects. Returns `Result<TData>` so callers can branch
|
|
29
|
-
* on `.ok` without `try/catch`.
|
|
30
|
-
*
|
|
31
|
-
* Use this for imperative flows where rejection-style errors are awkward — e.g. sequential
|
|
32
|
-
* `if (!hasAllowance) await approve(...); await action(...)` chains where the user-reject
|
|
33
|
-
* case is the modal failure mode, not an exceptional one.
|
|
34
|
-
*/
|
|
18
|
+
/** Like `mutateAsync` but never rejects; resolves to `Result<TData>`. */
|
|
35
19
|
mutateAsyncSafe: (vars: TVars, options?: MutateOptions<TData, TError, TVars, TContext>) => Promise<Result<TData>>;
|
|
36
20
|
};
|
|
37
21
|
|
|
38
|
-
/**
|
|
39
|
-
* Wraps a `Promise<T>` (typically `mutateAsync(vars)`) into a `Promise<Result<T>>` that never
|
|
40
|
-
* rejects. Pure, side-effect-free — extracted for unit testing.
|
|
41
|
-
*/
|
|
42
22
|
export async function toResult<T>(promise: Promise<T>): Promise<Result<T>> {
|
|
43
23
|
try {
|
|
44
24
|
const value = await promise;
|
|
@@ -48,11 +28,7 @@ export async function toResult<T>(promise: Promise<T>): Promise<Result<T>> {
|
|
|
48
28
|
}
|
|
49
29
|
}
|
|
50
30
|
|
|
51
|
-
/**
|
|
52
|
-
* Drop-in replacement for `useMutation` that augments the result with `mutateAsyncSafe`. Used
|
|
53
|
-
* by every dapp-kit mutation hook so consumers can pick rejection-style (`mutateAsync`) or
|
|
54
|
-
* Result-style (`mutateAsyncSafe`) ergonomics without the hook author having to think about it.
|
|
55
|
-
*/
|
|
31
|
+
/** `useMutation` plus `mutateAsyncSafe`; retries are suppressed once funds may have moved. */
|
|
56
32
|
export function useSafeMutation<TData, TError, TVars, TContext = unknown>(
|
|
57
33
|
options: UseMutationOptions<TData, TError, TVars, TContext>,
|
|
58
34
|
): SafeUseMutationResult<TData, TError, TVars, TContext> {
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { SodaxContext, type SodaxContextType } from '@/contexts/index.js';
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Hook to access the Sodax context which provides access to the Sodax SDK instance and chain configuration
|
|
6
|
-
* @throws {Error} If used outside of a SodaxProvider
|
|
7
|
-
* @returns {SodaxContextType} The Sodax context containing SDK instance and configuration
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
4
|
export const useSodaxContext = (): SodaxContextType => {
|
|
11
5
|
const context = useContext(SodaxContext);
|
|
12
6
|
if (!context) {
|
|
@@ -5,8 +5,7 @@ const statusCheck = vi.fn();
|
|
|
5
5
|
const trustlineCheck = vi.fn();
|
|
6
6
|
const requiresTrustline = vi.fn(() => true);
|
|
7
7
|
|
|
8
|
-
// Stubbing the child hooks keeps this a DOM-free assertion on the params the gate builds
|
|
9
|
-
// the resolver itself is covered by utils/stellarGate.test.ts.
|
|
8
|
+
// Stubbing the child hooks keeps this a DOM-free assertion on the params the gate builds.
|
|
10
9
|
vi.mock('../sponsoring/useStellarAccountStatus.js', () => ({
|
|
11
10
|
useStellarAccountStatus: (args: unknown) => statusCheck(args),
|
|
12
11
|
}));
|
|
@@ -30,10 +29,7 @@ const ADDRESS = 'GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
|
|
|
30
29
|
|
|
31
30
|
const idle = { isLoading: false, isError: false, data: undefined, error: null, refetch: vi.fn() };
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
* Drive the gate with a given account-status result. An absent `walletAddress` is what
|
|
35
|
-
* leaves `useStellarTrustlineCheck` disabled, so it stands in for "no Horizon read".
|
|
36
|
-
*/
|
|
32
|
+
// An absent `walletAddress` leaves `useStellarTrustlineCheck` disabled: it stands in for "no Horizon read".
|
|
37
33
|
const run = (status: unknown, overrides: Record<string, unknown> = {}) => {
|
|
38
34
|
statusCheck.mockReturnValue({ ...idle, ...(status as object) });
|
|
39
35
|
trustlineCheck.mockReturnValue(idle);
|
|
@@ -58,15 +54,12 @@ beforeEach(() => {
|
|
|
58
54
|
|
|
59
55
|
describe('useStellarGate — the trustline read is gated on account existence', () => {
|
|
60
56
|
it('does NOT read the trustline for an account that does not exist', () => {
|
|
61
|
-
// hasSufficientTrustline 404s on a missing account, and React Query would retry it.
|
|
62
57
|
const { gate, trustlineAddress } = run({ data: { exists: false, canAffordTrustline: false } });
|
|
63
58
|
|
|
64
59
|
expect(trustlineAddress).toBeUndefined();
|
|
65
|
-
// The gate still reaches the right conclusion without the trustline read.
|
|
66
60
|
expect(gate.needsActivation).toBe(true);
|
|
67
61
|
expect(gate.blocksAction).toBe(true);
|
|
68
62
|
expect(gate.checkFailed).toBe(false);
|
|
69
|
-
// No spurious error while the UI is showing "activate".
|
|
70
63
|
expect(gate.error).toBeUndefined();
|
|
71
64
|
});
|
|
72
65
|
|
|
@@ -33,10 +33,7 @@ export interface StellarGate extends StellarGateState {
|
|
|
33
33
|
requestTrustline: () => Promise<Result<string> | undefined>;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
* Gate Stellar delivery on account activation, trustline availability, and
|
|
38
|
-
* enough spendable XLM to create a missing trustline.
|
|
39
|
-
*/
|
|
36
|
+
/** Gates Stellar delivery on account activation, trustline, and enough spendable XLM to create one. */
|
|
40
37
|
export function useStellarGate({
|
|
41
38
|
dstChainKey,
|
|
42
39
|
token,
|
|
@@ -51,11 +48,8 @@ export function useStellarGate({
|
|
|
51
48
|
const gatedAddress = isStellarDestination ? address : undefined;
|
|
52
49
|
|
|
53
50
|
const statusCheck = useStellarAccountStatus({ params: { address: gatedAddress } });
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
// and surface the failure on `error` while the gate is correctly reporting `needsActivation`.
|
|
57
|
-
// `resolveStellarGate` decides activation from `statusCheck` alone and reads the unresolved
|
|
58
|
-
// trustline query as blocking, so this never changes the gate's outcome.
|
|
51
|
+
// `hasSufficientTrustline` 404s on a missing account, so keep the trustline query disabled until
|
|
52
|
+
// the account exists; otherwise its retries surface on `error` while the gate says `needsActivation`.
|
|
59
53
|
const trustlineAddress = statusCheck.data?.exists === true ? gatedAddress : undefined;
|
|
60
54
|
const trustlineCheck = useStellarTrustlineCheck({
|
|
61
55
|
params: { token, amount, chainId: dstChainKey, walletAddress: trustlineAddress },
|
|
@@ -44,8 +44,6 @@ describe('getStellarTrustlineCheckQueryOptions — query key', () => {
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
it('shares the useEstablishTrustline invalidation prefix (chain, token, account) across every amount', () => {
|
|
47
|
-
// useEstablishTrustline invalidates ['shared','stellarTrustlineCheck', srcChainKey, token, srcAddress];
|
|
48
|
-
// amount sits after that prefix, so the invalidation covers the account's checks at any amount.
|
|
49
47
|
const invalidationKey = ['shared', 'stellarTrustlineCheck', STELLAR, TOKEN, WALLET_A];
|
|
50
48
|
for (const amount of [100n, 10_000n]) {
|
|
51
49
|
expect(optionsFor({ amount }).queryKey.slice(0, invalidationKey.length)).toEqual(invalidationKey);
|
|
@@ -9,15 +9,13 @@ export type UseStellarTrustlineCheckParams = ReadHookParams<
|
|
|
9
9
|
token: string | undefined;
|
|
10
10
|
amount: bigint | undefined;
|
|
11
11
|
chainId: SpokeChainKey | undefined;
|
|
12
|
-
/** Resolved Stellar account address (e.g. `useXAccount('STELLAR').address`) — keys the cache per account. */
|
|
13
12
|
walletAddress: string | undefined;
|
|
14
13
|
}
|
|
15
14
|
>;
|
|
16
15
|
|
|
17
|
-
// Narrow slice
|
|
16
|
+
// Narrow slice so tests can pass a minimal stub without casting `Sodax`.
|
|
18
17
|
type StellarTrustlineReader = { spoke: { stellar: Pick<Sodax['spoke']['stellar'], 'hasSufficientTrustline'> } };
|
|
19
18
|
|
|
20
|
-
// Pure query options, extracted for unit testing (mirrors `getXBalancesQueryOptions`).
|
|
21
19
|
export function getStellarTrustlineCheckQueryOptions({
|
|
22
20
|
sodax,
|
|
23
21
|
token,
|
|
@@ -32,7 +30,6 @@ export function getStellarTrustlineCheckQueryOptions({
|
|
|
32
30
|
walletAddress: string | undefined;
|
|
33
31
|
}) {
|
|
34
32
|
return {
|
|
35
|
-
// Key on chain, token, account, amount so editing the amount (or switching account/chain) re-queries.
|
|
36
33
|
queryKey: ['shared', 'stellarTrustlineCheck', chainId, token, walletAddress, amount?.toString()] as const,
|
|
37
34
|
queryFn: async (): Promise<boolean> => {
|
|
38
35
|
if (chainId !== ChainKeys.STELLAR_MAINNET) return true;
|
|
@@ -2,10 +2,6 @@ import { type UseQueryResult, useQuery } from '@tanstack/react-query';
|
|
|
2
2
|
import type { SpokeChainKey, IXServiceBase, XToken } from '@sodax/sdk';
|
|
3
3
|
import type { ReadHookParams } from './types.js';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Domain inputs for {@link useXBalances}. `xChainId` is optional so the hook can be mounted
|
|
7
|
-
* before a chain is selected; `enabled` gates execution on every required field being present.
|
|
8
|
-
*/
|
|
9
5
|
export interface XBalancesInputs {
|
|
10
6
|
xService: IXServiceBase | undefined;
|
|
11
7
|
xChainId: SpokeChainKey | undefined;
|
|
@@ -17,14 +13,9 @@ export type UseXBalancesParams = ReadHookParams<Record<string, bigint>, XBalance
|
|
|
17
13
|
|
|
18
14
|
const REFETCH_INTERVAL_MS = 5_000;
|
|
19
15
|
|
|
20
|
-
/**
|
|
21
|
-
* Pure builder for {@link useXBalances} query options. Exported for unit
|
|
22
|
-
* tests and for advanced callers that compose their own `useQuery` wrapper.
|
|
23
|
-
*/
|
|
24
16
|
export function getXBalancesQueryOptions({ xService, xChainId, xTokens, address }: XBalancesInputs) {
|
|
25
17
|
return {
|
|
26
|
-
//
|
|
27
|
-
// can collide — e.g. scam tokens copying legitimate ticker).
|
|
18
|
+
// Symbol alone can collide (scam tokens copy tickers), so pair it with the address.
|
|
28
19
|
queryKey: ['shared', 'xBalances', xChainId, xTokens.map(x => [x.symbol, x.address] as const), address] as const,
|
|
29
20
|
queryFn: async (): Promise<Record<string, bigint>> => {
|
|
30
21
|
if (!xService) return {};
|
|
@@ -35,16 +26,7 @@ export function getXBalancesQueryOptions({ xService, xChainId, xTokens, address
|
|
|
35
26
|
};
|
|
36
27
|
}
|
|
37
28
|
|
|
38
|
-
/**
|
|
39
|
-
* Fetch token balances for multiple tokens on a specific chain. Returns an
|
|
40
|
-
* object mapping each token's address to its balance in smallest unit.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* const xService = useXService({ xChainType: getXChainType(xChainId) });
|
|
45
|
-
* const { data: balances } = useXBalances({ params: { xService, xChainId, xTokens, address } });
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
29
|
+
/** Balances keyed by token address, in smallest units. */
|
|
48
30
|
export function useXBalances({
|
|
49
31
|
params,
|
|
50
32
|
queryOptions,
|
|
@@ -8,7 +8,6 @@ export type UseXrpDestinationCheckParams = ReadHookParams<
|
|
|
8
8
|
{
|
|
9
9
|
chainId: SpokeChainKey | undefined;
|
|
10
10
|
token: string | undefined;
|
|
11
|
-
/** The XRPL account that receives the payout. */
|
|
12
11
|
address: string | undefined;
|
|
13
12
|
/** The least that arrives, in the token's decimals. */
|
|
14
13
|
amount: bigint | undefined;
|
|
@@ -52,10 +51,7 @@ export function getXrpDestinationCheckQueryOptions({
|
|
|
52
51
|
};
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
/**
|
|
56
|
-
* Whether an XRPL account can receive `amount` of `token` (up to `maxAmount`), and if not, why. It reads the
|
|
57
|
-
* same ledger state a swap or withdrawal is refused on before signing.
|
|
58
|
-
*/
|
|
54
|
+
/** Whether an XRPL account can receive `amount` of `token` (up to `maxAmount`), and if not, why. */
|
|
59
55
|
export function useXrpDestinationCheck({
|
|
60
56
|
params,
|
|
61
57
|
queryOptions,
|
|
@@ -6,8 +6,7 @@ const reserveCheck = vi.fn();
|
|
|
6
6
|
const establish = vi.fn();
|
|
7
7
|
const requiresTrustline = vi.fn(() => true);
|
|
8
8
|
|
|
9
|
-
// Stubbing the child hooks keeps this a DOM-free assertion on the params the gate builds
|
|
10
|
-
// the resolver itself is covered by utils/xrpGate.test.ts.
|
|
9
|
+
// Stubbing the child hooks keeps this a DOM-free assertion on the params the gate builds.
|
|
11
10
|
vi.mock('./useXrpDestinationCheck.js', () => ({
|
|
12
11
|
useXrpDestinationCheck: (args: unknown) => destinationCheck(args),
|
|
13
12
|
}));
|
|
@@ -99,7 +98,6 @@ describe('useXrpGate', () => {
|
|
|
99
98
|
const { gate } = run({ ready: false, reason: 'trustline_limit' });
|
|
100
99
|
|
|
101
100
|
await expect(gate.requestTrustline()).resolves.toEqual({ ok: true, value: 'hash' });
|
|
102
|
-
// The checked recipient travels with the request, so the mutation can refuse another connected account.
|
|
103
101
|
expect(establish).toHaveBeenCalledWith({ token: TOKEN, address: ADDRESS, walletProvider: XRP_WALLET });
|
|
104
102
|
|
|
105
103
|
establish.mockReset();
|
|
@@ -8,7 +8,6 @@ import { useXrpTrustlineReserveCheck } from './useXrpTrustlineReserveCheck.js';
|
|
|
8
8
|
export interface UseXrpGateParams {
|
|
9
9
|
dstChainKey: SpokeChainKey | undefined;
|
|
10
10
|
token: string | undefined;
|
|
11
|
-
/** The XRPL account that receives the payout. */
|
|
12
11
|
address: string | undefined;
|
|
13
12
|
/** The least that arrives, in the token's decimals. */
|
|
14
13
|
amount: bigint | undefined;
|
|
@@ -29,8 +28,8 @@ export interface XrpGate extends XrpGateState {
|
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* Gates XRPL delivery on a trustline with room for the payout and enough XRP to set one. Refusals a
|
|
32
|
+
* trustline cannot fix surface as `blockedReason`.
|
|
34
33
|
*/
|
|
35
34
|
export function useXrpGate({
|
|
36
35
|
dstChainKey,
|
|
@@ -4,7 +4,6 @@ import { waitForApiAllowance } from './waitForApiAllowance.js';
|
|
|
4
4
|
|
|
5
5
|
const valid = (value: boolean) => ({ ok: true as const, value: { valid: value } });
|
|
6
6
|
|
|
7
|
-
/** A backend failure as the API services surface it: `EXTERNAL_API_ERROR` with the status on context. */
|
|
8
7
|
const apiError = (status: number): SodaxError =>
|
|
9
8
|
new SodaxError('EXTERNAL_API_ERROR', `responded with ${status}`, {
|
|
10
9
|
feature: 'backend',
|
|
@@ -19,12 +19,8 @@ async function settleWithin<T>(promise: Promise<T>, ms: number): Promise<T | und
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* stale `valid: false` leaves Approve enabled after a successful approval. A failed check is retried like a
|
|
25
|
-
* stale one, except an auth failure, which no retry fixes. Each check gets `apiConfig` with its request timeout
|
|
26
|
-
* capped to the time left and is abandoned when that runs out, so a hanging API cannot stretch the wait. Never
|
|
27
|
-
* throws: the approval has already landed, and the caller's allowance refetch shows whatever the API reports last.
|
|
22
|
+
* Polls until the API reports `valid` (its RPC can trail the confirming node); stops on auth failure or
|
|
23
|
+
* when the budget runs out. Never throws, since the approval has already landed.
|
|
28
24
|
*/
|
|
29
25
|
export async function waitForApiAllowance(
|
|
30
26
|
check: (config: RequestOverrideConfig) => Promise<Result<{ valid: boolean }>>,
|
|
@@ -64,8 +64,7 @@ describe('useActivateStellarAccount — cache invalidation', () => {
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
it('invalidates Stellar balances through the shared invalidateBalances helper', () => {
|
|
67
|
-
// Routed through invalidateBalances (
|
|
68
|
-
// hand-rolled invalidateQueries call, so it is not one of the literal matches above.
|
|
67
|
+
// Routed through invalidateBalances (both balance hooks), so it is not a literal match above.
|
|
69
68
|
expect(SRC).toMatch(/invalidateBalances\(queryClient,\s*ChainKeys\.STELLAR_MAINNET\)/);
|
|
70
69
|
});
|
|
71
70
|
|
|
@@ -6,13 +6,9 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
7
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
8
8
|
|
|
9
|
-
/** Keep mutation variables aligned with the SDK operation. */
|
|
10
9
|
export type UseActivateStellarAccountVars = ActivateStellarAccountParams;
|
|
11
10
|
|
|
12
|
-
/**
|
|
13
|
-
* Activate a Stellar account through the sponsoring service. Both `submitted`
|
|
14
|
-
* and `alreadyActive` are successful outcomes.
|
|
15
|
-
*/
|
|
11
|
+
/** Both `submitted` and `alreadyActive` are successful outcomes. */
|
|
16
12
|
export function useActivateStellarAccount({
|
|
17
13
|
mutationOptions,
|
|
18
14
|
}: MutationHookParams<ActivateStellarAccountResult, UseActivateStellarAccountVars> = {}): SafeUseMutationResult<
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* mutation vars must reach the sponsoring `/accounts` POST as `x-api-key`, beating the
|
|
4
|
-
* instance-level key.
|
|
5
|
-
*
|
|
6
|
-
* Follows the package convention of testing hooks without a renderer (captured `mutationFn`),
|
|
7
|
-
* driving a real keyed `Sodax` end to end the way packages/sdk/src/sponsoring/SponsoringService.test.ts
|
|
8
|
-
* does: Horizon is stubbed on the instance, the wallet signs with a real throwaway keypair, and the
|
|
9
|
-
* config GET + account POST run call-through to a stubbed global fetch.
|
|
10
|
-
*
|
|
11
|
-
* `@stellar/stellar-sdk` is not a dapp-kit dependency, so it is loaded through `@sodax/sdk`'s own
|
|
12
|
-
* module graph — the same copy the SDK builds and verifies the transaction with.
|
|
13
|
-
*/
|
|
1
|
+
// `requestConfig.apiKey` in the mutation vars must reach the `/accounts` POST as `x-api-key`, beating the instance key.
|
|
2
|
+
// `@stellar/stellar-sdk` is not a dapp-kit dependency, so it is loaded through `@sodax/sdk`'s module graph.
|
|
14
3
|
|
|
15
4
|
import { createRequire } from 'node:module';
|
|
16
5
|
import { Sodax } from '@sodax/sdk';
|
|
@@ -19,7 +19,6 @@ export function getSponsorConfigQueryOptions({ sodax }: { sodax: SponsorConfigRe
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/** Read the sponsoring service's published transaction parameters. */
|
|
23
22
|
export function useSponsorConfig({
|
|
24
23
|
queryOptions,
|
|
25
24
|
}: UseSponsorConfigParams = {}): UseQueryResult<StellarSponsorConfig, Error> {
|
|
@@ -41,10 +41,7 @@ export function getStellarAccountStatusQueryOptions({
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* Read account existence and trustline affordability in one Horizon request.
|
|
46
|
-
* Prefer {@link useStellarGate} for destination gating.
|
|
47
|
-
*/
|
|
44
|
+
/** One Horizon request; prefer {@link useStellarGate} for destination gating. */
|
|
48
45
|
export function useStellarAccountStatus({
|
|
49
46
|
params,
|
|
50
47
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useCancelUnstake.ts
|
|
2
1
|
import type { CancelUnstakeAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -8,12 +7,7 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
8
7
|
|
|
9
8
|
export type UseCancelUnstakeVars<K extends SpokeChainKey = SpokeChainKey> = Omit<CancelUnstakeAction<K, false>, 'raw'>;
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
* React hook for cancelling a pending unstake request.
|
|
13
|
-
*
|
|
14
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
15
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
16
|
-
*/
|
|
10
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
17
11
|
export function useCancelUnstake<K extends SpokeChainKey = SpokeChainKey>({
|
|
18
12
|
mutationOptions,
|
|
19
13
|
}: MutationHookParams<TxHashPair, UseCancelUnstakeVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useClaim.ts
|
|
2
1
|
import type { ClaimAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -9,12 +8,7 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
9
8
|
|
|
10
9
|
export type UseClaimVars<K extends SpokeChainKey = SpokeChainKey> = Omit<ClaimAction<K, false>, 'raw'>;
|
|
11
10
|
|
|
12
|
-
/**
|
|
13
|
-
* React hook for claiming an unstaked SODA request that has reached the end of its waiting period.
|
|
14
|
-
*
|
|
15
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
16
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
17
|
-
*/
|
|
11
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
18
12
|
export function useClaim<K extends SpokeChainKey = SpokeChainKey>({
|
|
19
13
|
mutationOptions,
|
|
20
14
|
}: MutationHookParams<TxHashPair, UseClaimVars<K>> = {}): SafeUseMutationResult<TxHashPair, Error, UseClaimVars<K>> {
|
|
@@ -9,10 +9,7 @@ export type UseConvertedAssetsParams = ReadHookParams<
|
|
|
9
9
|
}
|
|
10
10
|
>;
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* React hook to convert an xSODA share amount to its underlying SODA value via the vault's
|
|
14
|
-
* exchange rate. Hub-only read. Throws on `!ok`.
|
|
15
|
-
*/
|
|
12
|
+
/** Converts xSODA shares to SODA at the vault rate. Throws on `!ok`. */
|
|
16
13
|
export function useConvertedAssets({
|
|
17
14
|
params,
|
|
18
15
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useInstantUnstake.ts
|
|
2
1
|
import type { InstantUnstakeAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -12,12 +11,7 @@ export type UseInstantUnstakeVars<K extends SpokeChainKey = SpokeChainKey> = Omi
|
|
|
12
11
|
'raw'
|
|
13
12
|
>;
|
|
14
13
|
|
|
15
|
-
/**
|
|
16
|
-
* React hook for instant-unstaking SODA (bypassing the waiting period at a slippage cost).
|
|
17
|
-
*
|
|
18
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
19
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
20
|
-
*/
|
|
14
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
21
15
|
export function useInstantUnstake<K extends SpokeChainKey = SpokeChainKey>({
|
|
22
16
|
mutationOptions,
|
|
23
17
|
}: MutationHookParams<TxHashPair, UseInstantUnstakeVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -11,11 +11,7 @@ export type UseInstantUnstakeAllowanceParams<K extends SpokeChainKey = SpokeChai
|
|
|
11
11
|
}
|
|
12
12
|
>;
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* React hook to check whether the user has approved sufficient xSODA spending for the
|
|
16
|
-
* instant-unstake action. Read-only — calls `staking.isAllowanceValid` with `raw: true` so no
|
|
17
|
-
* `walletProvider` is required.
|
|
18
|
-
*/
|
|
14
|
+
/** Read-only (`raw: true`), so no `walletProvider` is needed. */
|
|
19
15
|
export function useInstantUnstakeAllowance<K extends SpokeChainKey = SpokeChainKey>({
|
|
20
16
|
params,
|
|
21
17
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useInstantUnstakeApprove.ts
|
|
2
1
|
import type { GetWalletProviderType, InstantUnstakeParams, SpokeChainKey, TxReturnType } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -6,21 +5,12 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
5
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
8
7
|
|
|
9
|
-
/**
|
|
10
|
-
* Mutation variables for {@link useInstantUnstakeApprove}. The `action` literal is injected by
|
|
11
|
-
* the hook.
|
|
12
|
-
*/
|
|
13
8
|
export type UseInstantUnstakeApproveVars<K extends SpokeChainKey = SpokeChainKey> = {
|
|
14
9
|
params: Omit<InstantUnstakeParams<K>, 'action'>;
|
|
15
10
|
walletProvider: GetWalletProviderType<K>;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook for approving xSODA spending on the instant-unstake action.
|
|
20
|
-
*
|
|
21
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
22
|
-
* `onError`, `retry`). Returns the unwrapped tx return value on success.
|
|
23
|
-
*/
|
|
13
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped tx return value. */
|
|
24
14
|
export function useInstantUnstakeApprove<K extends SpokeChainKey = SpokeChainKey>({
|
|
25
15
|
mutationOptions,
|
|
26
16
|
}: MutationHookParams<TxReturnType<K, false>, UseInstantUnstakeApproveVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -9,10 +9,7 @@ export type UseInstantUnstakeRatioParams = ReadHookParams<
|
|
|
9
9
|
}
|
|
10
10
|
>;
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* React hook to estimate the SODA amount received from instant-unstaking a given xSODA amount
|
|
14
|
-
* (after slippage). Hub-only read. Throws on `!ok`.
|
|
15
|
-
*/
|
|
12
|
+
/** SODA received for instant-unstaking the xSODA amount, after slippage. Throws on `!ok`. */
|
|
16
13
|
export function useInstantUnstakeRatio({
|
|
17
14
|
params,
|
|
18
15
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useStake.ts
|
|
2
1
|
import type { SpokeChainKey, StakeAction, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -7,19 +6,9 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
7
6
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
8
7
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
9
8
|
|
|
10
|
-
/**
|
|
11
|
-
* Mutation variables for {@link useStake}. Generic over `K extends SpokeChainKey` (defaults to
|
|
12
|
-
* the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
13
|
-
* `walletProvider` and `params.srcChainKey` types.
|
|
14
|
-
*/
|
|
15
9
|
export type UseStakeVars<K extends SpokeChainKey = SpokeChainKey> = Omit<StakeAction<K, false>, 'raw'>;
|
|
16
10
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook for staking SODA tokens.
|
|
19
|
-
*
|
|
20
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
21
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
22
|
-
*/
|
|
11
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
23
12
|
export function useStake<K extends SpokeChainKey = SpokeChainKey>({
|
|
24
13
|
mutationOptions,
|
|
25
14
|
}: MutationHookParams<TxHashPair, UseStakeVars<K>> = {}): SafeUseMutationResult<TxHashPair, Error, UseStakeVars<K>> {
|
|
@@ -11,11 +11,7 @@ export type UseStakeAllowanceParams<K extends SpokeChainKey = SpokeChainKey> = R
|
|
|
11
11
|
}
|
|
12
12
|
>;
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* React hook to check whether the user has approved sufficient SODA spending for the stake
|
|
16
|
-
* action. Read-only — calls `staking.isAllowanceValid` with `raw: true` so no `walletProvider`
|
|
17
|
-
* is required.
|
|
18
|
-
*/
|
|
14
|
+
/** Read-only (`raw: true`), so no `walletProvider` is needed. */
|
|
19
15
|
export function useStakeAllowance<K extends SpokeChainKey = SpokeChainKey>({
|
|
20
16
|
params,
|
|
21
17
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useStakeApprove.ts
|
|
2
1
|
import type { GetWalletProviderType, SpokeChainKey, StakeParams, TxReturnType } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -6,21 +5,12 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
5
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
8
7
|
|
|
9
|
-
/**
|
|
10
|
-
* Mutation variables for {@link useStakeApprove}. The `action` literal is injected by the hook —
|
|
11
|
-
* callers pass the stake-specific fields only.
|
|
12
|
-
*/
|
|
13
8
|
export type UseStakeApproveVars<K extends SpokeChainKey = SpokeChainKey> = {
|
|
14
9
|
params: Omit<StakeParams<K>, 'action'>;
|
|
15
10
|
walletProvider: GetWalletProviderType<K>;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook for approving SODA spending on the stake action.
|
|
20
|
-
*
|
|
21
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
22
|
-
* `onError`, `retry`). Returns the unwrapped tx return value on success.
|
|
23
|
-
*/
|
|
13
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped tx return value. */
|
|
24
14
|
export function useStakeApprove<K extends SpokeChainKey = SpokeChainKey>({
|
|
25
15
|
mutationOptions,
|
|
26
16
|
}: MutationHookParams<TxReturnType<K, false>, UseStakeApproveVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -9,10 +9,7 @@ export type UseStakeRatioParams = ReadHookParams<
|
|
|
9
9
|
}
|
|
10
10
|
>;
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* React hook to estimate the SODA → xSODA stake ratio for a given amount. Hub-only read. Throws
|
|
14
|
-
* on `!ok`.
|
|
15
|
-
*/
|
|
12
|
+
/** Throws on `!ok`. */
|
|
16
13
|
export function useStakeRatio({
|
|
17
14
|
params,
|
|
18
15
|
queryOptions,
|
|
@@ -5,10 +5,7 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UseStakingConfigParams = ReadHookParams<StakingConfig>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* React hook to fetch the global staking config (unstaking period, min unstaking period, max
|
|
10
|
-
* penalty). Hub-only read; no chain context required. Throws on `!ok`.
|
|
11
|
-
*/
|
|
8
|
+
/** Throws on `!ok`. */
|
|
12
9
|
export function useStakingConfig({ queryOptions }: UseStakingConfigParams = {}): UseQueryResult<StakingConfig, Error> {
|
|
13
10
|
const { sodax } = useSodaxContext();
|
|
14
11
|
|
|
@@ -12,11 +12,7 @@ export type UseStakingInfoParams = ReadHookParams<
|
|
|
12
12
|
}
|
|
13
13
|
>;
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* React hook to fetch the user's staking info (xSODA balance, share value, underlying SODA) by
|
|
17
|
-
* deriving the hub wallet from the spoke `srcAddress` + `srcChainKey`. Throws on `!ok` so React
|
|
18
|
-
* Query lands in `error` state.
|
|
19
|
-
*/
|
|
15
|
+
/** Throws on `!ok`. */
|
|
20
16
|
export function useStakingInfo({
|
|
21
17
|
params,
|
|
22
18
|
queryOptions,
|