Skip to content

Commit

Permalink
feat: improved formatting for deposits tooltips when approaching cap
Browse files Browse the repository at this point in the history
  • Loading branch information
chambaz committed Jan 17, 2025
1 parent e0007f1 commit 71f8a0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
dynamicNumeralFormatter,
numeralFormatter,
percentFormatter,
percentFormatterMod,
usdFormatter,
} from "@mrgnlabs/mrgn-common";
import { IconAlertTriangle, IconExternalLink } from "@tabler/icons-react";
Expand Down Expand Up @@ -255,7 +256,12 @@ export const getDepositsCell = (depositsData: DepositsData) => {
<>
<span>
{depositsData.symbol} {depositsData.isInLendingMode ? "deposits" : "borrows"} are at{" "}
{percentFormatter.format(depositsData.capacity)} capacity.
{percentFormatterMod(depositsData.capacity, {
minFractionDigits: 0,
maxFractionDigits:
depositsData.isBankHigh && !depositsData.isBankFilled && depositsData.capacity >= 0.99 ? 4 : 2,
})}{" "}
capacity.
</span>
{!depositsData.isBankFilled && (
<>
Expand Down
18 changes: 18 additions & 0 deletions packages/mrgn-common/src/utils/formatters.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ const percentFormatterDyn = new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
});

const percentFormatterMod = (
value: number,
opts: { minFractionDigits: number; maxFractionDigits: number } = { minFractionDigits: 2, maxFractionDigits: 2 }
) => {
const percentFormatter = new Intl.NumberFormat("en-US", {
style: "percent",
minimumFractionDigits: opts.minFractionDigits,
maximumFractionDigits: opts.maxFractionDigits,
});

if (value === 0) {
return "0";
} else {
return percentFormatter.format(value);
}
};

const clampedNumeralFormatter = (value: number) => {
if (value === 0) {
return "0";
Expand Down Expand Up @@ -149,6 +166,7 @@ export {
clampedNumeralFormatter,
percentFormatter,
percentFormatterDyn,
percentFormatterMod,
usdFormatter,
usdFormatterDyn,
tokenPriceFormatter,
Expand Down

0 comments on commit 71f8a0d

Please sign in to comment.