Skip to content

Commit

Permalink
Fix formatValueByTokenType function (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
sablevsky authored Dec 9, 2024
1 parent 507406e commit a56a63f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const PositionAdditionalInfo: FC<{ loan: TokenLoan }> = ({ loan }) => {
label="PNL"
value={
<span>
{isNegativePnl ? '-' : '+'}
{isNegativePnl ? '' : '+'}
<DisplayValue
strictTokenType={loan.bondTradeTransaction.lendingToken}
value={loanPnl}
Expand Down
7 changes: 5 additions & 2 deletions src/utils/tokens/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TokenUnit,
} from './constants'

const isValueBelowThreshold = (value: number, threshold: number) => 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]
Expand All @@ -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)
Expand Down

0 comments on commit a56a63f

Please sign in to comment.