@turtleclub/hooks 0.2.1-beta.2 → 0.2.1-beta.3
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 +14 -198
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -185
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/campaigns-v2/constants.tsx +48 -49
- package/src/campaigns-v2/index.ts +1 -1
- package/src/hooks/index.ts +0 -1
- package/src/index.ts +0 -1
- package/src/hooks/earn/index.ts +0 -1
- package/src/hooks/earn/useEnhancedEarnDeals.ts +0 -146
package/dist/index.cjs
CHANGED
|
@@ -174,7 +174,6 @@ __export(index_exports, {
|
|
|
174
174
|
useEarnDeals: () => useEarnDeals,
|
|
175
175
|
useEarnRoute: () => useEarnRoute,
|
|
176
176
|
useEarnWalletBalances: () => useEarnWalletBalances,
|
|
177
|
-
useEnhancedEarnDeals: () => useEnhancedEarnDeals,
|
|
178
177
|
useExists: () => useExists,
|
|
179
178
|
useIndexerTvl: () => useIndexerTvl,
|
|
180
179
|
useOrganizationDeals: () => useOrganizationDeals,
|
|
@@ -502,120 +501,13 @@ function useEarnWalletBalances(options, { config, queryClient } = {}) {
|
|
|
502
501
|
return query2;
|
|
503
502
|
}
|
|
504
503
|
|
|
505
|
-
// src/hooks/
|
|
504
|
+
// src/hooks/endpoints/partner/usePartnerCampaigns.ts
|
|
506
505
|
var import_react_query14 = require("@tanstack/react-query");
|
|
507
506
|
var import_api14 = require("@turtleclub/api");
|
|
508
|
-
|
|
509
|
-
// src/utils/dataMatching.ts
|
|
510
|
-
function deduplicateDeals(deals) {
|
|
511
|
-
const dealsMap = /* @__PURE__ */ new Map();
|
|
512
|
-
deals.forEach((deal) => {
|
|
513
|
-
const key = deal.metadata.id + deal.token.address + deal.token.chain;
|
|
514
|
-
const existing = dealsMap.get(key);
|
|
515
|
-
if (!existing || hasMoreCompleteData(deal, existing)) {
|
|
516
|
-
dealsMap.set(key, deal);
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
return Array.from(dealsMap.values());
|
|
520
|
-
}
|
|
521
|
-
function hasMoreCompleteData(newDeal, existingDeal) {
|
|
522
|
-
if (newDeal.data.tvl > 0 && existingDeal.data.tvl === 0) return true;
|
|
523
|
-
if (newDeal.data.apy > 0 && existingDeal.data.apy === 0) return true;
|
|
524
|
-
if (newDeal.metadata.iconUrl && !existingDeal.metadata.iconUrl) return true;
|
|
525
|
-
if (newDeal.token.logos.length > existingDeal.token.logos.length) return true;
|
|
526
|
-
if (newDeal.underlying_tokens.length > existingDeal.underlying_tokens.length) return true;
|
|
527
|
-
return false;
|
|
528
|
-
}
|
|
529
|
-
function filterDealsByIds(deals, ids) {
|
|
530
|
-
if (!ids.length) return deals;
|
|
531
|
-
return deals.filter((deal) => ids.includes(deal.metadata.id));
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
// src/hooks/earn/useEnhancedEarnDeals.ts
|
|
535
|
-
function useEnhancedEarnDeals({
|
|
536
|
-
dealIds = [],
|
|
537
|
-
campaignIds = [],
|
|
538
|
-
fetchAllIfNoFilters = false
|
|
539
|
-
} = {}) {
|
|
540
|
-
const config = useConfig();
|
|
541
|
-
const shouldFetchAll = dealIds.length > 0 || fetchAllIfNoFilters && dealIds.length === 0 && campaignIds.length === 0;
|
|
542
|
-
const shouldFetchCampaigns = campaignIds.length > 0;
|
|
543
|
-
const queries = [];
|
|
544
|
-
if (shouldFetchAll) {
|
|
545
|
-
queries.push({
|
|
546
|
-
queryKey: ["earn-deals", "all"],
|
|
547
|
-
queryFn: () => (0, import_api14.earnDeals)({}, config),
|
|
548
|
-
enabled: true
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
if (shouldFetchCampaigns) {
|
|
552
|
-
campaignIds.forEach((campaignId) => {
|
|
553
|
-
queries.push({
|
|
554
|
-
queryKey: ["earn-deals", "campaign", campaignId],
|
|
555
|
-
queryFn: () => (0, import_api14.earnDeals)({ campaignId }, config),
|
|
556
|
-
enabled: true
|
|
557
|
-
});
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
if (queries.length === 0) {
|
|
561
|
-
queries.push({
|
|
562
|
-
queryKey: ["earn-deals", "none"],
|
|
563
|
-
queryFn: async () => ({ deals: [], metadata: {} }),
|
|
564
|
-
enabled: false
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
const results = (0, import_react_query14.useQueries)({
|
|
568
|
-
queries: queries.map((query2) => ({
|
|
569
|
-
...query2,
|
|
570
|
-
staleTime: 5 * 60 * 1e3,
|
|
571
|
-
refetchOnWindowFocus: false,
|
|
572
|
-
refetchOnMount: false,
|
|
573
|
-
refetchOnReconnect: false,
|
|
574
|
-
gcTime: 30 * 60 * 1e3
|
|
575
|
-
// 30 minutos de cache
|
|
576
|
-
}))
|
|
577
|
-
});
|
|
578
|
-
const isLoading = results.some((result) => result.isLoading);
|
|
579
|
-
const error = results.find((result) => result.error)?.error;
|
|
580
|
-
let allDeals = [];
|
|
581
|
-
const dealCampaignMap = /* @__PURE__ */ new Map();
|
|
582
|
-
results.forEach((result, index) => {
|
|
583
|
-
if (result.data?.deals) {
|
|
584
|
-
const queryKey = queries[index].queryKey;
|
|
585
|
-
if (queryKey.includes("all") && dealIds.length > 0) {
|
|
586
|
-
const filteredDeals = filterDealsByIds(result.data.deals, dealIds);
|
|
587
|
-
allDeals = [...allDeals, ...filteredDeals];
|
|
588
|
-
} else {
|
|
589
|
-
allDeals = [...allDeals, ...result.data.deals];
|
|
590
|
-
if (queryKey.includes("campaign") && queryKey[2]) {
|
|
591
|
-
const campaignId = queryKey[2];
|
|
592
|
-
result.data.deals.forEach((deal) => {
|
|
593
|
-
dealCampaignMap.set(deal.metadata.id, campaignId);
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
const uniqueDeals = deduplicateDeals(allDeals);
|
|
600
|
-
const refetch = () => {
|
|
601
|
-
results.forEach((result) => result.refetch());
|
|
602
|
-
};
|
|
603
|
-
return {
|
|
604
|
-
deals: uniqueDeals,
|
|
605
|
-
isLoading,
|
|
606
|
-
error,
|
|
607
|
-
refetch,
|
|
608
|
-
dealCampaignMap
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
// src/hooks/endpoints/partner/usePartnerCampaigns.ts
|
|
613
|
-
var import_react_query15 = require("@tanstack/react-query");
|
|
614
|
-
var import_api15 = require("@turtleclub/api");
|
|
615
507
|
function usePartnerCampaigns(options, { config, queryClient } = {}) {
|
|
616
508
|
const defaultConfig2 = useConfig();
|
|
617
509
|
const enabled = options !== void 0;
|
|
618
|
-
const query2 = (0,
|
|
510
|
+
const query2 = (0, import_react_query14.useQuery)({
|
|
619
511
|
queryKey: [
|
|
620
512
|
"partner-campaigns",
|
|
621
513
|
options?.idFilter,
|
|
@@ -624,7 +516,7 @@ function usePartnerCampaigns(options, { config, queryClient } = {}) {
|
|
|
624
516
|
queryFn: async () => {
|
|
625
517
|
if (!enabled)
|
|
626
518
|
return null;
|
|
627
|
-
return await (0,
|
|
519
|
+
return await (0, import_api14.earnCampaigns)(options, config ?? defaultConfig2);
|
|
628
520
|
},
|
|
629
521
|
enabled,
|
|
630
522
|
staleTime: 5 * 60 * 1e3,
|
|
@@ -638,12 +530,12 @@ function usePartnerCampaigns(options, { config, queryClient } = {}) {
|
|
|
638
530
|
}
|
|
639
531
|
|
|
640
532
|
// src/hooks/endpoints/partner/usePartnerDeals.ts
|
|
641
|
-
var
|
|
642
|
-
var
|
|
533
|
+
var import_react_query15 = require("@tanstack/react-query");
|
|
534
|
+
var import_api15 = require("@turtleclub/api");
|
|
643
535
|
function usePartnerDeals(options, { config, queryClient } = {}) {
|
|
644
536
|
const defaultConfig2 = useConfig();
|
|
645
537
|
const enabled = options !== void 0;
|
|
646
|
-
const query2 = (0,
|
|
538
|
+
const query2 = (0, import_react_query15.useQuery)({
|
|
647
539
|
queryKey: [
|
|
648
540
|
"partner-deals",
|
|
649
541
|
options?.status,
|
|
@@ -653,7 +545,7 @@ function usePartnerDeals(options, { config, queryClient } = {}) {
|
|
|
653
545
|
queryFn: async () => {
|
|
654
546
|
if (!enabled)
|
|
655
547
|
return null;
|
|
656
|
-
const result = await (0,
|
|
548
|
+
const result = await (0, import_api15.turtleDeals)(options || {}, config ?? defaultConfig2);
|
|
657
549
|
return result;
|
|
658
550
|
},
|
|
659
551
|
enabled,
|
|
@@ -674,7 +566,6 @@ __export(campaigns_v2_exports, {
|
|
|
674
566
|
KATANA_CAMPAIGN_NAME: () => KATANA_CAMPAIGN_NAME,
|
|
675
567
|
TAC_CAMPAIGN_NAME: () => TAC_CAMPAIGN_NAME,
|
|
676
568
|
getVaultAddress: () => getVaultAddress,
|
|
677
|
-
getVaultAprTooltip: () => getVaultAprTooltip,
|
|
678
569
|
getVaultBoostText: () => getVaultBoostText,
|
|
679
570
|
getVaultChain: () => getVaultChain,
|
|
680
571
|
getVaultChainId: () => getVaultChainId,
|
|
@@ -701,13 +592,13 @@ __export(campaigns_v2_exports, {
|
|
|
701
592
|
var import_react3 = require("react");
|
|
702
593
|
var import_wagmi = require("wagmi");
|
|
703
594
|
var import_viem3 = require("viem");
|
|
704
|
-
var
|
|
595
|
+
var import_react_query17 = require("@tanstack/react-query");
|
|
705
596
|
|
|
706
597
|
// src/campaigns-v2/useCampaign.ts
|
|
707
598
|
var import_react2 = require("react");
|
|
708
599
|
|
|
709
600
|
// src/campaigns-v2/api/builder/hooks.ts
|
|
710
|
-
var
|
|
601
|
+
var import_react_query16 = require("@tanstack/react-query");
|
|
711
602
|
var import_react = require("react");
|
|
712
603
|
var import_lodash = __toESM(require("lodash"), 1);
|
|
713
604
|
var appVersion = typeof __COMMIT_HASH__ !== "undefined" ? __COMMIT_HASH__ : "default-version";
|
|
@@ -717,7 +608,7 @@ function buildHooks(map, defaults = {}) {
|
|
|
717
608
|
const hookItem = map[key];
|
|
718
609
|
const rawKey = key;
|
|
719
610
|
result[key] = function(...args) {
|
|
720
|
-
return (0,
|
|
611
|
+
return (0, import_react_query16.useQuery)(
|
|
721
612
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
722
613
|
(0, import_react.useMemo)(
|
|
723
614
|
() => query(hookItem, rawKey, defaults, args),
|
|
@@ -729,7 +620,7 @@ function buildHooks(map, defaults = {}) {
|
|
|
729
620
|
}
|
|
730
621
|
const multicall = {
|
|
731
622
|
multicall(list) {
|
|
732
|
-
return (0,
|
|
623
|
+
return (0, import_react_query16.useQueries)({
|
|
733
624
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
734
625
|
queries: (0, import_react.useMemo)(() => list.map(([rawKey, ...args]) => query(map[rawKey], rawKey, defaults, args)), [list])
|
|
735
626
|
});
|
|
@@ -3794,7 +3685,6 @@ var indexHooks = buildHooks(
|
|
|
3794
3685
|
);
|
|
3795
3686
|
|
|
3796
3687
|
// src/campaigns-v2/constants.tsx
|
|
3797
|
-
var import_ui = require("@turtleclub/ui");
|
|
3798
3688
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
3799
3689
|
var VedaIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: "Veda" });
|
|
3800
3690
|
var UpshiftIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: "Upshift" });
|
|
@@ -3803,7 +3693,6 @@ var LagoonIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
|
3803
3693
|
var YieldfiIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: "Yieldfi" });
|
|
3804
3694
|
var ConcreteIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: "Concrete" });
|
|
3805
3695
|
var CianIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: "Cian" });
|
|
3806
|
-
var Info = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: "\u2139\uFE0F" });
|
|
3807
3696
|
var formatNumber = (num, decimals) => num.toFixed(decimals ?? 2);
|
|
3808
3697
|
var getVaultDeployment = (vault) => {
|
|
3809
3698
|
if (!vault) return void 0;
|
|
@@ -4051,78 +3940,6 @@ var getVaultEstApr = (campaign, vault) => {
|
|
|
4051
3940
|
if (apr === 0) return void 0;
|
|
4052
3941
|
return formatNumber(apr);
|
|
4053
3942
|
};
|
|
4054
|
-
var renderIncentiveItem = (incentive) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mb-2", children: [
|
|
4055
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between", children: [
|
|
4056
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
4057
|
-
incentive.iconUrl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
4058
|
-
"img",
|
|
4059
|
-
{
|
|
4060
|
-
src: incentive.iconUrl,
|
|
4061
|
-
alt: incentive.name || incentive.id,
|
|
4062
|
-
className: "size-4 rounded-full",
|
|
4063
|
-
loading: "lazy"
|
|
4064
|
-
}
|
|
4065
|
-
),
|
|
4066
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "font-medium", children: [
|
|
4067
|
-
incentive.estApr ? "Est. " : "",
|
|
4068
|
-
incentive.name || incentive.id
|
|
4069
|
-
] })
|
|
4070
|
-
] }),
|
|
4071
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold", children: incentive.apr !== void 0 ? `${incentive.estApr ? "\u2248 " : ""}${incentive.apr.toFixed(2)}%` : "-" })
|
|
4072
|
-
] }),
|
|
4073
|
-
incentive.tooltip && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mt-0.5 text-xs text-wise-white/60", children: incentive.tooltip })
|
|
4074
|
-
] }, incentive.id);
|
|
4075
|
-
var renderTotalApr = (totalApr, incentives) => {
|
|
4076
|
-
const hasEstApr = incentives.some((incentive) => incentive.estApr);
|
|
4077
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
4078
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mb-2 border-b border-wise-white/10" }),
|
|
4079
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between", children: [
|
|
4080
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-medium", children: "Total APR" }),
|
|
4081
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "font-semibold", children: [
|
|
4082
|
-
hasEstApr ? "\u2248 " : "= ",
|
|
4083
|
-
totalApr.toFixed(2),
|
|
4084
|
-
"%"
|
|
4085
|
-
] })
|
|
4086
|
-
] })
|
|
4087
|
-
] });
|
|
4088
|
-
};
|
|
4089
|
-
var renderIncentiveBreakdown = (title, incentives, showSeparator = false) => {
|
|
4090
|
-
const totalApr = incentives.reduce((acc, incentive) => acc + (incentive.apr ?? 0), 0);
|
|
4091
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
4092
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-base font-semibold", children: title }),
|
|
4093
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mb-2 border-b border-wise-white/10" }),
|
|
4094
|
-
incentives.map(renderIncentiveItem),
|
|
4095
|
-
renderTotalApr(totalApr, incentives),
|
|
4096
|
-
showSeparator && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "my-4 h-px bg-neon-green" })
|
|
4097
|
-
] });
|
|
4098
|
-
};
|
|
4099
|
-
var getVaultAprTooltip = (campaign, vault) => {
|
|
4100
|
-
if (!vault) return void 0;
|
|
4101
|
-
const incentives = getVaultIncentives(campaign, vault);
|
|
4102
|
-
const { incentivesByPhase, globalIncentives } = groupIncentivesByPhase(incentives);
|
|
4103
|
-
if (incentivesByPhase.size === 0) {
|
|
4104
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
4105
|
-
import_ui.Tooltip,
|
|
4106
|
-
{
|
|
4107
|
-
trigger: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Info, { className: "size-3 text-neon-green" }),
|
|
4108
|
-
maxWidth: "800px",
|
|
4109
|
-
content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-w-[250px] whitespace-normal break-words px-2 text-xs text-wise-white", children: renderIncentiveBreakdown("Vault APR", incentives) })
|
|
4110
|
-
}
|
|
4111
|
-
);
|
|
4112
|
-
}
|
|
4113
|
-
const phases = sortPhases(Array.from(incentivesByPhase.keys()), incentives);
|
|
4114
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
4115
|
-
import_ui.Tooltip,
|
|
4116
|
-
{
|
|
4117
|
-
trigger: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Info, { className: "size-3 text-neon-green" }),
|
|
4118
|
-
maxWidth: "800px",
|
|
4119
|
-
content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-w-[250px] whitespace-normal break-words px-2 text-xs text-wise-white", children: phases.map((phase, phaseIndex) => {
|
|
4120
|
-
const phaseIncentives = getPhaseIncentives(phase, incentivesByPhase, globalIncentives);
|
|
4121
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: renderIncentiveBreakdown(`${phase} Vault APR`, phaseIncentives, phaseIndex < phases.length - 1) }, phase);
|
|
4122
|
-
}) })
|
|
4123
|
-
}
|
|
4124
|
-
);
|
|
4125
|
-
};
|
|
4126
3943
|
var sortVaults = (groups, vaults) => {
|
|
4127
3944
|
const groupToRank = groups.reduce(
|
|
4128
3945
|
(acc, group) => {
|
|
@@ -4305,7 +4122,7 @@ function useEvmCampaignPositions({
|
|
|
4305
4122
|
isLoading,
|
|
4306
4123
|
error: queryError,
|
|
4307
4124
|
refetch: refetchUserPositions
|
|
4308
|
-
} = (0,
|
|
4125
|
+
} = (0, import_react_query17.useQuery)({
|
|
4309
4126
|
queryKey: ["positions", userAddress, campaignName, configs?.length],
|
|
4310
4127
|
queryFn: async () => {
|
|
4311
4128
|
if (!configs || !prices) {
|
|
@@ -4564,7 +4381,7 @@ function useEvmCampaignPositions({
|
|
|
4564
4381
|
|
|
4565
4382
|
// src/campaigns-v2/useTonCampaignPositions.ts
|
|
4566
4383
|
var import_react4 = require("react");
|
|
4567
|
-
var
|
|
4384
|
+
var import_react_query18 = require("@tanstack/react-query");
|
|
4568
4385
|
var import_ton = require("@ton/ton");
|
|
4569
4386
|
function useTonCampaignPositions({
|
|
4570
4387
|
campaignName,
|
|
@@ -4587,7 +4404,7 @@ function useTonCampaignPositions({
|
|
|
4587
4404
|
isLoading,
|
|
4588
4405
|
error: queryError,
|
|
4589
4406
|
refetch: refetchUserPositions
|
|
4590
|
-
} = (0,
|
|
4407
|
+
} = (0, import_react_query18.useQuery)({
|
|
4591
4408
|
queryKey: ["ton-positions", userAddress, campaignName, tonVaults.length],
|
|
4592
4409
|
queryFn: async () => {
|
|
4593
4410
|
if (!userAddress || tonVaults.length === 0) {
|
|
@@ -4722,7 +4539,6 @@ function useUserCampaignPositions({
|
|
|
4722
4539
|
useEarnDeals,
|
|
4723
4540
|
useEarnRoute,
|
|
4724
4541
|
useEarnWalletBalances,
|
|
4725
|
-
useEnhancedEarnDeals,
|
|
4726
4542
|
useExists,
|
|
4727
4543
|
useIndexerTvl,
|
|
4728
4544
|
useOrganizationDeals,
|