Skip to content

Commit 9e4332c

Browse files
chore: round sankey controls values to 3 decimal places
1 parent 275e6b6 commit 9e4332c

File tree

2 files changed

+68
-25
lines changed

2 files changed

+68
-25
lines changed

src/features/Overview/SlotPerformance/SankeyControls.tsx

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import styles from "./sankeyControls.module.css";
2-
import { Text } from "@radix-ui/themes";
2+
import { Text, Tooltip } from "@radix-ui/themes";
33
import * as ToggleGroup from "@radix-ui/react-toggle-group";
44
import { useAtom, useAtomValue } from "jotai";
55
import { DisplayType, sankeyDisplayTypeAtom, selectedSlotAtom } from "./atoms";
66
import { useSlotQueryResponse } from "../../../hooks/useSlotQuery";
77
import { fixValue } from "../../../utils";
88
import { useMemo } from "react";
99
import { lamportsPerSol } from "../../../consts";
10+
import { formatNumber } from "../../../numUtils";
1011

1112
export default function SankeyControls() {
1213
const [value, setValue] = useAtom(sankeyDisplayTypeAtom);
@@ -60,24 +61,45 @@ function SlotStats() {
6061
const totalTxns = fixValue(query.response.publish.transactions ?? 0);
6162
const nonVoteTxns = totalTxns - voteTxns;
6263

63-
const transactionFeeFull =
64-
query.response.publish.transaction_fee != null
65-
? (
66-
Number(query.response.publish.transaction_fee) / lamportsPerSol
67-
).toFixed(9)
68-
: "0";
64+
const transactionFee3Decimals = query.response.publish.transaction_fee
65+
? formatNumber(
66+
Number(query.response.publish.transaction_fee) / lamportsPerSol,
67+
{
68+
decimals: 3,
69+
},
70+
)
71+
: "0";
6972

70-
const priorityFeeFull =
71-
query.response.publish.priority_fee != null
72-
? (
73-
Number(query.response.publish.priority_fee) / lamportsPerSol
74-
).toFixed(9)
75-
: "0";
73+
const transactionFeeFull = query.response.publish.transaction_fee
74+
? (
75+
Number(query.response.publish.transaction_fee) / lamportsPerSol
76+
).toFixed(9)
77+
: "0";
7678

77-
const tips =
78-
query.response.publish.tips != null
79-
? (Number(query.response.publish.tips) / lamportsPerSol).toFixed(9)
80-
: "0";
79+
const priorityFee3Decimals = query.response.publish.priority_fee
80+
? formatNumber(
81+
Number(query.response.publish.priority_fee) / lamportsPerSol,
82+
{
83+
decimals: 3,
84+
},
85+
)
86+
: "0";
87+
88+
const priorityFeeFull = query.response.publish.priority_fee
89+
? (Number(query.response.publish.priority_fee) / lamportsPerSol).toFixed(
90+
9,
91+
)
92+
: "0";
93+
94+
const tips3Decimals = query.response.publish.tips
95+
? formatNumber(Number(query.response.publish.tips) / lamportsPerSol, {
96+
decimals: 3,
97+
})
98+
: "0";
99+
100+
const tips = query.response.publish.tips
101+
? (Number(query.response.publish.tips) / lamportsPerSol).toFixed(9)
102+
: "0";
81103

82104
const computeUnits = fixValue(query.response.publish.compute_units ?? 0);
83105

@@ -86,8 +108,11 @@ function SlotStats() {
86108
voteTxns,
87109
nonVoteTxns,
88110
transactionFeeFull,
111+
transactionFee3Decimals,
89112
priorityFeeFull,
113+
priorityFee3Decimals,
90114
tips,
115+
tips3Decimals,
91116
};
92117
}, [query.response]);
93118

@@ -96,15 +121,33 @@ function SlotStats() {
96121
return (
97122
<div className={styles.stats}>
98123
<Text>Priority Fees</Text>
99-
<Text style={{ textAlign: "right" }}>
100-
{values?.priorityFeeFull ?? "-"}
101-
</Text>
124+
<Tooltip
125+
content={
126+
values?.priorityFeeFull ? `${values?.priorityFeeFull} SOL` : null
127+
}
128+
>
129+
<Text style={{ textAlign: "right" }}>
130+
{values?.priorityFee3Decimals ?? "-"}
131+
</Text>
132+
</Tooltip>
102133
<Text>Transaction Fees</Text>
103-
<Text style={{ textAlign: "right" }}>
104-
{values?.transactionFeeFull ?? "-"}
105-
</Text>
134+
<Tooltip
135+
content={
136+
values?.transactionFeeFull
137+
? `${values?.transactionFeeFull} SOL`
138+
: null
139+
}
140+
>
141+
<Text style={{ textAlign: "right" }}>
142+
{values?.transactionFee3Decimals ?? "-"}
143+
</Text>
144+
</Tooltip>
106145
<Text>Tips</Text>
107-
<Text style={{ textAlign: "right" }}>{values?.tips ?? "-"}</Text>
146+
<Tooltip content={values?.tips ? `${values?.tips} SOL` : null}>
147+
<Text style={{ textAlign: "right" }}>
148+
{values?.tips3Decimals ?? "-"}
149+
</Text>
150+
</Tooltip>
108151
<Text>Vote Transactions</Text>
109152
<Text style={{ textAlign: "right" }}>
110153
{values?.voteTxns?.toLocaleString() ?? "-"}

src/features/Overview/SlotPerformance/sankeyControls.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/* align-items: center; */
1717
column-gap: 10px;
1818
row-gap: 4px;
19-
min-width: 170px;
19+
min-width: 203px;
2020
font-variant-numeric: tabular-nums;
2121

2222
border-radius: 5px;

0 commit comments

Comments
 (0)