Skip to content

Commit 0262913

Browse files
authored
Add Rewards to Add Liquidity form (#1685)
* Add Rewards to Add Liquidity form * Only show rewards indicator when rewards exist * Put yield rate on the left
1 parent 71e263d commit 0262913

File tree

5 files changed

+54
-43
lines changed

5 files changed

+54
-43
lines changed

apps/hyperdrive-trading/src/ui/hyperdrive/lp/AddLiquidityForm/AddLiquidityForm.tsx

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import { useLpShares } from "src/ui/hyperdrive/lp/hooks/useLpShares";
3434
import { useLpSharesTotalSupply } from "src/ui/hyperdrive/lp/hooks/useLpSharesTotalSupply";
3535
import { usePreviewAddLiquidity } from "src/ui/hyperdrive/lp/hooks/usePreviewAddLiquidity";
3636
import { PositionPicker } from "src/ui/markets/PositionPicker";
37+
import { RewardsTooltip } from "src/ui/rewards/RewardsTooltip";
38+
import { useRewards } from "src/ui/rewards/useRewards";
3739
import { ApproveTokenChoices } from "src/ui/token/ApproveTokenChoices";
3840
import { SlippageSettings } from "src/ui/token/SlippageSettings";
3941
import { TokenInput } from "src/ui/token/TokenInput";
@@ -336,17 +338,17 @@ export function AddLiquidityForm({
336338
}
337339
primaryStats={
338340
<div className="flex flex-row justify-between px-4 py-8">
341+
<div className="flex-1">
342+
<LpApyStat hyperdrive={hyperdrive} />
343+
</div>
344+
<div className="daisy-divider daisy-divider-horizontal mx-0" />
339345
<div className="flex-1">
340346
<YouReceiveStat
341347
addLiquidityPreviewStatus={addLiquidityPreviewStatus}
342348
lpSharesOut={lpSharesOut}
343349
hyperdrive={hyperdrive}
344350
/>
345351
</div>
346-
<div className="daisy-divider daisy-divider-horizontal mx-0" />
347-
<div className="flex-1">
348-
<LpApyStat hyperdrive={hyperdrive} />
349-
</div>
350352
</div>
351353
}
352354
disclaimer={(() => {
@@ -482,6 +484,7 @@ function YouReceiveStat({
482484
});
483485
return (
484486
<PrimaryStat
487+
alignment="right"
485488
label="You receive"
486489
subValue={
487490
addLiquidityPreviewStatus === "loading" ? (
@@ -534,42 +537,49 @@ function LpApyStat({ hyperdrive }: { hyperdrive: HyperdriveConfig }) {
534537
chainId: hyperdrive.chainId,
535538
hyperdriveAddress: hyperdrive.address,
536539
});
540+
const { rewards } = useRewards(hyperdrive);
537541

538542
const { vaultRate, vaultRateStatus } = useYieldSourceRate({
539543
hyperdriveAddress: hyperdrive.address,
540544
chainId: hyperdrive.chainId,
541545
});
542546

543-
const showSkeleton = !lpApy && lpApyStatus === "loading";
544547
const yieldSource = getYieldSource({
545548
hyperdriveAddress: hyperdrive.address,
546549
hyperdriveChainId: hyperdrive.chainId,
547550
appConfig,
548551
});
549552
return (
550553
<PrimaryStat
551-
alignment="right"
554+
valueLoading={!lpApy && lpApyStatus === "loading"}
552555
label="LP APY"
553556
value={(() => {
554-
if (showSkeleton) {
555-
return <Skeleton />;
556-
}
557-
if (lpApy === undefined || lpApy.isNew) {
558-
return <div className="flex gap-2 text-h3 font-bold">✨New✨</div>;
559-
}
560-
561557
return (
562558
<span className="text-h3 font-bold">
563-
{formatRate({ rate: lpApy?.netLpApy })}
559+
{isNewPool ? (
560+
"✨New✨"
561+
) : rewards?.length ? (
562+
<RewardsTooltip
563+
hyperdriveAddress={hyperdrive.address}
564+
baseRate={lpApy?.lpApy}
565+
netRate={lpApy?.netLpApy}
566+
chainId={hyperdrive.chainId}
567+
>
568+
<span className="gradient-text">
569+
{formatRate({ rate: lpApy?.netLpApy ?? 0n })}
570+
</span>
571+
572+
</RewardsTooltip>
573+
) : (
574+
<span className="gradient-text">
575+
{formatRate({ rate: lpApy?.netLpApy ?? 0n })}
576+
</span>
577+
)}
564578
</span>
565579
);
566580
})()}
567-
tooltipContent="The annual percentage yield projection for providing liquidity."
581+
tooltipContent="The projected annual percentage yield for providing liquidity."
568582
tooltipPosition="left"
569-
valueContainerClassName={classNames({
570-
"bg-gradient-to-r from-accent to-primary bg-clip-text text-transparent text-h3 font-bold":
571-
!isNewPool, // Don't use gradient text when displaying NEW, the emojis give enough emphasis.
572-
})}
573583
subValue={
574584
vaultRateStatus === "success" && vaultRate ? (
575585
<div>

apps/hyperdrive-trading/src/ui/hyperdrive/shorts/OpenShortForm/OpenShortForm.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { useOpenShort } from "src/ui/hyperdrive/shorts/hooks/useOpenShort";
3838
import { usePreviewOpenShort } from "src/ui/hyperdrive/shorts/hooks/usePreviewOpenShort";
3939
import { PositionPicker } from "src/ui/markets/PositionPicker";
4040
import { RewardsTooltip } from "src/ui/rewards/RewardsTooltip";
41+
import { useRewards } from "src/ui/rewards/useRewards";
4142
import { ApproveTokenChoices } from "src/ui/token/ApproveTokenChoices";
4243
import { SlippageSettings } from "src/ui/token/SlippageSettings";
4344
import { TokenInput } from "src/ui/token/TokenInput";
@@ -69,6 +70,7 @@ export function OpenShortForm({
6970
chainId: hyperdrive.chainId,
7071
});
7172

73+
const { rewards } = useRewards(hyperdrive);
7274
const { poolInfo } = usePoolInfo({
7375
chainId: hyperdrive.chainId,
7476
hyperdriveAddress: hyperdrive.address,
@@ -78,7 +80,7 @@ export function OpenShortForm({
7880
hyperdriveAddress: hyperdrive.address,
7981
appConfig,
8082
});
81-
const { vaultRate, vaultRateStatus } = useYieldSourceRate({
83+
const { vaultRate } = useYieldSourceRate({
8284
chainId: hyperdrive.chainId,
8385
hyperdriveAddress: hyperdrive.address,
8486
});
@@ -473,7 +475,7 @@ export function OpenShortForm({
473475
<span className="text-h3 font-bold">
474476
{isNewPool ? (
475477
"✨New✨"
476-
) : (
478+
) : rewards?.length ? (
477479
<RewardsTooltip
478480
hyperdriveAddress={hyperdrive.address}
479481
baseRate={vaultRate?.vaultRate}
@@ -482,6 +484,8 @@ export function OpenShortForm({
482484
>
483485
{formatRate({ rate: vaultRate?.netVaultRate ?? 0n })}
484486
</RewardsTooltip>
487+
) : (
488+
formatRate({ rate: vaultRate?.netVaultRate ?? 0n })
485489
)}
486490
</span>
487491
}

apps/hyperdrive-trading/src/ui/markets/PoolRow/LpApyStat.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export function LpApyStat({
4545
>
4646
{netApyLabel ? (
4747
<>
48-
<PercentLabel value={netApyLabel} />
48+
<PercentLabel value={netApyLabel} />
49+
<span className="mx-1"></span>
4950
</>
5051
) : null}
5152
</RewardsTooltip>

apps/hyperdrive-trading/src/ui/markets/PoolRow/VariableApyStat.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Skeleton from "react-loading-skeleton";
44
import { formatRate } from "src/base/formatRate";
55
import { calculateMarketYieldMultiplier } from "src/hyperdrive/calculateMarketYieldMultiplier";
66
import { GradientBadge } from "src/ui/base/components/GradientBadge";
7-
import { useIsNewPool } from "src/ui/hyperdrive/hooks/useIsNewPool";
87
import { useCurrentLongPrice } from "src/ui/hyperdrive/longs/hooks/useCurrentLongPrice";
98
import { PercentLabel } from "src/ui/markets/PoolRow/PercentLabel";
109
import { RewardsTooltip } from "src/ui/rewards/RewardsTooltip";
@@ -23,13 +22,12 @@ export function VariableApyStat({
2322
hyperdriveChainId: chainId,
2423
appConfig,
2524
});
26-
const { rewards: appConfigRewards } = useRewards(hyperdrive);
25+
const { rewards } = useRewards(hyperdrive);
2726
const { vaultRate: yieldSourceRate, vaultRateStatus: yieldSourceRateStatus } =
2827
useYieldSourceRate({
2928
chainId,
3029
hyperdriveAddress,
3130
});
32-
const isNewPool = useIsNewPool({ hyperdrive });
3331
const { longPrice, longPriceStatus } = useCurrentLongPrice({
3432
chainId: hyperdrive.chainId,
3533
hyperdriveAddress: hyperdrive.address,
@@ -40,15 +38,18 @@ export function VariableApyStat({
4038
? `${calculateMarketYieldMultiplier(longPrice).format({ decimals: 1 })}x`
4139
: undefined;
4240

43-
if (!appConfigRewards?.length && multiplierLabel && yieldSourceRate) {
41+
if (yieldSourceRateStatus !== "success") {
42+
return <Skeleton width={100} />;
43+
}
44+
if (!rewards?.length && multiplierLabel && yieldSourceRate) {
4445
return (
4546
<div className="flex items-center gap-2 whitespace-nowrap">
4647
<PercentLabel
4748
value={formatRate({
4849
rate: yieldSourceRate.netVaultRate,
4950
includePercentSign: false,
5051
})}
51-
className="text-h4"
52+
className="mr-1 text-h4"
5253
/>
5354
<GradientBadge>{multiplierLabel}</GradientBadge>
5455
</div>
@@ -62,18 +63,15 @@ export function VariableApyStat({
6263
baseRate={yieldSourceRate?.vaultRate}
6364
netRate={yieldSourceRate?.netVaultRate}
6465
>
65-
{yieldSourceRateStatus === "success" ? (
66-
<PercentLabel
67-
value={formatRate({
68-
rate: yieldSourceRate?.netVaultRate ?? 0n,
69-
includePercentSign: false,
70-
})}
71-
className="text-h4"
72-
/>
73-
) : (
74-
<Skeleton width={100} />
75-
)}
76-
<GradientBadge>{multiplierLabel}</GradientBadge>
66+
<PercentLabel
67+
value={formatRate({
68+
rate: yieldSourceRate?.netVaultRate ?? 0n,
69+
includePercentSign: false,
70+
})}
71+
className="mr-2 text-h4"
72+
/>
73+
<GradientBadge>{multiplierLabel}</GradientBadge>
74+
<span className="mx-1"></span>
7775
</RewardsTooltip>
7876
);
7977
}

apps/hyperdrive-trading/src/ui/rewards/RewardsTooltip.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,14 @@ export function RewardsTooltip({
4444

4545
if (!appConfigRewards?.length && multiplierLabel && (!netRate || !baseRate)) {
4646
return (
47-
<div className="flex items-center gap-2 whitespace-nowrap">
48-
{children}
49-
</div>
47+
<div className="flex items-center whitespace-nowrap">{children}</div>
5048
);
5149
}
5250

5351
return (
5452
<Tooltip.Provider>
5553
<Tooltip.Root>
56-
<Tooltip.Trigger className="flex items-center gap-2 whitespace-nowrap">
54+
<Tooltip.Trigger className="flex items-center whitespace-nowrap">
5755
{children}
5856
</Tooltip.Trigger>
5957
<Tooltip.Portal>

0 commit comments

Comments
 (0)