Skip to content

Commit

Permalink
fix small points amount display
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-babylonlabs committed Oct 7, 2024
1 parent 76e4689 commit 456bd57
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-staking",
"version": "0.3.7",
"version": "0.3.8",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
14 changes: 3 additions & 11 deletions src/app/components/Points/DelegationPoints.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from "react";
import { NumericFormat } from "react-number-format";

import { useDelegationsPoints } from "@/app/context/api/DelegationsPointsProvider";
import { useHealthCheck } from "@/app/hooks/useHealthCheck";
import { shouldDisplayPoints } from "@/config";

import { Points } from "./Points";

interface DelegationPointsProps {
stakingTxHash: string;
className?: string;
Expand Down Expand Up @@ -37,16 +38,7 @@ export const DelegationPoints: React.FC<DelegationPointsProps> = ({
<div className="flex items-center justify-end gap-1">
<p className="whitespace-nowrap">
<span className="lg:hidden">Points: </span>
{points !== undefined && points !== 0 ? (
<NumericFormat
value={points.toFixed(3)}
displayType="text"
thousandSeparator=","
decimalSeparator="."
/>
) : (
"n.a."
)}
<Points points={points} />
</p>
</div>
</div>
Expand Down
37 changes: 37 additions & 0 deletions src/app/components/Points/Points.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from "react";
import { NumericFormat } from "react-number-format";
import { Tooltip } from "react-tooltip";

interface PointsProps {
points: number | undefined;
}

export const Points: React.FC<PointsProps> = ({ points }) => {
if (points === undefined || points === 0) {
return <>n.a.</>;
}

if (points < 0.001 && points > 0) {
return (
<>
<span
className="cursor-pointer text-xs"
data-tooltip-id={`tooltip-points-${points}`}
data-tooltip-content={points.toFixed(8)}
>
&lt;0.001
</span>
<Tooltip id={`tooltip-points-${points}`} className="tooltip-wrap" />
</>
);
}

return (
<NumericFormat
value={points.toFixed(3)}
displayType="text"
thousandSeparator=","
decimalSeparator="."
/>
);
};
14 changes: 3 additions & 11 deletions src/app/components/Points/StakerPoints.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useQuery } from "@tanstack/react-query";
import React from "react";
import { NumericFormat } from "react-number-format";

import { getStakersPoints } from "@/app/api/getPoints";

import { Points } from "./Points";

interface StakerPointsProps {
publicKeyNoCoord: string;
}
Expand Down Expand Up @@ -35,16 +36,7 @@ export const StakerPoints: React.FC<StakerPointsProps> = ({
return (
<div className="flex items-center justify-end gap-1">
<p className="whitespace-nowrap font-semibold">
{points !== undefined && points !== 0 ? (
<NumericFormat
value={points.toFixed(3)}
displayType="text"
thousandSeparator=","
decimalSeparator="."
/>
) : (
"n.a."
)}
<Points points={points} />
</p>
</div>
);
Expand Down

0 comments on commit 456bd57

Please sign in to comment.