Skip to content

Commit

Permalink
limit percentage reduction in token details (#1660)
Browse files Browse the repository at this point in the history
Co-authored-by: gregs <[email protected]>
Co-authored-by: gregs <[email protected]>
  • Loading branch information
3 people authored Aug 21, 2024
1 parent 6741311 commit 5546483
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/entries/popup/pages/home/TokenDetails/PriceChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@ import { ChartData, ChartPoint, LineChart } from './LineChart';
import { ParsedTokenInfo } from './useTokenInfo';

const parsePriceChange = (
value: number,
): { color: TextProps['color']; symbol: SymbolName | '' } => {
if (value < 0) return { color: 'red', symbol: 'arrow.down' };
if (value > 0) return { color: 'green', symbol: 'arrow.up' };
return { color: 'labelSecondary', symbol: '' };
changePercentage: number,
): { label: string; color: TextProps['color']; symbol: SymbolName | '' } => {
const label = Math.abs(changePercentage).toFixed(2) + ' %';

if (changePercentage === Infinity)
return { label: '∞ %', color: 'green', symbol: '' };

if (changePercentage < 0)
return { label, color: 'red', symbol: 'arrow.down' };

if (changePercentage > 0)
return { label, color: 'green', symbol: 'arrow.up' };

return { label, color: 'labelSecondary', symbol: '' };
};

type PriceChange = {
Expand All @@ -44,7 +53,7 @@ const PriceChange = memo(function PriceChange({
changePercentage = 0,
date,
}: PriceChange) {
const { color, symbol } = parsePriceChange(+changePercentage.toFixed(2));
const { color, symbol, label } = parsePriceChange(changePercentage);
return (
<Box display="flex" flexDirection="column" gap="10px" alignItems="flex-end">
<Inline alignVertical="center" space="4px">
Expand All @@ -58,7 +67,7 @@ const PriceChange = memo(function PriceChange({
cursor="text"
userSelect="text"
>
{Math.abs(changePercentage).toFixed(2)} %
{label}
</Text>
</Inline>
<Text size="14pt" weight="heavy" color={color}>
Expand Down Expand Up @@ -165,7 +174,7 @@ const usePriceChart = ({
};

const percentDiff = (current = 1, last = 0) =>
((current - last) / current) * 100;
((current - last) / last) * 100 || 0;

const now = new Date();
const chartTimeToTimestamp = {
Expand Down

0 comments on commit 5546483

Please sign in to comment.