@turtleclub/hooks 0.0.1

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/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # @turtledev/hooks
2
+
3
+ React hooks and utilities for building applications with the Turtle ecosystem.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @turtledev/hooks
9
+ # or
10
+ yarn add @turtledev/hooks
11
+ # or
12
+ bun add @turtledev/hooks
13
+ ```
14
+
15
+ ## Features
16
+
17
+ - 🎣 **React Query hooks** for API endpoints
18
+ - 🔧 **Utility functions** for chains, formatting, and numbers
19
+ - 🔄 **Automatic caching** and persistence
20
+ - 📝 **TypeScript** support with full type safety
21
+
22
+ ## Usage
23
+
24
+ ### API Hooks
25
+
26
+ ```typescript
27
+ import { useOrganizations, useConfig } from "@turtledev/hooks";
28
+
29
+ function MyComponent() {
30
+ const { data: organizations, isLoading } = useOrganizations();
31
+
32
+ if (isLoading) return <div>Loading...</div>;
33
+
34
+ return <div>{organizations?.name}</div>;
35
+ }
36
+ ```
37
+
38
+ ## Available Hooks
39
+
40
+ ### Endpoints
41
+ - `useOrganizations()` - Get organization data
42
+ - `useOrganizationDeals()` - Get organization deals
43
+ - `useOrganizationsDeals()` - Get all organizations deals
44
+ - `useProjectTvl()` - Get project TVL data
45
+ - `useExists()` - Check if user exists
46
+ - `usePrepareSignup()` - Prepare signup process
47
+ - `useSignup()` - Complete signup
48
+
49
+ ### Configuration
50
+ - `useConfig()` - Get current API configuration
package/dist/index.cjs ADDED
@@ -0,0 +1,301 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ defaultQueryClient: () => defaultQueryClient,
24
+ useConfig: () => useConfig,
25
+ useEarnDeals: () => useEarnDeals,
26
+ useEarnRoute: () => useEarnRoute,
27
+ useEarnWalletBalances: () => useEarnWalletBalances,
28
+ useExists: () => useExists,
29
+ useOrganizationDeals: () => useOrganizationDeals,
30
+ useOrganizations: () => useOrganizations,
31
+ useOrganizationsDeals: () => useOrganizationsDeals,
32
+ usePrepareSignup: () => usePrepareSignup,
33
+ useProjectTvl: () => useProjectTvl,
34
+ useSignup: () => useSignup
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/hooks/useConfig.ts
39
+ var import_api = require("@turtleclub/api");
40
+ function useConfig() {
41
+ return import_api.defaultConfig;
42
+ }
43
+
44
+ // src/hooks/client.ts
45
+ var import_query_sync_storage_persister = require("@tanstack/query-sync-storage-persister");
46
+ var import_react_query = require("@tanstack/react-query");
47
+ var import_react_query_persist_client = require("@tanstack/react-query-persist-client");
48
+ var defaultQueryClient = new import_react_query.QueryClient({
49
+ defaultOptions: {
50
+ queries: {
51
+ refetchOnWindowFocus: false
52
+ }
53
+ }
54
+ });
55
+ if (typeof window !== "undefined") {
56
+ const localStoragePersister = (0, import_query_sync_storage_persister.createSyncStoragePersister)({
57
+ storage: window.localStorage,
58
+ key: "turtle-sdk"
59
+ });
60
+ (0, import_react_query_persist_client.persistQueryClient)({
61
+ queryClient: defaultQueryClient,
62
+ persister: localStoragePersister
63
+ });
64
+ }
65
+
66
+ // src/hooks/endpoints/useOrganizations.ts
67
+ var import_react_query2 = require("@tanstack/react-query");
68
+ var import_api2 = require("@turtleclub/api");
69
+ function useOrganizations({
70
+ config,
71
+ queryClient
72
+ } = {}) {
73
+ const defaultConfig2 = useConfig();
74
+ const query = (0, import_react_query2.useQuery)(
75
+ {
76
+ queryKey: ["organizations"],
77
+ queryFn: async () => {
78
+ return await (0, import_api2.organization)(config ?? defaultConfig2);
79
+ },
80
+ staleTime: 2 * 60 * 1e3,
81
+ refetchInterval: 1 * 60 * 1e3
82
+ },
83
+ queryClient ?? defaultQueryClient
84
+ );
85
+ return query;
86
+ }
87
+
88
+ // src/hooks/endpoints/useExists.ts
89
+ var import_react_query3 = require("@tanstack/react-query");
90
+ var import_api3 = require("@turtleclub/api");
91
+ function useExists(options, { config, queryClient } = {}) {
92
+ const defaultConfig2 = useConfig();
93
+ const enabled = options !== void 0;
94
+ const query = (0, import_react_query3.useQuery)({
95
+ queryKey: ["exists", options?.user],
96
+ queryFn: async () => {
97
+ if (!enabled)
98
+ return null;
99
+ return await (0, import_api3.exists)(options, config ?? defaultConfig2);
100
+ },
101
+ enabled,
102
+ staleTime: 2 * 60 * 1e3,
103
+ refetchInterval: 1 * 60 * 1e3,
104
+ refetchOnWindowFocus: true
105
+ }, queryClient ?? defaultQueryClient);
106
+ return query;
107
+ }
108
+
109
+ // src/hooks/endpoints/useOrganizationDeals.ts
110
+ var import_react_query4 = require("@tanstack/react-query");
111
+ var import_api4 = require("@turtleclub/api");
112
+ function useOrganizationDeals(options, { config, queryClient } = {}) {
113
+ const defaultConfig2 = useConfig();
114
+ const enabled = options !== void 0;
115
+ const query = (0, import_react_query4.useQuery)({
116
+ queryKey: ["organizationDeals", options?.organizationId],
117
+ queryFn: async () => {
118
+ if (!enabled)
119
+ return null;
120
+ return await (0, import_api4.organizationDeals)(options, config ?? defaultConfig2);
121
+ },
122
+ enabled,
123
+ staleTime: 2 * 60 * 1e3,
124
+ refetchInterval: 1 * 60 * 1e3
125
+ }, queryClient ?? defaultQueryClient);
126
+ return query;
127
+ }
128
+
129
+ // src/hooks/endpoints/useOrganizationsDeals.ts
130
+ var import_react_query5 = require("@tanstack/react-query");
131
+ var import_api5 = require("@turtleclub/api");
132
+ function useOrganizationsDeals(options, { config, queryClient } = {}) {
133
+ const defaultConfig2 = useConfig();
134
+ const enabled = options !== void 0;
135
+ const query = (0, import_react_query5.useQuery)({
136
+ queryKey: ["organizationsDeals", options?.organizationIds],
137
+ queryFn: async () => {
138
+ if (!enabled)
139
+ return null;
140
+ return await (0, import_api5.organizationsDeals)(options, config ?? defaultConfig2);
141
+ },
142
+ enabled,
143
+ staleTime: 2 * 60 * 1e3,
144
+ refetchInterval: 1 * 60 * 1e3,
145
+ throwOnError: true
146
+ }, queryClient ?? defaultQueryClient);
147
+ return query;
148
+ }
149
+
150
+ // src/hooks/endpoints/usePrepareSignup.ts
151
+ var import_react_query6 = require("@tanstack/react-query");
152
+ var import_api6 = require("@turtleclub/api");
153
+ function usePrepareSignup(options, { config, queryClient } = {}) {
154
+ const defaultConfig2 = useConfig();
155
+ const enabled = options !== void 0;
156
+ const query = (0, import_react_query6.useQuery)({
157
+ queryKey: ["prepareSignup", options?.user],
158
+ queryFn: async () => {
159
+ if (!enabled)
160
+ return null;
161
+ return await (0, import_api6.prepareSignup)(options, config ?? defaultConfig2);
162
+ },
163
+ enabled,
164
+ refetchInterval: 5 * 60 * 1e3
165
+ }, queryClient ?? defaultQueryClient);
166
+ return query;
167
+ }
168
+
169
+ // src/hooks/endpoints/useProjectTvl.ts
170
+ var import_react_query7 = require("@tanstack/react-query");
171
+ var import_api7 = require("@turtleclub/api");
172
+ function useProjectTvl(options, { config, queryClient } = {}) {
173
+ const defaultConfig2 = useConfig();
174
+ const enabled = options !== void 0;
175
+ const query = (0, import_react_query7.useQuery)({
176
+ queryKey: ["projectTvl", options?.projects],
177
+ queryFn: async () => {
178
+ if (!enabled)
179
+ return null;
180
+ return await (0, import_api7.projectTvl)(options, config ?? defaultConfig2);
181
+ },
182
+ enabled,
183
+ staleTime: 7 * 60 * 1e3,
184
+ refetchInterval: 5 * 60 * 1e3
185
+ }, queryClient ?? defaultQueryClient);
186
+ return query;
187
+ }
188
+
189
+ // src/hooks/endpoints/useSignup.ts
190
+ var import_react_query8 = require("@tanstack/react-query");
191
+ var import_api8 = require("@turtleclub/api");
192
+ function useSignup(options, { config, queryClient } = {}) {
193
+ const defaultConfig2 = useConfig();
194
+ const enabled = options !== void 0;
195
+ const mutation = (0, import_react_query8.useMutation)(
196
+ {
197
+ mutationFn: async (signature) => {
198
+ if (!enabled) return null;
199
+ return await (0, import_api8.signup)({ ...options, signature }, config ?? defaultConfig2);
200
+ }
201
+ },
202
+ queryClient ?? defaultQueryClient
203
+ );
204
+ return mutation;
205
+ }
206
+
207
+ // src/hooks/endpoints/earn/useDeals.ts
208
+ var import_react_query9 = require("@tanstack/react-query");
209
+ var import_api9 = require("@turtleclub/api");
210
+ function useEarnDeals(options, { config, queryClient } = {}) {
211
+ const defaultConfig2 = useConfig();
212
+ const enabled = options !== void 0;
213
+ const query = (0, import_react_query9.useQuery)({
214
+ queryKey: [
215
+ "earn-deals",
216
+ options?.campaignId,
217
+ options?.idFilter,
218
+ options?.protocolFilter
219
+ ],
220
+ queryFn: async () => {
221
+ if (!enabled)
222
+ return null;
223
+ return await (0, import_api9.earnDeals)(options, config ?? defaultConfig2);
224
+ },
225
+ enabled,
226
+ staleTime: 60 * 1e3,
227
+ refetchInterval: 30 * 1e3,
228
+ refetchOnWindowFocus: true
229
+ }, queryClient ?? defaultQueryClient);
230
+ return query;
231
+ }
232
+
233
+ // src/hooks/endpoints/earn/useRoute.ts
234
+ var import_react_query10 = require("@tanstack/react-query");
235
+ var import_api10 = require("@turtleclub/api");
236
+ function useEarnRoute(options, { config, queryClient } = {}) {
237
+ const defaultConfig2 = useConfig();
238
+ const enabled = options !== void 0;
239
+ const query = (0, import_react_query10.useQuery)({
240
+ queryKey: [
241
+ "earnRoute",
242
+ options?.user,
243
+ options?.chain,
244
+ options?.slippage,
245
+ options?.tokenIn,
246
+ options?.tokenOut,
247
+ options?.amount
248
+ ],
249
+ queryFn: async () => {
250
+ if (!enabled)
251
+ return null;
252
+ return await (0, import_api10.earnRoute)(options, config ?? defaultConfig2);
253
+ },
254
+ enabled,
255
+ staleTime: 2 * 60 * 1e3,
256
+ // 2 minutes - longer stale time for transaction stability
257
+ refetchInterval: false,
258
+ // Disable automatic refetch to prevent transaction state reset
259
+ refetchOnWindowFocus: true
260
+ }, queryClient ?? defaultQueryClient);
261
+ return query;
262
+ }
263
+
264
+ // src/hooks/endpoints/earn/useWalletBalances.ts
265
+ var import_react_query11 = require("@tanstack/react-query");
266
+ var import_api11 = require("@turtleclub/api");
267
+ function useEarnWalletBalances(options, { config, queryClient } = {}) {
268
+ const defaultConfig2 = useConfig();
269
+ const enabled = options !== void 0;
270
+ const query = (0, import_react_query11.useQuery)(
271
+ {
272
+ queryKey: ["earnWalletBalances", options?.chain, options?.user],
273
+ queryFn: async () => {
274
+ if (!enabled) return null;
275
+ return await (0, import_api11.earnWalletBalances)(options, config ?? defaultConfig2);
276
+ },
277
+ enabled,
278
+ staleTime: 30 * 1e3,
279
+ refetchInterval: 15 * 1e3,
280
+ refetchOnWindowFocus: true
281
+ },
282
+ queryClient ?? defaultQueryClient
283
+ );
284
+ return query;
285
+ }
286
+ // Annotate the CommonJS export names for ESM import in node:
287
+ 0 && (module.exports = {
288
+ defaultQueryClient,
289
+ useConfig,
290
+ useEarnDeals,
291
+ useEarnRoute,
292
+ useEarnWalletBalances,
293
+ useExists,
294
+ useOrganizationDeals,
295
+ useOrganizations,
296
+ useOrganizationsDeals,
297
+ usePrepareSignup,
298
+ useProjectTvl,
299
+ useSignup
300
+ });
301
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/hooks/useConfig.ts","../src/hooks/client.ts","../src/hooks/endpoints/useOrganizations.ts","../src/hooks/endpoints/useExists.ts","../src/hooks/endpoints/useOrganizationDeals.ts","../src/hooks/endpoints/useOrganizationsDeals.ts","../src/hooks/endpoints/usePrepareSignup.ts","../src/hooks/endpoints/useProjectTvl.ts","../src/hooks/endpoints/useSignup.ts","../src/hooks/endpoints/earn/useDeals.ts","../src/hooks/endpoints/earn/useRoute.ts","../src/hooks/endpoints/earn/useWalletBalances.ts"],"sourcesContent":["// Hooks\nexport * from \"./hooks/useConfig\";\nexport * from \"./hooks/client\";\n\n// Endpoint hooks\nexport * from \"./hooks/endpoints/useOrganizations\";\nexport * from \"./hooks/endpoints/useExists\";\nexport * from \"./hooks/endpoints/useOrganizationDeals\";\nexport * from \"./hooks/endpoints/useOrganizationsDeals\";\nexport * from \"./hooks/endpoints/usePrepareSignup\";\nexport * from \"./hooks/endpoints/useProjectTvl\";\nexport * from \"./hooks/endpoints/useSignup\";\n\n// Earn hooks\nexport * from \"./hooks/endpoints/earn\";\n","import type { Config } from \"@turtleclub/api\";\nimport { defaultConfig } from \"@turtleclub/api\";\n\nexport function useConfig(): Config {\n // Placeholder implementation - in real app this would use TurtleProvider context\n return defaultConfig;\n}\n","import { createSyncStoragePersister } from \"@tanstack/query-sync-storage-persister\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { persistQueryClient } from \"@tanstack/react-query-persist-client\";\n\nexport const defaultQueryClient = new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n },\n },\n});\n\n// Only persist on client side\nif (typeof window !== 'undefined') {\n const localStoragePersister = createSyncStoragePersister({\n storage: window.localStorage,\n key: \"turtle-sdk\",\n });\n\n persistQueryClient({\n queryClient: defaultQueryClient,\n persister: localStoragePersister,\n });\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, organization, type OrganizationResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseOrganizationsOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useOrganizations({\n config,\n queryClient,\n}: UseOrganizationsOptions = {}): UseQueryResult<OrganizationResponse | null> {\n const defaultConfig = useConfig();\n\n const query = useQuery(\n {\n queryKey: [\"organizations\"],\n queryFn: async () => {\n return await organization(config ?? defaultConfig);\n },\n staleTime: 2 * 60 * 1000,\n refetchInterval: 1 * 60 * 1000,\n },\n queryClient ?? defaultQueryClient\n );\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, exists, type ExistsOptions } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseExistsOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useExists(\n options?: ExistsOptions,\n { config, queryClient }: UseExistsOptions = {},\n): UseQueryResult<boolean | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\"exists\", options?.user],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await exists(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 2 * 60 * 1000,\n refetchInterval: 1 * 60 * 1000,\n refetchOnWindowFocus: true,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, organizationDeals, type OrganizationDealsOptions, type OrganizationDealsResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseOrganizationDealsOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useOrganizationDeals(\n options?: OrganizationDealsOptions,\n { config, queryClient }: UseOrganizationDealsOptions = {},\n): UseQueryResult<OrganizationDealsResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\"organizationDeals\", options?.organizationId],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await organizationDeals(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 2 * 60 * 1000,\n refetchInterval: 1 * 60 * 1000,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, organizationsDeals, type OrganizationsDealsOptions, type OrganizationsDealsResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseOrganizationsDealsOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useOrganizationsDeals(\n options?: OrganizationsDealsOptions,\n { config, queryClient }: UseOrganizationsDealsOptions = {},\n): UseQueryResult<OrganizationsDealsResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\"organizationsDeals\", options?.organizationIds],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await organizationsDeals(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 2 * 60 * 1000,\n refetchInterval: 1 * 60 * 1000,\n throwOnError: true,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, prepareSignup, type PrepareSignupOptions, type PrepareSignupResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UsePrepareSignupOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function usePrepareSignup(\n options?: PrepareSignupOptions,\n { config, queryClient }: UsePrepareSignupOptions = {},\n): UseQueryResult<PrepareSignupResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\"prepareSignup\", options?.user],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await prepareSignup(options, config ?? defaultConfig);\n },\n enabled,\n refetchInterval: 5 * 60 * 1000,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, projectTvl, type ProjectTvlOptions, type ProjectTvlResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseProjectTvlOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useProjectTvl(\n options?: ProjectTvlOptions,\n { config, queryClient }: UseProjectTvlOptions = {},\n): UseQueryResult<ProjectTvlResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\"projectTvl\", options?.projects],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await projectTvl(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 7 * 60 * 1000,\n refetchInterval: 5 * 60 * 1000,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import {\n type QueryClient,\n useMutation,\n type UseMutationResult,\n useQuery,\n} from \"@tanstack/react-query\";\nimport { type Config, signup, type SignupOptions } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseSignupOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useSignup(\n options?: Omit<SignupOptions, \"signature\">,\n { config, queryClient }: UseSignupOptions = {}\n): UseMutationResult<boolean | null, Error, string, unknown> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const mutation = useMutation(\n {\n mutationFn: async (signature: string) => {\n if (!enabled) return null;\n\n return await signup({ ...options, signature }, config ?? defaultConfig);\n },\n },\n queryClient ?? defaultQueryClient\n );\n\n return mutation;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, earnDeals, type EarnDealsOptions, type EarnDealsResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"@/hooks/client\";\nimport { useConfig } from \"@/hooks/useConfig\";\n\nexport interface UseEarnDealsOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useEarnDeals(\n options?: EarnDealsOptions,\n { config, queryClient }: UseEarnDealsOptions = {},\n): UseQueryResult<EarnDealsResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\n \"earn-deals\",\n options?.campaignId,\n options?.idFilter,\n options?.protocolFilter,\n ],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await earnDeals(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 60 * 1000,\n refetchInterval: 30 * 1000,\n refetchOnWindowFocus: true,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, earnRoute, type EarnRouteOptions, type EarnRouteResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../../client\";\nimport { useConfig } from \"../../useConfig\";\n\nexport interface UseEarnRouteOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useEarnRoute(\n options?: EarnRouteOptions,\n { config, queryClient }: UseEarnRouteOptions = {},\n): UseQueryResult<EarnRouteResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\n \"earnRoute\",\n options?.user,\n options?.chain,\n options?.slippage,\n options?.tokenIn,\n options?.tokenOut,\n options?.amount,\n ],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await earnRoute(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 2 * 60 * 1000, // 2 minutes - longer stale time for transaction stability\n refetchInterval: false, // Disable automatic refetch to prevent transaction state reset\n refetchOnWindowFocus: true,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport {\n type Config,\n earnWalletBalances,\n type EarnWalletBalancesOptions,\n type EarnWalletBalancesResponse,\n} from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../../client\";\nimport { useConfig } from \"../../useConfig\";\n\nexport interface UseEarnWalletBalancesOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useEarnWalletBalances(\n options?: EarnWalletBalancesOptions,\n { config, queryClient }: UseEarnWalletBalancesOptions = {}\n): UseQueryResult<EarnWalletBalancesResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery(\n {\n queryKey: [\"earnWalletBalances\", options?.chain, options?.user],\n queryFn: async () => {\n if (!enabled) return null;\n\n return await earnWalletBalances(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 30 * 1000,\n refetchInterval: 15 * 1000,\n refetchOnWindowFocus: true,\n },\n queryClient ?? defaultQueryClient\n );\n\n return query;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,iBAA8B;AAEvB,SAAS,YAAoB;AAElC,SAAO;AACT;;;ACNA,0CAA2C;AAC3C,yBAA4B;AAC5B,wCAAmC;AAE5B,IAAM,qBAAqB,IAAI,+BAAY;AAAA,EAChD,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,sBAAsB;AAAA,IACxB;AAAA,EACF;AACF,CAAC;AAGD,IAAI,OAAO,WAAW,aAAa;AACjC,QAAM,4BAAwB,gEAA2B;AAAA,IACvD,SAAS,OAAO;AAAA,IAChB,KAAK;AAAA,EACP,CAAC;AAED,4DAAmB;AAAA,IACjB,aAAa;AAAA,IACb,WAAW;AAAA,EACb,CAAC;AACH;;;ACvBA,IAAAA,sBAAgE;AAChE,IAAAC,cAAqE;AAS9D,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AACF,IAA6B,CAAC,GAAgD;AAC5E,QAAMC,iBAAgB,UAAU;AAEhC,QAAM,YAAQ;AAAA,IACZ;AAAA,MACE,UAAU,CAAC,eAAe;AAAA,MAC1B,SAAS,YAAY;AACnB,eAAO,UAAM,0BAAa,UAAUA,cAAa;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AY;AACnB,UAAI,CAAC;AACH,eAAO;AAET,aAAO,UAAM,wBAAU,SAAS,UAAUA,cAAa;AAAA,IACzD;AAAA,IACA;AAAA,IACA,WAAW,IAAI,KAAK;AAAA;AAAA,IACpB,iBAAiB;AAAA;AAAA,IACjB,sBAAsB;AAAA,EACxB,GAAG,eAAe,kBAAkB;AAEpC,SAAO;AACT;;;ACxCA,IAAAC,uBAAgE;AAChE,IAAAC,eAKO;AASA,SAAS,sBACd,SACA,EAAE,QAAQ,YAAY,IAAkC,CAAC,GACN;AACnD,QAAMC,iBAAgB,UAAU;AAChC,QAAM,UAAU,YAAY;AAE5B,QAAM,YAAQ;AAAA,IACZ;AAAA,MACE,UAAU,CAAC,sBAAsB,SAAS,OAAO,SAAS,IAAI;AAAA,MAC9D,SAAS,YAAY;AACnB,YAAI,CAAC,QAAS,QAAO;AAErB,eAAO,UAAM,iCAAmB,SAAS,UAAUA,cAAa;AAAA,MAClE;AAAA,MACA;AAAA,MACA,WAAW,KAAK;AAAA,MAChB,iBAAiB,KAAK;AAAA,MACtB,sBAAsB;AAAA,IACxB;AAAA,IACA,eAAe;AAAA,EACjB;AAEA,SAAO;AACT;","names":["import_react_query","import_api","defaultConfig","import_react_query","import_api","defaultConfig","import_react_query","import_api","defaultConfig","import_react_query","import_api","defaultConfig","import_react_query","import_api","defaultConfig","import_react_query","import_api","defaultConfig","import_react_query","import_api","defaultConfig","import_react_query","import_api","defaultConfig","import_react_query","import_api","defaultConfig","import_react_query","import_api","defaultConfig"]}
package/dist/index.js ADDED
@@ -0,0 +1,267 @@
1
+ // src/hooks/useConfig.ts
2
+ import { defaultConfig } from "@turtleclub/api";
3
+ function useConfig() {
4
+ return defaultConfig;
5
+ }
6
+
7
+ // src/hooks/client.ts
8
+ import { createSyncStoragePersister } from "@tanstack/query-sync-storage-persister";
9
+ import { QueryClient } from "@tanstack/react-query";
10
+ import { persistQueryClient } from "@tanstack/react-query-persist-client";
11
+ var defaultQueryClient = new QueryClient({
12
+ defaultOptions: {
13
+ queries: {
14
+ refetchOnWindowFocus: false
15
+ }
16
+ }
17
+ });
18
+ if (typeof window !== "undefined") {
19
+ const localStoragePersister = createSyncStoragePersister({
20
+ storage: window.localStorage,
21
+ key: "turtle-sdk"
22
+ });
23
+ persistQueryClient({
24
+ queryClient: defaultQueryClient,
25
+ persister: localStoragePersister
26
+ });
27
+ }
28
+
29
+ // src/hooks/endpoints/useOrganizations.ts
30
+ import { useQuery } from "@tanstack/react-query";
31
+ import { organization } from "@turtleclub/api";
32
+ function useOrganizations({
33
+ config,
34
+ queryClient
35
+ } = {}) {
36
+ const defaultConfig2 = useConfig();
37
+ const query = useQuery(
38
+ {
39
+ queryKey: ["organizations"],
40
+ queryFn: async () => {
41
+ return await organization(config ?? defaultConfig2);
42
+ },
43
+ staleTime: 2 * 60 * 1e3,
44
+ refetchInterval: 1 * 60 * 1e3
45
+ },
46
+ queryClient ?? defaultQueryClient
47
+ );
48
+ return query;
49
+ }
50
+
51
+ // src/hooks/endpoints/useExists.ts
52
+ import { useQuery as useQuery2 } from "@tanstack/react-query";
53
+ import { exists } from "@turtleclub/api";
54
+ function useExists(options, { config, queryClient } = {}) {
55
+ const defaultConfig2 = useConfig();
56
+ const enabled = options !== void 0;
57
+ const query = useQuery2({
58
+ queryKey: ["exists", options?.user],
59
+ queryFn: async () => {
60
+ if (!enabled)
61
+ return null;
62
+ return await exists(options, config ?? defaultConfig2);
63
+ },
64
+ enabled,
65
+ staleTime: 2 * 60 * 1e3,
66
+ refetchInterval: 1 * 60 * 1e3,
67
+ refetchOnWindowFocus: true
68
+ }, queryClient ?? defaultQueryClient);
69
+ return query;
70
+ }
71
+
72
+ // src/hooks/endpoints/useOrganizationDeals.ts
73
+ import { useQuery as useQuery3 } from "@tanstack/react-query";
74
+ import { organizationDeals } from "@turtleclub/api";
75
+ function useOrganizationDeals(options, { config, queryClient } = {}) {
76
+ const defaultConfig2 = useConfig();
77
+ const enabled = options !== void 0;
78
+ const query = useQuery3({
79
+ queryKey: ["organizationDeals", options?.organizationId],
80
+ queryFn: async () => {
81
+ if (!enabled)
82
+ return null;
83
+ return await organizationDeals(options, config ?? defaultConfig2);
84
+ },
85
+ enabled,
86
+ staleTime: 2 * 60 * 1e3,
87
+ refetchInterval: 1 * 60 * 1e3
88
+ }, queryClient ?? defaultQueryClient);
89
+ return query;
90
+ }
91
+
92
+ // src/hooks/endpoints/useOrganizationsDeals.ts
93
+ import { useQuery as useQuery4 } from "@tanstack/react-query";
94
+ import { organizationsDeals } from "@turtleclub/api";
95
+ function useOrganizationsDeals(options, { config, queryClient } = {}) {
96
+ const defaultConfig2 = useConfig();
97
+ const enabled = options !== void 0;
98
+ const query = useQuery4({
99
+ queryKey: ["organizationsDeals", options?.organizationIds],
100
+ queryFn: async () => {
101
+ if (!enabled)
102
+ return null;
103
+ return await organizationsDeals(options, config ?? defaultConfig2);
104
+ },
105
+ enabled,
106
+ staleTime: 2 * 60 * 1e3,
107
+ refetchInterval: 1 * 60 * 1e3,
108
+ throwOnError: true
109
+ }, queryClient ?? defaultQueryClient);
110
+ return query;
111
+ }
112
+
113
+ // src/hooks/endpoints/usePrepareSignup.ts
114
+ import { useQuery as useQuery5 } from "@tanstack/react-query";
115
+ import { prepareSignup } from "@turtleclub/api";
116
+ function usePrepareSignup(options, { config, queryClient } = {}) {
117
+ const defaultConfig2 = useConfig();
118
+ const enabled = options !== void 0;
119
+ const query = useQuery5({
120
+ queryKey: ["prepareSignup", options?.user],
121
+ queryFn: async () => {
122
+ if (!enabled)
123
+ return null;
124
+ return await prepareSignup(options, config ?? defaultConfig2);
125
+ },
126
+ enabled,
127
+ refetchInterval: 5 * 60 * 1e3
128
+ }, queryClient ?? defaultQueryClient);
129
+ return query;
130
+ }
131
+
132
+ // src/hooks/endpoints/useProjectTvl.ts
133
+ import { useQuery as useQuery6 } from "@tanstack/react-query";
134
+ import { projectTvl } from "@turtleclub/api";
135
+ function useProjectTvl(options, { config, queryClient } = {}) {
136
+ const defaultConfig2 = useConfig();
137
+ const enabled = options !== void 0;
138
+ const query = useQuery6({
139
+ queryKey: ["projectTvl", options?.projects],
140
+ queryFn: async () => {
141
+ if (!enabled)
142
+ return null;
143
+ return await projectTvl(options, config ?? defaultConfig2);
144
+ },
145
+ enabled,
146
+ staleTime: 7 * 60 * 1e3,
147
+ refetchInterval: 5 * 60 * 1e3
148
+ }, queryClient ?? defaultQueryClient);
149
+ return query;
150
+ }
151
+
152
+ // src/hooks/endpoints/useSignup.ts
153
+ import {
154
+ useMutation
155
+ } from "@tanstack/react-query";
156
+ import { signup } from "@turtleclub/api";
157
+ function useSignup(options, { config, queryClient } = {}) {
158
+ const defaultConfig2 = useConfig();
159
+ const enabled = options !== void 0;
160
+ const mutation = useMutation(
161
+ {
162
+ mutationFn: async (signature) => {
163
+ if (!enabled) return null;
164
+ return await signup({ ...options, signature }, config ?? defaultConfig2);
165
+ }
166
+ },
167
+ queryClient ?? defaultQueryClient
168
+ );
169
+ return mutation;
170
+ }
171
+
172
+ // src/hooks/endpoints/earn/useDeals.ts
173
+ import { useQuery as useQuery8 } from "@tanstack/react-query";
174
+ import { earnDeals } from "@turtleclub/api";
175
+ function useEarnDeals(options, { config, queryClient } = {}) {
176
+ const defaultConfig2 = useConfig();
177
+ const enabled = options !== void 0;
178
+ const query = useQuery8({
179
+ queryKey: [
180
+ "earn-deals",
181
+ options?.campaignId,
182
+ options?.idFilter,
183
+ options?.protocolFilter
184
+ ],
185
+ queryFn: async () => {
186
+ if (!enabled)
187
+ return null;
188
+ return await earnDeals(options, config ?? defaultConfig2);
189
+ },
190
+ enabled,
191
+ staleTime: 60 * 1e3,
192
+ refetchInterval: 30 * 1e3,
193
+ refetchOnWindowFocus: true
194
+ }, queryClient ?? defaultQueryClient);
195
+ return query;
196
+ }
197
+
198
+ // src/hooks/endpoints/earn/useRoute.ts
199
+ import { useQuery as useQuery9 } from "@tanstack/react-query";
200
+ import { earnRoute } from "@turtleclub/api";
201
+ function useEarnRoute(options, { config, queryClient } = {}) {
202
+ const defaultConfig2 = useConfig();
203
+ const enabled = options !== void 0;
204
+ const query = useQuery9({
205
+ queryKey: [
206
+ "earnRoute",
207
+ options?.user,
208
+ options?.chain,
209
+ options?.slippage,
210
+ options?.tokenIn,
211
+ options?.tokenOut,
212
+ options?.amount
213
+ ],
214
+ queryFn: async () => {
215
+ if (!enabled)
216
+ return null;
217
+ return await earnRoute(options, config ?? defaultConfig2);
218
+ },
219
+ enabled,
220
+ staleTime: 2 * 60 * 1e3,
221
+ // 2 minutes - longer stale time for transaction stability
222
+ refetchInterval: false,
223
+ // Disable automatic refetch to prevent transaction state reset
224
+ refetchOnWindowFocus: true
225
+ }, queryClient ?? defaultQueryClient);
226
+ return query;
227
+ }
228
+
229
+ // src/hooks/endpoints/earn/useWalletBalances.ts
230
+ import { useQuery as useQuery10 } from "@tanstack/react-query";
231
+ import {
232
+ earnWalletBalances
233
+ } from "@turtleclub/api";
234
+ function useEarnWalletBalances(options, { config, queryClient } = {}) {
235
+ const defaultConfig2 = useConfig();
236
+ const enabled = options !== void 0;
237
+ const query = useQuery10(
238
+ {
239
+ queryKey: ["earnWalletBalances", options?.chain, options?.user],
240
+ queryFn: async () => {
241
+ if (!enabled) return null;
242
+ return await earnWalletBalances(options, config ?? defaultConfig2);
243
+ },
244
+ enabled,
245
+ staleTime: 30 * 1e3,
246
+ refetchInterval: 15 * 1e3,
247
+ refetchOnWindowFocus: true
248
+ },
249
+ queryClient ?? defaultQueryClient
250
+ );
251
+ return query;
252
+ }
253
+ export {
254
+ defaultQueryClient,
255
+ useConfig,
256
+ useEarnDeals,
257
+ useEarnRoute,
258
+ useEarnWalletBalances,
259
+ useExists,
260
+ useOrganizationDeals,
261
+ useOrganizations,
262
+ useOrganizationsDeals,
263
+ usePrepareSignup,
264
+ useProjectTvl,
265
+ useSignup
266
+ };
267
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/useConfig.ts","../src/hooks/client.ts","../src/hooks/endpoints/useOrganizations.ts","../src/hooks/endpoints/useExists.ts","../src/hooks/endpoints/useOrganizationDeals.ts","../src/hooks/endpoints/useOrganizationsDeals.ts","../src/hooks/endpoints/usePrepareSignup.ts","../src/hooks/endpoints/useProjectTvl.ts","../src/hooks/endpoints/useSignup.ts","../src/hooks/endpoints/earn/useDeals.ts","../src/hooks/endpoints/earn/useRoute.ts","../src/hooks/endpoints/earn/useWalletBalances.ts"],"sourcesContent":["import type { Config } from \"@turtleclub/api\";\nimport { defaultConfig } from \"@turtleclub/api\";\n\nexport function useConfig(): Config {\n // Placeholder implementation - in real app this would use TurtleProvider context\n return defaultConfig;\n}\n","import { createSyncStoragePersister } from \"@tanstack/query-sync-storage-persister\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { persistQueryClient } from \"@tanstack/react-query-persist-client\";\n\nexport const defaultQueryClient = new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n },\n },\n});\n\n// Only persist on client side\nif (typeof window !== 'undefined') {\n const localStoragePersister = createSyncStoragePersister({\n storage: window.localStorage,\n key: \"turtle-sdk\",\n });\n\n persistQueryClient({\n queryClient: defaultQueryClient,\n persister: localStoragePersister,\n });\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, organization, type OrganizationResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseOrganizationsOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useOrganizations({\n config,\n queryClient,\n}: UseOrganizationsOptions = {}): UseQueryResult<OrganizationResponse | null> {\n const defaultConfig = useConfig();\n\n const query = useQuery(\n {\n queryKey: [\"organizations\"],\n queryFn: async () => {\n return await organization(config ?? defaultConfig);\n },\n staleTime: 2 * 60 * 1000,\n refetchInterval: 1 * 60 * 1000,\n },\n queryClient ?? defaultQueryClient\n );\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, exists, type ExistsOptions } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseExistsOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useExists(\n options?: ExistsOptions,\n { config, queryClient }: UseExistsOptions = {},\n): UseQueryResult<boolean | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\"exists\", options?.user],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await exists(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 2 * 60 * 1000,\n refetchInterval: 1 * 60 * 1000,\n refetchOnWindowFocus: true,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, organizationDeals, type OrganizationDealsOptions, type OrganizationDealsResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseOrganizationDealsOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useOrganizationDeals(\n options?: OrganizationDealsOptions,\n { config, queryClient }: UseOrganizationDealsOptions = {},\n): UseQueryResult<OrganizationDealsResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\"organizationDeals\", options?.organizationId],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await organizationDeals(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 2 * 60 * 1000,\n refetchInterval: 1 * 60 * 1000,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, organizationsDeals, type OrganizationsDealsOptions, type OrganizationsDealsResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseOrganizationsDealsOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useOrganizationsDeals(\n options?: OrganizationsDealsOptions,\n { config, queryClient }: UseOrganizationsDealsOptions = {},\n): UseQueryResult<OrganizationsDealsResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\"organizationsDeals\", options?.organizationIds],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await organizationsDeals(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 2 * 60 * 1000,\n refetchInterval: 1 * 60 * 1000,\n throwOnError: true,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, prepareSignup, type PrepareSignupOptions, type PrepareSignupResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UsePrepareSignupOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function usePrepareSignup(\n options?: PrepareSignupOptions,\n { config, queryClient }: UsePrepareSignupOptions = {},\n): UseQueryResult<PrepareSignupResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\"prepareSignup\", options?.user],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await prepareSignup(options, config ?? defaultConfig);\n },\n enabled,\n refetchInterval: 5 * 60 * 1000,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, projectTvl, type ProjectTvlOptions, type ProjectTvlResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseProjectTvlOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useProjectTvl(\n options?: ProjectTvlOptions,\n { config, queryClient }: UseProjectTvlOptions = {},\n): UseQueryResult<ProjectTvlResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\"projectTvl\", options?.projects],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await projectTvl(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 7 * 60 * 1000,\n refetchInterval: 5 * 60 * 1000,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import {\n type QueryClient,\n useMutation,\n type UseMutationResult,\n useQuery,\n} from \"@tanstack/react-query\";\nimport { type Config, signup, type SignupOptions } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../client\";\nimport { useConfig } from \"../useConfig\";\n\nexport interface UseSignupOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useSignup(\n options?: Omit<SignupOptions, \"signature\">,\n { config, queryClient }: UseSignupOptions = {}\n): UseMutationResult<boolean | null, Error, string, unknown> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const mutation = useMutation(\n {\n mutationFn: async (signature: string) => {\n if (!enabled) return null;\n\n return await signup({ ...options, signature }, config ?? defaultConfig);\n },\n },\n queryClient ?? defaultQueryClient\n );\n\n return mutation;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, earnDeals, type EarnDealsOptions, type EarnDealsResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"@/hooks/client\";\nimport { useConfig } from \"@/hooks/useConfig\";\n\nexport interface UseEarnDealsOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useEarnDeals(\n options?: EarnDealsOptions,\n { config, queryClient }: UseEarnDealsOptions = {},\n): UseQueryResult<EarnDealsResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\n \"earn-deals\",\n options?.campaignId,\n options?.idFilter,\n options?.protocolFilter,\n ],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await earnDeals(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 60 * 1000,\n refetchInterval: 30 * 1000,\n refetchOnWindowFocus: true,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { type Config, earnRoute, type EarnRouteOptions, type EarnRouteResponse } from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../../client\";\nimport { useConfig } from \"../../useConfig\";\n\nexport interface UseEarnRouteOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useEarnRoute(\n options?: EarnRouteOptions,\n { config, queryClient }: UseEarnRouteOptions = {},\n): UseQueryResult<EarnRouteResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery({\n queryKey: [\n \"earnRoute\",\n options?.user,\n options?.chain,\n options?.slippage,\n options?.tokenIn,\n options?.tokenOut,\n options?.amount,\n ],\n queryFn: async () => {\n if (!enabled)\n return null;\n\n return await earnRoute(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 2 * 60 * 1000, // 2 minutes - longer stale time for transaction stability\n refetchInterval: false, // Disable automatic refetch to prevent transaction state reset\n refetchOnWindowFocus: true,\n }, queryClient ?? defaultQueryClient);\n\n return query;\n}\n","import { type QueryClient, useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport {\n type Config,\n earnWalletBalances,\n type EarnWalletBalancesOptions,\n type EarnWalletBalancesResponse,\n} from \"@turtleclub/api\";\nimport { defaultQueryClient } from \"../../client\";\nimport { useConfig } from \"../../useConfig\";\n\nexport interface UseEarnWalletBalancesOptions {\n config?: Config;\n queryClient?: QueryClient;\n}\n\nexport function useEarnWalletBalances(\n options?: EarnWalletBalancesOptions,\n { config, queryClient }: UseEarnWalletBalancesOptions = {}\n): UseQueryResult<EarnWalletBalancesResponse | null> {\n const defaultConfig = useConfig();\n const enabled = options !== undefined;\n\n const query = useQuery(\n {\n queryKey: [\"earnWalletBalances\", options?.chain, options?.user],\n queryFn: async () => {\n if (!enabled) return null;\n\n return await earnWalletBalances(options, config ?? defaultConfig);\n },\n enabled,\n staleTime: 30 * 1000,\n refetchInterval: 15 * 1000,\n refetchOnWindowFocus: true,\n },\n queryClient ?? defaultQueryClient\n );\n\n return query;\n}\n"],"mappings":";AACA,SAAS,qBAAqB;AAEvB,SAAS,YAAoB;AAElC,SAAO;AACT;;;ACNA,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AAE5B,IAAM,qBAAqB,IAAI,YAAY;AAAA,EAChD,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,sBAAsB;AAAA,IACxB;AAAA,EACF;AACF,CAAC;AAGD,IAAI,OAAO,WAAW,aAAa;AACjC,QAAM,wBAAwB,2BAA2B;AAAA,IACvD,SAAS,OAAO;AAAA,IAChB,KAAK;AAAA,EACP,CAAC;AAED,qBAAmB;AAAA,IACjB,aAAa;AAAA,IACb,WAAW;AAAA,EACb,CAAC;AACH;;;ACvBA,SAA2B,gBAAqC;AAChE,SAAsB,oBAA+C;AAS9D,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AACF,IAA6B,CAAC,GAAgD;AAC5E,QAAMA,iBAAgB,UAAU;AAEhC,QAAM,QAAQ;AAAA,IACZ;AAAA,MACE,UAAU,CAAC,eAAe;AAAA,MAC1B,SAAS,YAAY;AACnB,eAAO,MAAM,aAAa,UAAUA,cAAa;AAAA,MACnD;AAAA,MACA,WAAW,IAAI,KAAK;AAAA,MACpB,iBAAiB,IAAI,KAAK;AAAA,IAC5B;AAAA,IACA,eAAe;AAAA,EACjB;AAEA,SAAO;AACT;;;AC7BA,SAA2B,YAAAC,iBAAqC;AAChE,SAAsB,cAAkC;AASjD,SAAS,UACd,SACA,EAAE,QAAQ,YAAY,IAAsB,CAAC,GACb;AAChC,QAAMC,iBAAgB,UAAU;AAChC,QAAM,UAAU,YAAY;AAE5B,QAAM,QAAQC,UAAS;AAAA,IACrB,UAAU,CAAC,UAAU,SAAS,IAAI;AAAA,IAClC,SAAS,YAAY;AAC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,CAAC,GACN;AACnD,QAAMC,iBAAgB,UAAU;AAChC,QAAM,UAAU,YAAY;AAE5B,QAAM,QAAQC;AAAA,IACZ;AAAA,MACE,UAAU,CAAC,sBAAsB,SAAS,OAAO,SAAS,IAAI;AAAA,MAC9D,SAAS,YAAY;AACnB,YAAI,CAAC,QAAS,QAAO;AAErB,eAAO,MAAM,mBAAmB,SAAS,UAAUD,cAAa;AAAA,MAClE;AAAA,MACA;AAAA,MACA,WAAW,KAAK;AAAA,MAChB,iBAAiB,KAAK;AAAA,MACtB,sBAAsB;AAAA,IACxB;AAAA,IACA,eAAe;AAAA,EACjB;AAEA,SAAO;AACT;","names":["defaultConfig","useQuery","defaultConfig","useQuery","useQuery","defaultConfig","useQuery","useQuery","defaultConfig","useQuery","useQuery","defaultConfig","useQuery","useQuery","defaultConfig","useQuery","defaultConfig","useQuery","defaultConfig","useQuery","useQuery","defaultConfig","useQuery","useQuery","defaultConfig","useQuery"]}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@turtleclub/hooks",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "license": "MIT",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.cjs",
10
+ "types": "./src/index.ts"
11
+ }
12
+ },
13
+ "main": "dist/index.cjs",
14
+ "module": "dist/index.js",
15
+ "types": "src/index.ts",
16
+ "source": "src/index.ts",
17
+ "files": [
18
+ "dist",
19
+ "src"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "dev:widget": "tsup --watch",
24
+ "dev": "tsup --watch",
25
+ "lint": "eslint . --max-warnings 0",
26
+ "type-check": "tsc --noEmit"
27
+ },
28
+ "dependencies": {
29
+ "@tanstack/query-sync-storage-persister": "^5.55.3",
30
+ "@tanstack/react-query": "^5.55.3",
31
+ "@tanstack/react-query-persist-client": "^5.55.3",
32
+ "@turtleclub/api": "workspace:*",
33
+ "@turtleclub/chains": "workspace:*",
34
+ "@turtleclub/utils": "workspace:*",
35
+ "@wagmi/core": "^2.17.2",
36
+ "react": "^19.1.0",
37
+ "wagmi": "^2.15.4",
38
+ "zod": "^3.25.17"
39
+ },
40
+ "devDependencies": {
41
+ "@types/react": "^19.1.5",
42
+ "tsup": "^8.5.0",
43
+ "typescript": "^5.8.3"
44
+ },
45
+ "peerDependencies": {
46
+ "react": ">=18.0.0"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ }
51
+ }
@@ -0,0 +1,24 @@
1
+ import { createSyncStoragePersister } from "@tanstack/query-sync-storage-persister";
2
+ import { QueryClient } from "@tanstack/react-query";
3
+ import { persistQueryClient } from "@tanstack/react-query-persist-client";
4
+
5
+ export const defaultQueryClient = new QueryClient({
6
+ defaultOptions: {
7
+ queries: {
8
+ refetchOnWindowFocus: false,
9
+ },
10
+ },
11
+ });
12
+
13
+ // Only persist on client side
14
+ if (typeof window !== 'undefined') {
15
+ const localStoragePersister = createSyncStoragePersister({
16
+ storage: window.localStorage,
17
+ key: "turtle-sdk",
18
+ });
19
+
20
+ persistQueryClient({
21
+ queryClient: defaultQueryClient,
22
+ persister: localStoragePersister,
23
+ });
24
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./useDeals";
2
+ export * from "./useRoute";
3
+ export * from "./useWalletBalances";
@@ -0,0 +1,38 @@
1
+ import { type QueryClient, useQuery, type UseQueryResult } from "@tanstack/react-query";
2
+ import { type Config, earnDeals, type EarnDealsOptions, type EarnDealsResponse } from "@turtleclub/api";
3
+ import { defaultQueryClient } from "@/hooks/client";
4
+ import { useConfig } from "@/hooks/useConfig";
5
+
6
+ export interface UseEarnDealsOptions {
7
+ config?: Config;
8
+ queryClient?: QueryClient;
9
+ }
10
+
11
+ export function useEarnDeals(
12
+ options?: EarnDealsOptions,
13
+ { config, queryClient }: UseEarnDealsOptions = {},
14
+ ): UseQueryResult<EarnDealsResponse | null> {
15
+ const defaultConfig = useConfig();
16
+ const enabled = options !== undefined;
17
+
18
+ const query = useQuery({
19
+ queryKey: [
20
+ "earn-deals",
21
+ options?.campaignId,
22
+ options?.idFilter,
23
+ options?.protocolFilter,
24
+ ],
25
+ queryFn: async () => {
26
+ if (!enabled)
27
+ return null;
28
+
29
+ return await earnDeals(options, config ?? defaultConfig);
30
+ },
31
+ enabled,
32
+ staleTime: 60 * 1000,
33
+ refetchInterval: 30 * 1000,
34
+ refetchOnWindowFocus: true,
35
+ }, queryClient ?? defaultQueryClient);
36
+
37
+ return query;
38
+ }
@@ -0,0 +1,41 @@
1
+ import { type QueryClient, useQuery, type UseQueryResult } from "@tanstack/react-query";
2
+ import { type Config, earnRoute, type EarnRouteOptions, type EarnRouteResponse } from "@turtleclub/api";
3
+ import { defaultQueryClient } from "../../client";
4
+ import { useConfig } from "../../useConfig";
5
+
6
+ export interface UseEarnRouteOptions {
7
+ config?: Config;
8
+ queryClient?: QueryClient;
9
+ }
10
+
11
+ export function useEarnRoute(
12
+ options?: EarnRouteOptions,
13
+ { config, queryClient }: UseEarnRouteOptions = {},
14
+ ): UseQueryResult<EarnRouteResponse | null> {
15
+ const defaultConfig = useConfig();
16
+ const enabled = options !== undefined;
17
+
18
+ const query = useQuery({
19
+ queryKey: [
20
+ "earnRoute",
21
+ options?.user,
22
+ options?.chain,
23
+ options?.slippage,
24
+ options?.tokenIn,
25
+ options?.tokenOut,
26
+ options?.amount,
27
+ ],
28
+ queryFn: async () => {
29
+ if (!enabled)
30
+ return null;
31
+
32
+ return await earnRoute(options, config ?? defaultConfig);
33
+ },
34
+ enabled,
35
+ staleTime: 2 * 60 * 1000, // 2 minutes - longer stale time for transaction stability
36
+ refetchInterval: false, // Disable automatic refetch to prevent transaction state reset
37
+ refetchOnWindowFocus: true,
38
+ }, queryClient ?? defaultQueryClient);
39
+
40
+ return query;
41
+ }
@@ -0,0 +1,40 @@
1
+ import { type QueryClient, useQuery, type UseQueryResult } from "@tanstack/react-query";
2
+ import {
3
+ type Config,
4
+ earnWalletBalances,
5
+ type EarnWalletBalancesOptions,
6
+ type EarnWalletBalancesResponse,
7
+ } from "@turtleclub/api";
8
+ import { defaultQueryClient } from "../../client";
9
+ import { useConfig } from "../../useConfig";
10
+
11
+ export interface UseEarnWalletBalancesOptions {
12
+ config?: Config;
13
+ queryClient?: QueryClient;
14
+ }
15
+
16
+ export function useEarnWalletBalances(
17
+ options?: EarnWalletBalancesOptions,
18
+ { config, queryClient }: UseEarnWalletBalancesOptions = {}
19
+ ): UseQueryResult<EarnWalletBalancesResponse | null> {
20
+ const defaultConfig = useConfig();
21
+ const enabled = options !== undefined;
22
+
23
+ const query = useQuery(
24
+ {
25
+ queryKey: ["earnWalletBalances", options?.chain, options?.user],
26
+ queryFn: async () => {
27
+ if (!enabled) return null;
28
+
29
+ return await earnWalletBalances(options, config ?? defaultConfig);
30
+ },
31
+ enabled,
32
+ staleTime: 30 * 1000,
33
+ refetchInterval: 15 * 1000,
34
+ refetchOnWindowFocus: true,
35
+ },
36
+ queryClient ?? defaultQueryClient
37
+ );
38
+
39
+ return query;
40
+ }
@@ -0,0 +1,8 @@
1
+ export * from "./earn";
2
+ export * from "./useExists";
3
+ export * from "./useOrganizationDeals";
4
+ export * from "./useOrganizations";
5
+ export * from "./useOrganizationsDeals";
6
+ export * from "./usePrepareSignup";
7
+ export * from "./useProjectTvl";
8
+ export * from "./useSignup";
@@ -0,0 +1,33 @@
1
+ import { type QueryClient, useQuery, type UseQueryResult } from "@tanstack/react-query";
2
+ import { type Config, exists, type ExistsOptions } from "@turtleclub/api";
3
+ import { defaultQueryClient } from "../client";
4
+ import { useConfig } from "../useConfig";
5
+
6
+ export interface UseExistsOptions {
7
+ config?: Config;
8
+ queryClient?: QueryClient;
9
+ }
10
+
11
+ export function useExists(
12
+ options?: ExistsOptions,
13
+ { config, queryClient }: UseExistsOptions = {},
14
+ ): UseQueryResult<boolean | null> {
15
+ const defaultConfig = useConfig();
16
+ const enabled = options !== undefined;
17
+
18
+ const query = useQuery({
19
+ queryKey: ["exists", options?.user],
20
+ queryFn: async () => {
21
+ if (!enabled)
22
+ return null;
23
+
24
+ return await exists(options, config ?? defaultConfig);
25
+ },
26
+ enabled,
27
+ staleTime: 2 * 60 * 1000,
28
+ refetchInterval: 1 * 60 * 1000,
29
+ refetchOnWindowFocus: true,
30
+ }, queryClient ?? defaultQueryClient);
31
+
32
+ return query;
33
+ }
@@ -0,0 +1,32 @@
1
+ import { type QueryClient, useQuery, type UseQueryResult } from "@tanstack/react-query";
2
+ import { type Config, organizationDeals, type OrganizationDealsOptions, type OrganizationDealsResponse } from "@turtleclub/api";
3
+ import { defaultQueryClient } from "../client";
4
+ import { useConfig } from "../useConfig";
5
+
6
+ export interface UseOrganizationDealsOptions {
7
+ config?: Config;
8
+ queryClient?: QueryClient;
9
+ }
10
+
11
+ export function useOrganizationDeals(
12
+ options?: OrganizationDealsOptions,
13
+ { config, queryClient }: UseOrganizationDealsOptions = {},
14
+ ): UseQueryResult<OrganizationDealsResponse | null> {
15
+ const defaultConfig = useConfig();
16
+ const enabled = options !== undefined;
17
+
18
+ const query = useQuery({
19
+ queryKey: ["organizationDeals", options?.organizationId],
20
+ queryFn: async () => {
21
+ if (!enabled)
22
+ return null;
23
+
24
+ return await organizationDeals(options, config ?? defaultConfig);
25
+ },
26
+ enabled,
27
+ staleTime: 2 * 60 * 1000,
28
+ refetchInterval: 1 * 60 * 1000,
29
+ }, queryClient ?? defaultQueryClient);
30
+
31
+ return query;
32
+ }
@@ -0,0 +1,30 @@
1
+ import { type QueryClient, useQuery, type UseQueryResult } from "@tanstack/react-query";
2
+ import { type Config, organization, type OrganizationResponse } from "@turtleclub/api";
3
+ import { defaultQueryClient } from "../client";
4
+ import { useConfig } from "../useConfig";
5
+
6
+ export interface UseOrganizationsOptions {
7
+ config?: Config;
8
+ queryClient?: QueryClient;
9
+ }
10
+
11
+ export function useOrganizations({
12
+ config,
13
+ queryClient,
14
+ }: UseOrganizationsOptions = {}): UseQueryResult<OrganizationResponse | null> {
15
+ const defaultConfig = useConfig();
16
+
17
+ const query = useQuery(
18
+ {
19
+ queryKey: ["organizations"],
20
+ queryFn: async () => {
21
+ return await organization(config ?? defaultConfig);
22
+ },
23
+ staleTime: 2 * 60 * 1000,
24
+ refetchInterval: 1 * 60 * 1000,
25
+ },
26
+ queryClient ?? defaultQueryClient
27
+ );
28
+
29
+ return query;
30
+ }
@@ -0,0 +1,33 @@
1
+ import { type QueryClient, useQuery, type UseQueryResult } from "@tanstack/react-query";
2
+ import { type Config, organizationsDeals, type OrganizationsDealsOptions, type OrganizationsDealsResponse } from "@turtleclub/api";
3
+ import { defaultQueryClient } from "../client";
4
+ import { useConfig } from "../useConfig";
5
+
6
+ export interface UseOrganizationsDealsOptions {
7
+ config?: Config;
8
+ queryClient?: QueryClient;
9
+ }
10
+
11
+ export function useOrganizationsDeals(
12
+ options?: OrganizationsDealsOptions,
13
+ { config, queryClient }: UseOrganizationsDealsOptions = {},
14
+ ): UseQueryResult<OrganizationsDealsResponse | null> {
15
+ const defaultConfig = useConfig();
16
+ const enabled = options !== undefined;
17
+
18
+ const query = useQuery({
19
+ queryKey: ["organizationsDeals", options?.organizationIds],
20
+ queryFn: async () => {
21
+ if (!enabled)
22
+ return null;
23
+
24
+ return await organizationsDeals(options, config ?? defaultConfig);
25
+ },
26
+ enabled,
27
+ staleTime: 2 * 60 * 1000,
28
+ refetchInterval: 1 * 60 * 1000,
29
+ throwOnError: true,
30
+ }, queryClient ?? defaultQueryClient);
31
+
32
+ return query;
33
+ }
@@ -0,0 +1,31 @@
1
+ import { type QueryClient, useQuery, type UseQueryResult } from "@tanstack/react-query";
2
+ import { type Config, prepareSignup, type PrepareSignupOptions, type PrepareSignupResponse } from "@turtleclub/api";
3
+ import { defaultQueryClient } from "../client";
4
+ import { useConfig } from "../useConfig";
5
+
6
+ export interface UsePrepareSignupOptions {
7
+ config?: Config;
8
+ queryClient?: QueryClient;
9
+ }
10
+
11
+ export function usePrepareSignup(
12
+ options?: PrepareSignupOptions,
13
+ { config, queryClient }: UsePrepareSignupOptions = {},
14
+ ): UseQueryResult<PrepareSignupResponse | null> {
15
+ const defaultConfig = useConfig();
16
+ const enabled = options !== undefined;
17
+
18
+ const query = useQuery({
19
+ queryKey: ["prepareSignup", options?.user],
20
+ queryFn: async () => {
21
+ if (!enabled)
22
+ return null;
23
+
24
+ return await prepareSignup(options, config ?? defaultConfig);
25
+ },
26
+ enabled,
27
+ refetchInterval: 5 * 60 * 1000,
28
+ }, queryClient ?? defaultQueryClient);
29
+
30
+ return query;
31
+ }
@@ -0,0 +1,32 @@
1
+ import { type QueryClient, useQuery, type UseQueryResult } from "@tanstack/react-query";
2
+ import { type Config, projectTvl, type ProjectTvlOptions, type ProjectTvlResponse } from "@turtleclub/api";
3
+ import { defaultQueryClient } from "../client";
4
+ import { useConfig } from "../useConfig";
5
+
6
+ export interface UseProjectTvlOptions {
7
+ config?: Config;
8
+ queryClient?: QueryClient;
9
+ }
10
+
11
+ export function useProjectTvl(
12
+ options?: ProjectTvlOptions,
13
+ { config, queryClient }: UseProjectTvlOptions = {},
14
+ ): UseQueryResult<ProjectTvlResponse | null> {
15
+ const defaultConfig = useConfig();
16
+ const enabled = options !== undefined;
17
+
18
+ const query = useQuery({
19
+ queryKey: ["projectTvl", options?.projects],
20
+ queryFn: async () => {
21
+ if (!enabled)
22
+ return null;
23
+
24
+ return await projectTvl(options, config ?? defaultConfig);
25
+ },
26
+ enabled,
27
+ staleTime: 7 * 60 * 1000,
28
+ refetchInterval: 5 * 60 * 1000,
29
+ }, queryClient ?? defaultQueryClient);
30
+
31
+ return query;
32
+ }
@@ -0,0 +1,35 @@
1
+ import {
2
+ type QueryClient,
3
+ useMutation,
4
+ type UseMutationResult,
5
+ useQuery,
6
+ } from "@tanstack/react-query";
7
+ import { type Config, signup, type SignupOptions } from "@turtleclub/api";
8
+ import { defaultQueryClient } from "../client";
9
+ import { useConfig } from "../useConfig";
10
+
11
+ export interface UseSignupOptions {
12
+ config?: Config;
13
+ queryClient?: QueryClient;
14
+ }
15
+
16
+ export function useSignup(
17
+ options?: Omit<SignupOptions, "signature">,
18
+ { config, queryClient }: UseSignupOptions = {}
19
+ ): UseMutationResult<boolean | null, Error, string, unknown> {
20
+ const defaultConfig = useConfig();
21
+ const enabled = options !== undefined;
22
+
23
+ const mutation = useMutation(
24
+ {
25
+ mutationFn: async (signature: string) => {
26
+ if (!enabled) return null;
27
+
28
+ return await signup({ ...options, signature }, config ?? defaultConfig);
29
+ },
30
+ },
31
+ queryClient ?? defaultQueryClient
32
+ );
33
+
34
+ return mutation;
35
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./endpoints";
2
+ export * from "./useConfig";
@@ -0,0 +1,7 @@
1
+ import type { Config } from "@turtleclub/api";
2
+ import { defaultConfig } from "@turtleclub/api";
3
+
4
+ export function useConfig(): Config {
5
+ // Placeholder implementation - in real app this would use TurtleProvider context
6
+ return defaultConfig;
7
+ }
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ // Hooks
2
+ export * from "./hooks/useConfig";
3
+ export * from "./hooks/client";
4
+
5
+ // Endpoint hooks
6
+ export * from "./hooks/endpoints/useOrganizations";
7
+ export * from "./hooks/endpoints/useExists";
8
+ export * from "./hooks/endpoints/useOrganizationDeals";
9
+ export * from "./hooks/endpoints/useOrganizationsDeals";
10
+ export * from "./hooks/endpoints/usePrepareSignup";
11
+ export * from "./hooks/endpoints/useProjectTvl";
12
+ export * from "./hooks/endpoints/useSignup";
13
+
14
+ // Earn hooks
15
+ export * from "./hooks/endpoints/earn";