From a56a63f138ac97a89752c37c088c37f0cc47face Mon Sep 17 00:00:00 2001 From: Vladislav <24393100+sablevsky@users.noreply.github.com> Date: Mon, 9 Dec 2024 18:14:42 +0100 Subject: [PATCH] Fix formatValueByTokenType function (#1095) --- .../LeveragePositionCard/LeveragePositionCard.tsx | 2 +- src/utils/tokens/helpers.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/tokenLending/LeveragePage/LeveragePositionsContent/components/LeveragePositionCard/LeveragePositionCard.tsx b/src/pages/tokenLending/LeveragePage/LeveragePositionsContent/components/LeveragePositionCard/LeveragePositionCard.tsx index 65a76b2dd..88675ed78 100644 --- a/src/pages/tokenLending/LeveragePage/LeveragePositionsContent/components/LeveragePositionCard/LeveragePositionCard.tsx +++ b/src/pages/tokenLending/LeveragePage/LeveragePositionsContent/components/LeveragePositionCard/LeveragePositionCard.tsx @@ -132,7 +132,7 @@ const PositionAdditionalInfo: FC<{ loan: TokenLoan }> = ({ loan }) => { label="PNL" value={ - {isNegativePnl ? '-' : '+'} + {isNegativePnl ? '' : '+'} value < threshold +const isValueBelowThreshold = (value: number, threshold: number) => Math.abs(value) < threshold export const convertToHumanNumber = (value: number, tokenType: LendingTokenType): number => { const decimals = TOKEN_DECIMALS[tokenType] @@ -27,8 +27,11 @@ export const formatValueByTokenType = (value: number, tokenType: LendingTokenTyp const convertedValue = convertToHumanNumber(value, tokenType) + const isNumberNegative = convertedValue < 0 + if (isValueBelowThreshold(convertedValue, MIN_VALUE_TO_DISPLAY[tokenType])) { - return `<${MIN_VALUE_TO_DISPLAY[tokenType]}` + //? Use MIN_VALUE_TO_DISPLAY for negative numbers + return `<${isNumberNegative ? '-' : ''}${MIN_VALUE_TO_DISPLAY[tokenType]}` } return formatTokenValue(convertedValue, tokenType)