Skip to content

Commit

Permalink
fix(prices): hide NaN values from displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
schnogz committed May 20, 2022
1 parent 0d65118 commit 2901ec4
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { ReactNode } from 'react'
import styled from 'styled-components'

import { Exchange } from '@core'
Expand Down Expand Up @@ -31,26 +31,31 @@ export const PriceChange = ({
isPortfolioPosition,
priceChange
}: {
children: any
children: ReactNode
currency: FiatType
isPortfolioPosition?: boolean
priceChange: PriceChangeType
}) => {
const change = isPortfolioPosition ? priceChange.positionChange : priceChange.overallChange
let priceFormatted
const price = formatFiat(change.diff)
const hidePrices = Number.isNaN(price) || Number.isNaN(change.percentChange)
const priceChangePercentFormatted = formatFiat(change.percentChange)
let priceFormatted

if (change.movement === 'down') {
priceFormatted = `-${Exchange.getSymbol(currency)}${price.substring(1)}`
} else {
priceFormatted = `${Exchange.getSymbol(currency)}${price}`
}

const hasNanValues = Number.isNaN(Number(price)) || Number.isNaN(Number(change.percentChange))

if (hasNanValues) return null

return (
<PriceChangeText>
{!hidePrices && (
{!hasNanValues && (
<PriceChangeColoredText change={change}>
{priceFormatted} ({formatFiat(change.percentChange)})%
{priceFormatted} ({priceChangePercentFormatted})%
</PriceChangeColoredText>
)}
{children}
Expand Down

0 comments on commit 2901ec4

Please sign in to comment.