@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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turtleclub/hooks",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.0-beta.
|
|
4
|
+
"version": "0.5.0-beta.78",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "779a08749b5462c7c3e32f110a867db992416687"
|
|
58
58
|
}
|
package/src/v2/covers/api.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { apiClient } from "../lib/api-client";
|
|
2
|
-
import type { CoverRequestData, SubmitCoverRequestResponse, CheckCoverRequestResponse } from "./schema";
|
|
3
|
-
import { submitCoverRequestResponseSchema, checkCoverRequestResponseSchema } from "./schema";
|
|
2
|
+
import type { CoverRequestData, SubmitCoverRequestResponse, CheckCoverRequestResponse, SubmitCoverPurchaseData, SubmitCoverPurchaseResponse } from "./schema";
|
|
3
|
+
import { submitCoverRequestResponseSchema, checkCoverRequestResponseSchema, submitCoverPurchaseResponseSchema } from "./schema";
|
|
4
4
|
|
|
5
5
|
// POST /turtle/nexus-cover-requests
|
|
6
6
|
export async function submitCoverRequest(
|
|
@@ -14,13 +14,32 @@ export async function submitCoverRequest(
|
|
|
14
14
|
const result = submitCoverRequestResponseSchema.safeParse(response);
|
|
15
15
|
|
|
16
16
|
if (!result.success) {
|
|
17
|
-
console.
|
|
17
|
+
console.error("[ZOD ERROR]", result.error);
|
|
18
18
|
throw new Error(`Failed to submit cover request due to an invalid server response.`);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
return result.data;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// POST /turtle/nexus-cover-purchases
|
|
25
|
+
export async function submitCoverPurchase(
|
|
26
|
+
data: SubmitCoverPurchaseData
|
|
27
|
+
): Promise<SubmitCoverPurchaseResponse> {
|
|
28
|
+
const response = await apiClient.fetch("/turtle/nexus-cover-purchases", {
|
|
29
|
+
method: "POST",
|
|
30
|
+
body: data,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const result = submitCoverPurchaseResponseSchema.safeParse(response);
|
|
34
|
+
|
|
35
|
+
if (!result.success) {
|
|
36
|
+
console.error("[ZOD ERROR]", result.error);
|
|
37
|
+
throw new Error("Failed to submit cover purchase tracking due to an invalid server response.");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return result.data;
|
|
41
|
+
}
|
|
42
|
+
|
|
24
43
|
// GET /turtle/nexus-cover-requests?protocolName=X
|
|
25
44
|
export async function checkCoverRequest({
|
|
26
45
|
protocolName,
|
package/src/v2/covers/index.ts
CHANGED
|
@@ -6,11 +6,11 @@ export type { UseSubmitCoverRequestOptions, UseCheckCoverRequestOptions } from "
|
|
|
6
6
|
export { coversQueries } from "./queries";
|
|
7
7
|
|
|
8
8
|
// API functions
|
|
9
|
-
export { submitCoverRequest, checkCoverRequest } from "./api";
|
|
9
|
+
export { submitCoverRequest, checkCoverRequest, submitCoverPurchase } from "./api";
|
|
10
10
|
|
|
11
11
|
// Schemas
|
|
12
|
-
export { coverRequestDataSchema, submitCoverRequestResponseSchema, checkCoverRequestResponseSchema } from "./schema";
|
|
12
|
+
export { coverRequestDataSchema, submitCoverRequestResponseSchema, checkCoverRequestResponseSchema, submitCoverPurchaseDataSchema, submitCoverPurchaseResponseSchema } from "./schema";
|
|
13
13
|
|
|
14
14
|
// Types
|
|
15
|
-
export type { CoverRequestData, SubmitCoverRequestResponse, CheckCoverRequestResponse } from "./schema";
|
|
15
|
+
export type { CoverRequestData, SubmitCoverRequestResponse, CheckCoverRequestResponse, SubmitCoverPurchaseData, SubmitCoverPurchaseResponse } from "./schema";
|
|
16
16
|
|
package/src/v2/covers/schema.ts
CHANGED
|
@@ -24,3 +24,19 @@ export type CoverRequestData = z.infer<typeof coverRequestDataSchema>;
|
|
|
24
24
|
export type SubmitCoverRequestResponse = z.infer<typeof submitCoverRequestResponseSchema>;
|
|
25
25
|
export type CheckCoverRequestResponse = z.infer<typeof checkCoverRequestResponseSchema>;
|
|
26
26
|
|
|
27
|
+
// --- Nexus Cover Purchase Tracking ---
|
|
28
|
+
|
|
29
|
+
export const submitCoverPurchaseDataSchema = z.object({
|
|
30
|
+
walletAddress: z.string().regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address"),
|
|
31
|
+
txHash: z.string().regex(/^0x[a-fA-F0-9]{64}$/, "Invalid transaction hash"),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export const submitCoverPurchaseResponseSchema = z.object({
|
|
35
|
+
success: z.boolean(),
|
|
36
|
+
message: z.string(),
|
|
37
|
+
id: z.string(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export type SubmitCoverPurchaseData = z.infer<typeof submitCoverPurchaseDataSchema>;
|
|
41
|
+
export type SubmitCoverPurchaseResponse = z.infer<typeof submitCoverPurchaseResponseSchema>;
|
|
42
|
+
|
|
@@ -5,6 +5,7 @@ import { filterExcludedTokens } from "../../balance/utils";
|
|
|
5
5
|
|
|
6
6
|
import type { TokenBalance } from "../../balance/types";
|
|
7
7
|
import { Opportunity } from "../../opportunities";
|
|
8
|
+
import { getDepositModeFlags, resolveEffectiveDepositMode } from "./utils";
|
|
8
9
|
|
|
9
10
|
export interface UseActionsDefaultParamsOptions {
|
|
10
11
|
opportunity: Opportunity | null;
|
|
@@ -41,9 +42,9 @@ export function useActionsDefaultParams({
|
|
|
41
42
|
? Number(opportunity.receiptToken.chain.chainId)
|
|
42
43
|
: undefined;
|
|
43
44
|
|
|
44
|
-
//
|
|
45
|
-
const
|
|
46
|
-
const effectiveDepositMode =
|
|
45
|
+
// Determine effective deposit mode based on swap flags
|
|
46
|
+
const flags = getDepositModeFlags(opportunity);
|
|
47
|
+
const effectiveDepositMode = resolveEffectiveDepositMode(depositMode, flags);
|
|
47
48
|
const useOnChainBalances = effectiveDepositMode === "native";
|
|
48
49
|
|
|
49
50
|
// Fetch deposit token balances (on-chain)
|
|
@@ -3,6 +3,7 @@ import { useMemo } from "react";
|
|
|
3
3
|
import type { TokenBalance } from "../../balance/types";
|
|
4
4
|
import { formatUnits } from "viem";
|
|
5
5
|
import { Opportunity } from "../../opportunities";
|
|
6
|
+
import { getDepositModeFlags } from "./utils";
|
|
6
7
|
|
|
7
8
|
export interface UseDepositValidationOptions {
|
|
8
9
|
opportunity: Opportunity | null;
|
|
@@ -114,7 +115,8 @@ export function useDepositValidation({
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
const vaultConfig = opportunity.vaultConfig;
|
|
117
|
-
const
|
|
118
|
+
const { noModesEnabled } = getDepositModeFlags(opportunity);
|
|
119
|
+
const depositDisabled = (opportunity.depositDisabled ?? false) || noModesEnabled;
|
|
118
120
|
const depositDisabledReason = opportunity.depositDisabledReason || null;
|
|
119
121
|
|
|
120
122
|
const depositFee = vaultConfig?.depositFee ?? null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Opportunity } from "../../opportunities";
|
|
2
|
+
|
|
3
|
+
export type DepositMode = "native" | "route";
|
|
4
|
+
|
|
5
|
+
export interface DepositModeFlags {
|
|
6
|
+
isSecondaryOnly: boolean;
|
|
7
|
+
routeModeEnabled: boolean;
|
|
8
|
+
directModeEnabled: boolean;
|
|
9
|
+
noModesEnabled: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getDepositModeFlags(opportunity: Opportunity | null): DepositModeFlags {
|
|
13
|
+
const isSecondaryOnly = opportunity?.vaultConfig?.secondaryOnly === true;
|
|
14
|
+
const routeModeEnabled = opportunity?.swapRouteEnabled ?? false;
|
|
15
|
+
const directModeEnabled = opportunity?.swapDirectEnabled ?? true;
|
|
16
|
+
const noModesEnabled = !routeModeEnabled && !directModeEnabled;
|
|
17
|
+
return { isSecondaryOnly, routeModeEnabled, directModeEnabled, noModesEnabled };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function resolveEffectiveDepositMode(
|
|
21
|
+
depositMode: DepositMode,
|
|
22
|
+
flags: DepositModeFlags
|
|
23
|
+
): DepositMode {
|
|
24
|
+
if (flags.isSecondaryOnly) return "route";
|
|
25
|
+
if (!flags.directModeEnabled && flags.routeModeEnabled) return "route";
|
|
26
|
+
return depositMode;
|
|
27
|
+
}
|
|
@@ -43,3 +43,11 @@ export {
|
|
|
43
43
|
type UseActionsDefaultParamsOptions,
|
|
44
44
|
type UseActionsDefaultParamsReturn,
|
|
45
45
|
} from "./hooks/useActionsDefaultParams";
|
|
46
|
+
|
|
47
|
+
// Re-export deposit mode utilities
|
|
48
|
+
export {
|
|
49
|
+
getDepositModeFlags,
|
|
50
|
+
resolveEffectiveDepositMode,
|
|
51
|
+
type DepositMode,
|
|
52
|
+
type DepositModeFlags,
|
|
53
|
+
} from "./hooks/utils";
|
|
@@ -35,6 +35,8 @@ export const opportunitySchema = z.object({
|
|
|
35
35
|
turtleTvl: z.number(),
|
|
36
36
|
turtleUsers: z.number(),
|
|
37
37
|
earnEnabled: z.boolean(),
|
|
38
|
+
swapDirectEnabled: z.boolean().optional().default(true),
|
|
39
|
+
swapRouteEnabled: z.boolean().optional().default(false),
|
|
38
40
|
createdAt: z.string().datetime().optional(),
|
|
39
41
|
updatedAt: z.string().datetime().optional(),
|
|
40
42
|
mainStreamId: z.string().optional(),
|