|
1 | 1 | import styles from "./sankeyControls.module.css"; |
2 | | -import { Button, Flex, Text, Tooltip } from "@radix-ui/themes"; |
3 | 2 | import * as ToggleGroup from "@radix-ui/react-toggle-group"; |
4 | | -import { useAtom, useAtomValue } from "jotai"; |
5 | | -import { DisplayType, sankeyDisplayTypeAtom, selectedSlotAtom } from "./atoms"; |
6 | | -import { useSlotQueryResponseDetailed } from "../../../hooks/useSlotQuery"; |
7 | | -import { fixValue } from "../../../utils"; |
8 | | -import { useMemo, useState } from "react"; |
9 | | -import { lamportsPerSol, solDecimals } from "../../../consts"; |
10 | | -import { formatNumber } from "../../../numUtils"; |
11 | | -import RowSeparator from "../../../components/RowSeparator"; |
12 | | -import { PlusIcon, MinusIcon } from "@radix-ui/react-icons"; |
| 3 | +import { useAtom } from "jotai"; |
| 4 | +import { DisplayType, sankeyDisplayTypeAtom } from "./atoms"; |
13 | 5 |
|
14 | 6 | export default function SankeyControls() { |
15 | 7 | const [value, setValue] = useAtom(sankeyDisplayTypeAtom); |
@@ -47,130 +39,6 @@ export default function SankeyControls() { |
47 | 39 | Rate |
48 | 40 | </ToggleGroup.Item> |
49 | 41 | </ToggleGroup.Root> |
50 | | - <SlotStats /> |
51 | 42 | </div> |
52 | 43 | ); |
53 | 44 | } |
54 | | - |
55 | | -function SlotStats() { |
56 | | - const [isExpanded, setIsExpanded] = useState(true); |
57 | | - |
58 | | - const selectedSlot = useAtomValue(selectedSlotAtom); |
59 | | - const query = useSlotQueryResponseDetailed(selectedSlot); |
60 | | - |
61 | | - const values = useMemo(() => { |
62 | | - if (!query.response?.publish) return; |
63 | | - |
64 | | - const transactionFeeRounded = query.response.publish.transaction_fee |
65 | | - ? formatNumber( |
66 | | - Number(query.response.publish.transaction_fee) / lamportsPerSol, |
67 | | - { |
68 | | - decimals: solDecimals, |
69 | | - }, |
70 | | - ) |
71 | | - : "0"; |
72 | | - |
73 | | - const transactionFeeFull = query.response.publish.transaction_fee |
74 | | - ? ( |
75 | | - Number(query.response.publish.transaction_fee) / lamportsPerSol |
76 | | - ).toFixed(9) |
77 | | - : "0"; |
78 | | - |
79 | | - const priorityFeeRounded = query.response.publish.priority_fee |
80 | | - ? formatNumber( |
81 | | - Number(query.response.publish.priority_fee) / lamportsPerSol, |
82 | | - { |
83 | | - decimals: solDecimals, |
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 tipsRounded = query.response.publish.tips |
95 | | - ? formatNumber(Number(query.response.publish.tips) / lamportsPerSol, { |
96 | | - decimals: solDecimals, |
97 | | - }) |
98 | | - : "0"; |
99 | | - |
100 | | - const tips = query.response.publish.tips |
101 | | - ? (Number(query.response.publish.tips) / lamportsPerSol).toFixed(9) |
102 | | - : "0"; |
103 | | - |
104 | | - const computeUnits = fixValue(query.response.publish.compute_units ?? 0); |
105 | | - |
106 | | - return { |
107 | | - computeUnits, |
108 | | - transactionFeeFull, |
109 | | - transactionFeeRounded, |
110 | | - priorityFeeFull, |
111 | | - priorityFeeRounded, |
112 | | - tips, |
113 | | - tipsRounded, |
114 | | - }; |
115 | | - }, [query.response]); |
116 | | - |
117 | | - if (!selectedSlot) return; |
118 | | - |
119 | | - return ( |
120 | | - <Flex direction="column" gap="1" className={styles.statsContainer}> |
121 | | - <Button |
122 | | - size="2" |
123 | | - variant="outline" |
124 | | - className={styles.slotStatsToggleButton} |
125 | | - onClick={() => setIsExpanded((prev) => !prev)} |
126 | | - > |
127 | | - Metrics{" "} |
128 | | - {isExpanded ? ( |
129 | | - <MinusIcon style={{ width: 10, height: 10 }} /> |
130 | | - ) : ( |
131 | | - <PlusIcon style={{ width: 10, height: 10 }} /> |
132 | | - )} |
133 | | - </Button> |
134 | | - |
135 | | - {isExpanded && ( |
136 | | - <div className={styles.stats}> |
137 | | - <Text color="cyan">Priority Fees</Text> |
138 | | - <Tooltip |
139 | | - content={ |
140 | | - values?.priorityFeeFull ? `${values?.priorityFeeFull} SOL` : null |
141 | | - } |
142 | | - > |
143 | | - <Text align="right" color="cyan"> |
144 | | - {values?.priorityFeeRounded ?? "-"} |
145 | | - </Text> |
146 | | - </Tooltip> |
147 | | - <Text color="indigo">Transaction Fees</Text> |
148 | | - <Tooltip |
149 | | - content={ |
150 | | - values?.transactionFeeFull |
151 | | - ? `${values?.transactionFeeFull} SOL` |
152 | | - : null |
153 | | - } |
154 | | - > |
155 | | - <Text align="right" color="indigo"> |
156 | | - {values?.transactionFeeRounded ?? "-"} |
157 | | - </Text> |
158 | | - </Tooltip> |
159 | | - <Text color="jade">Tips</Text> |
160 | | - <Tooltip content={values?.tips ? `${values?.tips} SOL` : null}> |
161 | | - <Text align="right" color="jade"> |
162 | | - {values?.tipsRounded ?? "-"} |
163 | | - </Text> |
164 | | - </Tooltip> |
165 | | - <div style={{ gridColumn: "span 2" }}> |
166 | | - <RowSeparator my="0" /> |
167 | | - </div> |
168 | | - <Text color="plum">Compute Units</Text> |
169 | | - <Text align="right" color="plum"> |
170 | | - {values?.computeUnits?.toLocaleString() ?? "-"} |
171 | | - </Text> |
172 | | - </div> |
173 | | - )} |
174 | | - </Flex> |
175 | | - ); |
176 | | -} |
0 commit comments