From 2bac18c7b4a014e07ff4a4308e834a1516c1e0ea Mon Sep 17 00:00:00 2001 From: Madalina Raicu Date: Thu, 15 Jun 2023 12:53:30 +0100 Subject: [PATCH] fix: liquidity provision table quantum formatting --- .../client-pages/liquidity/liquidity.tsx | 3 + .../liquidity-supplied/liquidity-supplied.tsx | 21 +- libs/liquidity/src/lib/liquidity-table.tsx | 266 ++++++++++-------- 3 files changed, 170 insertions(+), 120 deletions(-) diff --git a/apps/trading/client-pages/liquidity/liquidity.tsx b/apps/trading/client-pages/liquidity/liquidity.tsx index b7d5fac8b..a15dded2f 100644 --- a/apps/trading/client-pages/liquidity/liquidity.tsx +++ b/apps/trading/client-pages/liquidity/liquidity.tsx @@ -83,6 +83,8 @@ export const LiquidityContainer = ({ const assetDecimalPlaces = market?.tradableInstrument.instrument.product.settlementAsset.decimals || 0; + const quantum = + market?.tradableInstrument.instrument.product.settlementAsset.quantum || 0; const symbol = market?.tradableInstrument.instrument.product.settlementAsset.symbol; @@ -98,6 +100,7 @@ export const LiquidityContainer = ({ rowData={data} symbol={symbol} assetDecimalPlaces={assetDecimalPlaces} + quantum={quantum} stakeToCcyVolume={stakeToCcyVolume} overlayNoRowsTemplate={error ? error.message : t('No data')} /> diff --git a/apps/trading/components/liquidity-supplied/liquidity-supplied.tsx b/apps/trading/components/liquidity-supplied/liquidity-supplied.tsx index e56951c40..d5aeb5bc6 100644 --- a/apps/trading/components/liquidity-supplied/liquidity-supplied.tsx +++ b/apps/trading/components/liquidity-supplied/liquidity-supplied.tsx @@ -125,14 +125,19 @@ export const MarketLiquiditySupplied = ({
- - {t('View liquidity provision table')} - - {DocsLinks && ( - - {t('Learn about providing liquidity')} - - )} +
+ + {t('View liquidity provision table')} + + {DocsLinks && ( + + {t('Learn about providing liquidity')} + + )} +
{showMessage && (

{t( diff --git a/libs/liquidity/src/lib/liquidity-table.tsx b/libs/liquidity/src/lib/liquidity-table.tsx index 5988dfc4c..c13f9693e 100644 --- a/libs/liquidity/src/lib/liquidity-table.tsx +++ b/libs/liquidity/src/lib/liquidity-table.tsx @@ -1,20 +1,22 @@ -import { forwardRef } from 'react'; +import { forwardRef, useMemo } from 'react'; import { addDecimalsFormatNumber, + addDecimalsFormatNumberQuantum, formatNumberPercentage, getDateTimeFormat, } from '@vegaprotocol/utils'; import { t } from '@vegaprotocol/i18n'; -import type { - VegaValueFormatterParams, - TypedDataAgGrid, -} from '@vegaprotocol/datagrid'; +import type { TypedDataAgGrid } from '@vegaprotocol/datagrid'; import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid'; import { TooltipCellComponent } from '@vegaprotocol/ui-toolkit'; import type { AgGridReact } from 'ag-grid-react'; -import { AgGridColumn } from 'ag-grid-react'; -import type { ValueFormatterParams } from 'ag-grid-community'; +import type { + ColDef, + ITooltipParams, + ValueFormatterParams, +} from 'ag-grid-community'; import BigNumber from 'bignumber.js'; +import type { LiquidityProvisionStatus } from '@vegaprotocol/types'; import { LiquidityProvisionStatusMapping } from '@vegaprotocol/types'; import type { LiquidityProvisionData } from './liquidity-data-provider'; @@ -35,21 +37,152 @@ export interface LiquidityTableProps symbol?: string; assetDecimalPlaces?: number; stakeToCcyVolume: string | null; + quantum?: string | number; } export const LiquidityTable = forwardRef( - ({ symbol = '', assetDecimalPlaces, stakeToCcyVolume, ...props }, ref) => { - const assetDecimalsFormatter = ({ value }: ValueFormatterParams) => { - if (!value) return '-'; - return `${addDecimalsFormatNumber(value, assetDecimalPlaces ?? 0, 5)}`; - }; - const stakeToCcyVolumeFormatter = ({ value }: ValueFormatterParams) => { - if (!value) return '-'; - const newValue = new BigNumber(value) - .times(Number(stakeToCcyVolume) || 1) - .toString(); - return `${addDecimalsFormatNumber(newValue, assetDecimalPlaces ?? 0, 5)}`; - }; + ( + { symbol = '', assetDecimalPlaces, stakeToCcyVolume, quantum, ...props }, + ref + ) => { + const colDefs = useMemo(() => { + const assetDecimalsFormatter = ({ value }: ITooltipParams) => { + if (!value) return '-'; + return `${addDecimalsFormatNumber(value, assetDecimalPlaces ?? 0)}`; + }; + + const assetDecimalsQuantumFormatter = ({ + value, + }: ValueFormatterParams) => { + if (!value) return '-'; + return `${addDecimalsFormatNumberQuantum( + value, + assetDecimalPlaces ?? 0, + quantum ?? 0 + )}`; + }; + + const stakeToCcyVolumeFormatter = ({ value }: ITooltipParams) => { + if (!value) return '-'; + const newValue = new BigNumber(value) + .times(Number(stakeToCcyVolume) || 1) + .toString(); + return `${addDecimalsFormatNumber(newValue, assetDecimalPlaces ?? 0)}`; + }; + + const stakeToCcyVolumeQuantumFormatter = ({ + value, + }: ValueFormatterParams) => { + if (!value) return '-'; + const newValue = new BigNumber(value) + .times(Number(stakeToCcyVolume) || 1) + .toString(); + return `${addDecimalsFormatNumberQuantum( + newValue, + assetDecimalPlaces ?? 0, + quantum ?? 0 + )}`; + }; + + const defs: ColDef[] = [ + { + headerName: t('Party'), + field: 'party.id', + headerTooltip: t( + 'The public key of the party making this commitment.' + ), + }, + { + headerName: t(`Commitment (${symbol})`), + field: 'commitmentAmount', + type: 'rightAligned', + headerTooltip: t( + 'The amount committed to the market by this liquidity provider.' + ), + valueFormatter: assetDecimalsQuantumFormatter, + tooltipValueGetter: assetDecimalsFormatter, + }, + { + headerName: t(`Share`), + field: 'equityLikeShare', + type: 'rightAligned', + headerTooltip: t( + 'The equity-like share of liquidity of the market used to determine allocation of LP fees. Calculated based on share of total liquidity, with a premium added for length of commitment.' + ), + valueFormatter: percentageFormatter, + }, + { + headerName: t('Proposed fee'), + headerTooltip: t( + 'The fee percentage (per trade) proposed by each liquidity provider.' + ), + field: 'fee', + type: 'rightAligned', + valueFormatter: percentageFormatter, + }, + { + headerName: t('Market valuation at entry'), + field: 'averageEntryValuation', + type: 'rightAligned', + headerTooltip: t( + 'The valuation of the market at the time the liquidity commitment was made. Commitments made at a lower valuation earlier in the lifetime of the market would be expected to have a higher equity-like share if the market has grown. If a commitment is amended, value will reflect the average of the market valuations across the lifetime of the commitment.' + ), + minWidth: 160, + valueFormatter: assetDecimalsQuantumFormatter, + tooltipValueGetter: assetDecimalsFormatter, + }, + { + headerName: t('Obligation'), + field: 'commitmentAmount', + type: 'rightAligned', + headerTooltip: t( + `The liquidity provider's obligation to the market, calculated as the liquidity commitment amount multiplied by the value of the stake_to_ccy_siskas network parameter to convert into units of liquidity volume. The obligation can be met by a combination of LP orders and limit orders on the order book.` + ), + valueFormatter: stakeToCcyVolumeQuantumFormatter, + tooltipValueGetter: stakeToCcyVolumeFormatter, + }, + { + headerName: t('Supplied'), + field: 'balance', + type: 'rightAligned', + headerTooltip: t( + `The amount of liquidity volume supplied by the LP order in order to meet the obligation. If the obligation is already met in full by other limit orders from the same Vega key the LP order is not required and this value will be zero. Also note if the target stake for the market is less than the obligation the full value of the obligation may not be required.` + ), + valueFormatter: stakeToCcyVolumeQuantumFormatter, + tooltipValueGetter: stakeToCcyVolumeFormatter, + }, + { + headerName: t('Status'), + headerTooltip: t('The current status of this liquidity provision.'), + field: 'status', + valueFormatter: ({ value }) => { + if (!value) return value; + return LiquidityProvisionStatusMapping[ + value as LiquidityProvisionStatus + ]; + }, + }, + { + headerName: t('Created'), + headerTooltip: t( + 'The date and time this liquidity provision was created.' + ), + field: 'createdAt', + type: 'rightAligned', + valueFormatter: dateValueFormatter, + }, + { + headerName: t('Updated'), + headerTooltip: t( + 'The date and time this liquidity provision was last updated.' + ), + field: 'updatedAt', + type: 'rightAligned', + valueFormatter: dateValueFormatter, + }, + ]; + return defs; + }, [assetDecimalPlaces, quantum, stakeToCcyVolume, symbol]); return ( ( }} storeKey="liquidityProvisionTable" {...props} - > - - - - - - - - ) => { - if (!value) return value; - return LiquidityProvisionStatusMapping[value]; - }} - /> - - - + columnDefs={colDefs} + > ); } );