From 4b7338ed943c6f1ad9cfe959aa9040059744992b Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Fri, 17 Nov 2023 10:33:24 -0800 Subject: [PATCH] chore(deal-ticket,markets): dont show margin estimate for perps (#5305) --- .../deal-ticket/deal-ticket-fee-details.tsx | 190 ++++++++++-------- libs/markets/src/lib/market-utils.ts | 16 ++ 2 files changed, 119 insertions(+), 87 deletions(-) diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket-fee-details.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket-fee-details.tsx index 075d3225f..e7b2cfb10 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket-fee-details.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket-fee-details.tsx @@ -1,6 +1,6 @@ import { useCallback, useState } from 'react'; import { t } from '@vegaprotocol/i18n'; -import { getAsset, getQuoteName } from '@vegaprotocol/markets'; +import { getAsset, getProductType, getQuoteName } from '@vegaprotocol/markets'; import type { OrderSubmissionBody } from '@vegaprotocol/wallet'; import { useVegaWallet } from '@vegaprotocol/wallet'; @@ -286,99 +286,115 @@ export const DealTicketMarginDetails = ({ ); const quoteName = getQuoteName(market); + const productType = getProductType(market); return ( -
- - -
-
- - {t('Margin required')} - +
+ {/* + TODO: remove this conditional check once the following PRs are deployed + and the estimatePosition query is working for perps - -
- + + -
- {formatValue( - marginRequiredWorstCase, +
+
+ + + {t('Margin required')} + + + + +
+ +
+ {formatValue( + marginRequiredWorstCase, + assetDecimals, + quantum + )}{' '} + {assetSymbol || ''} +
+
+
+ + } + > +
+ - + ), + assetSymbol + )} + /> + {deductionFromCollateral} + setBreakdownDialog(true) + : undefined + } + value={formatValue(marginAccountBalance, assetDecimals)} + symbol={assetSymbol} + labelDescription={MARGIN_ACCOUNT_TOOLTIP_TEXT} + formattedValue={formatValue( + marginAccountBalance, + assetDecimals, + quantum + )} + />
- - } - > -
- - {deductionFromCollateral} - setBreakdownDialog(true) - : undefined - } - value={formatValue(marginAccountBalance, assetDecimals)} - symbol={assetSymbol} - labelDescription={MARGIN_ACCOUNT_TOOLTIP_TEXT} - formattedValue={formatValue( - marginAccountBalance, - assetDecimals, - quantum - )} - /> -
- - - {projectedMargin} + + + {projectedMargin} + + )} ) => { throw new Error('Failed to retrieve asset. Invalid product type'); }; +export const getProductType = (market: Partial) => { + if (!market.tradableInstrument?.instrument.product) { + throw new Error( + 'Failed to retrieve product type. Invalid tradable instrument' + ); + } + + const type = market.tradableInstrument.instrument.product.__typename; + + if (!type) { + throw new Error('Failed to retrieve asset. Invalid product type'); + } + + return type; +}; + export const getQuoteName = (market: Partial) => { if (!market.tradableInstrument?.instrument.product) { throw new Error(