chore: improve typing in markets list page on the lpdashboard (#2363)
* chore: add some missing properties to the Market type * chore: improve typing of value formatters in market list page Replacing ValueFormatterParams with VegaValueFormatterParams<T, Y> in a bunch of places. Doing this also highlighted we weren't dealing with a bunch of undefined cases, so we now have fallback formatting for those. Co-authored-by: Madalina Raicu <madalina@raygroup.uk>
This commit is contained in:
parent
1180a5ff97
commit
c217741924
@ -11,6 +11,7 @@ import {
|
|||||||
t,
|
t,
|
||||||
toBigNum,
|
toBigNum,
|
||||||
} from '@vegaprotocol/react-helpers';
|
} from '@vegaprotocol/react-helpers';
|
||||||
|
import type { VegaValueFormatterParams } from '@vegaprotocol/ui-toolkit';
|
||||||
import type * as Schema from '@vegaprotocol/types';
|
import type * as Schema from '@vegaprotocol/types';
|
||||||
import {
|
import {
|
||||||
AsyncRenderer,
|
AsyncRenderer,
|
||||||
@ -18,11 +19,7 @@ import {
|
|||||||
PriceCellChange,
|
PriceCellChange,
|
||||||
TooltipCellComponent,
|
TooltipCellComponent,
|
||||||
} from '@vegaprotocol/ui-toolkit';
|
} from '@vegaprotocol/ui-toolkit';
|
||||||
import type {
|
import type { GetRowIdParams, RowClickedEvent } from 'ag-grid-community';
|
||||||
GetRowIdParams,
|
|
||||||
RowClickedEvent,
|
|
||||||
ValueFormatterParams,
|
|
||||||
} from 'ag-grid-community';
|
|
||||||
import 'ag-grid-community/dist/styles/ag-grid.css';
|
import 'ag-grid-community/dist/styles/ag-grid.css';
|
||||||
import 'ag-grid-community/dist/styles/ag-theme-alpine.css';
|
import 'ag-grid-community/dist/styles/ag-theme-alpine.css';
|
||||||
import { AgGridColumn } from 'ag-grid-react';
|
import { AgGridColumn } from 'ag-grid-react';
|
||||||
@ -115,19 +112,26 @@ export const MarketList = () => {
|
|||||||
headerName={t('Last Price')}
|
headerName={t('Last Price')}
|
||||||
headerTooltip={t('Latest price for this market')}
|
headerTooltip={t('Latest price for this market')}
|
||||||
field="data.markPrice"
|
field="data.markPrice"
|
||||||
valueFormatter={({ value, data }: ValueFormatterParams) =>
|
valueFormatter={({
|
||||||
formatWithAsset(
|
value,
|
||||||
|
data,
|
||||||
|
}: VegaValueFormatterParams<Market, 'data.markPrice'>) =>
|
||||||
|
value && data
|
||||||
|
? formatWithAsset(
|
||||||
value,
|
value,
|
||||||
data.tradableInstrument.instrument.product.settlementAsset
|
data.tradableInstrument.instrument.product.settlementAsset
|
||||||
)
|
)
|
||||||
|
: '-'
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<AgGridColumn
|
<AgGridColumn
|
||||||
headerName={t('Change (24h)')}
|
headerName={t('Change (24h)')}
|
||||||
headerTooltip={t('Change in price over the last 24h')}
|
headerTooltip={t('Change in price over the last 24h')}
|
||||||
cellRenderer={({ data }: { data: Market }) => {
|
cellRenderer={({
|
||||||
if (data.candles) {
|
data,
|
||||||
|
}: VegaValueFormatterParams<Market, 'data.candles'>) => {
|
||||||
|
if (data && data.candles) {
|
||||||
const prices = data.candles.map((candle) => candle.close);
|
const prices = data.candles.map((candle) => candle.close);
|
||||||
return (
|
return (
|
||||||
<PriceCellChange
|
<PriceCellChange
|
||||||
@ -135,19 +139,24 @@ export const MarketList = () => {
|
|||||||
decimalPlaces={data?.decimalPlaces}
|
decimalPlaces={data?.decimalPlaces}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else return <div>{t('No data')}</div>;
|
} else return <div>{t('-')}</div>;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<AgGridColumn
|
<AgGridColumn
|
||||||
headerName={t('Volume (24h)')}
|
headerName={t('Volume (24h)')}
|
||||||
field="dayVolume"
|
field="dayVolume"
|
||||||
valueFormatter={({ value, data }: ValueFormatterParams) =>
|
valueFormatter={({
|
||||||
`${addDecimalsFormatNumber(
|
value,
|
||||||
|
data,
|
||||||
|
}: VegaValueFormatterParams<Market, 'dayVolume'>) =>
|
||||||
|
value && data
|
||||||
|
? `${addDecimalsFormatNumber(
|
||||||
value,
|
value,
|
||||||
data.tradableInstrument.instrument.product.settlementAsset
|
data.tradableInstrument.instrument.product.settlementAsset
|
||||||
.decimals
|
.decimals
|
||||||
)} (${displayChange(data.volumeChange)})`
|
)} (${displayChange(data.volumeChange)})`
|
||||||
|
: '-'
|
||||||
}
|
}
|
||||||
headerTooltip={t('The trade volume over the last 24h')}
|
headerTooltip={t('The trade volume over the last 24h')}
|
||||||
/>
|
/>
|
||||||
@ -155,11 +164,16 @@ export const MarketList = () => {
|
|||||||
<AgGridColumn
|
<AgGridColumn
|
||||||
headerName={t('Total staked by LPs')}
|
headerName={t('Total staked by LPs')}
|
||||||
field="liquidityCommitted"
|
field="liquidityCommitted"
|
||||||
valueFormatter={({ value, data }: ValueFormatterParams) =>
|
valueFormatter={({
|
||||||
formatWithAsset(
|
|
||||||
value,
|
value,
|
||||||
|
data,
|
||||||
|
}: VegaValueFormatterParams<Market, 'liquidityCommitted'>) =>
|
||||||
|
data && value
|
||||||
|
? formatWithAsset(
|
||||||
|
value.toString(),
|
||||||
data.tradableInstrument.instrument.product.settlementAsset
|
data.tradableInstrument.instrument.product.settlementAsset
|
||||||
)
|
)
|
||||||
|
: '-'
|
||||||
}
|
}
|
||||||
headerTooltip={t(
|
headerTooltip={t(
|
||||||
'The amount of funds allocated to provide liquidity'
|
'The amount of funds allocated to provide liquidity'
|
||||||
@ -169,11 +183,16 @@ export const MarketList = () => {
|
|||||||
<AgGridColumn
|
<AgGridColumn
|
||||||
headerName={t('Target stake')}
|
headerName={t('Target stake')}
|
||||||
field="target"
|
field="target"
|
||||||
valueFormatter={({ value, data }: ValueFormatterParams) =>
|
valueFormatter={({
|
||||||
formatWithAsset(
|
value,
|
||||||
|
data,
|
||||||
|
}: VegaValueFormatterParams<Market, 'target'>) =>
|
||||||
|
data && value
|
||||||
|
? formatWithAsset(
|
||||||
value,
|
value,
|
||||||
data.tradableInstrument.instrument.product.settlementAsset
|
data.tradableInstrument.instrument.product.settlementAsset
|
||||||
)
|
)
|
||||||
|
: '-'
|
||||||
}
|
}
|
||||||
headerTooltip={t(
|
headerTooltip={t(
|
||||||
'The ideal committed liquidity to operate the market. If total commitment currently below this level then LPs can set the fee level with new commitment.'
|
'The ideal committed liquidity to operate the market. If total commitment currently below this level then LPs can set the fee level with new commitment.'
|
||||||
@ -182,15 +201,21 @@ export const MarketList = () => {
|
|||||||
|
|
||||||
<AgGridColumn
|
<AgGridColumn
|
||||||
headerName={t('% Target stake met')}
|
headerName={t('% Target stake met')}
|
||||||
valueFormatter={({ data }: ValueFormatterParams) => {
|
valueFormatter={({
|
||||||
|
data,
|
||||||
|
}: VegaValueFormatterParams<Market, ''>) => {
|
||||||
|
if (data) {
|
||||||
const roundedPercentage =
|
const roundedPercentage =
|
||||||
parseInt(
|
parseInt(
|
||||||
(data.liquidityCommitted / parseFloat(data.target)).toFixed(0)
|
(data.liquidityCommitted / parseFloat(data.target)).toFixed(
|
||||||
|
0
|
||||||
|
)
|
||||||
) * 100;
|
) * 100;
|
||||||
const display = Number.isNaN(roundedPercentage)
|
const display = Number.isNaN(roundedPercentage)
|
||||||
? 'N/A'
|
? 'N/A'
|
||||||
: formatNumberPercentage(toBigNum(roundedPercentage, 2));
|
: formatNumberPercentage(toBigNum(roundedPercentage, 2));
|
||||||
return display;
|
return display;
|
||||||
|
} else return '-';
|
||||||
}}
|
}}
|
||||||
headerTooltip={t('% Target stake met')}
|
headerTooltip={t('% Target stake met')}
|
||||||
/>
|
/>
|
||||||
@ -198,8 +223,10 @@ export const MarketList = () => {
|
|||||||
<AgGridColumn
|
<AgGridColumn
|
||||||
headerName={t('Fee levels')}
|
headerName={t('Fee levels')}
|
||||||
field="fees"
|
field="fees"
|
||||||
valueFormatter={({ value, data }: ValueFormatterParams) =>
|
valueFormatter={({
|
||||||
`${value.factors.liquidityFee}%`
|
value,
|
||||||
|
}: VegaValueFormatterParams<Market, 'fees'>) =>
|
||||||
|
value ? `${value.factors.liquidityFee}%` : '-'
|
||||||
}
|
}
|
||||||
headerTooltip={t('Fee level for this market')}
|
headerTooltip={t('Fee level for this market')}
|
||||||
/>
|
/>
|
||||||
|
@ -38,7 +38,13 @@ export interface FeeLevels {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type Market = MarketWithData &
|
export type Market = MarketWithData &
|
||||||
MarketWithCandles & { feeLevels: FeeLevels[]; target: string };
|
MarketWithCandles & {
|
||||||
|
feeLevels: FeeLevels[];
|
||||||
|
target: string;
|
||||||
|
dayVolume: string;
|
||||||
|
liquidityCommitted: number;
|
||||||
|
volumeChange: string;
|
||||||
|
};
|
||||||
|
|
||||||
export interface Markets {
|
export interface Markets {
|
||||||
markets: Market[];
|
markets: Market[];
|
||||||
|
Loading…
Reference in New Issue
Block a user