Skip to content

Commit 8cd4792

Browse files
committed
clean up code a bit
1 parent 71dd9f4 commit 8cd4792

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

apps/staking/src/components/Header/stats.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,30 @@ export const Stats = ({ className, ...props }: HTMLProps<HTMLDivElement>) => {
5252
};
5353

5454
const Loading = () => (
55-
<div className="mb-1 h-5 w-10 animate-pulse rounded-md bg-white/30" />
55+
<div className="inline-block h-[1em] w-10 animate-pulse rounded-md bg-white/30" />
5656
);
5757

5858
const fetchStats = async (connection: Connection) => {
5959
const client = new PythStakingClient({ connection });
60-
const poolData = await client.getPoolDataAccount();
61-
const rewardCustodyAccount = await client.getRewardCustodyAccount();
62-
const totalDelegated = sum(
63-
poolData.delState.map(
64-
({ totalDelegation, deltaDelegation }) =>
65-
totalDelegation + deltaDelegation,
66-
),
67-
);
68-
const totalSelfStaked = sum(
69-
poolData.selfDelState.map(
70-
({ totalDelegation, deltaDelegation }) =>
71-
totalDelegation + deltaDelegation,
72-
),
73-
);
60+
const [poolData, rewardCustodyAccount] = await Promise.all([
61+
client.getPoolDataAccount(),
62+
client.getRewardCustodyAccount(),
63+
]);
7464

7565
return {
76-
totalStaked: totalDelegated + totalSelfStaked,
66+
totalStaked:
67+
sumDelegations(poolData.delState) + sumDelegations(poolData.selfDelState),
7768
rewardsDistributed:
7869
poolData.claimableRewards +
7970
INITIAL_REWARD_POOL_SIZE -
8071
rewardCustodyAccount.amount,
8172
};
8273
};
8374

84-
const sum = (values: bigint[]): bigint =>
85-
values.reduce((acc, value) => acc + value, 0n);
75+
const sumDelegations = (
76+
values: { totalDelegation: bigint; deltaDelegation: bigint }[],
77+
) =>
78+
values.reduce(
79+
(acc, value) => acc + value.totalDelegation + value.deltaDelegation,
80+
0n,
81+
);

0 commit comments

Comments
 (0)