@turtleclub/hooks 0.5.0-beta.13 → 0.5.0-beta.14

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turtleclub/hooks",
3
3
  "type": "module",
4
- "version": "0.5.0-beta.13",
4
+ "version": "0.5.0-beta.14",
5
5
  "license": "MIT",
6
6
  "exports": {
7
7
  ".": {
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  },
57
- "gitHead": "a69f1878fb9b00207bb246e83976af054776ed63"
57
+ "gitHead": "1c079d74e9530d05b212ee03ee221e668ae3ce96"
58
58
  }
@@ -0,0 +1,23 @@
1
+ import { apiClient } from "../lib/api-client";
2
+ import type { CoverRequestData, SubmitCoverRequestResponse } from "./schema";
3
+ import { submitCoverRequestResponseSchema } from "./schema";
4
+
5
+ // POST /turtle/nexus-cover-requests
6
+ export async function submitCoverRequest(
7
+ data: CoverRequestData
8
+ ): Promise<SubmitCoverRequestResponse> {
9
+ const response = await apiClient.fetch("/turtle/nexus-cover-requests", {
10
+ method: "POST",
11
+ body: data,
12
+ });
13
+
14
+ const result = submitCoverRequestResponseSchema.safeParse(response);
15
+
16
+ if (!result.success) {
17
+ console.log("[ZOD ERROR]", result.error);
18
+ throw new Error(`Failed to submit cover request due to an invalid server response.`);
19
+ }
20
+
21
+ return result.data;
22
+ }
23
+
@@ -0,0 +1,20 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+ import { submitCoverRequest } from "./api";
3
+
4
+ export interface UseSubmitCoverRequestOptions {
5
+ onSuccess?: (message: string) => void;
6
+ onError?: (message: string) => void;
7
+ }
8
+
9
+ export function useSubmitCoverRequest(options?: UseSubmitCoverRequestOptions) {
10
+ return useMutation({
11
+ mutationFn: submitCoverRequest,
12
+ onSuccess: () => {
13
+ options?.onSuccess?.("Cover request submitted successfully!");
14
+ },
15
+ onError: (error) => {
16
+ console.error("[useSubmitCoverRequest]", error);
17
+ options?.onError?.("Failed to submit Cover Request");
18
+ },
19
+ });
20
+ }
@@ -0,0 +1,13 @@
1
+ // Hooks
2
+ export { useSubmitCoverRequest } from "./hooks";
3
+ export type { UseSubmitCoverRequestOptions } from "./hooks";
4
+
5
+ // API functions
6
+ export { submitCoverRequest } from "./api";
7
+
8
+ // Schemas
9
+ export { coverRequestDataSchema, submitCoverRequestResponseSchema } from "./schema";
10
+
11
+ // Types
12
+ export type { CoverRequestData, SubmitCoverRequestResponse } from "./schema";
13
+
@@ -0,0 +1,20 @@
1
+ import { z } from "zod";
2
+
3
+ export const coverRequestDataSchema = z.object({
4
+ protocolName: z.string(),
5
+ coverageAmount: z.string(),
6
+ periodDays: z.number(),
7
+ desiredApySacrifice: z.string(),
8
+ calculatedEstimatedPremium: z.string(),
9
+ tokenSymbol: z.string(),
10
+ });
11
+
12
+
13
+ export const submitCoverRequestResponseSchema = z.object({
14
+ success: z.boolean(),
15
+ });
16
+
17
+
18
+ export type CoverRequestData = z.infer<typeof coverRequestDataSchema>;
19
+ export type SubmitCoverRequestResponse = z.infer<typeof submitCoverRequestResponseSchema>;
20
+
package/src/v2/index.ts CHANGED
@@ -12,6 +12,7 @@ import { streamsQueries } from "./streams/queries";
12
12
  import { supportedChainsQueries } from "./supported-chains/queries";
13
13
  import { supportedTokensQueries } from "./supported-tokens/queries";
14
14
  import { usersQueries } from "./users/queries";
