fix(trading): condense deal ticket & market info price range snags (#3012)

This commit is contained in:
m.ray 2023-02-27 13:04:13 -05:00 committed by GitHub
parent a02100b079
commit 4eb6e09bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 96 additions and 69 deletions

View File

@ -184,9 +184,8 @@ export const MarketDetails = ({
content: ( content: (
<> <>
<p className="text-xs mb-4"> <p className="text-xs mb-4">
{`For liquidity orders count towards a commitment they have to be {`For liquidity orders to count towards a commitment, they must be
within either the liquidity or price monitoring bounds (whichever is within the liquidity monitoring bounds.`}
tighter).`}
</p> </p>
<p className="text-xs mb-4"> <p className="text-xs mb-4">
{`The liquidity price range is a ${liquidityPriceRange} difference from the mid {`The liquidity price range is a ${liquidityPriceRange} difference from the mid

View File

@ -98,7 +98,7 @@ export const AssetDetailsDialog = ({
}} }}
> >
{content} {content}
<p className="text-sm mb-4"> <p className="text-sm my-4">
{t( {t(
'There is 1 unit of the settlement asset (%s) to every 1 quote unit.', 'There is 1 unit of the settlement asset (%s) to every 1 quote unit.',
[assetSymbol] [assetSymbol]

View File

@ -12,7 +12,7 @@ export const DealTicketButton = ({ disabled, variant }: Props) => {
const { pubKey, isReadOnly } = useVegaWallet(); const { pubKey, isReadOnly } = useVegaWallet();
const isDisabled = !pubKey || isReadOnly || disabled; const isDisabled = !pubKey || isReadOnly || disabled;
return ( return (
<div className="mb-4"> <div className="mb-2">
<Button <Button
variant={variant} variant={variant}
fill fill

View File

@ -31,7 +31,7 @@ export const DealTicketFeeDetails = ({
<div> <div>
{details.map(({ label, value, labelDescription, symbol }) => ( {details.map(({ label, value, labelDescription, symbol }) => (
<div <div
key={label} key={typeof label === 'string' ? label : 'value-dropdown'}
className="text-xs mt-2 flex justify-between items-center gap-4 flex-wrap" className="text-xs mt-2 flex justify-between items-center gap-4 flex-wrap"
> >
<div> <div>

View File

@ -38,7 +38,7 @@ export const DealTicketLimitAmount = ({
}; };
return ( return (
<div className="mb-6"> <div className="mb-2">
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
<div className="flex-1"> <div className="flex-1">
<FormGroup <FormGroup

View File

@ -29,9 +29,9 @@ export const DealTicketMarketAmount = ({
: undefined; : undefined;
return ( return (
<div className="mb-6"> <div className="mb-2">
<div className="flex items-end gap-4 mb-2"> <div className="flex items-end gap-4 mb-2">
<div className="flex-1 text-sm">Size</div> <div className="flex-1 text-sm">{t('Size')}</div>
<div /> <div />
<div className="flex-2 text-sm text-right"> <div className="flex-2 text-sm text-right">
{isMarketInAuction(marketData.marketTradingMode) && ( {isMarketInAuction(marketData.marketTradingMode) && (

View File

@ -307,7 +307,7 @@ const SummaryMessage = memo(
); );
if (isReadOnly) { if (isReadOnly) {
return ( return (
<div className="mb-4"> <div className="mb-2">
<InputError testId="dealticket-error-message-summary"> <InputError testId="dealticket-error-message-summary">
{ {
'You need to connect your own wallet to start trading on this market' 'You need to connect your own wallet to start trading on this market'
@ -318,7 +318,7 @@ const SummaryMessage = memo(
} }
if (!pubKey) { if (!pubKey) {
return ( return (
<div className="mb-4"> <div className="mb-2">
<Notification <Notification
testId={'deal-ticket-connect-wallet'} testId={'deal-ticket-connect-wallet'}
intent={Intent.Warning} intent={Intent.Warning}
@ -343,7 +343,7 @@ const SummaryMessage = memo(
} }
if (errorMessage === SummaryValidationType.NoCollateral) { if (errorMessage === SummaryValidationType.NoCollateral) {
return ( return (
<div className="mb-4"> <div className="mb-2">
<ZeroBalanceError <ZeroBalanceError
asset={market.tradableInstrument.instrument.product.settlementAsset} asset={market.tradableInstrument.instrument.product.settlementAsset}
onClickCollateral={onClickCollateral} onClickCollateral={onClickCollateral}
@ -356,7 +356,7 @@ const SummaryMessage = memo(
// submission render that first // submission render that first
if (errorMessage) { if (errorMessage) {
return ( return (
<div className="mb-4"> <div className="mb-2">
<InputError testId="dealticket-error-message-summary"> <InputError testId="dealticket-error-message-summary">
{errorMessage} {errorMessage}
</InputError> </InputError>
@ -368,7 +368,7 @@ const SummaryMessage = memo(
// balance render the margin warning, but still allow submission // balance render the margin warning, but still allow submission
if (balanceError) { if (balanceError) {
return ( return (
<div className="mb-4"> <div className="mb-2">
<MarginWarning balance={balance} margin={margin} asset={asset} />; <MarginWarning balance={balance} margin={margin} asset={asset} />;
</div> </div>
); );
@ -383,7 +383,7 @@ const SummaryMessage = memo(
].includes(marketData.marketTradingMode) ].includes(marketData.marketTradingMode)
) { ) {
return ( return (
<div className="mb-4"> <div className="mb-2">
<Notification <Notification
intent={Intent.Warning} intent={Intent.Warning}
testId={'dealticket-warning-auction'} testId={'dealticket-warning-auction'}

View File

@ -145,7 +145,7 @@ export const Info = ({ market, onSelect }: InfoProps) => {
}} }}
decimalPlaces={market.decimalPlaces} decimalPlaces={market.decimalPlaces}
/> />
<p className="text-xs"> <p className="text-xs mt-4">
{t( {t(
'There is 1 unit of the settlement asset (%s) to every 1 quote unit (%s).', 'There is 1 unit of the settlement asset (%s) to every 1 quote unit (%s).',
[assetSymbol, quoteUnit] [assetSymbol, quoteUnit]
@ -249,7 +249,7 @@ export const Info = ({ market, onSelect }: InfoProps) => {
dtClassName="text-black dark:text-white text-ui !px-0 !font-normal" dtClassName="text-black dark:text-white text-ui !px-0 !font-normal"
ddClassName="text-black dark:text-white text-ui !px-0 !font-normal max-w-full" ddClassName="text-black dark:text-white text-ui !px-0 !font-normal max-w-full"
/> />
<p className="text-xs"> <p className="text-xs mt-4">
{t( {t(
'There is 1 unit of the settlement asset (%s) to every 1 quote unit (%s).', 'There is 1 unit of the settlement asset (%s) to every 1 quote unit (%s).',
[assetSymbol, quoteUnit] [assetSymbol, quoteUnit]
@ -309,27 +309,40 @@ export const Info = ({ market, onSelect }: InfoProps) => {
), ),
}, },
...(market.priceMonitoringSettings?.parameters?.triggers || []).map( ...(market.priceMonitoringSettings?.parameters?.triggers || []).map(
(trigger, i) => ({ (trigger, i) => {
title: t(`Price monitoring trigger ${i + 1}`), const bounds = market.data?.priceMonitoringBounds?.[i];
content: <MarketInfoTable data={trigger} />, return {
}) title: t(`Price monitoring bounds ${i + 1}`),
),
...(market.data?.priceMonitoringBounds || []).map((trigger, i) => ({
title: t(`Price monitoring bound ${i + 1}`),
content: ( content: (
<> <div className="text-xs">
<div className="grid grid-cols-2 text-xs mb-4">
<p className="col-span-1">
{t('%s% probability of trading', [
formatNumber(trigger.probability * 100),
])}
</p>
<p className="col-span-1 text-right">
{t('Within %s seconds', [formatNumber(trigger.horizonSecs)])}
</p>
</div>
<div className="pl-2 pb-0 text-xs border-l-2">
{bounds && (
<MarketInfoTable <MarketInfoTable
data={trigger} data={{
decimalPlaces={market.decimalPlaces} highestPrice: bounds.maxValidPrice,
omits={['referencePrice', '__typename']} lowestPrice: bounds.minValidPrice,
/> referencePrice: bounds.referencePrice,
<MarketInfoTable }}
data={{ referencePrice: trigger.referencePrice }}
decimalPlaces={assetDecimals} decimalPlaces={assetDecimals}
assetSymbol={quoteUnit}
/> />
</> )}
</div>
</div>
),
};
}
), ),
})),
{ {
title: t('Liquidity monitoring parameters'), title: t('Liquidity monitoring parameters'),
content: ( content: (
@ -369,14 +382,14 @@ export const Info = ({ market, onSelect }: InfoProps) => {
content: ( content: (
<> <>
<p className="text-xs mb-4"> <p className="text-xs mb-4">
{`For liquidity orders count towards a commitment they have to be {`For liquidity orders to count towards a commitment, they must be
within either the liquidity or price monitoring bounds (whichever is within the liquidity monitoring bounds.`}
tighter).`}
</p> </p>
<p className="text-xs mb-4"> <p className="text-xs mb-4">
{`The liquidity price range is a ${liquidityPriceRange} difference from the mid {`The liquidity price range is a ${liquidityPriceRange} difference from the mid
price.`} price.`}
</p> </p>
<div className="pl-2 pb-0 text-xs border-l-2">
<MarketInfoTable <MarketInfoTable
data={{ data={{
liquidityPriceRange: `${liquidityPriceRange} of mid price`, liquidityPriceRange: `${liquidityPriceRange} of mid price`,
@ -400,6 +413,7 @@ export const Info = ({ market, onSelect }: InfoProps) => {
)} ${quoteUnit}`, )} ${quoteUnit}`,
}} }}
></MarketInfoTable> ></MarketInfoTable>
</div>
</> </>
), ),
}, },

View File

@ -6,6 +6,7 @@ import {
formatNumber, formatNumber,
formatNumberPercentage, formatNumberPercentage,
isNumeric, isNumeric,
toDecimal,
toNumberParts, toNumberParts,
} from './number'; } from './number';
@ -197,3 +198,20 @@ describe('compactNumber', () => {
} }
); );
}); });
describe('toDecimal', () => {
it.each([
{ v: 0, o: '1' },
{ v: 1, o: '0.1' },
{ v: 2, o: '0.01' },
{ v: 3, o: '0.001' },
{ v: 4, o: '0.0001' },
{ v: 5, o: '0.00001' },
{ v: 6, o: '0.000001' },
{ v: 7, o: '0.0000001' },
{ v: 8, o: '0.00000001' },
{ v: 9, o: '0.000000001' },
])('formats with toNumber given number correctly', ({ v, o }) => {
expect(toDecimal(v)).toStrictEqual(o);
});
});

View File

@ -20,7 +20,7 @@ export const FormGroup = ({
labelAlign = 'left', labelAlign = 'left',
hideLabel = false, hideLabel = false,
}: FormGroupProps) => { }: FormGroupProps) => {
const wrapperClasses = classNames('relative mb-6', className); const wrapperClasses = classNames('relative mb-2', className);
const labelClasses = classNames('block mb-2 text-sm', { const labelClasses = classNames('block mb-2 text-sm', {
'text-right': labelAlign === 'right', 'text-right': labelAlign === 'right',
'sr-only': hideLabel, 'sr-only': hideLabel,

View File

@ -24,11 +24,7 @@ export const KeyValueTable = ({
return ( return (
<React.Fragment> <React.Fragment>
{title && <TitleTag className={`text-xl my-2`}>{title}</TitleTag>} {title && <TitleTag className={`text-xl my-2`}>{title}</TitleTag>}
<div <div data-testid="key-value-table" {...rest} className={className}>
data-testid="key-value-table"
{...rest}
className={classNames('mb-4', className)}
>
<div> <div>
{children && {children &&
React.Children.map( React.Children.map(