Skip to content

Commit

Permalink
Update 0.00% (#3798)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattupham authored Aug 29, 2024
1 parent f1f7923 commit 418c44f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/web/components/assets/price.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PricePretty, RatePretty } from "@keplr-wallet/unit";
import { Dec } from "@keplr-wallet/unit";
import { CommonPriceChartTimeFrame } from "@osmosis-labs/server";
import classNames from "classnames";
import { FunctionComponent, useMemo } from "react";
Expand All @@ -11,6 +12,9 @@ import { api } from "~/utils/trpc";
import { Sparkline } from "../chart/sparkline";
import { CustomClasses } from "../types";

// 0.01%
const THRESHOLD = 0.0001;

/** Colored price change text with up/down arrow. */
export const PriceChange: FunctionComponent<
{
Expand All @@ -19,21 +23,27 @@ export const PriceChange: FunctionComponent<
value?: PricePretty;
} & CustomClasses
> = ({ priceChange, overrideTextClasses = "body1", className, value }) => {
const isBullish = priceChange.toDec().isPositive();
const isBearish = priceChange.toDec().isNegative();
const isBullish = priceChange.toDec().gt(new Dec(THRESHOLD));
const isBearish = priceChange.toDec().lt(new Dec(-THRESHOLD));
const isFlat = !isBullish && !isBearish;

console.log("----");
console.log("priceChange.toDec(): ", priceChange.toDec().toString());
console.log("priceChange", priceChange.toDec().toString());

// remove negative symbol since we're using arrows
if (isBearish) {
priceChange = priceChange.mul(new RatePretty(-1));
value = value?.mul(new RatePretty(-1));
}

const priceChangeDisplay = priceChange
.maxDecimals(1)
.maxDecimals(2)
.inequalitySymbol(false)
.toString();

console.log("priceChangeDisplay: ", priceChangeDisplay);
console.log("----");
const formattedPriceChangeDisplay =
value !== undefined ? `(${priceChangeDisplay})` : priceChangeDisplay;

Expand Down Expand Up @@ -67,7 +77,7 @@ export const PriceChange: FunctionComponent<
>
{value !== undefined ? value.toString() + " " : null}

{isFlat ? "-" : formattedPriceChangeDisplay}
{isFlat ? "0.00%" : formattedPriceChangeDisplay}
</div>
</div>
);
Expand Down

0 comments on commit 418c44f

Please sign in to comment.