Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text in tips on staking page #34

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ui/pages/Staking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Staking = () => {
const detailsInfoItems = [
{
title: 'Total Validators',
hint: 'Validators secure the Polkadot Relay Chain by validating blocks.',
hint: 'Validators secure the Atleta Relay Chain by validating blocks.',
isLoading,
value: stats.totalValidators,
},
Expand All @@ -34,7 +34,7 @@ const Staking = () => {
},
{
title: 'Active Pools',
hint: 'The current amount of active nomination pools on Polkadot.',
hint: 'The current amount of active nomination pools on Atleta.',
isLoading,
value: stats.activePools,
},
Expand Down
9 changes: 6 additions & 3 deletions ui/staking/StakingStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useSupply } from './utils/useSupply';
const StakingStats = () => {
const registry = useRegistry();

const eraRemaining = useEraRemaining();
const { erasProgress, estimatedEraLength } = useEraRemaining();
const supply = useSupply();

return (
Expand Down Expand Up @@ -41,8 +41,11 @@ const StakingStats = () => {
<StatsItem
icon="clock-light"
title="Time Remaining This Era"
value={ `${ Math.trunc(eraRemaining.asHours()) }h ${ eraRemaining.minutes() }m ${ eraRemaining.seconds() }s` }
tooltipLabel="At the end of each era, validators are rewarded DOT based on era points accumulated. 1 era is currently 24 hours in Polkadot."
value={ `${ Math.trunc(erasProgress.asHours()) }h ${ erasProgress.minutes() }m ${ erasProgress.seconds() }s` }
tooltipLabel={
`At the end of each era, validators are rewarded ${ registry.symbol } based on era points accumulated. ` +
`1 era is currently ${ estimatedEraLength.asHours() } hour${ estimatedEraLength.asHours() > 1 ? 's' : '' } in Atleta.`
}
/>
</Grid>
);
Expand Down
19 changes: 15 additions & 4 deletions ui/staking/utils/useEraRemaining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type CalcRemainingProps = {
expectedBlockTime: number;
}

type CalcRemainingReturn = {
erasProgress: number;
estimatedEraLength: number;
}

dayjs.extend(duration);

const calcRemaining = ({
Expand All @@ -29,7 +34,7 @@ const calcRemaining = ({
erasStartSessionIndex,
sessionsPerEra,
expectedBlockTime,
}: CalcRemainingProps): number => {
}: CalcRemainingProps): CalcRemainingReturn => {
// era length in slots
const estimatedEraLength = sessionsPerEra * sessionLength * expectedBlockTime;
// when epoch started
Expand All @@ -41,11 +46,14 @@ const calcRemaining = ({

// slots length possinble may be in constants
// now it's 6000
return estimatedEraLength - erasProgress * 6000;
return {
erasProgress: estimatedEraLength - erasProgress * 6000,
estimatedEraLength,
};
};

export const useEraRemaining = () => {
const [ remaining, setRemaining ] = useState(0);
const [ remaining, setRemaining ] = useState<CalcRemainingReturn>({ erasProgress: 0, estimatedEraLength: 0 });
const { api } = usePolkadotApi();

useEffect(() => {
Expand Down Expand Up @@ -93,5 +101,8 @@ export const useEraRemaining = () => {
};
}, [ api ]);

return dayjs.duration(remaining);
return {
erasProgress: dayjs.duration(remaining.erasProgress),
estimatedEraLength: dayjs.duration(remaining.estimatedEraLength),
};
};
Loading