@turtleclub/hooks 0.5.0-beta.2 → 0.5.0-beta.4

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.js CHANGED
@@ -684,7 +684,7 @@ async function getProducts(filters) {
684
684
  const params = new URLSearchParams();
685
685
  if (filters?.organizationId) params.append("organizationId", filters.organizationId);
686
686
  const queryString = params.toString();
687
- const endpoint = `/admin/products${queryString ? `?${queryString}` : ""}`;
687
+ const endpoint = `/turtle/products${queryString ? `?${queryString}` : ""}`;
688
688
  const data = await apiClient.fetch(endpoint, {
689
689
  method: "GET"
690
690
  });
@@ -696,7 +696,7 @@ async function getProducts(filters) {
696
696
  return result.data;
697
697
  }
698
698
  async function getProduct(id) {
699
- const endpoint = `/admin/products/${id}`;
699
+ const endpoint = `/turtle/products/${id}`;
700
700
  const data = await apiClient.fetch(endpoint, {
701
701
  method: "GET"
702
702
  });
@@ -937,6 +937,114 @@ var supportedTokensQueries = createQueryKeys10("supportedTokens", {
937
937
  })
938
938
  });
939
939
 
940
+ // src/v2/users/queries.ts
941
+ import { createQueryKeys as createQueryKeys11 } from "@lukemorales/query-key-factory";
942
+
943
+ // src/v2/users/schemas.ts
944
+ import { z as z12 } from "zod";
945
+ var walletDataSchema = z12.object({
946
+ address: z12.string(),
947
+ totalAmountInUSD: z12.string(),
948
+ tokens: z12.array(tokenSchema)
949
+ });
950
+ var holdingsDataSchema = z12.object({
951
+ totalAmountInUSD: z12.string(),
952
+ chains: z12.array(chainSchema).nullish(),
953
+ wallets: z12.array(walletDataSchema).nullish()
954
+ });
955
+ var userEarningsSchema = z12.object({
956
+ productId: z12.string().uuid(),
957
+ value: z12.number(),
958
+ referralsEarnings: z12.number().nullish(),
959
+ rewardName: z12.string().nullish(),
960
+ rewardType: z12.string().nullish()
961
+ });
962
+ var portfolioSchema = z12.object({
963
+ productsEarnings: z12.array(userEarningsSchema),
964
+ holdings: holdingsDataSchema.nullish()
965
+ });
966
+ var holdingInfoSchema = z12.object({
967
+ amount: z12.number(),
968
+ usdValue: z12.number(),
969
+ token: tokenSchema.nullish()
970
+ });
971
+ var walletInfoSchema = z12.object({
972
+ address: z12.string().nullish(),
973
+ ecosystem: z12.string().nullish(),
974
+ isMain: z12.boolean().nullish(),
975
+ holdings: z12.array(holdingInfoSchema).nullish()
976
+ });
977
+ var userWithDetailsSchema = z12.object({
978
+ id: z12.string(),
979
+ email: z12.string().nullable(),
980
+ username: z12.string().nullish(),
981
+ firstName: z12.string().nullish(),
982
+ lastName: z12.string().nullish(),
983
+ avatarUrl: z12.string().nullish(),
984
+ telegramHandle: z12.string().nullish(),
985
+ xUsername: z12.string().nullish(),
986
+ role: z12.string(),
987
+ createdAt: z12.string(),
988
+ updatedAt: z12.string(),
989
+ tags: z12.array(z12.string()).nullish(),
990
+ wallets: z12.array(walletInfoSchema).nullish()
991
+ });
992
+ var getUserTurtlePortfolioInputSchema = z12.object({
993
+ userId: z12.string().uuid()
994
+ });
995
+ var getUserTurtlePortfolioOutputSchema = z12.object({
996
+ portfolio: portfolioSchema
997
+ });
998
+ var getUserTurtlePortfolioPathSchema = z12.object({
999
+ userId: z12.string().uuid()
1000
+ });
1001
+ var getUserByIdInputSchema = z12.object({
1002
+ userId: z12.string().uuid()
1003
+ });
1004
+ var getUserByIdOutputSchema = z12.object({
1005
+ user: userWithDetailsSchema.nullable(),
1006
+ error: z12.string().optional()
1007
+ });
1008
+
1009
+ // src/v2/users/api.ts
1010
+ async function getUserById(input) {
1011
+ console.log("input", input);
1012
+ const endpoint = `/admin/users/${input.userId}`;
1013
+ const data = await apiClient.fetch(endpoint, {
1014
+ method: "GET"
1015
+ });
1016
+ const result = getUserByIdOutputSchema.safeParse(data);
1017
+ if (result.success === false) {
1018
+ console.log("[ZOD ERROR]", result.error);
1019
+ throw new Error(`Failed to parse user: ${result.error.message}`);
1020
+ }
1021
+ return result.data;
1022
+ }
1023
+ async function getUserPortfolio(input) {
1024
+ const endpoint = `/admin/users/${input.userId}/portfolio`;
1025
+ const data = await apiClient.fetch(endpoint, {
1026
+ method: "GET"
1027
+ });
1028
+ const result = getUserTurtlePortfolioOutputSchema.safeParse(data);
1029
+ if (result.success === false) {
1030
+ console.log("[ZOD ERROR]", result.error);
1031
+ throw new Error(`Failed to parse user portfolio: ${result.error.message}`);
1032
+ }
1033
+ return result.data;
1034
+ }
1035
+
1036
+ // src/v2/users/queries.ts
1037
+ var usersQueries = createQueryKeys11("users", {
1038
+ byId: (input) => ({
1039
+ queryKey: [input.userId],
1040
+ queryFn: () => getUserById(input)
1041
+ }),
1042
+ portfolio: (input) => ({
1043
+ queryKey: ["portfolio", input.userId],
1044
+ queryFn: () => getUserPortfolio(input)
1045
+ })
1046
+ });
1047
+
940
1048
  // src/v2/earn-opportunities/hooks.ts
