Skip to content

Commit

Permalink
Merge pull request #3022 from cardano-foundation/fix/MET-1955-show-ep…
Browse files Browse the repository at this point in the history
…och-incorrect

fix: MET-1955 fix show epoch incorrect
  • Loading branch information
Sotatek-TaiTruong authored Feb 19, 2024
2 parents 8677686 + 0675eac commit 59b46de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/components/DelegationPool/DelegationOverview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ const OverViews: React.FC = () => {
</Grid>
);
}
const slot = (currentEpoch?.slot || 0) % MAX_SLOT_EPOCH;

const slot = moment(`${currentEpoch?.endTime} GMT+0000`).isAfter(moment().utc())
? (currentEpoch?.slot || 0) % MAX_SLOT_EPOCH
: MAX_SLOT_EPOCH;
const countdown = MAX_SLOT_EPOCH - slot;
const duration = moment.duration(countdown ? countdown : 0, "second");
const days = duration.days();
Expand Down Expand Up @@ -102,7 +105,9 @@ const OverViews: React.FC = () => {
<StyledCard.Content>
<StyledCard.Title>{t("glossary.slot")}</StyledCard.Title>
<StyledCard.Value>
{(currentEpoch?.slot || 0) % MAX_SLOT_EPOCH}
{moment(`${currentEpoch?.endTime} GMT+0000`).isAfter(moment().utc())
? (currentEpoch?.slot || 0) % MAX_SLOT_EPOCH
: MAX_SLOT_EPOCH}
<Box component="span" sx={{ color: (theme) => theme.palette.secondary.light, fontWeight: "400" }}>
/ {MAX_SLOT_EPOCH}
</Box>
Expand All @@ -113,7 +118,11 @@ const OverViews: React.FC = () => {
<Box position={"relative"} top={-60} px={4}>
<StyledLinearProgress
variant="determinate"
value={(((currentEpoch?.slot || 0) % MAX_SLOT_EPOCH) / MAX_SLOT_EPOCH) * 100}
value={
moment(`${currentEpoch?.endTime} GMT+0000`).isAfter(moment().utc())
? (((currentEpoch?.slot || 0) % MAX_SLOT_EPOCH) / MAX_SLOT_EPOCH) * 100
: 100
}
/>
</Box>
</Box>
Expand Down
5 changes: 2 additions & 3 deletions src/components/Home/Statistic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ const MIN_PERCENT_SHOW_FIRST_BAR = 9;
const HomeStatistic = () => {
const { t } = useTranslation();
const { currentEpoch, blockNo } = useSelector(({ system }: RootState) => system);

const { data } = useFetch<StakeAnalytics>(API.STAKE.ANALYTICS, undefined, false, blockNo);
const { theme: themeMode } = useSelector(({ theme }: RootState) => theme);
const { liveStake = 0, activeStake = 1 } = data || {};
const supply = BigNumber(currentEpoch?.circulatingSupply || 0).div(10 ** 6);
const liveRate = new BigNumber(liveStake).div(MILION).div(supply).multipliedBy(100);
const circulatingSupply = new BigNumber(supply).multipliedBy(MILION);
const progress = moment(currentEpoch?.endTime).isAfter(moment())
const progress = moment(`${currentEpoch?.endTime} GMT+0000`).isAfter(moment().utc())
? (((currentEpoch?.slot || 0) / MAX_SLOT_EPOCH) * 100).toFixed(0)
: 100;
const isShowProgressPendingText = +progress < MAX_PERCENT_SHOW_LAST_BAR;
Expand Down Expand Up @@ -227,7 +226,7 @@ const HomeStatistic = () => {
<Title data-testid="current-epoch-number">{numberWithCommas(currentEpoch?.no)}</Title>
<Box color={({ palette }) => palette.secondary.light}>
{t("common.slot")}:{" "}
{moment(currentEpoch?.endTime).isAfter(moment())
{moment(`${currentEpoch?.endTime} GMT+0000`).isAfter(moment().utc())
? numberWithCommas(currentEpoch?.slot)
: numberWithCommas(MAX_SLOT_EPOCH)}
/ {numberWithCommas(MAX_SLOT_EPOCH)}
Expand Down

0 comments on commit 59b46de

Please sign in to comment.