fix: deal ticket estimated uncrossing (#1636)

* fix: invalid uncrossing price

* chore: align estimated uncrossing price with size label

* fix: 0 used balance on margin and bond accounts should not be displayed

* fix: small tweaks and bugfixes

* fix: filter empty acounts

* fix: fix unit test

* fix: fix unit test

Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
This commit is contained in:
m.ray 2022-10-07 16:19:01 +01:00 committed by GitHub
parent eb3ca33eae
commit a71f40956b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 43 deletions

View File

@ -114,10 +114,12 @@ const getTotalBalance = (accounts: AccountFieldsFragment[]) =>
accounts.reduce((acc, a) => acc + BigInt(a.balance), BigInt(0)); accounts.reduce((acc, a) => acc + BigInt(a.balance), BigInt(0));
export const getAccountData = (data: Account[]): AccountFields[] => { export const getAccountData = (data: Account[]): AccountFields[] => {
return getAssetIds(data).map((assetId) => { return getAssetIds(data)
const accounts = data.filter((a) => a.asset.id === assetId); .map((assetId) => {
return accounts && getAssetAccountAggregation(accounts, assetId); const accounts = data.filter((a) => a.asset.id === assetId);
}); return accounts && getAssetAccountAggregation(accounts, assetId);
})
.filter((a) => a.deposited !== '0'); // filter empty accounts
}; };
const getAssetAccountAggregation = ( const getAssetAccountAggregation = (
@ -150,7 +152,8 @@ const getAssetAccountAggregation = (
deposited: balanceAccount.deposited, deposited: balanceAccount.deposited,
available: balanceAccount.available, available: balanceAccount.available,
used: a.balance, used: a.balance,
})); }))
.filter((a) => a.used !== '0');
return { ...balanceAccount, breakdown }; return { ...balanceAccount, breakdown };
}; };

View File

