-
Notifications
You must be signed in to change notification settings - Fork 2
Polish open and close position modals #1188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
efd6913
34613bc
ea0495e
46a285e
4931c4a
57fb2fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Long, calculateAprFromPrice } from "@delvtech/hyperdrive-viem"; | ||
import { calculateAprFromPrice } from "@delvtech/hyperdrive-viem"; | ||
import { ArrowRightIcon } from "@heroicons/react/16/solid"; | ||
import { | ||
HyperdriveConfig, | ||
|
@@ -20,7 +20,8 @@ import { useFixedRate } from "src/ui/hyperdrive/longs/hooks/useFixedRate"; | |
|
||
interface OpenLongPreviewProps { | ||
hyperdrive: HyperdriveConfig; | ||
long: Long; | ||
bondAmount: bigint; | ||
amountPaid: bigint; | ||
openLongPreviewStatus: "error" | "idle" | "loading" | "success"; | ||
spotRateAfterOpen: bigint | undefined; | ||
activeToken: TokenConfig<any>; | ||
|
@@ -31,8 +32,9 @@ interface OpenLongPreviewProps { | |
|
||
export function OpenLongPreview({ | ||
hyperdrive, | ||
long, | ||
openLongPreviewStatus, | ||
amountPaid, | ||
bondAmount, | ||
spotRateAfterOpen, | ||
activeToken, | ||
curveFee, | ||
|
@@ -51,14 +53,23 @@ export function OpenLongPreview({ | |
const { fixedApr } = useFixedRate(hyperdrive.address); | ||
|
||
const isBaseAmount = asBase || sharesToken.extensions.isSharesPeggedToBase; | ||
const amountPaidInBase = isBaseAmount | ||
? amountPaid | ||
: convertSharesToBase({ | ||
sharesAmount: amountPaid, | ||
vaultSharePrice: vaultSharePrice, | ||
decimals: baseToken.decimals, | ||
}); | ||
const yieldAtMaturity = bondAmount - amountPaidInBase; | ||
Comment on lines
55
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this replacing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is different. |
||
|
||
return ( | ||
<div className="flex flex-col gap-3.5 px-2"> | ||
<div className="flex flex-col gap-3"> | ||
<LabelValue | ||
label="You spend" | ||
value={ | ||
<span>{`${formatBalance({ | ||
balance: long.baseAmountPaid, | ||
balance: amountPaid, | ||
decimals: baseToken.decimals, | ||
places: baseToken.places, | ||
})} ${activeToken.symbol}`}</span> | ||
|
@@ -71,7 +82,7 @@ export function OpenLongPreview({ | |
<Skeleton width={100} /> | ||
) : ( | ||
<span className="font-bold">{`${formatBalance({ | ||
balance: long.bondAmount, | ||
balance: bondAmount, | ||
decimals: baseToken.decimals, | ||
places: baseToken.places, | ||
})} hy${baseToken.symbol}`}</span> | ||
|
@@ -109,21 +120,13 @@ export function OpenLongPreview({ | |
className="gradient-text daisy-tooltip daisy-tooltip-top daisy-tooltip-left cursor-help border-b border-dashed border-current before:border" | ||
data-tip="Your net fixed rate after pool fees and slippage are applied." | ||
> | ||
{long.bondAmount > 0 | ||
{bondAmount > 0 | ||
? `${formatRate( | ||
calculateAprFromPrice({ | ||
positionDuration: | ||
hyperdrive.poolConfig.positionDuration || 0n, | ||
baseAmount: isBaseAmount | ||
? long.baseAmountPaid | ||
: // TODO: move sharesAmountPaid into the sdk's Long interface | ||
// instead of converting here | ||
convertSharesToBase({ | ||
sharesAmount: long.baseAmountPaid, | ||
vaultSharePrice: vaultSharePrice, | ||
decimals: activeToken.decimals, | ||
}), | ||
bondAmount: long.bondAmount, | ||
baseAmount: amountPaidInBase, | ||
bondAmount: bondAmount, | ||
}), | ||
baseToken.decimals, | ||
)}%` | ||
|
@@ -142,30 +145,12 @@ export function OpenLongPreview({ | |
className="daisy-tooltip daisy-tooltip-top daisy-tooltip-left cursor-help before:border" | ||
data-tip={`Total ${baseToken.symbol} expected in return at the end of the term, excluding fees.`} | ||
> | ||
{long.bondAmount > 0 ? ( | ||
{bondAmount > 0 ? ( | ||
<span className="cursor-help border-b border-dashed border-success text-success"> | ||
{long.bondAmount - | ||
(isBaseAmount | ||
? long.baseAmountPaid | ||
: convertSharesToBase({ | ||
sharesAmount: long.baseAmountPaid, | ||
vaultSharePrice: vaultSharePrice, | ||
decimals: baseToken.decimals, | ||
})) | ||
? "+" | ||
: ""} | ||
{long.baseAmountPaid | ||
{yieldAtMaturity | ||
? // TODO: Add ROI here in parenthesis after the yield amount | ||
`${formatBalance({ | ||
balance: | ||
long.bondAmount - | ||
(isBaseAmount | ||
? long.baseAmountPaid | ||
: convertSharesToBase({ | ||
sharesAmount: long.baseAmountPaid, | ||
vaultSharePrice: vaultSharePrice, | ||
decimals: baseToken.decimals, | ||
})), | ||
`+${formatBalance({ | ||
balance: yieldAtMaturity, | ||
decimals: baseToken.decimals, | ||
places: baseToken.places, | ||
})} ${baseToken.symbol}` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: A small doc block over the option could help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh good call