Skip to content

Commit 67a3351

Browse files
committed
Replace BrandProgressBar with custom Oasis UI Library component
1 parent e40b95c commit 67a3351

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

src/app/components/ProgressBar/index.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { FC } from 'react'
1+
import { FC, ReactNode } from 'react'
22
import Box from '@mui/material/Box'
33
import LinearProgress, { linearProgressClasses } from '@mui/material/LinearProgress'
44
import { styled } from '@mui/material/styles'
55
import { COLORS } from 'styles/theme/colors'
6+
import { Progress } from '@oasisprotocol/ui-library/src/components/progress'
67

78
type VerticalProgressBarProps = {
89
value: number
@@ -43,11 +44,23 @@ const StyledLinearProgress = styled(LinearProgress, {
4344
...(barBackgroundColor && { backgroundColor: barBackgroundColor }),
4445
}))
4546

46-
export const BrandProgressBar = styled(LinearProgress)(() => ({
47-
[`&.${linearProgressClasses.determinate} > .${linearProgressClasses.bar1Determinate}`]: {
48-
backgroundColor: COLORS.brandDark,
49-
},
50-
borderColor: COLORS.grayLight,
51-
backgroundColor: COLORS.grayLight,
52-
height: '12px',
53-
}))
47+
type CustomProgressProps = {
48+
value?: number
49+
max?: number
50+
label: ReactNode
51+
}
52+
53+
export const CustomProgress: FC<CustomProgressProps> = ({ value, max, label }) => {
54+
if (!value || !max) {
55+
return null
56+
}
57+
58+
return (
59+
<div className="w-full relative">
60+
<Progress value={(value / max) * 100} className="h-8 bg-muted-foreground rounded-[8px]" />
61+
<span className="absolute inset-y-0 left-3 flex items-center text-white text-xs font-normal">
62+
{label}
63+
</span>
64+
</div>
65+
)
66+
}

src/app/pages/ConsensusDashboardPage/SnapshotEpoch.tsx

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { useGetConsensusEpochs } from '../../../oasis-nexus/api'
55
import { useGetStatus } from '../../../oasis-nexus/api'
66
import { SearchScope } from '../../../types/searchScope'
77
import { SnapshotTextCard } from '../../components/Snapshots/SnapshotCard'
8-
import { BrandProgressBar } from '../../components/ProgressBar'
8+
import { PercentageValue } from '../../components/PercentageValue'
9+
import { CustomProgress } from '../../components/ProgressBar'
910

1011
// We need to get the previous epoch to compute end_height for the current one
1112
// This may not be precise during abnormal network conditions, but such conditions never happened so far
@@ -18,17 +19,17 @@ export const SnapshotEpoch: FC<{ scope: SearchScope }> = ({ scope }) => {
1819
const epochsQuery = useGetConsensusEpochs(scope.network, { limit: epochsLimit })
1920
const epochs = epochsQuery.data?.data.epochs
2021
const epoch = epochs?.length && epochs[0].id
21-
let percentageValue = undefined
22+
let epochDiffHeight = undefined
23+
let completedBlocksInCurrentEpoch = undefined
2224

2325
if (epochs && epochs[1]?.end_height && blockHeight) {
24-
const epochDiffHeight = epochs[1]?.end_height - epochs[1]?.start_height
25-
const completedBlocksInCurrentEpoch = blockHeight - epochs[0]?.start_height
26-
percentageValue = completedBlocksInCurrentEpoch / epochDiffHeight
26+
epochDiffHeight = epochs[1]?.end_height - epochs[1]?.start_height + 1
27+
completedBlocksInCurrentEpoch = blockHeight - epochs[0]?.start_height
2728
}
2829

2930
return (
3031
<SnapshotTextCard
31-
title={t('currentEpoch')}
32+
title={t('snapshotEpochTitle')}
3233
label={
3334
blockHeight !== undefined && (
3435
<Typography className="font-normal flex gap-2 items-center">
@@ -46,30 +47,21 @@ export const SnapshotEpoch: FC<{ scope: SearchScope }> = ({ scope }) => {
4647
}
4748
>
4849
{epoch !== undefined && (
49-
<>
50-
{percentageValue !== undefined && (
51-
<div className="-mt-2 mb-2">
52-
<BrandProgressBar value={percentageValue * 100} variant="determinate" />
53-
</div>
54-
)}
55-
<div className="flex items-baseline gap-2">
56-
{epoch.toLocaleString()}
57-
{percentageValue !== undefined && (
58-
<Typography variant="xsmall" textColor="muted">
59-
(
60-
{t('common.valuePair', {
61-
value: percentageValue,
62-
formatParams: {
63-
value: {
64-
style: 'percent',
65-
} satisfies Intl.NumberFormatOptions,
66-
},
67-
})}
68-
)
69-
</Typography>
70-
)}
71-
</div>
72-
</>
50+
<CustomProgress
51+
value={completedBlocksInCurrentEpoch}
52+
max={epochDiffHeight}
53+
label={
54+
<>
55+
<span className="font-bold">{completedBlocksInCurrentEpoch}</span>/{epochDiffHeight} (
56+
<PercentageValue
57+
value={completedBlocksInCurrentEpoch}
58+
total={epochDiffHeight}
59+
maximumFractionDigits={1}
60+
/>
61+
)
62+
</>
63+
}
64+
/>
7365
)}
7466
</SnapshotTextCard>
7567
)

src/locales/en/translation.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@
200200
}
201201
},
202202
"consensusSnapshot": {
203-
"blockHeight": "Block Height <BlockHeight />",
203+
"blockHeight": "Current block height <BlockHeight />",
204204
"title": "Consensus Snapshot",
205205
"totalCirculation": "This is <StakedPercentage /> of the total circulation"
206206
},
207-
"currentEpoch": "Current Epoch",
207+
"snapshotEpochTitle": "Current epoch & block height",
208208
"networkProposal": {
209209
"close": "Closed",
210210
"closeTooltip": "Voting ended on epoch shown.",

0 commit comments

Comments
 (0)