feat(deal-ticket): show worst case instead of ranges in estimated values (#4870)
This commit is contained in:
parent
cd5c73d3fd
commit
89b3c06107
@ -12,6 +12,7 @@ import { formatRange, formatValue } from '@vegaprotocol/utils';
|
|||||||
import { marketMarginDataProvider } from '@vegaprotocol/accounts';
|
import { marketMarginDataProvider } from '@vegaprotocol/accounts';
|
||||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||||
import * as AccordionPrimitive from '@radix-ui/react-accordion';
|
import * as AccordionPrimitive from '@radix-ui/react-accordion';
|
||||||
|
import * as Schema from '@vegaprotocol/types';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MARGIN_DIFF_TOOLTIP_TEXT,
|
MARGIN_DIFF_TOOLTIP_TEXT,
|
||||||
@ -87,6 +88,7 @@ export interface DealTicketMarginDetailsProps {
|
|||||||
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
||||||
assetSymbol: string;
|
assetSymbol: string;
|
||||||
positionEstimate: EstimatePositionQuery['estimatePosition'];
|
positionEstimate: EstimatePositionQuery['estimatePosition'];
|
||||||
|
side: Schema.Side;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DealTicketMarginDetails = ({
|
export const DealTicketMarginDetails = ({
|
||||||
@ -96,6 +98,7 @@ export const DealTicketMarginDetails = ({
|
|||||||
market,
|
market,
|
||||||
onMarketClick,
|
onMarketClick,
|
||||||
positionEstimate,
|
positionEstimate,
|
||||||
|
side,
|
||||||
}: DealTicketMarginDetailsProps) => {
|
}: DealTicketMarginDetailsProps) => {
|
||||||
const [breakdownDialog, setBreakdownDialog] = useState(false);
|
const [breakdownDialog, setBreakdownDialog] = useState(false);
|
||||||
const { pubKey: partyId } = useVegaWallet();
|
const { pubKey: partyId } = useVegaWallet();
|
||||||
@ -165,10 +168,7 @@ export const DealTicketMarginDetails = ({
|
|||||||
: '0',
|
: '0',
|
||||||
assetDecimals
|
assetDecimals
|
||||||
)}
|
)}
|
||||||
formattedValue={formatRange(
|
formattedValue={formatValue(
|
||||||
deductionFromCollateralBestCase > 0
|
|
||||||
? deductionFromCollateralBestCase.toString()
|
|
||||||
: '0',
|
|
||||||
deductionFromCollateralWorstCase > 0
|
deductionFromCollateralWorstCase > 0
|
||||||
? deductionFromCollateralWorstCase.toString()
|
? deductionFromCollateralWorstCase.toString()
|
||||||
: '0',
|
: '0',
|
||||||
@ -187,8 +187,7 @@ export const DealTicketMarginDetails = ({
|
|||||||
marginEstimate?.worstCase.initialLevel,
|
marginEstimate?.worstCase.initialLevel,
|
||||||
assetDecimals
|
assetDecimals
|
||||||
)}
|
)}
|
||||||
formattedValue={formatRange(
|
formattedValue={formatValue(
|
||||||
marginEstimate?.bestCase.initialLevel,
|
|
||||||
marginEstimate?.worstCase.initialLevel,
|
marginEstimate?.worstCase.initialLevel,
|
||||||
assetDecimals,
|
assetDecimals,
|
||||||
quantum
|
quantum
|
||||||
@ -200,6 +199,7 @@ export const DealTicketMarginDetails = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
let liquidationPriceEstimate = emptyValue;
|
let liquidationPriceEstimate = emptyValue;
|
||||||
|
let liquidationPriceEstimateRange = emptyValue;
|
||||||
|
|
||||||
if (liquidationEstimate) {
|
if (liquidationEstimate) {
|
||||||
const liquidationEstimateBestCaseIncludingBuyOrders = BigInt(
|
const liquidationEstimateBestCaseIncludingBuyOrders = BigInt(
|
||||||
@ -209,8 +209,7 @@ export const DealTicketMarginDetails = ({
|
|||||||
liquidationEstimate.bestCase.including_sell_orders.replace(/\..*/, '')
|
liquidationEstimate.bestCase.including_sell_orders.replace(/\..*/, '')
|
||||||
);
|
);
|
||||||
const liquidationEstimateBestCase =
|
const liquidationEstimateBestCase =
|
||||||
liquidationEstimateBestCaseIncludingBuyOrders >
|
side === Schema.Side.SIDE_BUY
|
||||||
liquidationEstimateBestCaseIncludingSellOrders
|
|
||||||
? liquidationEstimateBestCaseIncludingBuyOrders
|
? liquidationEstimateBestCaseIncludingBuyOrders
|
||||||
: liquidationEstimateBestCaseIncludingSellOrders;
|
: liquidationEstimateBestCaseIncludingSellOrders;
|
||||||
|
|
||||||
@ -221,14 +220,19 @@ export const DealTicketMarginDetails = ({
|
|||||||
liquidationEstimate.worstCase.including_sell_orders.replace(/\..*/, '')
|
liquidationEstimate.worstCase.including_sell_orders.replace(/\..*/, '')
|
||||||
);
|
);
|
||||||
const liquidationEstimateWorstCase =
|
const liquidationEstimateWorstCase =
|
||||||
liquidationEstimateWorstCaseIncludingBuyOrders >
|
side === Schema.Side.SIDE_BUY
|
||||||
liquidationEstimateWorstCaseIncludingSellOrders
|
|
||||||
? liquidationEstimateWorstCaseIncludingBuyOrders
|
? liquidationEstimateWorstCaseIncludingBuyOrders
|
||||||
: liquidationEstimateWorstCaseIncludingSellOrders;
|
: liquidationEstimateWorstCaseIncludingSellOrders;
|
||||||
|
|
||||||
// The estimate order query API gives us the liquidation price in formatted by asset decimals.
|
// The estimate order query API gives us the liquidation price in formatted by asset decimals.
|
||||||
// We need to calculate it with asset decimals, but display it with market decimals precision until the API changes.
|
// We need to calculate it with asset decimals, but display it with market decimals precision until the API changes.
|
||||||
liquidationPriceEstimate = formatRange(
|
liquidationPriceEstimate = formatValue(
|
||||||
|
liquidationEstimateWorstCase.toString(),
|
||||||
|
assetDecimals,
|
||||||
|
undefined,
|
||||||
|
market.decimalPlaces
|
||||||
|
);
|
||||||
|
liquidationPriceEstimateRange = formatRange(
|
||||||
(liquidationEstimateBestCase < liquidationEstimateWorstCase
|
(liquidationEstimateBestCase < liquidationEstimateWorstCase
|
||||||
? liquidationEstimateBestCase
|
? liquidationEstimateBestCase
|
||||||
: liquidationEstimateWorstCase
|
: liquidationEstimateWorstCase
|
||||||
@ -287,8 +291,7 @@ export const DealTicketMarginDetails = ({
|
|||||||
noUnderline
|
noUnderline
|
||||||
>
|
>
|
||||||
<div className="font-mono text-right">
|
<div className="font-mono text-right">
|
||||||
{formatRange(
|
{formatValue(
|
||||||
marginRequiredBestCase,
|
|
||||||
marginRequiredWorstCase,
|
marginRequiredWorstCase,
|
||||||
assetDecimals,
|
assetDecimals,
|
||||||
quantum
|
quantum
|
||||||
@ -346,7 +349,7 @@ export const DealTicketMarginDetails = ({
|
|||||||
{projectedMargin}
|
{projectedMargin}
|
||||||
<KeyValue
|
<KeyValue
|
||||||
label={t('Liquidation')}
|
label={t('Liquidation')}
|
||||||
value={liquidationPriceEstimate}
|
value={liquidationPriceEstimateRange}
|
||||||
formattedValue={liquidationPriceEstimate}
|
formattedValue={liquidationPriceEstimate}
|
||||||
symbol={quoteName}
|
symbol={quoteName}
|
||||||
labelDescription={LIQUIDATION_PRICE_ESTIMATE_TOOLTIP_TEXT}
|
labelDescription={LIQUIDATION_PRICE_ESTIMATE_TOOLTIP_TEXT}
|
||||||
|
@ -676,6 +676,7 @@ export const DealTicket = ({
|
|||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
<DealTicketMarginDetails
|
<DealTicketMarginDetails
|
||||||
|
side={normalizedOrder.side}
|
||||||
onMarketClick={onMarketClick}
|
onMarketClick={onMarketClick}
|
||||||
assetSymbol={assetSymbol}
|
assetSymbol={assetSymbol}
|
||||||
marginAccountBalance={marginAccountBalance}
|
marginAccountBalance={marginAccountBalance}
|
||||||
|
Loading…
Reference in New Issue
Block a user