Skip to content

Commit 356e630

Browse files
chore: show 4 decimals
1 parent 8ada977 commit 356e630

File tree

9 files changed

+53
-47
lines changed

9 files changed

+53
-47
lines changed

src/consts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export const slotsPerLeader = 4;
22
export const slotsListPinnedSlotOffset = 5;
33
export const scheduleUpcomingSlotsCount = 3;
44

5+
export const solDecimals = 4;
6+
57
export const lamportsPerSol = 1_000_000_000;
68

79
/** Max compute units is dynamic and pulled from the server,

src/features/LeaderSchedule/Slots/CardValidatorSummary.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ function ValidatorInfo({ peer }: ValidatorInfoProps) {
128128
? `${peer.gossip.version[0] === "0" ? "Frankendancer" : "Agave"} v${peer.gossip.version}`
129129
: undefined;
130130

131-
const message = [
132-
peer?.gossip?.version
133-
? `${peer.gossip.version[0] === "0" ? "Frankendancer" : "Agave"} v${peer.gossip.version}`
134-
: undefined,
135-
getStakeMsg(peer, peerStats?.activeStake, peerStats?.delinquentStake),
136-
peer?.gossip?.sockets["tvu"]?.split(":")[0],
137-
]
131+
const stakeMsg = getStakeMsg(
132+
peer,
133+
peerStats?.activeStake,
134+
peerStats?.delinquentStake,
135+
);
136+
137+
const ipWithoutPort = peer?.gossip?.sockets["tvu"]?.split(":")[0];
138+
139+
const message = [validator, stakeMsg, ipWithoutPort]
138140
.filter(isDefined)
139141
.join(" - ");
140142

@@ -143,9 +145,8 @@ function ValidatorInfo({ peer }: ValidatorInfoProps) {
143145
const isFd = validator?.startsWith("Frankendancer");
144146
const isAgave = validator && !isFd;
145147
const validatorText = validator || "Unknown";
146-
const stakeText =
147-
getStakeMsg(peer, peerStats?.activeStake, peerStats?.delinquentStake) ?? "";
148-
const ipText = peer?.gossip?.sockets["tvu"]?.split(":")[0] || "Offline";
148+
const stakeText = stakeMsg ?? "";
149+
const ipText = ipWithoutPort || "Offline";
149150
const textLength = (validatorText + stakeText + ipText).length;
150151
const shouldWrap = textLength > 54;
151152
const textProps: TextProps = shouldWrap

src/features/LeaderSchedule/Slots/SlotCardGrid.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { useSlotQueryPublish } from "../../../hooks/useSlotQuery";
88
import type { SlotPublish } from "../../../api/types";
99
import { fixValue } from "../../../utils";
1010
import { useMedia, usePrevious, useUnmount } from "react-use";
11-
import { defaultMaxComputeUnits, lamportsPerSol } from "../../../consts";
11+
import {
12+
defaultMaxComputeUnits,
13+
lamportsPerSol,
14+
solDecimals,
15+
} from "../../../consts";
1216
import { formatNumberLamports } from "../../Overview/ValidatorsCard/formatAmt";
1317
import {
1418
setScrollFuncsAtom,
@@ -222,9 +226,9 @@ function getRowValues(publish: SlotPublish): RowValues {
222226
);
223227
const totalFees = formatNumberLamports(
224228
(publish.transaction_fee ?? 0n) + (publish.priority_fee ?? 0n),
225-
3,
229+
solDecimals,
226230
{
227-
decimals: 3,
231+
decimals: solDecimals,
228232
trailingZeroes: true,
229233
},
230234
);
@@ -239,8 +243,8 @@ function getRowValues(publish: SlotPublish): RowValues {
239243
? (Number(publish.priority_fee) / lamportsPerSol).toString()
240244
: "0";
241245

242-
const tips = formatNumberLamports(publish.tips ?? 0n, 3, {
243-
decimals: 3,
246+
const tips = formatNumberLamports(publish.tips ?? 0n, solDecimals, {
247+
decimals: solDecimals,
244248
trailingZeroes: true,
245249
});
246250
const tipsFull =

src/features/Overview/SlotPerformance/ComputeUnitsCard/CuChartTooltip.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import styles from "./cuChartTooltip.module.css";
55
import { Text } from "@radix-ui/themes";
66
import clsx from "clsx";
77
import { getFmtStake } from "../../../../utils";
8+
import { solDecimals } from "../../../../consts";
89

910
export default function CuChartTooltip() {
1011
const chartData = useAtomValue(cuChartTooltipDataAtom);
@@ -34,11 +35,11 @@ export default function CuChartTooltip() {
3435
</Text>
3536
<Text className={clsx(styles.tips, styles.label)}>Tips</Text>
3637
<Text className={styles.tips}>
37-
{getFmtStake(BigInt(chartData.tips || 0))}
38+
{getFmtStake(BigInt(chartData.tips || 0), solDecimals)}
3839
</Text>
3940
<Text className={clsx(styles.fees, styles.label)}>Fees</Text>
4041
<Text className={styles.fees}>
41-
{getFmtStake(BigInt(chartData.fees || 0))}
42+
{getFmtStake(BigInt(chartData.fees || 0), solDecimals)}
4243
</Text>
4344
</div>
4445
)}

src/features/Overview/SlotPerformance/SankeyControls.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { DisplayType, sankeyDisplayTypeAtom, selectedSlotAtom } from "./atoms";
66
import { useSlotQueryResponseDetailed } from "../../../hooks/useSlotQuery";
77
import { fixValue } from "../../../utils";
88
import { useMemo, useState } from "react";
9-
import { lamportsPerSol } from "../../../consts";
9+
import { lamportsPerSol, solDecimals } from "../../../consts";
1010
import { formatNumber } from "../../../numUtils";
1111
import RowSeparator from "../../../components/RowSeparator";
1212
import { PlusIcon, MinusIcon } from "@radix-ui/react-icons";
@@ -61,11 +61,11 @@ function SlotStats() {
6161
const values = useMemo(() => {
6262
if (!query.response?.publish) return;
6363

64-
const transactionFee3Decimals = query.response.publish.transaction_fee
64+
const transactionFeeRounded = query.response.publish.transaction_fee
6565
? formatNumber(
6666
Number(query.response.publish.transaction_fee) / lamportsPerSol,
6767
{
68-
decimals: 3,
68+
decimals: solDecimals,
6969
},
7070
)
7171
: "0";
@@ -76,11 +76,11 @@ function SlotStats() {
7676
).toFixed(9)
7777
: "0";
7878

79-
const priorityFee3Decimals = query.response.publish.priority_fee
79+
const priorityFeeRounded = query.response.publish.priority_fee
8080
? formatNumber(
8181
Number(query.response.publish.priority_fee) / lamportsPerSol,
8282
{
83-
decimals: 3,
83+
decimals: solDecimals,
8484
},
8585
)
8686
: "0";
@@ -91,9 +91,9 @@ function SlotStats() {
9191
)
9292
: "0";
9393

94-
const tips3Decimals = query.response.publish.tips
94+
const tipsRounded = query.response.publish.tips
9595
? formatNumber(Number(query.response.publish.tips) / lamportsPerSol, {
96-
decimals: 3,
96+
decimals: solDecimals,
9797
})
9898
: "0";
9999

@@ -106,11 +106,11 @@ function SlotStats() {
106106
return {
107107
computeUnits,
108108
transactionFeeFull,
109-
transactionFee3Decimals,
109+
transactionFeeRounded,
110110
priorityFeeFull,
111-
priorityFee3Decimals,
111+
priorityFeeRounded,
112112
tips,
113-
tips3Decimals,
113+
tipsRounded,
114114
};
115115
}, [query.response]);
116116

@@ -141,7 +141,7 @@ function SlotStats() {
141141
}
142142
>
143143
<Text align="right" color="cyan">
144-
{values?.priorityFee3Decimals ?? "-"}
144+
{values?.priorityFeeRounded ?? "-"}
145145
</Text>
146146
</Tooltip>
147147
<Text color="indigo">Transaction Fees</Text>
@@ -153,13 +153,13 @@ function SlotStats() {
153153
}
154154
>
155155
<Text align="right" color="indigo">
156-
{values?.transactionFee3Decimals ?? "-"}
156+
{values?.transactionFeeRounded ?? "-"}
157157
</Text>
158158
</Tooltip>
159159
<Text color="jade">Tips</Text>
160160
<Tooltip content={values?.tips ? `${values?.tips} SOL` : null}>
161161
<Text align="right" color="jade">
162-
{values?.tips3Decimals ?? "-"}
162+
{values?.tipsRounded ?? "-"}
163163
</Text>
164164
</Tooltip>
165165
<div style={{ gridColumn: "span 2" }}>

src/features/Overview/SlotPerformance/TransactionBarsCard/ChartTooltip.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
incomePerCuToggleControlColor,
2828
iconButtonColor,
2929
} from "../../../../colors";
30+
import { solDecimals } from "../../../../consts";
3031

3132
export default function ChartTooltip() {
3233
const slot = useAtomValue(selectedSlotAtom);
@@ -164,10 +165,9 @@ function IncomeDisplay({ transactions, txnIdx }: IncomeDisplayProps) {
164165
return (
165166
<LabelValueDisplay
166167
label="CU Income"
167-
value={`${calcTxnIncome(
168-
transactions,
169-
txnIdx,
170-
)?.toLocaleString()}${rankText}`}
168+
value={`${calcTxnIncome(transactions, txnIdx)?.toLocaleString(undefined, {
169+
maximumFractionDigits: solDecimals,
170+
})}${rankText}`}
171171
color={incomePerCuToggleControlColor}
172172
/>
173173
);

src/features/Overview/ValidatorsCard/formatAmt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { lamportsPerSol } from "../../../consts";
1+
import { lamportsPerSol, solDecimals } from "../../../consts";
22
import type { FormatNumberOptions } from "../../../numUtils";
33
import { formatNumber } from "../../../numUtils";
44

55
export function formatNumberLamports(
66
value: bigint,
7-
decimalCount: number = 3,
7+
decimalCount: number = solDecimals,
88
formatOptions?: FormatNumberOptions,
99
) {
1010
if (!value) return "0";

src/numUtils.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ export interface NumberFormatOptions {
1616
trailingZeroes?: boolean;
1717
}
1818

19-
export const numberFormat = ({
20-
decimals = 4,
21-
significantDigits,
22-
trailingZeroes = true,
23-
}: NumberFormatOptions = {}): Intl.NumberFormat =>
24-
nfMemo(decimals, significantDigits, trailingZeroes);
25-
2619
const nfMemo = memoize(
2720
(decimals?: number, significantDigits?: number, trailingZeroes?: boolean) => {
2821
return new Intl.NumberFormat(undefined, {

src/utils.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,17 @@ export function getStake(peer: Peer) {
105105
);
106106
}
107107

108-
export function getSolString(lamportAmount?: bigint) {
108+
export function getSolString(
109+
lamportAmount?: bigint,
110+
smallValueDecimals?: number,
111+
) {
109112
if (lamportAmount === undefined) return;
110113

111114
const solAmount = Number(lamportAmount) / lamportsPerSol;
112115
if (solAmount < 1) {
113-
return solAmount.toLocaleString();
116+
return solAmount.toLocaleString(undefined, {
117+
maximumFractionDigits: smallValueDecimals,
118+
});
114119
}
115120

116121
if (solAmount < 100) {
@@ -124,8 +129,8 @@ export function getSolString(lamportAmount?: bigint) {
124129
});
125130
}
126131

127-
export function getFmtStake(stake?: bigint) {
128-
const solString = getSolString(stake);
132+
export function getFmtStake(stake?: bigint, smallValueDecimals?: number) {
133+
const solString = getSolString(stake, smallValueDecimals);
129134
if (solString === undefined) return;
130135

131136
return `${solString}\xa0SOL`;

0 commit comments

Comments
 (0)