@@ -52,34 +52,30 @@ export const Stats = ({ className, ...props }: HTMLProps<HTMLDivElement>) => {
52
52
} ;
53
53
54
54
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" />
56
56
) ;
57
57
58
58
const fetchStats = async ( connection : Connection ) => {
59
59
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
+ ] ) ;
74
64
75
65
return {
76
- totalStaked : totalDelegated + totalSelfStaked ,
66
+ totalStaked :
67
+ sumDelegations ( poolData . delState ) + sumDelegations ( poolData . selfDelState ) ,
77
68
rewardsDistributed :
78
69
poolData . claimableRewards +
79
70
INITIAL_REWARD_POOL_SIZE -
80
71
rewardCustodyAccount . amount ,
81
72
} ;
82
73
} ;
83
74
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