fix(trading): use asset decimals to format liquidation price in posions table (#4787)
Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
This commit is contained in:
parent
af6719cc9d
commit
fbd01dc1bd
@ -84,6 +84,7 @@ const ocoPostfix = (id: string, postfix = true) => (postfix ? `${id}-oco` : id);
|
|||||||
|
|
||||||
const mockDataProvider = jest.fn((...args) => ({
|
const mockDataProvider = jest.fn((...args) => ({
|
||||||
data: Array(0),
|
data: Array(0),
|
||||||
|
reload: jest.fn(),
|
||||||
}));
|
}));
|
||||||
jest.mock('@vegaprotocol/data-provider', () => ({
|
jest.mock('@vegaprotocol/data-provider', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/data-provider'),
|
...jest.requireActual('@vegaprotocol/data-provider'),
|
||||||
@ -473,6 +474,7 @@ describe('StopOrder', () => {
|
|||||||
|
|
||||||
it('shows limit of active stop orders number', async () => {
|
it('shows limit of active stop orders number', async () => {
|
||||||
mockDataProvider.mockReturnValue({
|
mockDataProvider.mockReturnValue({
|
||||||
|
reload: jest.fn(),
|
||||||
data: Array(4),
|
data: Array(4),
|
||||||
});
|
});
|
||||||
render(generateJsx());
|
render(generateJsx());
|
||||||
@ -484,6 +486,7 @@ describe('StopOrder', () => {
|
|||||||
|
|
||||||
it('counts oco as two orders', async () => {
|
it('counts oco as two orders', async () => {
|
||||||
mockDataProvider.mockReturnValue({
|
mockDataProvider.mockReturnValue({
|
||||||
|
reload: jest.fn(),
|
||||||
data: Array(3),
|
data: Array(3),
|
||||||
});
|
});
|
||||||
render(generateJsx());
|
render(generateJsx());
|
||||||
|
@ -7,13 +7,21 @@ export const LiquidationPrice = ({
|
|||||||
marketId,
|
marketId,
|
||||||
openVolume,
|
openVolume,
|
||||||
collateralAvailable,
|
collateralAvailable,
|
||||||
marketDecimalPlaces,
|
decimalPlaces,
|
||||||
|
formatDecimals,
|
||||||
}: {
|
}: {
|
||||||
marketId: string;
|
marketId: string;
|
||||||
openVolume: string;
|
openVolume: string;
|
||||||
collateralAvailable: string;
|
collateralAvailable: string;
|
||||||
marketDecimalPlaces: number;
|
decimalPlaces: number;
|
||||||
|
formatDecimals: number;
|
||||||
}) => {
|
}) => {
|
||||||
|
// NOTE!
|
||||||
|
//
|
||||||
|
// The estimate order query API gives us the liquidation price unformatted but expecting to be converted
|
||||||
|
// using asset decimal placse.
|
||||||
|
//
|
||||||
|
// We need to convert it with asset decimals, but display it formatted with market decimals precision until the API changes.
|
||||||
const { data: currentData, previousData } = useEstimatePositionQuery({
|
const { data: currentData, previousData } = useEstimatePositionQuery({
|
||||||
variables: {
|
variables: {
|
||||||
marketId,
|
marketId,
|
||||||
@ -43,8 +51,8 @@ export const LiquidationPrice = ({
|
|||||||
/\..*/,
|
/\..*/,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
worstCase = addDecimalsFormatNumber(worstCase, marketDecimalPlaces);
|
worstCase = addDecimalsFormatNumber(worstCase, decimalPlaces, formatDecimals);
|
||||||
bestCase = addDecimalsFormatNumber(bestCase, marketDecimalPlaces);
|
bestCase = addDecimalsFormatNumber(bestCase, decimalPlaces, formatDecimals);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
@ -53,11 +61,11 @@ export const LiquidationPrice = ({
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{t('Worst case')}</th>
|
<th>{t('Worst case')}</th>
|
||||||
<td className="text-right font-mono pl-2">{worstCase}</td>
|
<td className="pl-2 font-mono text-right">{worstCase}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{t('Best case')}</th>
|
<th>{t('Best case')}</th>
|
||||||
<td className="text-right font-mono pl-2">{bestCase}</td>
|
<td className="pl-2 font-mono text-right">{bestCase}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -339,12 +339,16 @@ export const PositionsTable = ({
|
|||||||
if (!data) {
|
if (!data) {
|
||||||
return '-';
|
return '-';
|
||||||
}
|
}
|
||||||
|
// The estimate order query API gives us the liquidation price unformatted but expecting
|
||||||
|
// conversion using asset decimals. We need to convert it with asset decimals, but format
|
||||||
|
// it with market decimals precision until the API changes.
|
||||||
return (
|
return (
|
||||||
<LiquidationPrice
|
<LiquidationPrice
|
||||||
marketId={data.marketId}
|
marketId={data.marketId}
|
||||||
openVolume={data.openVolume}
|
openVolume={data.openVolume}
|
||||||
collateralAvailable={data.totalBalance}
|
collateralAvailable={data.totalBalance}
|
||||||
marketDecimalPlaces={data.marketDecimalPlaces}
|
decimalPlaces={data.assetDecimals}
|
||||||
|
formatDecimals={data.marketDecimalPlaces}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user