Skip to content

Commit

Permalink
feat: ✨ improve price axis formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideSegullo committed Jun 6, 2024
1 parent f1cabae commit 96ec061
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions packages/web/components/chart/light-weight-charts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { Dec } from "@keplr-wallet/unit";

import { formatPretty } from "~/utils/formatter";
import { formatPretty, getPriceExtendedFormatOptions } from "~/utils/formatter";
import { getDecimalCount } from "~/utils/number";

export const priceFormatter = (price: number) => {
const minimumDecimals = 2;
const maxDecimals = Math.max(getDecimalCount(price), minimumDecimals);

const priceDec = new Dec(price);

const formatOpts = getPriceExtendedFormatOptions(priceDec);

return formatPretty(priceDec, {
maxDecimals,
currency: "USD",
style: "currency",
maxDecimals: 3,
minimumSignificantDigits: 3,
disabledTrimZeros: true,
...formatOpts,
});
};
4 changes: 2 additions & 2 deletions packages/web/components/chart/price-historical-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const seriesOpt: DeepPartial<AreaSeriesOptions> = {
crosshairMarkerRadius: 8,
priceFormat: {
type: "price",
precision: 4,
minMove: 0.0001,
precision: 10,
minMove: 0.0000001,
},
};

Expand Down

0 comments on commit 96ec061

Please sign in to comment.