Skip to content

Commit

Permalink
add threshold updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mattupham committed Sep 3, 2024
1 parent fe083b3 commit dac7a6f
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/web/components/assets/price.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { api } from "~/utils/trpc";
import { Sparkline } from "../chart/sparkline";
import { CustomClasses } from "../types";

// 0.01%
const THRESHOLD = 0.0001;
// 0.1%
const THRESHOLD = 0.001;

/** Colored price change text with up/down arrow. */
export const PriceChange: FunctionComponent<
Expand All @@ -23,22 +23,21 @@ export const PriceChange: FunctionComponent<
value?: PricePretty;
} & CustomClasses
> = ({ priceChange, overrideTextClasses = "body1", className, value }) => {
const isBullish = priceChange.toDec().gt(new Dec(THRESHOLD));
const isBearish = priceChange.toDec().lt(new Dec(-THRESHOLD));
console.log("-------------------");
console.log("PriceChange toDec toString: ", priceChange.toDec().toString());
console.log("Threshold toDec toString: ", new Dec(-THRESHOLD).toString());
const isBullish = priceChange.toDec().gte(new Dec(THRESHOLD));
const isBearish = priceChange.toDec().lte(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(2)
.maxDecimals(1)
.inequalitySymbol(false)
.toString();

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

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

0 comments on commit dac7a6f

Please sign in to comment.