@ -38,7 +38,7 @@ describe('AccountsTable', () => {
<AccountTable rowData={singleRowData} onClickAsset={() => null} /> <AccountTable rowData={singleRowData} onClickAsset={() => null} />
); );
}); });
const expectedHeaders = ['Asset', 'Deposited', 'Used', '', '']; const expectedHeaders = ['Asset', 'Total', 'Used', '', ''];
const headers = await screen.findAllByRole('columnheader'); const headers = await screen.findAllByRole('columnheader');
expect(headers).toHaveLength(expectedHeaders.length); expect(headers).toHaveLength(expectedHeaders.length);
expect( expect(

View File

@ -109,8 +109,11 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
maxWidth={300} maxWidth={300}
/> />
<AgGridColumn <AgGridColumn
headerName={t('Deposited')} headerName={t('Total')}
field="deposited" field="deposited"
headerTooltip={t(
'This is the total amount of collateral used plus the amount available in your general account.'
)}
valueFormatter={({ valueFormatter={({
value, value,
data, data,
@ -125,6 +128,7 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
headerName={t('Used')} headerName={t('Used')}
field="used" field="used"
flex={2} flex={2}
minWidth={150}
maxWidth={500} maxWidth={500}
headerComponentParams={progressBarHeaderComponentParams} headerComponentParams={progressBarHeaderComponentParams}
cellRendererSelector={progressBarCellRendererSelector} cellRendererSelector={progressBarCellRendererSelector}
@ -133,7 +137,7 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
<AgGridColumn <AgGridColumn
headerName="" headerName=""
field="breakdown" field="breakdown"
maxWidth={150} minWidth={150}
cellRenderer={({ cellRenderer={({
value, value,
}: VegaICellRendererParams<AccountFields, 'breakdown'>) => { }: VegaICellRendererParams<AccountFields, 'breakdown'>) => {
@ -154,6 +158,7 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
colId="transact" colId="transact"
headerName="" headerName=""
sortable={false} sortable={false}
minWidth={250}
cellRenderer={({ cellRenderer={({
data, data,
}: VegaICellRendererParams<AccountFields>) => { }: VegaICellRendererParams<AccountFields>) => {

View File

@ -37,10 +37,10 @@ describe('BreakdownTable', () => {
render(<BreakdownTable data={singleRowData} />); render(<BreakdownTable data={singleRowData} />);
}); });
const headers = await screen.findAllByRole('columnheader'); const headers = await screen.findAllByRole('columnheader');
expect(headers).toHaveLength(5); expect(headers).toHaveLength(4);
expect( expect(
headers.map((h) => h.querySelector('[ref="eText"]')?.textContent?.trim()) headers.map((h) => h.querySelector('[ref="eText"]')?.textContent?.trim())
).toEqual(['Account type', 'Market', 'Used', 'Deposited', 'Balance']); ).toEqual(['Account type', 'Market', 'Used', 'Balance']);
}); });
it('should apply correct formatting', async () => { it('should apply correct formatting', async () => {

View File

@ -74,21 +74,6 @@ const BreakdownTable = forwardRef<AgGridReact, BreakdownTableProps>(
cellRendererSelector={progressBarCellRendererSelector} cellRendererSelector={progressBarCellRendererSelector}
valueFormatter={progressBarValueFormatter} valueFormatter={progressBarValueFormatter}
/> />
<AgGridColumn
headerName={t('Deposited')}
field="deposited"
valueFormatter={({
value,
data,
}: VegaValueFormatterParams<AccountFields, 'deposited'>) => {
if (data && data.asset) {
return addDecimalsFormatNumber(value, data.asset.decimals);
}
return '-';
}}
maxWidth={300}
/>
<AgGridColumn <AgGridColumn
headerName={t('Balance')} headerName={t('Balance')}
field="balance" field="balance"

View File

@ -17,7 +17,7 @@ export const DealTicketMarketAmount = ({
}: DealTicketMarketAmountProps) => { }: DealTicketMarketAmountProps) => {
const sizeStep = toDecimal(market?.positionDecimalPlaces); const sizeStep = toDecimal(market?.positionDecimalPlaces);
return ( return (
<div className="flex items-center gap-4"> <div className="flex items-center gap-4 relative">
<div className="flex-1"> <div className="flex-1">
<FormGroup label={t('Size')} labelFor="input-order-size-market"> <FormGroup label={t('Size')} labelFor="input-order-size-market">
<Input <Input
@ -44,12 +44,12 @@ export const DealTicketMarketAmount = ({
'This market is in auction. The uncrossing price is an indication of what the price is expected to be when the auction ends.' 'This market is in auction. The uncrossing price is an indication of what the price is expected to be when the auction ends.'
)} )}
> >
<span className={'block mb-2 text-sm text-left'}> <div className="absolute top-0 right-0 text-sm">
{t(`Estimated uncrossing price`)} {t(`Estimated uncrossing price`)}
</span> </div>
</Tooltip> </Tooltip>
)} )}
<span className="text-sm"> <div className="text-sm text-right">
{price && quoteName ? ( {price && quoteName ? (
<> <>
~{price} {quoteName} ~{price} {quoteName}
@ -57,7 +57,7 @@ export const DealTicketMarketAmount = ({
) : ( ) : (
'-' '-'
)} )}
</span> </div>
</div> </div>
</div> </div>
); );

View File

@ -15,8 +15,10 @@ import { ExpirySelector } from './expiry-selector';
import type { OrderSubmissionBody } from '@vegaprotocol/wallet'; import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
import { OrderTimeInForce, OrderType } from '@vegaprotocol/types'; import { OrderTimeInForce, OrderType } from '@vegaprotocol/types';
import { getDefaultOrder } from '../deal-ticket-validation'; import { getDefaultOrder } from '../deal-ticket-validation';
import { useOrderValidation } from '../deal-ticket-validation/use-order-validation'; import {
import { MarketTradingMode } from '@vegaprotocol/types'; isMarketInAuction,
useOrderValidation,
} from '../deal-ticket-validation/use-order-validation';
export type TransactionStatus = 'default' | 'pending'; export type TransactionStatus = 'default' | 'pending';
@ -73,16 +75,15 @@ export const DealTicket = ({
); );
const getPrice = () => { const getPrice = () => {
if ( if (isMarketInAuction(market)) {
market.tradingMode === MarketTradingMode.TRADING_MODE_OPENING_AUCTION || // 0 can never be a valid uncrossing price as it would require there being orders on the book at that price.
market.tradingMode === MarketTradingMode.TRADING_MODE_BATCH_AUCTION if (
) { market.data?.indicativePrice &&
return market.data?.indicativePrice; BigInt(market.data?.indicativePrice) !== BigInt(0)
} ) {
if ( return market.data.indicativePrice;
market.tradingMode === MarketTradingMode.TRADING_MODE_MONITORING_AUCTION }
) { return '-';
return null;
} }
return market.depth.lastTrade?.price; return market.depth.lastTrade?.price;
}; };

View File

@ -77,7 +77,7 @@ export const compileGridData = (
'~' + '~' +
addDecimalsFormatNumber( addDecimalsFormatNumber(
market.data.indicativePrice, market.data.indicativePrice,
market.positionDecimalPlaces market.decimalPlaces
), ),
}); });
} }