Commit d8eb4d18 authored by cartcrom's avatar cartcrom Committed by GitHub

fix: display 0 percent change on explore (#4747)

* fixed issue
parent 25d64911
...@@ -56,17 +56,21 @@ export function calculateDelta(start: number, current: number) { ...@@ -56,17 +56,21 @@ export function calculateDelta(start: number, current: number) {
return (current / start - 1) * 100 return (current / start - 1) * 100
} }
export function getDeltaArrow(delta: number) { export function getDeltaArrow(delta: number | null | undefined) {
if (Math.sign(delta) > 0) { // Null-check not including zero
return <StyledUpArrow size={16} key="arrow-up" /> if (delta === null || delta === undefined) {
} else if (delta === 0) {
return null return null
} else { } else if (Math.sign(delta) < 0) {
return <StyledDownArrow size={16} key="arrow-down" /> return <StyledDownArrow size={16} key="arrow-down" />
} }
return <StyledUpArrow size={16} key="arrow-up" />
} }
export function formatDelta(delta: number) { export function formatDelta(delta: number | null | undefined) {
// Null-check not including zero
if (delta === null || delta === undefined) {
return '-'
}
let formattedDelta = delta.toFixed(2) + '%' let formattedDelta = delta.toFixed(2) + '%'
if (Math.sign(delta) > 0) { if (Math.sign(delta) > 0) {
formattedDelta = '+' + formattedDelta formattedDelta = '+' + formattedDelta
......
...@@ -485,8 +485,8 @@ export const LoadedRow = forwardRef((props: LoadedRowProps, ref: ForwardedRef<HT ...@@ -485,8 +485,8 @@ export const LoadedRow = forwardRef((props: LoadedRowProps, ref: ForwardedRef<HT
const L2Icon = getChainInfo(CHAIN_NAME_TO_CHAIN_ID[filterNetwork]).circleLogoUrl const L2Icon = getChainInfo(CHAIN_NAME_TO_CHAIN_ID[filterNetwork]).circleLogoUrl
const timePeriod = useAtomValue(filterTimeAtom) const timePeriod = useAtomValue(filterTimeAtom)
const delta = token.market?.pricePercentChange?.value const delta = token.market?.pricePercentChange?.value
const arrow = delta ? getDeltaArrow(delta) : null const arrow = getDeltaArrow(delta)
const formattedDelta = delta ? formatDelta(delta) : null const formattedDelta = formatDelta(delta)
const sortAscending = useAtomValue(sortAscendingAtom) const sortAscending = useAtomValue(sortAscendingAtom)
const exploreTokenSelectedEventProperties = { const exploreTokenSelectedEventProperties = {
...@@ -544,7 +544,7 @@ export const LoadedRow = forwardRef((props: LoadedRowProps, ref: ForwardedRef<HT ...@@ -544,7 +544,7 @@ export const LoadedRow = forwardRef((props: LoadedRowProps, ref: ForwardedRef<HT
} }
percentChange={ percentChange={
<ClickableContent> <ClickableContent>
{formattedDelta ?? '-'} {formattedDelta}
{arrow} {arrow}
</ClickableContent> </ClickableContent>
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment