@turtleclub/hooks 0.5.0-beta.76 → 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 +59 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/v2/covers/api.ts +22 -3
- package/src/v2/covers/index.ts +3 -3
- package/src/v2/covers/schema.ts +16 -0
- 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,
|
|
@@ -183,6 +185,9 @@ __export(index_exports, {
|
|
|
183
185
|
streamWalletSchema: () => streamWalletSchema,
|
|
184
186
|
streamWalletSnapshotSchema: () => streamWalletSnapshotSchema,
|
|
185
187
|
streamsQueries: () => streamsQueries,
|
|
188
|
+
submitCoverPurchase: () => submitCoverPurchase,
|
|
189
|
+
submitCoverPurchaseDataSchema: () => submitCoverPurchaseDataSchema,
|
|
190
|
+
submitCoverPurchaseResponseSchema: () => submitCoverPurchaseResponseSchema,
|
|
186
191
|
submitCoverRequest: () => submitCoverRequest,
|
|
187
192
|
submitCoverRequestResponseSchema: () => submitCoverRequestResponseSchema,
|
|
188
193
|
supportedChainEcosystemSchema: () => supportedChainEcosystemSchema,
|
|
@@ -1285,6 +1290,8 @@ var opportunitySchema = import_zod8.z.object({
|
|
|
1285
1290
|
turtleTvl: import_zod8.z.number(),
|
|
1286
1291
|
turtleUsers: import_zod8.z.number(),
|
|
1287
1292
|
earnEnabled: import_zod8.z.boolean(),
|
|
1293
|
+
swapDirectEnabled: import_zod8.z.boolean().optional().default(true),
|
|
1294
|
+
swapRouteEnabled: import_zod8.z.boolean().optional().default(false),
|
|
1288
1295
|
createdAt: import_zod8.z.string().datetime().optional(),
|
|
1289
1296
|
updatedAt: import_zod8.z.string().datetime().optional(),
|
|
1290
1297
|
mainStreamId: import_zod8.z.string().optional(),
|
|
@@ -2238,6 +2245,15 @@ var checkCoverRequestResponseSchema = import_zod16.z.object({
|
|
|
2238
2245
|
canSubmit: import_zod16.z.boolean(),
|
|
2239
2246
|
existingRequest: coverRequestDataSchema.nullable()
|
|
2240
2247
|
});
|
|
2248
|
+
var submitCoverPurchaseDataSchema = import_zod16.z.object({
|
|
2249
|
+
walletAddress: import_zod16.z.string().regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address"),
|
|
2250
|
+
txHash: import_zod16.z.string().regex(/^0x[a-fA-F0-9]{64}$/, "Invalid transaction hash")
|
|
2251
|
+
});
|
|
2252
|
+
var submitCoverPurchaseResponseSchema = import_zod16.z.object({
|
|
2253
|
+
success: import_zod16.z.boolean(),
|
|
2254
|
+
message: import_zod16.z.string(),
|
|
2255
|
+
id: import_zod16.z.string()
|
|
2256
|
+
});
|
|
2241
2257
|
|
|
2242
2258
|
// src/v2/covers/api.ts
|
|
2243
2259
|
async function submitCoverRequest(data) {
|
|
@@ -2247,11 +2263,23 @@ async function submitCoverRequest(data) {
|
|
|
2247
2263
|
});
|
|
2248
2264
|
const result = submitCoverRequestResponseSchema.safeParse(response);
|
|
2249
2265
|
if (!result.success) {
|
|
2250
|
-
console.
|
|
2266
|
+
console.error("[ZOD ERROR]", result.error);
|
|
2251
2267
|
throw new Error(`Failed to submit cover request due to an invalid server response.`);
|
|
2252
2268
|
}
|
|
2253
2269
|
return result.data;
|
|
2254
2270
|
}
|
|
2271
|
+
async function submitCoverPurchase(data) {
|
|
2272
|
+
const response = await apiClient.fetch("/turtle/nexus-cover-purchases", {
|
|
2273
|
+
method: "POST",
|
|
2274
|
+
body: data
|
|
2275
|
+
});
|
|
2276
|
+
const result = submitCoverPurchaseResponseSchema.safeParse(response);
|
|
2277
|
+
if (!result.success) {
|
|
2278
|
+
console.error("[ZOD ERROR]", result.error);
|
|
2279
|
+
throw new Error("Failed to submit cover purchase tracking due to an invalid server response.");
|
|
2280
|
+
}
|
|
2281
|
+
return result.data;
|
|
2282
|
+
}
|
|
2255
2283
|
async function checkCoverRequest({
|
|
2256
2284
|
protocolName
|
|
2257
2285
|
}) {
|
|
@@ -2707,6 +2735,22 @@ var import_react_query12 = require("@tanstack/react-query");
|
|
|
2707
2735
|
// src/v2/earn-deposits/hooks/useDepositValidation.ts
|
|
2708
2736
|
var import_react2 = require("react");
|
|
2709
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
|
|
2710
2754
|
function calculateUsdValue(amount, token) {
|
|
2711
2755
|
if (!token.priceUsd) return null;
|
|
2712
2756
|
const formatted = parseFloat((0, import_viem.formatUnits)(amount, token.decimals));
|
|
@@ -2752,7 +2796,8 @@ function useDepositValidation({
|
|
|
2752
2796
|
};
|
|
2753
2797
|
}
|
|
2754
2798
|
const vaultConfig = opportunity.vaultConfig;
|
|
2755
|
-
const
|
|
2799
|
+
const { noModesEnabled } = getDepositModeFlags(opportunity);
|
|
2800
|
+
const depositDisabled = (opportunity.depositDisabled ?? false) || noModesEnabled;
|
|
2756
2801
|
const depositDisabledReason = opportunity.depositDisabledReason || null;
|
|
2757
2802
|
const depositFee = vaultConfig?.depositFee ?? null;
|
|
2758
2803
|
const performanceFee = vaultConfig?.performanceFee ?? null;
|
|
@@ -2871,7 +2916,7 @@ var import_react4 = require("react");
|
|
|
2871
2916
|
// src/v2/balance/hooks/useTokenBalance.ts
|
|
2872
2917
|
var import_react3 = require("react");
|
|
2873
2918
|
var import_viem2 = require("viem");
|
|
2874
|
-
var
|
|
2919
|
+
var import_utils3 = require("@turtleclub/utils");
|
|
2875
2920
|
function checkInsufficientBalance(tokenBalance, amount) {
|
|
2876
2921
|
if (!tokenBalance || !amount) return false;
|
|
2877
2922
|
try {
|
|
@@ -2886,7 +2931,7 @@ function checkInsufficientBalance(tokenBalance, amount) {
|
|
|
2886
2931
|
function useTokenBalance({ tokenBalance, amount, setAmount }) {
|
|
2887
2932
|
const token = tokenBalance?.token;
|
|
2888
2933
|
const usdValue = (0, import_react3.useMemo)(
|
|
2889
|
-
() => (0,
|
|
2934
|
+
() => (0, import_utils3.calculateUsdValue)(amount, token?.priceUsd),
|
|
2890
2935
|
[amount, token?.priceUsd]
|
|
2891
2936
|
);
|
|
2892
2937
|
const hasInsufficientBalance = (0, import_react3.useMemo)(
|
|
@@ -2895,7 +2940,7 @@ function useTokenBalance({ tokenBalance, amount, setAmount }) {
|
|
|
2895
2940
|
);
|
|
2896
2941
|
const handleMaxClick = (0, import_react3.useCallback)(() => {
|
|
2897
2942
|
if (!tokenBalance?.token || !tokenBalance.amount) return;
|
|
2898
|
-
const maxAmount = (0,
|
|
2943
|
+
const maxAmount = (0, import_utils3.calculateMaxAmount)(tokenBalance.amount, tokenBalance.token.decimals);
|
|
2899
2944
|
setAmount(maxAmount);
|
|
2900
2945
|
}, [tokenBalance, setAmount]);
|
|
2901
2946
|
const amountBigInt = (0, import_react3.useMemo)(() => {
|
|
@@ -3646,8 +3691,8 @@ function useActionsDefaultParams({
|
|
|
3646
3691
|
depositMode
|
|
3647
3692
|
}) {
|
|
3648
3693
|
const opportunityChainId = opportunity ? Number(opportunity.receiptToken.chain.chainId) : void 0;
|
|
3649
|
-
const
|
|
3650
|
-
const effectiveDepositMode =
|
|
3694
|
+
const flags = getDepositModeFlags(opportunity);
|
|
3695
|
+
const effectiveDepositMode = resolveEffectiveDepositMode(depositMode, flags);
|
|
3651
3696
|
const useOnChainBalances = effectiveDepositMode === "native";
|
|
3652
3697
|
const {
|
|
3653
3698
|
balances: depositTokenBalances,
|
|
@@ -4205,7 +4250,7 @@ function useGeocheck(options = {}) {
|
|
|
4205
4250
|
var import_react17 = require("react");
|
|
4206
4251
|
|
|
4207
4252
|
// src/v2/swap/route-processor.ts
|
|
4208
|
-
var
|
|
4253
|
+
var import_utils8 = require("@turtleclub/utils");
|
|
4209
4254
|
var parseEnsoStep = (kind, fromToken, toToken) => {
|
|
4210
4255
|
return {
|
|
4211
4256
|
in: {
|
|
@@ -4227,7 +4272,7 @@ var parseApproveStep = (token, amount) => {
|
|
|
4227
4272
|
symbol: token.symbol
|
|
4228
4273
|
},
|
|
4229
4274
|
out: null,
|
|
4230
|
-
amount: (0,
|
|
4275
|
+
amount: (0, import_utils8.formatToken)(amount, { decimals: token.decimals }, true, false, 4),
|
|
4231
4276
|
type: "approve"
|
|
4232
4277
|
};
|
|
4233
4278
|
};
|
|
@@ -4670,6 +4715,7 @@ var queries = (0, import_query_key_factory21.mergeQueryKeys)(
|
|
|
4670
4715
|
filterTagSchema,
|
|
4671
4716
|
geoCheckResponseSchema,
|
|
4672
4717
|
geocheckQueries,
|
|
4718
|
+
getDepositModeFlags,
|
|
4673
4719
|
getDeposits,
|
|
4674
4720
|
getEarnOpportunities,
|
|
4675
4721
|
getEarnRoute,
|
|
@@ -4746,6 +4792,7 @@ var queries = (0, import_query_key_factory21.mergeQueryKeys)(
|
|
|
4746
4792
|
productsResponseSchema,
|
|
4747
4793
|
queries,
|
|
4748
4794
|
requestStreamSignature,
|
|
4795
|
+
resolveEffectiveDepositMode,
|
|
4749
4796
|
routeMetadataSchema,
|
|
4750
4797
|
routeStepSchema,
|
|
4751
4798
|
routeToken,
|
|
@@ -4762,6 +4809,9 @@ var queries = (0, import_query_key_factory21.mergeQueryKeys)(
|
|
|
4762
4809
|
streamWalletSchema,
|
|
4763
4810
|
streamWalletSnapshotSchema,
|
|
4764
4811
|
streamsQueries,
|
|
4812
|
+
submitCoverPurchase,
|
|
4813
|
+
submitCoverPurchaseDataSchema,
|
|
4814
|
+
submitCoverPurchaseResponseSchema,
|
|
4765
4815
|
submitCoverRequest,
|
|
4766
4816
|
submitCoverRequestResponseSchema,
|
|
4767
4817
|
supportedChainEcosystemSchema,
|