941
1049
  import { useQuery } from "@tanstack/react-query";
942
1050
 
@@ -1182,33 +1290,33 @@ var BalanceSourcePriority = /* @__PURE__ */ ((BalanceSourcePriority2) => {
1182
1290
  })(BalanceSourcePriority || {});
1183
1291
 
1184
1292
  // src/v2/balance/schema.ts
1185
- import { z as z12 } from "zod";
1186
- var portfolioTokenSchema = z12.object({
1187
- id: z12.string(),
1188
- address: z12.string(),
1189
- name: z12.string(),
1190
- symbol: z12.string(),
1191
- decimals: z12.number(),
1192
- isNative: z12.boolean(),
1193
- logoUrl: z12.string().nullable(),
1194
- amount: z12.string(),
1293
+ import { z as z13 } from "zod";
1294
+ var portfolioTokenSchema = z13.object({
1295
+ id: z13.string(),
1296
+ address: z13.string(),
1297
+ name: z13.string(),
1298
+ symbol: z13.string(),
1299
+ decimals: z13.number(),
1300
+ isNative: z13.boolean(),
1301
+ logoUrl: z13.string().nullable(),
1302
+ amount: z13.string(),
1195
1303
  // Portfolio-specific field (decimal format)
1196
- price: z12.string().nullable().transform((val) => val ? parseFloat(val) : null),
1304
+ price: z13.string().nullable().transform((val) => val ? parseFloat(val) : null),
1197
1305
  // Portfolio-specific field
1198
1306
  // Chain with optional fields to match Portfolio API response
1199
1307
  chain: chainSchema.partial().required({ chainId: true })
1200
1308
  });
1201
- var portfolioWalletSchema = z12.object({
1202
- id: z12.string().optional(),
1203
- address: z12.string(),
1204
- blockchain: z12.string().optional(),
1205
- tokens: z12.array(portfolioTokenSchema)
1309
+ var portfolioWalletSchema = z13.object({
1310
+ id: z13.string().optional(),
1311
+ address: z13.string(),
1312
+ blockchain: z13.string().optional(),
1313
+ tokens: z13.array(portfolioTokenSchema)
1206
1314
  });
1207
- var portfolioHoldingsSchema = z12.object({
1208
- wallets: z12.array(portfolioWalletSchema)
1315
+ var portfolioHoldingsSchema = z13.object({
1316
+ wallets: z13.array(portfolioWalletSchema)
1209
1317
  });
1210
- var portfolioBalanceResponseSchema = z12.object({
1211
- portfolio: z12.object({
1318
+ var portfolioBalanceResponseSchema = z13.object({
1319
+ portfolio: z13.object({
1212
1320
  holdings: portfolioHoldingsSchema
1213
1321
  })
1214
1322
  });
@@ -1229,8 +1337,8 @@ async function getPortfolioBalance(address, options) {
1229
1337
  }
1230
1338
 
1231
1339
  // src/v2/balance/queries.ts
1232
- import { createQueryKeys as createQueryKeys11 } from "@lukemorales/query-key-factory";
1233
- var balanceQueries = createQueryKeys11("balance", {
1340
+ import { createQueryKeys as createQueryKeys12 } from "@lukemorales/query-key-factory";
1341
+ var balanceQueries = createQueryKeys12("balance", {
1234
1342
  // Portfolio balance by address
1235
1343
  portfolio: (address) => ({
1236
1344
  queryKey: [address],
@@ -1776,10 +1884,28 @@ function useSwapRoute(isEnabled, userAddress, distributorId, options, referralCo
1776
1884
  };
1777
1885
  }
1778
1886
 
1887
+ // src/v2/users/hooks.ts
1888
+ import { useQuery as useQuery12 } from "@tanstack/react-query";
1889
+ function useUserById({ userId, enabled = true }) {
1890
+ return useQuery12({
1891
+ ...usersQueries.byId({ userId }),
1892
+ ...queryDefaults,
1893
+ enabled
1894
+ });
1895
+ }
1896
+ function useUserPortfolio({ userId, enabled = true }) {
1897
+ const input = { userId };
1898
+ return useQuery12({
1899
+ ...usersQueries.portfolio(input),
1900
+ ...queryDefaults,
1901
+ enabled
1902
+ });
1903
+ }
1904
+
1779
1905
  // src/v2/lib/turtle-provider.tsx
1780
1906
  import { useEffect, useMemo as useMemo9 } from "react";
1781
1907
  import { Fragment, jsx } from "react/jsx-runtime";
1782
- function TurtleProvider({
1908
+ function TurtleHooksProvider({
1783
1909
  children,
1784
1910
  apiUrl,
1785
1911
  earnUrl,
@@ -1807,12 +1933,13 @@ var queries = mergeQueryKeys(
1807
1933
  ensoBalancesQueries,
1808
1934
  widgetQueries,
1809
1935
  supportedChainsQueries,
1810
- supportedTokensQueries
1936
+ supportedTokensQueries,
1937
+ usersQueries
1811
1938
  );
1812
1939
  export {
1813
1940
  ApiError,
1814
1941
  BalanceSourcePriority,
1815
- TurtleProvider,
1942
+ TurtleHooksProvider,
1816
1943
  apiClient,
1817
1944
  approveStep,
1818
1945
  asset,
@@ -1856,8 +1983,16 @@ export {
1856
1983
  getSourcePriority,
1857
1984
  getSupportedChains,
1858
1985
  getSupportedTokens,
1986
+ getUserById,
1987
+ getUserByIdInputSchema,
1988
+ getUserByIdOutputSchema,
1989
+ getUserPortfolio,
1990
+ getUserTurtlePortfolioInputSchema,
1991
+ getUserTurtlePortfolioOutputSchema,
1992
+ getUserTurtlePortfolioPathSchema,
1859
1993
  getWalletBalances,
1860
1994
  getWidgetOpportunities,
1995
+ holdingsDataSchema,
1861
1996
  incentiveSchema,
1862
1997
  lendingConfigSchema,
1863
1998
  mergeBalancesByPriority,
@@ -1867,6 +2002,7 @@ export {
1867
2002
  paginationMetadataSchema,
1868
2003
  portfolioBalanceResponseSchema,
1869
2004
  portfolioHoldingsSchema,
2005
+ portfolioSchema,
1870
2006
  portfolioTokenSchema,
1871
2007
  portfolioWalletSchema,
1872
2008
  processRouteDetails,
@@ -1908,10 +2044,16 @@ export {
1908
2044
  useTokenBalance,
1909
2045
  useUpdateProduct,
1910
2046
  useUploadProductLogo,
2047
+ useUserById,
2048
+ useUserPortfolio,
1911
2049
  useWidgetOpportunities,
2050
+ userEarningsSchema,
2051
+ userWithDetailsSchema,
2052
+ usersQueries,
1912
2053
  vaultConfigSchema,
1913
2054
  walletBalanceSchema,
1914
2055
  walletBalancesResponseSchema,
2056
+ walletDataSchema,
1915
2057
  walletEcosystemEnum,
1916
2058
  widgetOpportunitiesResponseSchema,
1917
2059
  widgetQueries