@turtleclub/hooks 0.5.0-beta.77 → 0.5.0-beta.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +31 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/v2/earn-deposits/hooks/useActionsDefaultParams.ts +4 -3
- package/src/v2/earn-deposits/hooks/useDepositValidation.ts +3 -1
- package/src/v2/earn-deposits/hooks/utils.ts +27 -0
- package/src/v2/earn-deposits/hooks.ts +8 -0
- package/src/v2/opportunities/schema.ts +2 -0
package/dist/index.cjs
CHANGED
|
@@ -91,6 +91,7 @@ __export(index_exports, {
|
|
|
91
91
|
filterTagSchema: () => filterTagSchema,
|
|
92
92
|
geoCheckResponseSchema: () => geoCheckResponseSchema,
|
|
93
93
|
geocheckQueries: () => geocheckQueries,
|
|
94
|
+
getDepositModeFlags: () => getDepositModeFlags,
|
|
94
95
|
getDeposits: () => getDeposits,
|
|
95
96
|
getEarnOpportunities: () => getEarnOpportunities,
|
|
96
97
|
getEarnRoute: () => getEarnRoute,
|
|
@@ -167,6 +168,7 @@ __export(index_exports, {
|
|
|
167
168
|
productsResponseSchema: () => productsResponseSchema,
|
|
168
169
|
queries: () => queries,
|
|
169
170
|
requestStreamSignature: () => requestStreamSignature,
|
|
171
|
+
resolveEffectiveDepositMode: () => resolveEffectiveDepositMode,
|
|
170
172
|
routeMetadataSchema: () => routeMetadataSchema,
|
|
171
173
|
routeStepSchema: () => routeStepSchema,
|
|
172
174
|
routeToken: () => routeToken,
|
|
@@ -1288,6 +1290,8 @@ var opportunitySchema = import_zod8.z.object({
|
|
|
1288
1290
|
turtleTvl: import_zod8.z.number(),
|
|
1289
1291
|
turtleUsers: import_zod8.z.number(),
|
|
1290
1292
|
earnEnabled: import_zod8.z.boolean(),
|
|
1293
|
+
swapDirectEnabled: import_zod8.z.boolean().optional().default(true),
|
|
1294
|
+
swapRouteEnabled: import_zod8.z.boolean().optional().default(false),
|
|
1291
1295
|
createdAt: import_zod8.z.string().datetime().optional(),
|
|
1292
1296
|
updatedAt: import_zod8.z.string().datetime().optional(),
|
|
1293
1297
|
mainStreamId: import_zod8.z.string().optional(),
|
|
@@ -2731,6 +2735,22 @@ var import_react_query12 = require("@tanstack/react-query");
|
|
|
2731
2735
|
// src/v2/earn-deposits/hooks/useDepositValidation.ts
|
|
2732
2736
|
var import_react2 = require("react");
|
|
2733
2737
|
var import_viem = require("viem");
|
|
2738
|
+
|
|
2739
|
+
// src/v2/earn-deposits/hooks/utils.ts
|
|
2740
|
+
function getDepositModeFlags(opportunity) {
|
|
2741
|
+
const isSecondaryOnly = opportunity?.vaultConfig?.secondaryOnly === true;
|
|
2742
|
+
const routeModeEnabled = opportunity?.swapRouteEnabled ?? false;
|
|
2743
|
+
const directModeEnabled = opportunity?.swapDirectEnabled ?? true;
|
|
2744
|
+
const noModesEnabled = !routeModeEnabled && !directModeEnabled;
|
|
2745
|
+
return { isSecondaryOnly, routeModeEnabled, directModeEnabled, noModesEnabled };
|
|
2746
|
+
}
|
|
2747
|
+
function resolveEffectiveDepositMode(depositMode, flags) {
|
|
2748
|
+
if (flags.isSecondaryOnly) return "route";
|
|
2749
|
+
if (!flags.directModeEnabled && flags.routeModeEnabled) return "route";
|
|
2750
|
+
return depositMode;
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
// src/v2/earn-deposits/hooks/useDepositValidation.ts
|
|
2734
2754
|
function calculateUsdValue(amount, token) {
|
|
2735
2755
|
if (!token.priceUsd) return null;
|
|
2736
2756
|
const formatted = parseFloat((0, import_viem.formatUnits)(amount, token.decimals));
|
|
@@ -2776,7 +2796,8 @@ function useDepositValidation({
|
|
|
2776
2796
|
};
|
|
2777
2797
|
}
|
|
2778
2798
|
const vaultConfig = opportunity.vaultConfig;
|
|
2779
|
-
const
|
|
2799
|
+
const { noModesEnabled } = getDepositModeFlags(opportunity);
|
|
2800
|
+
const depositDisabled = (opportunity.depositDisabled ?? false) || noModesEnabled;
|
|
2780
2801
|
const depositDisabledReason = opportunity.depositDisabledReason || null;
|
|
2781
2802
|
const depositFee = vaultConfig?.depositFee ?? null;
|
|
2782
2803
|
const performanceFee = vaultConfig?.performanceFee ?? null;
|
|
@@ -2895,7 +2916,7 @@ var import_react4 = require("react");
|
|
|
2895
2916
|
// src/v2/balance/hooks/useTokenBalance.ts
|
|
2896
2917
|
var import_react3 = require("react");
|
|
2897
2918
|
var import_viem2 = require("viem");
|
|
2898
|
-
var
|
|
2919
|
+
var import_utils3 = require("@turtleclub/utils");
|
|
2899
2920
|
function checkInsufficientBalance(tokenBalance, amount) {
|
|
2900
2921
|
if (!tokenBalance || !amount) return false;
|
|
2901
2922
|
try {
|
|
@@ -2910,7 +2931,7 @@ function checkInsufficientBalance(tokenBalance, amount) {
|
|
|
2910
2931
|
function useTokenBalance({ tokenBalance, amount, setAmount }) {
|
|
2911
2932
|
const token = tokenBalance?.token;
|
|
2912
2933
|
const usdValue = (0, import_react3.useMemo)(
|
|
2913
|
-
() => (0,
|
|
2934
|
+
() => (0, import_utils3.calculateUsdValue)(amount, token?.priceUsd),
|
|
2914
2935
|
[amount, token?.priceUsd]
|
|
2915
2936
|
);
|
|
2916
2937
|
const hasInsufficientBalance = (0, import_react3.useMemo)(
|
|
@@ -2919,7 +2940,7 @@ function useTokenBalance({ tokenBalance, amount, setAmount }) {
|
|
|
2919
2940
|
);
|
|
2920
2941
|
const handleMaxClick = (0, import_react3.useCallback)(() => {
|
|
2921
2942
|
if (!tokenBalance?.token || !tokenBalance.amount) return;
|
|
2922
|
-
const maxAmount = (0,
|
|
2943
|
+
const maxAmount = (0, import_utils3.calculateMaxAmount)(tokenBalance.amount, tokenBalance.token.decimals);
|
|
2923
2944
|
setAmount(maxAmount);
|
|
2924
2945
|
}, [tokenBalance, setAmount]);
|
|
2925
2946
|
const amountBigInt = (0, import_react3.useMemo)(() => {
|
|
@@ -3670,8 +3691,8 @@ function useActionsDefaultParams({
|
|
|
3670
3691
|
depositMode
|
|
3671
3692
|
}) {
|
|
3672
3693
|
const opportunityChainId = opportunity ? Number(opportunity.receiptToken.chain.chainId) : void 0;
|
|
3673
|
-
const
|
|
3674
|
-
const effectiveDepositMode =
|
|
3694
|
+
const flags = getDepositModeFlags(opportunity);
|
|
3695
|
+
const effectiveDepositMode = resolveEffectiveDepositMode(depositMode, flags);
|
|
3675
3696
|
const useOnChainBalances = effectiveDepositMode === "native";
|
|
3676
3697
|
const {
|
|
3677
3698
|
balances: depositTokenBalances,
|
|
@@ -4229,7 +4250,7 @@ function useGeocheck(options = {}) {
|
|
|
4229
4250
|
var import_react17 = require("react");
|
|
4230
4251
|
|
|
4231
4252
|
// src/v2/swap/route-processor.ts
|
|
4232
|
-
var
|
|
4253
|
+
var import_utils8 = require("@turtleclub/utils");
|
|
4233
4254
|
var parseEnsoStep = (kind, fromToken, toToken) => {
|
|
4234
4255
|
return {
|
|
4235
4256
|
in: {
|
|
@@ -4251,7 +4272,7 @@ var parseApproveStep = (token, amount) => {
|
|
|
4251
4272
|
symbol: token.symbol
|
|
4252
4273
|
},
|
|
4253
4274
|
out: null,
|
|
4254
|
-
amount: (0,
|
|
4275
|
+
amount: (0, import_utils8.formatToken)(amount, { decimals: token.decimals }, true, false, 4),
|
|
4255
4276
|
type: "approve"
|
|
4256
4277
|
};
|
|
4257
4278
|
};
|
|
@@ -4694,6 +4715,7 @@ var queries = (0, import_query_key_factory21.mergeQueryKeys)(
|
|
|
4694
4715
|
filterTagSchema,
|
|
4695
4716
|
geoCheckResponseSchema,
|
|
4696
4717
|
geocheckQueries,
|
|
4718
|
+
getDepositModeFlags,
|
|
4697
4719
|
getDeposits,
|
|
4698
4720
|
getEarnOpportunities,
|
|
4699
4721
|
getEarnRoute,
|
|
@@ -4770,6 +4792,7 @@ var queries = (0, import_query_key_factory21.mergeQueryKeys)(
|
|
|
4770
4792
|
productsResponseSchema,
|
|
4771
4793
|
queries,
|
|
4772
4794
|
requestStreamSignature,
|
|
4795
|
+
resolveEffectiveDepositMode,
|
|
4773
4796
|
routeMetadataSchema,
|
|
4774
4797
|
routeStepSchema,
|
|
4775
4798
|
routeToken,
|