|
3 | 3 | QueryOptionsProvider, |
4 | 4 | useLazyLoadQuery, |
5 | 5 | useNativeTokenAmountFromPlanck, |
6 | | - Await, |
7 | 6 | } from "@reactive-dot/react"; |
8 | 7 | import { createFileRoute } from "@tanstack/react-router"; |
9 | 8 | import { Suspense } from "react"; |
@@ -40,16 +39,9 @@ function ValidatorsPage() { |
40 | 39 | <SuspendableTotalValidators /> |
41 | 40 | </Suspense> |
42 | 41 | </InfoHeader.Item> |
43 | | - <InfoHeader.Item title="Nominators"> |
| 42 | + <InfoHeader.Item title="Active nominators"> |
44 | 43 | <Suspense fallback={<CircularProgressIndicator size="text" />}> |
45 | | - <Await |
46 | | - promise={useLazyLoadQuery( |
47 | | - (query) => query.storage("Staking", "CounterForNominators"), |
48 | | - { chainId: useStakingChainId(), use: false }, |
49 | | - )} |
50 | | - > |
51 | | - {(count) => count.toLocaleString()} |
52 | | - </Await> |
| 44 | + <SuspendableActiveNominators /> |
53 | 45 | </Suspense> |
54 | 46 | </InfoHeader.Item> |
55 | 47 | </InfoHeader> |
@@ -90,6 +82,26 @@ function SuspendableTotalValidators() { |
90 | 82 | return `${validatorCount.toLocaleString()} / ${maxValidatorCount?.toLocaleString()}`; |
91 | 83 | } |
92 | 84 |
|
| 85 | +function SuspendableActiveNominators() { |
| 86 | + const [activeEra, totalNominators] = useLazyLoadQuery( |
| 87 | + (query) => |
| 88 | + query |
| 89 | + .storage("Staking", "ActiveEra", []) |
| 90 | + .storage("Staking", "CounterForNominators"), |
| 91 | + { chainId: useStakingChainId() }, |
| 92 | + ); |
| 93 | + |
| 94 | + const stakers = useLazyLoadQuery( |
| 95 | + (query) => |
| 96 | + query.storageEntries("Staking", "ErasStakersOverview", [ |
| 97 | + activeEra?.index ?? 0, |
| 98 | + ]), |
| 99 | + { chainId: useStakingChainId() }, |
| 100 | + ); |
| 101 | + |
| 102 | + return `${stakers.reduce((prev, [__, curr]) => prev + curr.nominator_count, 0).toLocaleString()} / ${totalNominators.toLocaleString()}`; |
| 103 | +} |
| 104 | + |
93 | 105 | function SuspendableTotalStaked() { |
94 | 106 | const activeEra = useLazyLoadQuery( |
95 | 107 | (builder) => builder.storage("Staking", "ActiveEra"), |
|
0 commit comments