@turtleclub/hooks 0.5.0-beta.77 → 0.5.0-beta.79
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 +33 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -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/src/v2/streams/api.ts +1 -0
- package/src/v2/streams/schemas.ts +1 -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,
|
|
@@ -1058,6 +1060,7 @@ var getStreamsQuerySchema = import_zod7.z.object({
|
|
|
1058
1060
|
userId: import_zod7.z.string().optional(),
|
|
1059
1061
|
organizationId: import_zod7.z.string().optional(),
|
|
1060
1062
|
withSnapshots: import_zod7.z.boolean().optional(),
|
|
1063
|
+
withFeeSnapshots: import_zod7.z.boolean().optional(),
|
|
1061
1064
|
usersCount: import_zod7.z.boolean().optional()
|
|
1062
1065
|
});
|
|
1063
1066
|
var getStreamPointsQuerySchema = import_zod7.z.object({
|
|
@@ -1111,6 +1114,7 @@ async function getStreams(query) {
|
|
|
1111
1114
|
if (query?.organizationId) params.set("organizationId", query.organizationId);
|
|
1112
1115
|
if (query?.withSnapshots) params.append("withSnapshots", "true");
|
|
1113
1116
|
if (query?.usersCount && query?.withSnapshots) params.append("usersCount", "true");
|
|
1117
|
+
if (query?.withFeeSnapshots) params.append("withFeeSnapshots", "true");
|
|
1114
1118
|
const queryString = params.toString();
|
|
1115
1119
|
const endpoint = `/streams${queryString ? `?${queryString}` : ""}`;
|
|
1116
1120
|
const data = await apiClient.fetch(endpoint, { method: "GET" });
|
|
@@ -1288,6 +1292,8 @@ var opportunitySchema = import_zod8.z.object({
|
|
|
1288
1292
|
turtleTvl: import_zod8.z.number(),
|
|
1289
1293
|
turtleUsers: import_zod8.z.number(),
|
|
1290
1294
|
earnEnabled: import_zod8.z.boolean(),
|
|
1295
|
+
swapDirectEnabled: import_zod8.z.boolean().optional().default(true),
|
|
1296
|
+
swapRouteEnabled: import_zod8.z.boolean().optional().default(false),
|
|
1291
1297
|
createdAt: import_zod8.z.string().datetime().optional(),
|
|
1292
1298
|
updatedAt: import_zod8.z.string().datetime().optional(),
|
|
1293
1299
|
mainStreamId: import_zod8.z.string().optional(),
|
|
@@ -2731,6 +2737,22 @@ var import_react_query12 = require("@tanstack/react-query");
|
|
|
2731
2737
|
// src/v2/earn-deposits/hooks/useDepositValidation.ts
|
|
2732
2738
|
var import_react2 = require("react");
|
|
2733
2739
|
var import_viem = require("viem");
|
|
2740
|
+
|
|
2741
|
+
// src/v2/earn-deposits/hooks/utils.ts
|
|
2742
|
+
function getDepositModeFlags(opportunity) {
|
|
2743
|
+
const isSecondaryOnly = opportunity?.vaultConfig?.secondaryOnly === true;
|
|
2744
|
+
const routeModeEnabled = opportunity?.swapRouteEnabled ?? false;
|
|
2745
|
+
const directModeEnabled = opportunity?.swapDirectEnabled ?? true;
|
|
2746
|
+
const noModesEnabled = !routeModeEnabled && !directModeEnabled;
|
|
2747
|
+
return { isSecondaryOnly, routeModeEnabled, directModeEnabled, noModesEnabled };
|
|
2748
|
+
}
|
|
2749
|
+
function resolveEffectiveDepositMode(depositMode, flags) {
|
|
2750
|
+
if (flags.isSecondaryOnly) return "route";
|
|
2751
|
+
if (!flags.directModeEnabled && flags.routeModeEnabled) return "route";
|
|
2752
|
+
return depositMode;
|
|
2753
|
+
}
|
|
2754
|
+
|
|
2755
|
+
// src/v2/earn-deposits/hooks/useDepositValidation.ts
|
|
2734
2756
|
function calculateUsdValue(amount, token) {
|
|
2735
2757
|
if (!token.priceUsd) return null;
|
|
2736
2758
|
const formatted = parseFloat((0, import_viem.formatUnits)(amount, token.decimals));
|
|
@@ -2776,7 +2798,8 @@ function useDepositValidation({
|
|
|
2776
2798
|
};
|
|
2777
2799
|
}
|
|
2778
2800
|
const vaultConfig = opportunity.vaultConfig;
|
|
2779
|
-
const
|
|
2801
|
+
const { noModesEnabled } = getDepositModeFlags(opportunity);
|
|
2802
|
+
const depositDisabled = (opportunity.depositDisabled ?? false) || noModesEnabled;
|
|
2780
2803
|
const depositDisabledReason = opportunity.depositDisabledReason || null;
|
|
2781
2804
|
const depositFee = vaultConfig?.depositFee ?? null;
|
|
2782
2805
|
const performanceFee = vaultConfig?.performanceFee ?? null;
|
|
@@ -2895,7 +2918,7 @@ var import_react4 = require("react");
|
|
|
2895
2918
|
// src/v2/balance/hooks/useTokenBalance.ts
|
|
2896
2919
|
var import_react3 = require("react");
|
|
2897
2920
|
var import_viem2 = require("viem");
|
|
2898
|
-
var
|
|
2921
|
+
var import_utils3 = require("@turtleclub/utils");
|
|
2899
2922
|
function checkInsufficientBalance(tokenBalance, amount) {
|
|
2900
2923
|
if (!tokenBalance || !amount) return false;
|
|
2901
2924
|
try {
|
|
@@ -2910,7 +2933,7 @@ function checkInsufficientBalance(tokenBalance, amount) {
|
|
|
2910
2933
|
function useTokenBalance({ tokenBalance, amount, setAmount }) {
|
|
2911
2934
|
const token = tokenBalance?.token;
|
|
2912
2935
|
const usdValue = (0, import_react3.useMemo)(
|
|
2913
|
-
() => (0,
|
|
2936
|
+
() => (0, import_utils3.calculateUsdValue)(amount, token?.priceUsd),
|
|
2914
2937
|
[amount, token?.priceUsd]
|
|
2915
2938
|
);
|
|
2916
2939
|
const hasInsufficientBalance = (0, import_react3.useMemo)(
|
|
@@ -2919,7 +2942,7 @@ function useTokenBalance({ tokenBalance, amount, setAmount }) {
|
|
|
2919
2942
|
);
|
|
2920
2943
|
const handleMaxClick = (0, import_react3.useCallback)(() => {
|
|
2921
2944
|
if (!tokenBalance?.token || !tokenBalance.amount) return;
|
|
2922
|
-
const maxAmount = (0,
|
|
2945
|
+
const maxAmount = (0, import_utils3.calculateMaxAmount)(tokenBalance.amount, tokenBalance.token.decimals);
|
|
2923
2946
|
setAmount(maxAmount);
|
|
2924
2947
|
}, [tokenBalance, setAmount]);
|
|
2925
2948
|
const amountBigInt = (0, import_react3.useMemo)(() => {
|
|
@@ -3670,8 +3693,8 @@ function useActionsDefaultParams({
|
|
|
3670
3693
|
depositMode
|
|
3671
3694
|
}) {
|
|
3672
3695
|
const opportunityChainId = opportunity ? Number(opportunity.receiptToken.chain.chainId) : void 0;
|
|
3673
|
-
const
|
|
3674
|
-
const effectiveDepositMode =
|
|
3696
|
+
const flags = getDepositModeFlags(opportunity);
|
|
3697
|
+
const effectiveDepositMode = resolveEffectiveDepositMode(depositMode, flags);
|
|
3675
3698
|
const useOnChainBalances = effectiveDepositMode === "native";
|
|
3676
3699
|
const {
|
|
3677
3700
|
balances: depositTokenBalances,
|
|
@@ -4229,7 +4252,7 @@ function useGeocheck(options = {}) {
|
|
|
4229
4252
|
var import_react17 = require("react");
|
|
4230
4253
|
|
|
4231
4254
|
// src/v2/swap/route-processor.ts
|
|
4232
|
-
var
|
|
4255
|
+
var import_utils8 = require("@turtleclub/utils");
|
|
4233
4256
|
var parseEnsoStep = (kind, fromToken, toToken) => {
|
|
4234
4257
|
return {
|
|
4235
4258
|
in: {
|
|
@@ -4251,7 +4274,7 @@ var parseApproveStep = (token, amount) => {
|
|
|
4251
4274
|
symbol: token.symbol
|
|
4252
4275
|
},
|
|
4253
4276
|
out: null,
|
|
4254
|
-
amount: (0,
|
|
4277
|
+
amount: (0, import_utils8.formatToken)(amount, { decimals: token.decimals }, true, false, 4),
|
|
4255
4278
|
type: "approve"
|
|
4256
4279
|
};
|
|
4257
4280
|
};
|
|
@@ -4694,6 +4717,7 @@ var queries = (0, import_query_key_factory21.mergeQueryKeys)(
|
|
|
4694
4717
|
filterTagSchema,
|
|
4695
4718
|
geoCheckResponseSchema,
|
|
4696
4719
|
geocheckQueries,
|
|
4720
|
+
getDepositModeFlags,
|
|
4697
4721
|
getDeposits,
|
|
4698
4722
|
getEarnOpportunities,
|
|
4699
4723
|
getEarnRoute,
|
|
@@ -4770,6 +4794,7 @@ var queries = (0, import_query_key_factory21.mergeQueryKeys)(
|
|
|
4770
4794
|
productsResponseSchema,
|
|
4771
4795
|
queries,
|
|
4772
4796
|
requestStreamSignature,
|
|
4797
|
+
resolveEffectiveDepositMode,
|
|
4773
4798
|
routeMetadataSchema,
|
|
4774
4799
|
routeStepSchema,
|
|
4775
4800
|
routeToken,
|