Skip to content

Commit fe0b8cb

Browse files
committed
add voting power and commission data
1 parent 751e2c2 commit fe0b8cb

File tree

5 files changed

+62
-26
lines changed

5 files changed

+62
-26
lines changed

examples/stake-tokens/components/react/all-validators.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,14 @@ const AllValidators = ({
200200
: ''
201201
}
202202
name={currentValidator?.description?.moniker || ''}
203-
commission={5}
203+
commission={
204+
currentValidator?.commission?.commissionRates?.rate
205+
? exponentiate(
206+
currentValidator.commission.commissionRates.rate,
207+
-16
208+
).toFixed(0)
209+
: 0
210+
}
204211
apr={22.08}
205212
/>
206213
<ValidatorDesc
@@ -273,12 +280,18 @@ const AllValidators = ({
273280
</Box>
274281
</Td>
275282
<Td>
276-
{/* {validator.voting} <Token color="blackAlpha.800" /> */}
277-
10,000,000&nbsp;
283+
{Math.floor(exponentiate(validator.tokens, -exp))}
284+
&nbsp;
278285
<Token color="blackAlpha.800" token={coin.symbol} />
279286
</Td>
280-
{/* <Td>{validator.commission}</Td> */}
281-
<Td>5%</Td>
287+
<Td>
288+
{validator.commission?.commissionRates?.rate &&
289+
exponentiate(
290+
validator.commission.commissionRates.rate,
291+
-16
292+
).toFixed(0)}
293+
%
294+
</Td>
282295
<Td>
283296
<Box width="100%" display="flex" alignItems="center">
284297
{/* <Text>{validator.apr}</Text> */}

examples/stake-tokens/components/react/delegate-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const ValidatorInfo = ({
3434
}: {
3535
imgUrl: string;
3636
name: string;
37-
commission: number;
37+
commission: number | string;
3838
apr: number;
3939
}) => (
4040
<Flex alignItems="center" gap={4} mb={4}>

examples/stake-tokens/components/react/my-validators.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ const MyValidators = ({
161161
address: validator.operatorAddress,
162162
staked: exponentiate(delegation.balance!.amount, -exp),
163163
reward: Number(exponentiate(rewardAmount, -exp).toFixed(6)),
164+
commission: validator?.commission?.commissionRates?.rate,
164165
};
165166
});
166167

@@ -391,7 +392,11 @@ const MyValidators = ({
391392
: ''
392393
}
393394
name={currentValidator?.name || ''}
394-
commission={5}
395+
commission={
396+
currentValidator?.commission
397+
? exponentiate(currentValidator.commission, -16).toFixed(0)
398+
: 0
399+
}
395400
apr={22.08}
396401
/>
397402
<ValidatorDesc description={currentValidator?.details || ''} />
@@ -443,7 +448,11 @@ const MyValidators = ({
443448
: ''
444449
}
445450
name={currentValidator?.name || ''}
446-
commission={5}
451+
commission={
452+
currentValidator?.commission
453+
? exponentiate(currentValidator.commission, -16).toFixed(0)
454+
: 0
455+
}
447456
apr={22.08}
448457
/>
449458
<DelegateWarning unbondingDays={unbondingDays} />
@@ -494,7 +503,11 @@ const MyValidators = ({
494503
: ''
495504
}
496505
name={currentValidator?.name || ''}
497-
commission={5}
506+
commission={
507+
currentValidator?.commission
508+
? exponentiate(currentValidator.commission, -16).toFixed(0)
509+
: 0
510+
}
498511
apr={22.08}
499512
/>
500513
<Stack direction="column" spacing={4}>
@@ -579,12 +592,18 @@ const MyValidators = ({
579592
</Box>
580593
</Td>
581594
<Td>
582-
{/* {validator.voting} <Token color="blackAlpha.800" /> */}
583-
10,000,000&nbsp;
595+
{Math.floor(exponentiate(validator.tokens, -exp))}
596+
&nbsp;
584597
<Token color="blackAlpha.800" token={coin.symbol} />
585598
</Td>
586-
{/* <Td>{validator.commission}</Td> */}
587-
<Td>5%</Td>
599+
<Td>
600+
{validator.commission?.commissionRates?.rate &&
601+
exponentiate(
602+
validator.commission.commissionRates.rate,
603+
-16
604+
).toFixed(0)}
605+
%
606+
</Td>
588607
<Td>
589608
<Box width="100%" display="flex" alignItems="center">
590609
{/* <Text>{validator.apr}</Text> */}

examples/stake-tokens/components/react/staking.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,22 @@ export const StakingSection = ({ chainName }: { chainName: ChainName }) => {
129129
const totalReward = Number(exponentiate(reward, -exp).toFixed(6));
130130

131131
// ALL VALIDATORS
132-
const { validators: allValidators } =
133-
await client.cosmos.staking.v1beta1.validators({
134-
status: cosmos.staking.v1beta1.bondStatusToJSON(
135-
cosmos.staking.v1beta1.BondStatus.BOND_STATUS_BONDED
136-
),
137-
pagination: {
138-
key: new Uint8Array(),
139-
offset: Long.fromNumber(0),
140-
limit: Long.fromNumber(200),
141-
countTotal: false,
142-
reverse: false,
143-
},
144-
});
132+
const { validators } = await client.cosmos.staking.v1beta1.validators({
133+
status: cosmos.staking.v1beta1.bondStatusToJSON(
134+
cosmos.staking.v1beta1.BondStatus.BOND_STATUS_BONDED
135+
),
136+
pagination: {
137+
key: new Uint8Array(),
138+
offset: Long.fromNumber(0),
139+
limit: Long.fromNumber(200),
140+
countTotal: false,
141+
reverse: false,
142+
},
143+
});
144+
145+
const allValidators = validators.sort((a, b) =>
146+
new BigNumber(b.tokens).minus(new BigNumber(a.tokens)).toNumber()
147+
);
145148

146149
// DELEGATIONS
147150
const { delegationResponses: delegations } =

examples/stake-tokens/components/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,5 @@ export interface MyValidator {
9797
staked: number;
9898
reward: number;
9999
identity: string | undefined;
100+
commission: string | undefined;
100101
}

0 commit comments

Comments
 (0)