@turtleclub/hooks 0.5.0-beta.0 → 0.5.0-beta.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/dist/index.cjs +180 -196
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +157 -174
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/v2/balance/api.ts +1 -1
- package/src/v2/earn-deposits/api.ts +1 -1
- package/src/v2/earn-membership/api.ts +5 -5
- package/src/v2/earn-opportunities/api.ts +1 -1
- package/src/v2/earn-route/api.ts +2 -2
- package/src/v2/enso-balances/api.ts +2 -3
- package/src/v2/index.ts +5 -3
- package/src/v2/lib/api-client.ts +101 -62
- package/src/v2/lib/turtle-provider.tsx +48 -0
- package/src/v2/opportunities/api.ts +2 -2
- package/src/v2/products/api.ts +31 -77
- package/src/v2/products/hooks.ts +6 -13
- package/src/v2/products/queries.ts +6 -6
- package/src/v2/products/schema.ts +1 -1
- package/src/v2/supported-chains/api.ts +1 -1
- package/src/v2/supported-tokens/api.ts +1 -1
- package/src/v2/widget/api.ts +1 -1
- package/src/v2/lib/auth-provider.tsx +0 -30
- package/src/v2/lib/authenticated-api-client.ts +0 -22
package/dist/index.cjs
CHANGED
|
@@ -20,8 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
23
|
+
ApiError: () => ApiError,
|
|
24
24
|
BalanceSourcePriority: () => BalanceSourcePriority,
|
|
25
|
+
TurtleProvider: () => TurtleProvider,
|
|
26
|
+
apiClient: () => apiClient,
|
|
25
27
|
approveStep: () => approveStep,
|
|
26
28
|
asset: () => asset,
|
|
27
29
|
assetData: () => assetData,
|
|
@@ -91,7 +93,6 @@ __export(index_exports, {
|
|
|
91
93
|
supportedTokensResponseSchema: () => supportedTokensResponseSchema,
|
|
92
94
|
swapSubstep: () => swapSubstep,
|
|
93
95
|
tokenSchema: () => tokenSchema,
|
|
94
|
-
useAuthToken: () => useAuthToken,
|
|
95
96
|
useBalance: () => useBalance,
|
|
96
97
|
useCheckMembership: () => useCheckMembership,
|
|
97
98
|
useCreateMembership: () => useCreateMembership,
|
|
@@ -133,8 +134,8 @@ var import_query_key_factory12 = require("@lukemorales/query-key-factory");
|
|
|
133
134
|
var import_query_key_factory = require("@lukemorales/query-key-factory");
|
|
134
135
|
|
|
135
136
|
// src/v2/lib/api-client.ts
|
|
136
|
-
var API_BASE_URL = "https://api.turtle.
|
|
137
|
-
var EARN_BASE_URL = "https://earn.turtle.
|
|
137
|
+
var API_BASE_URL = "https://api.turtle.club";
|
|
138
|
+
var EARN_BASE_URL = "https://earn.turtle.club";
|
|
138
139
|
var ApiError = class extends Error {
|
|
139
140
|
constructor(message, status, response) {
|
|
140
141
|
super(message);
|
|
@@ -143,58 +144,87 @@ var ApiError = class extends Error {
|
|
|
143
144
|
this.name = "ApiError";
|
|
144
145
|
}
|
|
145
146
|
};
|
|
146
|
-
var
|
|
147
|
-
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const resolvedBaseUrl = domain === "earn" ? getEarnUrl() : domain === "custom" ? baseUrl : getApiUrl();
|
|
155
|
-
const url = `${resolvedBaseUrl}${endpoint}`;
|
|
156
|
-
if (debug) {
|
|
157
|
-
console.log("[API Request]", {
|
|
158
|
-
method: fetchOptions.method ?? "GET",
|
|
159
|
-
url,
|
|
160
|
-
headers: fetchOptions.headers,
|
|
161
|
-
body: fetchOptions.body
|
|
162
|
-
});
|
|
147
|
+
var ApiClient = class _ApiClient {
|
|
148
|
+
static instance;
|
|
149
|
+
config = {};
|
|
150
|
+
static getInstance() {
|
|
151
|
+
if (!_ApiClient.instance) {
|
|
152
|
+
_ApiClient.instance = new _ApiClient();
|
|
153
|
+
}
|
|
154
|
+
return _ApiClient.instance;
|
|
163
155
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
156
|
+
configure(config) {
|
|
157
|
+
this.config = { ...this.config, ...config };
|
|
158
|
+
}
|
|
159
|
+
getConfig() {
|
|
160
|
+
return this.config;
|
|
161
|
+
}
|
|
162
|
+
getBaseUrl(domain) {
|
|
163
|
+
if (domain === "earn") {
|
|
164
|
+
return this.config.earnUrl || EARN_BASE_URL;
|
|
165
|
+
}
|
|
166
|
+
return this.config.apiUrl || API_BASE_URL;
|
|
167
|
+
}
|
|
168
|
+
async fetch(endpoint, options) {
|
|
169
|
+
const { domain = "api", debug = this.config.debug, body, ...fetchOptions } = options ?? {};
|
|
170
|
+
const baseUrl = this.getBaseUrl(domain);
|
|
171
|
+
const url = `${baseUrl}${endpoint}`;
|
|
172
|
+
const token = this.config.getToken?.();
|
|
173
|
+
const isFormData = body instanceof FormData;
|
|
174
|
+
const headers = {
|
|
175
|
+
// Don't set Content-Type for FormData - browser sets it with boundary
|
|
176
|
+
...!isFormData && { "Content-Type": "application/json" },
|
|
177
|
+
...fetchOptions.headers
|
|
178
|
+
};
|
|
179
|
+
if (token) {
|
|
180
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
181
|
+
}
|
|
173
182
|
if (debug) {
|
|
174
|
-
console.log("[
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
183
|
+
console.log("[ApiClient Request]", {
|
|
184
|
+
method: fetchOptions.method ?? "GET",
|
|
185
|
+
url,
|
|
186
|
+
headers,
|
|
187
|
+
body: isFormData ? "[FormData]" : body
|
|
178
188
|
});
|
|
179
189
|
}
|
|
180
|
-
|
|
190
|
+
try {
|
|
191
|
+
const response = await fetch(url, {
|
|
192
|
+
...fetchOptions,
|
|
193
|
+
headers,
|
|
194
|
+
body: body ? isFormData ? body : JSON.stringify(body) : void 0
|
|
195
|
+
});
|
|
196
|
+
const data = await response.json();
|
|
197
|
+
if (debug) {
|
|
198
|
+
console.log("[ApiClient Response]", {
|
|
199
|
+
status: response.status,
|
|
200
|
+
ok: response.ok,
|
|
201
|
+
data
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if (!response.ok) {
|
|
205
|
+
throw new ApiError(
|
|
206
|
+
`API error: ${response.status} ${response.statusText}`,
|
|
207
|
+
response.status,
|
|
208
|
+
data
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
return data;
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (debug) {
|
|
214
|
+
console.error("[ApiClient Error]", error);
|
|
215
|
+
}
|
|
216
|
+
if (error instanceof ApiError) {
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
181
219
|
throw new ApiError(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
220
|
+
error instanceof Error ? error.message : "Unknown error",
|
|
221
|
+
0,
|
|
222
|
+
error
|
|
185
223
|
);
|
|
186
224
|
}
|
|
187
|
-
return data;
|
|
188
|
-
} catch (error) {
|
|
189
|
-
if (debug) {
|
|
190
|
-
console.error("[API Error]", error);
|
|
191
|
-
}
|
|
192
|
-
if (error instanceof ApiError) {
|
|
193
|
-
throw error;
|
|
194
|
-
}
|
|
195
|
-
throw new ApiError(error instanceof Error ? error.message : "Unknown error", 0, error);
|
|
196
225
|
}
|
|
197
|
-
}
|
|
226
|
+
};
|
|
227
|
+
var apiClient = ApiClient.getInstance();
|
|
198
228
|
|
|
199
229
|
// src/v2/schemas/shared.ts
|
|
200
230
|
var import_zod = require("zod");
|
|
@@ -350,7 +380,7 @@ async function getOpportunities(filters, options) {
|
|
|
350
380
|
if (filters?.productId) params.append("productId", filters.productId);
|
|
351
381
|
const queryString = params.toString();
|
|
352
382
|
const endpoint = `/turtle/opportunities${queryString ? `?${queryString}` : ""}`;
|
|
353
|
-
const data = await apiClient(endpoint, {
|
|
383
|
+
const data = await apiClient.fetch(endpoint, {
|
|
354
384
|
method: "GET",
|
|
355
385
|
debug: options?.debug
|
|
356
386
|
});
|
|
@@ -362,7 +392,7 @@ async function getOpportunities(filters, options) {
|
|
|
362
392
|
return result.data;
|
|
363
393
|
}
|
|
364
394
|
async function getOpportunityById(id, options) {
|
|
365
|
-
const data = await apiClient(`/turtle/opportunities/${id}`, {
|
|
395
|
+
const data = await apiClient.fetch(`/turtle/opportunities/${id}`, {
|
|
366
396
|
method: "GET",
|
|
367
397
|
debug: options?.debug
|
|
368
398
|
});
|
|
@@ -417,7 +447,7 @@ var earnOpportunitiesResponseSchema = import_zod3.z.object({
|
|
|
417
447
|
|
|
418
448
|
// src/v2/earn-opportunities/api.ts
|
|
419
449
|
async function getEarnOpportunities(context) {
|
|
420
|
-
const data = await apiClient("/v1/opportunities/", {
|
|
450
|
+
const data = await apiClient.fetch("/v1/opportunities/", {
|
|
421
451
|
method: "GET",
|
|
422
452
|
domain: "earn",
|
|
423
453
|
signal: context?.signal
|
|
@@ -534,7 +564,7 @@ async function getEarnRoute(params, context) {
|
|
|
534
564
|
...params.referral_code && { referral_code: params.referral_code },
|
|
535
565
|
...params.id && { id: params.id }
|
|
536
566
|
});
|
|
537
|
-
const response = await apiClient(`/v1/route/?${searchParams.toString()}`, {
|
|
567
|
+
const response = await apiClient.fetch(`/v1/route/?${searchParams.toString()}`, {
|
|
538
568
|
method: "GET",
|
|
539
569
|
domain: "earn",
|
|
540
570
|
signal: context?.signal
|
|
@@ -593,7 +623,7 @@ async function checkMembership(params, context) {
|
|
|
593
623
|
address: params.address,
|
|
594
624
|
...params.walletEcosystem && { walletEcosystem: params.walletEcosystem }
|
|
595
625
|
});
|
|
596
|
-
const data = await apiClient(`/v1/membership/?${searchParams.toString()}`, {
|
|
626
|
+
const data = await apiClient.fetch(`/v1/membership/?${searchParams.toString()}`, {
|
|
597
627
|
method: "GET",
|
|
598
628
|
domain: "earn",
|
|
599
629
|
signal: context?.signal
|
|
@@ -606,10 +636,10 @@ async function checkMembership(params, context) {
|
|
|
606
636
|
return result.data;
|
|
607
637
|
}
|
|
608
638
|
async function createMembershipAgreement(request) {
|
|
609
|
-
const data = await apiClient("/v1/membership/agreement", {
|
|
639
|
+
const data = await apiClient.fetch("/v1/membership/agreement", {
|
|
610
640
|
method: "POST",
|
|
611
641
|
domain: "earn",
|
|
612
|
-
body:
|
|
642
|
+
body: request
|
|
613
643
|
});
|
|
614
644
|
const result = createAgreementResponseSchema.safeParse(data);
|
|
615
645
|
if (result.success === false) {
|
|
@@ -619,10 +649,10 @@ async function createMembershipAgreement(request) {
|
|
|
619
649
|
return result.data;
|
|
620
650
|
}
|
|
621
651
|
async function createMembership(request) {
|
|
622
|
-
const data = await apiClient("/v1/membership/", {
|
|
652
|
+
const data = await apiClient.fetch("/v1/membership/", {
|
|
623
653
|
method: "POST",
|
|
624
654
|
domain: "earn",
|
|
625
|
-
body:
|
|
655
|
+
body: request
|
|
626
656
|
});
|
|
627
657
|
const result = createMembershipResponseSchema.safeParse(data);
|
|
628
658
|
if (result.success === false) {
|
|
@@ -674,7 +704,7 @@ async function getDeposits(params, context) {
|
|
|
674
704
|
});
|
|
675
705
|
const queryString = searchParams.toString();
|
|
676
706
|
const endpoint = `/v1/deposit/${distributor_id}${queryString ? `?${queryString}` : ""}`;
|
|
677
|
-
const data = await apiClient(endpoint, {
|
|
707
|
+
const data = await apiClient.fetch(endpoint, {
|
|
678
708
|
method: "GET",
|
|
679
709
|
domain: "earn",
|
|
680
710
|
signal: context?.signal
|
|
@@ -698,21 +728,10 @@ var earnDepositsQueries = (0, import_query_key_factory5.createQueryKeys)("earnDe
|
|
|
698
728
|
// src/v2/products/queries.ts
|
|
699
729
|
var import_query_key_factory6 = require("@lukemorales/query-key-factory");
|
|
700
730
|
|
|
701
|
-
// src/v2/lib/authenticated-api-client.ts
|
|
702
|
-
async function authenticatedApiClient(endpoint, options, token = null) {
|
|
703
|
-
return apiClient(endpoint, {
|
|
704
|
-
...options,
|
|
705
|
-
headers: {
|
|
706
|
-
...token && { Authorization: `Bearer ${token}` },
|
|
707
|
-
...options?.headers
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
|
|
712
731
|
// src/v2/products/schema.ts
|
|
713
732
|
var import_zod7 = require("zod");
|
|
714
733
|
var ProductTypeSchema = import_zod7.z.enum(["deal", "campaign"]);
|
|
715
|
-
var ProductStatusSchema = import_zod7.z.enum(["active", "paused", "ended"]);
|
|
734
|
+
var ProductStatusSchema = import_zod7.z.enum(["draft", "active", "paused", "ended"]);
|
|
716
735
|
var TurtleOrganizationSchema = import_zod7.z.object({
|
|
717
736
|
id: import_zod7.z.string().uuid(),
|
|
718
737
|
name: import_zod7.z.string(),
|
|
@@ -782,19 +801,14 @@ var ProductFiltersSchema = import_zod7.z.object({
|
|
|
782
801
|
});
|
|
783
802
|
|
|
784
803
|
// src/v2/products/api.ts
|
|
785
|
-
async function getProducts(filters
|
|
804
|
+
async function getProducts(filters) {
|
|
786
805
|
const params = new URLSearchParams();
|
|
787
806
|
if (filters?.organizationId) params.append("organizationId", filters.organizationId);
|
|
788
807
|
const queryString = params.toString();
|
|
789
808
|
const endpoint = `/admin/products${queryString ? `?${queryString}` : ""}`;
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
{
|
|
794
|
-
method: "GET"
|
|
795
|
-
},
|
|
796
|
-
token
|
|
797
|
-
);
|
|
809
|
+
const data = await apiClient.fetch(endpoint, {
|
|
810
|
+
method: "GET"
|
|
811
|
+
});
|
|
798
812
|
const result = ProductsResponseSchema.safeParse(data);
|
|
799
813
|
if (result.success === false) {
|
|
800
814
|
console.log("[ZOD ERROR]", result.error);
|
|
@@ -802,16 +816,11 @@ async function getProducts(filters, token) {
|
|
|
802
816
|
}
|
|
803
817
|
return result.data;
|
|
804
818
|
}
|
|
805
|
-
async function getProduct(id
|
|
819
|
+
async function getProduct(id) {
|
|
806
820
|
const endpoint = `/admin/products/${id}`;
|
|
807
|
-
const data = await
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
method: "GET"
|
|
811
|
-
},
|
|
812
|
-
token
|
|
813
|
-
);
|
|
814
|
-
console.log(data);
|
|
821
|
+
const data = await apiClient.fetch(endpoint, {
|
|
822
|
+
method: "GET"
|
|
823
|
+
});
|
|
815
824
|
const result = ProductResponseSchema.safeParse(data);
|
|
816
825
|
if (result.success === false) {
|
|
817
826
|
console.log("[ZOD ERROR]", result.error);
|
|
@@ -819,19 +828,12 @@ async function getProduct(id, token) {
|
|
|
819
828
|
}
|
|
820
829
|
return result.data;
|
|
821
830
|
}
|
|
822
|
-
async function createProduct(input
|
|
831
|
+
async function createProduct(input) {
|
|
823
832
|
const endpoint = `/admin/products`;
|
|
824
|
-
const data = await
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
body: JSON.stringify(input),
|
|
829
|
-
headers: {
|
|
830
|
-
"Content-Type": "application/json"
|
|
831
|
-
}
|
|
832
|
-
},
|
|
833
|
-
token
|
|
834
|
-
);
|
|
833
|
+
const data = await apiClient.fetch(endpoint, {
|
|
834
|
+
method: "POST",
|
|
835
|
+
body: input
|
|
836
|
+
});
|
|
835
837
|
const result = CreateProductResponseSchema.safeParse(data);
|
|
836
838
|
if (result.success === false) {
|
|
837
839
|
console.log("[ZOD ERROR]", result.error);
|
|
@@ -839,19 +841,12 @@ async function createProduct(input, token) {
|
|
|
839
841
|
}
|
|
840
842
|
return result.data;
|
|
841
843
|
}
|
|
842
|
-
async function updateProduct(input
|
|
844
|
+
async function updateProduct(input) {
|
|
843
845
|
const endpoint = `/admin/products/${input.product.id}`;
|
|
844
|
-
const data = await
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
body: JSON.stringify(input),
|
|
849
|
-
headers: {
|
|
850
|
-
"Content-Type": "application/json"
|
|
851
|
-
}
|
|
852
|
-
},
|
|
853
|
-
token
|
|
854
|
-
);
|
|
846
|
+
const data = await apiClient.fetch(endpoint, {
|
|
847
|
+
method: "PUT",
|
|
848
|
+
body: input
|
|
849
|
+
});
|
|
855
850
|
const result = UpdateProductResponseSchema.safeParse(data);
|
|
856
851
|
if (result.success === false) {
|
|
857
852
|
console.log("[ZOD ERROR]", result.error);
|
|
@@ -859,36 +854,28 @@ async function updateProduct(input, token) {
|
|
|
859
854
|
}
|
|
860
855
|
return result.data;
|
|
861
856
|
}
|
|
862
|
-
async function deleteProduct(id
|
|
857
|
+
async function deleteProduct(id) {
|
|
863
858
|
const endpoint = `/admin/products/${id}`;
|
|
864
|
-
const data = await
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
method: "DELETE",
|
|
868
|
-
headers: {
|
|
869
|
-
"Content-Type": "application/json"
|
|
870
|
-
}
|
|
871
|
-
},
|
|
872
|
-
token
|
|
873
|
-
);
|
|
859
|
+
const data = await apiClient.fetch(endpoint, {
|
|
860
|
+
method: "DELETE"
|
|
861
|
+
});
|
|
874
862
|
const result = ProductResponseSchema.safeParse(data);
|
|
875
863
|
if (result.success === false) {
|
|
876
864
|
console.log("[ZOD ERROR]", result.error);
|
|
877
865
|
throw new Error(`Failed to delete product: ${result.error.message}`);
|
|
878
866
|
}
|
|
879
867
|
}
|
|
880
|
-
async function uploadProductLogo({
|
|
868
|
+
async function uploadProductLogo({
|
|
869
|
+
file,
|
|
870
|
+
filename
|
|
871
|
+
}) {
|
|
881
872
|
const endpoint = `/admin/products/upload-logo`;
|
|
882
873
|
const formData = new FormData();
|
|
883
874
|
formData.append("file", file, filename || file.name);
|
|
884
|
-
const data = await
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
body: formData
|
|
889
|
-
},
|
|
890
|
-
token
|
|
891
|
-
);
|
|
875
|
+
const data = await apiClient.fetch(endpoint, {
|
|
876
|
+
method: "POST",
|
|
877
|
+
body: formData
|
|
878
|
+
});
|
|
892
879
|
const result = UploadProductLogoResponseSchema.safeParse(data);
|
|
893
880
|
if (result.success === false) {
|
|
894
881
|
console.log("[ZOD ERROR]", result.error);
|
|
@@ -900,17 +887,17 @@ async function uploadProductLogo({ file, filename }, token) {
|
|
|
900
887
|
// src/v2/products/queries.ts
|
|
901
888
|
var productsQueries = (0, import_query_key_factory6.createQueryKeys)("products", {
|
|
902
889
|
// Get all products (no filters)
|
|
903
|
-
all: (
|
|
890
|
+
all: () => ({
|
|
904
891
|
queryKey: ["all"],
|
|
905
|
-
queryFn: () => getProducts(
|
|
892
|
+
queryFn: () => getProducts()
|
|
906
893
|
}),
|
|
907
|
-
list: (filters
|
|
894
|
+
list: (filters) => ({
|
|
908
895
|
queryKey: [{ filters }],
|
|
909
|
-
queryFn: () => getProducts(filters
|
|
896
|
+
queryFn: () => getProducts(filters)
|
|
910
897
|
}),
|
|
911
|
-
byId: (id
|
|
898
|
+
byId: (id) => ({
|
|
912
899
|
queryKey: [id],
|
|
913
|
-
queryFn: () => getProduct(id
|
|
900
|
+
queryFn: () => getProduct(id)
|
|
914
901
|
})
|
|
915
902
|
});
|
|
916
903
|
|
|
@@ -944,10 +931,9 @@ async function getWalletBalances(params, context) {
|
|
|
944
931
|
chain: chain.toString()
|
|
945
932
|
});
|
|
946
933
|
const endpoint = `/v1/api/wallet_balances?${searchParams.toString()}`;
|
|
947
|
-
const data = await apiClient(endpoint, {
|
|
934
|
+
const data = await apiClient.fetch(endpoint, {
|
|
948
935
|
method: "GET",
|
|
949
|
-
domain: "
|
|
950
|
-
baseUrl: "https://earn.turtle.vision",
|
|
936
|
+
domain: "earn",
|
|
951
937
|
signal: context?.signal
|
|
952
938
|
});
|
|
953
939
|
const result = walletBalancesResponseSchema.safeParse(data);
|
|
@@ -978,7 +964,7 @@ var widgetOpportunitiesResponseSchema = import_zod9.z.object({
|
|
|
978
964
|
|
|
979
965
|
// src/v2/widget/api.ts
|
|
980
966
|
async function getWidgetOpportunities(distributorId, context) {
|
|
981
|
-
const data = await apiClient(`/widget/${distributorId}/opportunities`, {
|
|
967
|
+
const data = await apiClient.fetch(`/widget/${distributorId}/opportunities`, {
|
|
982
968
|
method: "GET",
|
|
983
969
|
signal: context?.signal
|
|
984
970
|
});
|
|
@@ -1009,7 +995,7 @@ var supportedChainsResponseSchema = import_zod10.z.object({
|
|
|
1009
995
|
|
|
1010
996
|
// src/v2/supported-chains/api.ts
|
|
1011
997
|
async function getSupportedChains(options) {
|
|
1012
|
-
const data = await apiClient("/turtle/chains", {
|
|
998
|
+
const data = await apiClient.fetch("/turtle/chains", {
|
|
1013
999
|
method: "GET",
|
|
1014
1000
|
debug: options?.debug
|
|
1015
1001
|
});
|
|
@@ -1052,7 +1038,7 @@ async function getSupportedTokens(filters, options) {
|
|
|
1052
1038
|
if (filters?.search) params.append("search", filters.search);
|
|
1053
1039
|
const queryString = params.toString();
|
|
1054
1040
|
const endpoint = `/turtle/tokens${queryString ? `?${queryString}` : ""}`;
|
|
1055
|
-
const data = await apiClient(endpoint, {
|
|
1041
|
+
const data = await apiClient.fetch(endpoint, {
|
|
1056
1042
|
method: "GET",
|
|
1057
1043
|
debug: options?.debug
|
|
1058
1044
|
});
|
|
@@ -1223,70 +1209,47 @@ function useOpportunity({ id, ...options }) {
|
|
|
1223
1209
|
|
|
1224
1210
|
// src/v2/products/hooks.ts
|
|
1225
1211
|
var import_react_query7 = require("@tanstack/react-query");
|
|
1226
|
-
|
|
1227
|
-
// src/v2/lib/auth-provider.tsx
|
|
1228
|
-
var import_react2 = require("react");
|
|
1229
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1230
|
-
var AuthContext = (0, import_react2.createContext)(null);
|
|
1231
|
-
function AuthProvider({ getToken, children }) {
|
|
1232
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AuthContext.Provider, { value: { getToken }, children });
|
|
1233
|
-
}
|
|
1234
|
-
function useAuthToken() {
|
|
1235
|
-
const context = (0, import_react2.useContext)(AuthContext);
|
|
1236
|
-
if (!context) {
|
|
1237
|
-
throw new Error("useAuthToken must be used within AuthProvider");
|
|
1238
|
-
}
|
|
1239
|
-
return context;
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
// src/v2/products/hooks.ts
|
|
1243
1212
|
function useProducts({ filters, enabled = true }) {
|
|
1244
|
-
const { getToken } = useAuthToken();
|
|
1245
1213
|
return (0, import_react_query7.useQuery)({
|
|
1246
|
-
...productsQueries.list(filters
|
|
1214
|
+
...productsQueries.list(filters),
|
|
1247
1215
|
...queryDefaults,
|
|
1248
1216
|
enabled
|
|
1249
1217
|
});
|
|
1250
1218
|
}
|
|
1251
1219
|
function useProduct({ id, enabled = true }) {
|
|
1252
|
-
const { getToken } = useAuthToken();
|
|
1253
1220
|
return (0, import_react_query7.useQuery)({
|
|
1254
|
-
...productsQueries.byId(id
|
|
1221
|
+
...productsQueries.byId(id),
|
|
1255
1222
|
...queryDefaults,
|
|
1256
1223
|
enabled
|
|
1257
1224
|
});
|
|
1258
1225
|
}
|
|
1259
1226
|
function useCreateProduct(options) {
|
|
1260
|
-
const { getToken } = useAuthToken();
|
|
1261
1227
|
return (0, import_react_query7.useMutation)({
|
|
1262
|
-
mutationFn: (input) => createProduct(input
|
|
1228
|
+
mutationFn: (input) => createProduct(input),
|
|
1263
1229
|
...options
|
|
1264
1230
|
});
|
|
1265
1231
|
}
|
|
1266
1232
|
function useUpdateProduct(options) {
|
|
1267
|
-
const { getToken } = useAuthToken();
|
|
1268
1233
|
return (0, import_react_query7.useMutation)({
|
|
1269
|
-
mutationFn: (input) => updateProduct(input
|
|
1234
|
+
mutationFn: (input) => updateProduct(input),
|
|
1270
1235
|
...options
|
|
1271
1236
|
});
|
|
1272
1237
|
}
|
|
1273
1238
|
function useDeleteProduct(options) {
|
|
1274
|
-
const { getToken } = useAuthToken();
|
|
1275
1239
|
return (0, import_react_query7.useMutation)({
|
|
1276
|
-
mutationFn: (id) => deleteProduct(id
|
|
1240
|
+
mutationFn: (id) => deleteProduct(id),
|
|
1277
1241
|
...options
|
|
1278
1242
|
});
|
|
1279
1243
|
}
|
|
1280
1244
|
function useUploadProductLogo(options) {
|
|
1281
|
-
const { getToken } = useAuthToken();
|
|
1282
1245
|
return (0, import_react_query7.useMutation)({
|
|
1283
|
-
mutationFn: (request) => uploadProductLogo(request
|
|
1246
|
+
mutationFn: (request) => uploadProductLogo(request),
|
|
1284
1247
|
...options
|
|
1285
1248
|
});
|
|
1286
1249
|
}
|
|
1287
1250
|
|
|
1288
1251
|
// src/v2/balance/hooks/useTokenBalance.ts
|
|
1289
|
-
var
|
|
1252
|
+
var import_react2 = require("react");
|
|
1290
1253
|
var import_viem = require("viem");
|
|
1291
1254
|
var import_utils2 = require("@turtleclub/utils");
|
|
1292
1255
|
function checkInsufficientBalance(tokenBalance, amount) {
|
|
@@ -1302,20 +1265,20 @@ function checkInsufficientBalance(tokenBalance, amount) {
|
|
|
1302
1265
|
}
|
|
1303
1266
|
function useTokenBalance({ tokenBalance, amount, setAmount }) {
|
|
1304
1267
|
const token = tokenBalance?.token;
|
|
1305
|
-
const usdValue = (0,
|
|
1268
|
+
const usdValue = (0, import_react2.useMemo)(
|
|
1306
1269
|
() => (0, import_utils2.calculateUsdValue)(amount, token?.priceUsd),
|
|
1307
1270
|
[amount, token?.priceUsd]
|
|
1308
1271
|
);
|
|
1309
|
-
const hasInsufficientBalance = (0,
|
|
1272
|
+
const hasInsufficientBalance = (0, import_react2.useMemo)(
|
|
1310
1273
|
() => checkInsufficientBalance(tokenBalance, amount),
|
|
1311
1274
|
[tokenBalance, amount]
|
|
1312
1275
|
);
|
|
1313
|
-
const handleMaxClick = (0,
|
|
1276
|
+
const handleMaxClick = (0, import_react2.useCallback)(() => {
|
|
1314
1277
|
if (!tokenBalance?.token || !tokenBalance.amount) return;
|
|
1315
1278
|
const maxAmount = (0, import_utils2.calculateMaxAmount)(tokenBalance.amount, tokenBalance.token.decimals);
|
|
1316
1279
|
setAmount(maxAmount);
|
|
1317
1280
|
}, [tokenBalance, setAmount]);
|
|
1318
|
-
const amountBigInt = (0,
|
|
1281
|
+
const amountBigInt = (0, import_react2.useMemo)(() => {
|
|
1319
1282
|
if (!token || !amount) return void 0;
|
|
1320
1283
|
try {
|
|
1321
1284
|
return (0, import_viem.parseUnits)(amount, token.decimals);
|
|
@@ -1373,7 +1336,7 @@ var portfolioBalanceResponseSchema = import_zod12.z.object({
|
|
|
1373
1336
|
|
|
1374
1337
|
// src/v2/balance/api.ts
|
|
1375
1338
|
async function getPortfolioBalance(address, options) {
|
|
1376
|
-
const data = await apiClient(`/wallet/${address}/balance`, {
|
|
1339
|
+
const data = await apiClient.fetch(`/wallet/${address}/balance`, {
|
|
1377
1340
|
method: "GET",
|
|
1378
1341
|
domain: "api",
|
|
1379
1342
|
debug: options?.debug
|
|
@@ -1397,19 +1360,19 @@ var balanceQueries = (0, import_query_key_factory11.createQueryKeys)("balance",
|
|
|
1397
1360
|
});
|
|
1398
1361
|
|
|
1399
1362
|
// src/v2/balance/hooks/useBalance.ts
|
|
1400
|
-
var
|
|
1363
|
+
var import_react7 = require("react");
|
|
1401
1364
|
|
|
1402
1365
|
// src/v2/balance/hooks/useGetOnChainBalance.ts
|
|
1403
1366
|
var import_wagmi = require("wagmi");
|
|
1404
1367
|
var import_viem2 = require("viem");
|
|
1405
|
-
var
|
|
1368
|
+
var import_react3 = require("react");
|
|
1406
1369
|
function useGetOnChainBalance({
|
|
1407
1370
|
tokens,
|
|
1408
1371
|
chainId,
|
|
1409
1372
|
address,
|
|
1410
1373
|
enabled = true
|
|
1411
1374
|
}) {
|
|
1412
|
-
const contracts = (0,
|
|
1375
|
+
const contracts = (0, import_react3.useMemo)(() => {
|
|
1413
1376
|
if (!address || !enabled) return [];
|
|
1414
1377
|
return tokens.map((token) => ({
|
|
1415
1378
|
address: token.address,
|
|
@@ -1433,7 +1396,7 @@ function useGetOnChainBalance({
|
|
|
1433
1396
|
refetchOnWindowFocus: true
|
|
1434
1397
|
}
|
|
1435
1398
|
});
|
|
1436
|
-
const balances = (0,
|
|
1399
|
+
const balances = (0, import_react3.useMemo)(() => {
|
|
1437
1400
|
if (!results || results.length === 0) return [];
|
|
1438
1401
|
return tokens.map((token, index) => {
|
|
1439
1402
|
const result = results[index];
|
|
@@ -1458,7 +1421,7 @@ function useGetOnChainBalance({
|
|
|
1458
1421
|
|
|
1459
1422
|
// src/v2/balance/hooks/usePortfolioBalance.ts
|
|
1460
1423
|
var import_react_query10 = require("@tanstack/react-query");
|
|
1461
|
-
var
|
|
1424
|
+
var import_react5 = require("react");
|
|
1462
1425
|
|
|
1463
1426
|
// src/v2/supported-chains/hooks.ts
|
|
1464
1427
|
var import_react_query8 = require("@tanstack/react-query");
|
|
@@ -1479,7 +1442,7 @@ function useSupportedChains() {
|
|
|
1479
1442
|
|
|
1480
1443
|
// src/v2/supported-tokens/hooks.ts
|
|
1481
1444
|
var import_react_query9 = require("@tanstack/react-query");
|
|
1482
|
-
var
|
|
1445
|
+
var import_react4 = require("react");
|
|
1483
1446
|
function useSupportedTokens({
|
|
1484
1447
|
page = 0,
|
|
1485
1448
|
limit = 20,
|
|
@@ -1497,7 +1460,7 @@ function useSupportedTokens({
|
|
|
1497
1460
|
// Don't refetch on tab focus
|
|
1498
1461
|
enabled
|
|
1499
1462
|
});
|
|
1500
|
-
const tokens = (0,
|
|
1463
|
+
const tokens = (0, import_react4.useMemo)(() => {
|
|
1501
1464
|
if (!data?.tokens) return [];
|
|
1502
1465
|
return data.tokens.map(({ active, ...token }) => token);
|
|
1503
1466
|
}, [data?.tokens]);
|
|
@@ -1535,7 +1498,7 @@ function usePortfolioBalance({
|
|
|
1535
1498
|
refetchInterval: 1 * 60 * 1e3
|
|
1536
1499
|
// 1 minute
|
|
1537
1500
|
});
|
|
1538
|
-
const balances = (0,
|
|
1501
|
+
const balances = (0, import_react5.useMemo)(() => {
|
|
1539
1502
|
if (!portfolioData) return [];
|
|
1540
1503
|
const tokenBalances = [];
|
|
1541
1504
|
portfolioData.portfolio.holdings.wallets.forEach((wallet) => {
|
|
@@ -1591,7 +1554,7 @@ function usePortfolioBalance({
|
|
|
1591
1554
|
}
|
|
1592
1555
|
|
|
1593
1556
|
// src/v2/balance/hooks/useEnsoBalances.ts
|
|
1594
|
-
var
|
|
1557
|
+
var import_react6 = require("react");
|
|
1595
1558
|
function useEnsoBalances({
|
|
1596
1559
|
address,
|
|
1597
1560
|
chainIds
|
|
@@ -1606,7 +1569,7 @@ function useEnsoBalances({
|
|
|
1606
1569
|
chainIds,
|
|
1607
1570
|
address
|
|
1608
1571
|
});
|
|
1609
|
-
const balances = (0,
|
|
1572
|
+
const balances = (0, import_react6.useMemo)(() => {
|
|
1610
1573
|
if (isSupportedTokensLoading || isLoading) return [];
|
|
1611
1574
|
const tokenBalances = [];
|
|
1612
1575
|
Object.entries(ensoBalances).forEach(([, chainBalances]) => {
|
|
@@ -1743,7 +1706,7 @@ function useBalance({
|
|
|
1743
1706
|
address,
|
|
1744
1707
|
chainIds
|
|
1745
1708
|
});
|
|
1746
|
-
const consolidatedBalances = (0,
|
|
1709
|
+
const consolidatedBalances = (0, import_react7.useMemo)(() => {
|
|
1747
1710
|
const sources = [];
|
|
1748
1711
|
if (depositOpportunity && onChainBalances.length > 0) {
|
|
1749
1712
|
sources.push(onChainBalances);
|
|
@@ -1837,7 +1800,7 @@ function useGeocheck(options = {}) {
|
|
|
1837
1800
|
}
|
|
1838
1801
|
|
|
1839
1802
|
// src/v2/swap/useSwapRoute.ts
|
|
1840
|
-
var
|
|
1803
|
+
var import_react8 = require("react");
|
|
1841
1804
|
|
|
1842
1805
|
// src/v2/swap/route-processor.ts
|
|
1843
1806
|
var import_utils4 = require("@turtleclub/utils");
|
|
@@ -1896,7 +1859,7 @@ function toEnsoTokenAddress(address) {
|
|
|
1896
1859
|
return address;
|
|
1897
1860
|
}
|
|
1898
1861
|
function useSwapRoute(isEnabled, userAddress, distributorId, options, referralCode) {
|
|
1899
|
-
const params = (0,
|
|
1862
|
+
const params = (0, import_react8.useMemo)(() => {
|
|
1900
1863
|
if (!options || !isEnabled) return void 0;
|
|
1901
1864
|
return {
|
|
1902
1865
|
...options,
|
|
@@ -1905,7 +1868,7 @@ function useSwapRoute(isEnabled, userAddress, distributorId, options, referralCo
|
|
|
1905
1868
|
referral_code: referralCode
|
|
1906
1869
|
};
|
|
1907
1870
|
}, [options, userAddress, distributorId, referralCode]);
|
|
1908
|
-
const hasRequiredParams = (0,
|
|
1871
|
+
const hasRequiredParams = (0, import_react8.useMemo)(() => {
|
|
1909
1872
|
return !!(userAddress && params?.token_in && params?.token_out && params?.amount && params?.chain && params?.slippage && params?.distributor_id);
|
|
1910
1873
|
}, [options]);
|
|
1911
1874
|
const { data, isLoading, error } = useEarnRoute({
|
|
@@ -1922,7 +1885,7 @@ function useSwapRoute(isEnabled, userAddress, distributorId, options, referralCo
|
|
|
1922
1885
|
},
|
|
1923
1886
|
enabled: hasRequiredParams && isEnabled
|
|
1924
1887
|
});
|
|
1925
|
-
const routeDetails = (0,
|
|
1888
|
+
const routeDetails = (0, import_react8.useMemo)(() => processRouteDetails(data ?? null), [data]);
|
|
1926
1889
|
return {
|
|
1927
1890
|
fetchedRoute: data ?? null,
|
|
1928
1891
|
outputAmount: data?.amount_out ?? void 0,
|
|
@@ -1934,6 +1897,26 @@ function useSwapRoute(isEnabled, userAddress, distributorId, options, referralCo
|
|
|
1934
1897
|
};
|
|
1935
1898
|
}
|
|
1936
1899
|
|
|
1900
|
+
// src/v2/lib/turtle-provider.tsx
|
|
1901
|
+
var import_react9 = require("react");
|
|
1902
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1903
|
+
function TurtleProvider({
|
|
1904
|
+
children,
|
|
1905
|
+
apiUrl,
|
|
1906
|
+
earnUrl,
|
|
1907
|
+
getToken,
|
|
1908
|
+
debug
|
|
1909
|
+
}) {
|
|
1910
|
+
const config = (0, import_react9.useMemo)(
|
|
1911
|
+
() => ({ apiUrl, earnUrl, getToken, debug }),
|
|
1912
|
+
[apiUrl, earnUrl, getToken, debug]
|
|
1913
|
+
);
|
|
1914
|
+
(0, import_react9.useEffect)(() => {
|
|
1915
|
+
apiClient.configure(config);
|
|
1916
|
+
}, [config]);
|
|
1917
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1937
1920
|
// src/v2/index.ts
|
|
1938
1921
|
var queries = (0, import_query_key_factory12.mergeQueryKeys)(
|
|
1939
1922
|
opportunitiesQueries,
|
|
@@ -1949,8 +1932,10 @@ var queries = (0, import_query_key_factory12.mergeQueryKeys)(
|
|
|
1949
1932
|
);
|
|
1950
1933
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1951
1934
|
0 && (module.exports = {
|
|
1952
|
-
|
|
1935
|
+
ApiError,
|
|
1953
1936
|
BalanceSourcePriority,
|
|
1937
|
+
TurtleProvider,
|
|
1938
|
+
apiClient,
|
|
1954
1939
|
approveStep,
|
|
1955
1940
|
asset,
|
|
1956
1941
|
assetData,
|
|
@@ -2020,7 +2005,6 @@ var queries = (0, import_query_key_factory12.mergeQueryKeys)(
|
|
|
2020
2005
|
supportedTokensResponseSchema,
|
|
2021
2006
|
swapSubstep,
|
|
2022
2007
|
tokenSchema,
|
|
2023
|
-
useAuthToken,
|
|
2024
2008
|
useBalance,
|
|
2025
2009
|
useCheckMembership,
|
|
2026
2010
|
useCreateMembership,
|