Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ConnectWalletButton } from "src/ui/compliance/ConnectWallet";
import { LpCurrentValueCell } from "src/ui/hyperdrive/lp/LpAndWithdrawalSharesTable/LpCurrentValueCell";
import { ManageLpAndWithdrawalSharesButton } from "src/ui/hyperdrive/lp/LpAndWithdrawalSharesTable/ManageLpAndWithdrawalSharesButton";
import { SizeAndPoolShareCell } from "src/ui/hyperdrive/lp/LpAndWithdrawalSharesTable/SizeAndPoolShareCell";
import { TotalLpValue } from "src/ui/hyperdrive/lp/LpAndWithdrawalSharesTable/TotalLpValue";
import { WithdrawalQueueCell } from "src/ui/hyperdrive/lp/LpAndWithdrawalSharesTable/WithdrawalQueueCell";
import { AssetStack } from "src/ui/markets/AssetStack";
import { usePortfolioLpData } from "src/ui/portfolio/usePortfolioLpData";
Expand Down Expand Up @@ -128,6 +129,7 @@ export function LpAndWithdrawalSharesContainer(): ReactElement {
{hyperdrive.name.replace(/\d{1,3}d/, "")}
</p>
</div>
<TotalLpValue hyperdrive={hyperdrive} />
</div>
<OpenLpTableDesktop
hyperdrive={hyperdrive}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { fixed } from "@delvtech/fixed-point-wasm";
import {
appConfig,
findBaseToken,
HyperdriveConfig,
} from "@delvtech/hyperdrive-appconfig";

import { ReactElement } from "react";
import Skeleton from "react-loading-skeleton";
import { formatBalance } from "src/ui/base/formatting/formatBalance";
import { useOpenLpPosition } from "src/ui/hyperdrive/lp/hooks/useOpenLpPosition";
import { useTokenFiatPrice } from "src/ui/token/hooks/useTokenFiatPrice";
import { useAccount } from "wagmi";
import { sepolia } from "wagmi/chains";

export function TotalLpValue({
hyperdrive,
}: {
hyperdrive: HyperdriveConfig;
}): ReactElement {
const { address: account } = useAccount();
const chainInfo = appConfig.chains[hyperdrive.chainId];
const baseToken = findBaseToken({
hyperdriveChainId: hyperdrive.chainId,
hyperdriveAddress: hyperdrive.address,
appConfig,
});
const { baseValue, openLpPositionStatus } = useOpenLpPosition({
hyperdriveAddress: hyperdrive.address,
account,
chainId: hyperdrive.chainId,
});

const { fiatPrice } = useTokenFiatPrice({
chainId: baseToken.chainId,
tokenAddress: baseToken.address,
});
const isFiatPriceEnabled = chainInfo.id !== sepolia.id;

return (
<div className="flex items-center gap-2">
<img src={chainInfo.iconUrl} className="size-7 rounded-full" />
<p className="flex gap-2 font-dmMono text-h4">
{openLpPositionStatus === "loading" ? (
<Skeleton className="w-24" />
) : isFiatPriceEnabled ? (
`$${formatBalance({
balance: fiatPrice
? fixed(baseValue, baseToken.decimals).mul(
fiatPrice,
baseToken.decimals,
).bigint
: 0n,
decimals: hyperdrive.decimals,
places: baseToken?.places,
})}`
) : (
`${formatBalance({
balance: baseValue,
decimals: hyperdrive.decimals,
places: baseToken?.places,
})} ${baseToken.symbol}`
)}{" "}
</p>
</div>
);
}
Loading