15
+ import { nftsQueries } from "./nfts/queries";
15
16
 
16
17
  // Merged query keys for cache invalidation
17
18
  export const queries = mergeQueryKeys(
@@ -27,7 +28,8 @@ export const queries = mergeQueryKeys(
27
28
  streamsQueries,
28
29
  supportedChainsQueries,
29
30
  supportedTokensQueries,
30
- usersQueries
31
+ usersQueries,
32
+ nftsQueries
31
33
  );
32
34
 
33
35
  // Features - Earn API
@@ -49,6 +51,8 @@ export * from "./geocheck";
49
51
  export * from "./streams";
50
52
  export * from "./swap";
51
53
  export * from "./users";
54
+ export * from "./nfts";
55
+ export * from "./covers";
52
56
 
53
57
  // Shared schemas
54
58
  export * from "./schemas/shared";
@@ -0,0 +1,25 @@
1
+ import type { UserNft } from "./schema";
2
+
3
+
4
+ const LUMON_API_BASE_URL = "https://lumon.turtle.xyz";
5
+
6
+ export async function fetchUserNfts(userAddress: string, chain: number): Promise<UserNft[]> {
7
+ const endpoint = `${LUMON_API_BASE_URL}/query/token/erc721_portfolio`;
8
+ const response = await fetch(endpoint, {
9
+ method: "POST",
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ },
13
+ body: JSON.stringify({
14
+ user: userAddress,
15
+ chain,
16
+ }),
17
+ });
18
+
19
+ if (!response.ok) {
20
+ throw new Error("Failed to fetch user NFTs");
21
+ }
22
+
23
+ return response.json();
24
+ }
25
+
@@ -0,0 +1,24 @@
1
+ import { skipToken, useQuery } from "@tanstack/react-query";
2
+ import { createQueryOptions } from "../lib/query-config";
3
+ import { nftsQueries } from "./queries";
4
+ import type { UserNft } from "./schema";
5
+
6
+ export interface UseUserNftsOptions {
7
+ userAddress: string | undefined;
8
+ chain: number;
9
+ tokenAddress?: string;
10
+ }
11
+
12
+ export function useUserNfts({ userAddress, chain, tokenAddress }: UseUserNftsOptions) {
13
+ return useQuery(
14
+ userAddress
15
+ ? createQueryOptions(nftsQueries.byUser(userAddress, chain), {
16
+ select: (data: UserNft[]) =>
17
+ tokenAddress
18
+ ? data.filter((nft) => nft.token.toLowerCase() === tokenAddress.toLowerCase())
19
+ : data,
20
+ })
21
+ : { queryKey: ["nfts", "byUser", "skip"], queryFn: skipToken }
22
+ );
23
+ }
24
+
@@ -0,0 +1,13 @@
1
+ // Hooks
2
+ export { useUserNfts } from "./hooks";
3
+ export type { UseUserNftsOptions } from "./hooks";
4
+
5
+ // Query keys
6
+ export { nftsQueries } from "./queries";
7
+
8
+ // API functions
9
+ export { fetchUserNfts } from "./api";
10
+
11
+ // Types
12
+ export type { UserNft, UserNftsFilters } from "./schema";
13
+
@@ -0,0 +1,10 @@
1
+ import { createQueryKeys } from "@lukemorales/query-key-factory";
2
+ import { fetchUserNfts } from "./api";
3
+
4
+ export const nftsQueries = createQueryKeys("nfts", {
5
+ byUser: (userAddress: string, chain: number) => ({
6
+ queryKey: [userAddress, chain],
7
+ queryFn: () => fetchUserNfts(userAddress, chain),
8
+ }),
9
+ });
10
+
@@ -0,0 +1,12 @@
1
+ export interface UserNft {
2
+ user: string;
3
+ chain: number;
4
+ token: string;
5
+ token_id: string;
6
+ last_transfer: string;
7
+ }
8
+
9
+ export interface UserNftsFilters {
10
+ tokenAddress?: string;
11
+ }
12
+