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

feat: The header dep's block no need 4 epochs ago. #2461

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'
import { getCompensatedTime, getCompensationPeriod, CONSTANTS, CompensationPeriod, uniformTimeFormatter } from 'utils'
import styles from './compensationPeriodTooltip.module.scss'

const { WITHDRAW_EPOCHS, IMMATURE_EPOCHS } = CONSTANTS
const { WITHDRAW_EPOCHS } = CONSTANTS

const HOUR = 3_600_000
const HOURS_PER_EPOCH = 4 * HOUR
Expand Down Expand Up @@ -47,22 +47,6 @@ const CompensationPeriodTooltip = ({
endEpochTimestamp - (1 - CompensationPeriod.REQUEST_START) * WITHDRAW_EPOCHS * HOURS_PER_EPOCH

const { days, hours } = getCompensatedTime({ currentEpochValue: baseEpochValue, depositEpochValue })
const isImmature = baseEpochValue < depositEpochValue + IMMATURE_EPOCHS

if (isImmature) {
return (
<div className={styles.container}>
<div className={styles.compensated}>
<span>{t('nervos-dao.compensation-period.tooltip.compensated-period')}</span>
<span>{t('nervos-dao.compensation-period.tooltip.days-hours', { days, hours })}</span>
</div>
<div className={styles.divider} />
<div className={styles.times}>
<div className={styles.immature}>{t('nervos-dao.compensation-period.tooltip.immature-for-withdraw')}</div>
</div>
</div>
)
}

let stage = 'normal'
if (baseEpochTimestamp > endingStartEpochTimestamp) {
Expand Down
25 changes: 1 addition & 24 deletions packages/neuron-ui/src/components/NervosDAORecord/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import CopyZone from 'widgets/CopyZone'
import {
calculateClaimEpochValue,
ConnectionStatus,
CONSTANTS,
shannonToCKBFormatter,
uniformTimeFormatter,
getDAOCellStatus,
Expand All @@ -18,8 +17,6 @@ import CompensationPeriodTooltip from 'components/CompensationPeriodTooltip'
import styles from './daoRecordRow.module.scss'
import hooks from './hooks'

const { IMMATURE_EPOCHS, HOURS_PER_EPOCH } = CONSTANTS

const EPOCHS_PER_DAY = 6

const getDaysAndHours = (seconds: number) => {
Expand Down Expand Up @@ -122,30 +119,10 @@ export const DAORecord = ({
message = t('nervos-dao.compensation-period.stage-messages.pending')
break
}
case CellStatus.ImmatureForWithdraw: {
let hours: string | number = (depositEpochValue + IMMATURE_EPOCHS - currentEpochValue) * HOURS_PER_EPOCH
if (Number.isNaN(hours) || hours < 0 || hours > HOURS_PER_EPOCH * IMMATURE_EPOCHS) {
hours = '--'
} else {
hours = hours.toFixed(1)
}
message = t('nervos-dao.compensation-period.stage-messages.immature-for-withdraw', { hours })
break
}
case CellStatus.Deposited: {
message = t('nervos-dao.compensation-period.stage-messages.next-compensation-cycle', { days: leftDays || '--' })
break
}
case CellStatus.ImmatureForUnlock: {
let hours: number | string = (compensationEndEpochValue + IMMATURE_EPOCHS - currentEpochValue) * HOURS_PER_EPOCH
if (Number.isNaN(hours) || hours < 0 || hours > HOURS_PER_EPOCH * IMMATURE_EPOCHS) {
hours = '--'
} else {
hours = hours.toFixed(1)
}
message = t('nervos-dao.compensation-period.stage-messages.immature-for-unlock', { hours })
break
}
case CellStatus.Locked: {
message = t('nervos-dao.compensation-period.stage-messages.compensation-cycle-will-end', {
days: leftDays || '--',
Expand Down Expand Up @@ -186,7 +163,7 @@ export const DAORecord = ({
<>
<div className={styles.stage}>
<CompensationProgressBar
pending={[CellStatus.Depositing, CellStatus.ImmatureForWithdraw].includes(cellStatus)}
pending={CellStatus.Depositing === cellStatus}
currentEpochValue={currentEpochValue}
endEpochValue={compensationEndEpochValue}
withdrawEpochValue={withdrawEpochValue}
Expand Down
12 changes: 6 additions & 6 deletions packages/neuron-ui/src/tests/getDAOCellStatus/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"expected": "Depositing"
},
"deposited 3.9 epochs": {
"can deposited 3.9 epochs less than 4 epochs": {
"params": {
"status": "live",
"depositEpoch": "0xa000100030a",
Expand All @@ -17,7 +17,7 @@
"currentEpochValue": 782,
"withdrawEpoch": ""
},
"expected": "ImmatureForWithdraw"
"expected": "Deposited"
},
"deposited 4 epochs": {
"params": {
Expand Down Expand Up @@ -78,7 +78,7 @@
},
"expected": "Locked"
},
"immature for unlock at 180.1 epochs": {
"unlockable at 180.1 epochs": {
"params": {
"withdrawInfo": {
"txHash": "withdraw tx hash",
Expand All @@ -92,9 +92,9 @@
"withdrawEpoch": "0xa0000000305",
"withdrawnEpochValue": 773
},
"expected": "ImmatureForUnlock"
"expected": "Unlockable"
},
"immature for unlock at 183.9 epochs": {
"unlockable at 183.9 epochs": {
"params": {
"withdrawInfo": {
"txHash": "withdraw tx hash",
Expand All @@ -108,7 +108,7 @@
"withdrawEpoch": "0xa0000000305",
"withdrawnEpochValue": 773
},
"expected": "ImmatureForUnlock"
"expected": "Unlockable"
},
"unlockable": {
"params": {
Expand Down
1 change: 0 additions & 1 deletion packages/neuron-ui/src/utils/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const SHANNON_CKB_RATIO = 1e8

export const MEDIUM_FEE_RATE = 2000
export const WITHDRAW_EPOCHS = 180
export const IMMATURE_EPOCHS = 4
export const MILLISECONDS_IN_YEAR = 365 * 24 * 3600 * 1000
export const HOURS_PER_EPOCH = 4
export const HOURS_PER_DAY = 24
Expand Down
16 changes: 1 addition & 15 deletions packages/neuron-ui/src/utils/getDAOCellStatus.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { epochParser } from 'utils/parsers'
import calculateClaimEpochValue from 'utils/calculateClaimEpochValue'
import { IMMATURE_EPOCHS } from 'utils/const'

export enum CellStatus {
Depositing,
ImmatureForWithdraw,
Deposited,
Withdrawing,
ImmatureForUnlock,
Locked,
Unlockable,
Unlocking,
Expand Down Expand Up @@ -57,12 +54,8 @@ export const getDAOCellStatus = ({

const unlockEpochValue = calculateClaimEpochValue(depositEpochInfo, withdrawEpochInfo)

if (unlockEpochValue + IMMATURE_EPOCHS <= currentEpochInfo.value) {
return CellStatus.Unlockable
}

if (unlockEpochValue < currentEpochInfo.value) {
return CellStatus.ImmatureForUnlock
return CellStatus.Unlockable
}
}

Expand All @@ -73,13 +66,6 @@ export const getDAOCellStatus = ({
if (status === 'sent') {
return CellStatus.Depositing
}
const currentEpochInfo = epochParser(currentEpoch)
const depositEpochInfo = epochParser(depositEpoch)

if (currentEpochInfo.value < depositEpochInfo.value + IMMATURE_EPOCHS) {
// deposited but immature
return CellStatus.ImmatureForWithdraw
}
return CellStatus.Deposited
}

Expand Down