diff --git a/apps/hyperdrive-trading/src/ui/base/components/PrimaryStat.tsx b/apps/hyperdrive-trading/src/ui/base/components/PrimaryStat.tsx index 2a29d908d..2272e6712 100644 --- a/apps/hyperdrive-trading/src/ui/base/components/PrimaryStat.tsx +++ b/apps/hyperdrive-trading/src/ui/base/components/PrimaryStat.tsx @@ -27,7 +27,7 @@ export function PrimaryStat({ return (
-

{label}

+

{label}

{tooltipContent && (
{ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (window as any)["withdrawalLpModal"]?.close(); + ( + document.getElementById("withdrawalLpModal") as HTMLDialogElement + )?.close(); }, onExecuted: () => { setAmount(""); @@ -196,124 +213,147 @@ export function RemoveLiquidityForm({ }); } + const poolShareRemaining = + lpSharesTotalSupplyStatus === "success" + ? (() => { + // Calculate the ratio of remaining shares to the total supply + const ratio = calculateRatio({ + a: lpShares - (lpSharesIn || 0n) - (withdrawalShares || 0n), // Remaining LP Shares in pool after removing input value lpShares and withdrawalShares received + b: lpSharesTotalSupply || 0n, + decimals: hyperdrive?.decimals, + }); + // Ensure the ratio is not negative + return ratio < 0n ? 0n : ratio; + })() + : 0n; + return ( - setActiveWithdrawToken(tokenAddress)} - tokens={withdrawTokenChoices} - /> - } + - {" "} - - {baseToken.symbol}-LP - -
- } - settings={ - - } - value={amount ?? ""} - maxValue={formatUnits(lpShares, baseToken.decimals)} - stat={ -
- - {lpShares && !!poolInfo - ? `Withdrawable: ${formatBalance({ - balance: lpShares, - decimals: hyperdrive.decimals, - places: baseToken.places, - })} ${baseToken.symbol}-LP` - : undefined} +
+ + } + value={amount ?? ""} + maxValue={formatUnits(lpShares, baseToken.decimals)} + bottomRightElement={ + + {`Withdrawable: ${formatBalance({ + balance: lpShares, + decimals: baseToken.decimals, + places: baseToken.places, + })}`} - {`Slippage: ${slippage || "0.5"}%`} -
- } - onChange={(newAmount) => setAmount(newAmount)} - /> - } - transactionPreview={ -
- setAmount(newAmount)} /> - + setActiveWithdrawToken(tokenAddress) + } + /> + } value={ - - {actualValueOut - ? `${formatBalance({ - balance: actualValueOut, - decimals: activeWithdrawToken.decimals, - places: activeWithdrawToken.places, - })}` - : "0"}{" "} - {activeWithdrawToken.symbol} - + actualValueOut + ? fixed(actualValueOut, hyperdrive.decimals).toString() + : "0" + } + maxValue={ + actualValueOut + ? fixed(actualValueOut, hyperdrive.decimals).toString() + : "" } + disabled + bottomLeftElement={ + // Defillama fetches the token price via {chain}:{tokenAddress}. Since the token address differs on testnet, price display is disabled there. + !isTestnetChain(hyperdrive.chainId) ? ( + + ) : null + } + onChange={(newAmount) => setAmount(newAmount)} /> - + } + primaryStats={ +
+ +
{formattedWithdrawalSharesOut || 0} {baseToken.symbol} - +
+ } + /> +
+ + {poolShareRemaining !== null ? ( + `${fixed(poolShareRemaining).format({ decimals: 4 })}%` + ) : ( + + )} +
} />
} - disclaimer={ - <> - {lpSharesIn && !hasEnoughBalance ? ( -

- Insufficient balance -

- ) : null} - -

- You can withdraw liquidity at any time. The utilized portion may be - queued for delayed withdrawal. -

- - } actionButton={(() => { if (!account) { - return ; + return ; + } + if (connectedChainId !== hyperdrive.chainId) { + return ( + + ); + } + if (!!lpSharesIn && !hasEnoughBalance) { + return ( + + Insufficient balance + + ); } - if (removeLiquidityStatus === "loading") { - return ; + return ; } - return (
{bottomLeftStatistic} -
- +
+ {bottomRightStatistic ? ( + + ) : null} {maxValue !== undefined && !disabled ? ( -
- -
+ ) : null}