diff --git a/packages/neuron-ui/src/components/CustomRows/DAORecordRow.tsx b/packages/neuron-ui/src/components/CustomRows/DAORecordRow.tsx index 48db722a70..af02271ba9 100644 --- a/packages/neuron-ui/src/components/CustomRows/DAORecordRow.tsx +++ b/packages/neuron-ui/src/components/CustomRows/DAORecordRow.tsx @@ -4,8 +4,9 @@ import { useTranslation } from 'react-i18next' import { ckbCore, getBlockByNumber } from 'services/chain' import calculateAPY from 'utils/calculateAPY' import { shannonToCKBFormatter, uniformTimeFormatter, localNumberFormatter } from 'utils/formatters' +import calculateClaimEpochNumber from 'utils/calculateClaimEpochNumber' import { epochParser } from 'utils/parsers' -import { WITHDRAW_EPOCHS } from 'utils/const' +// import { WITHDRAW_EPOCHS } from 'utils/const' import * as styles from './daoRecordRow.module.scss' @@ -74,24 +75,16 @@ const DAORecord = ({ } else { const depositEpochInfo = epochParser(depositEpoch) const currentEpochInfo = epochParser(epoch) - - let depositedEpochs = currentEpochInfo.number - depositEpochInfo.number - const depositEpochFraction = depositEpochInfo.index * currentEpochInfo.length - const currentEpochFraction = currentEpochInfo.index * depositEpochInfo.length - if (currentEpochFraction > depositEpochFraction) { - depositedEpochs += BigInt(1) - } - const minLockEpochs = - ((depositedEpochs + BigInt(WITHDRAW_EPOCHS - 1)) / BigInt(WITHDRAW_EPOCHS)) * BigInt(WITHDRAW_EPOCHS) - const targetEpochNumber = depositEpochInfo.number + minLockEpochs - + const targetEpochNumber = calculateClaimEpochNumber(depositEpochInfo, currentEpochInfo) if (targetEpochNumber < currentEpochInfo.number + BigInt(1) && targetEpochNumber >= currentEpochInfo.number) { metaInfo = 'Ready' ready = true } else { + const epochs = targetEpochNumber - currentEpochInfo.number - BigInt(1) metaInfo = t('nervos-dao.blocks-left', { - epochs: localNumberFormatter(targetEpochNumber - currentEpochInfo.number - BigInt(1)), - blocks: currentEpochInfo.length - currentEpochInfo.index, + epochs: localNumberFormatter(epochs), + blocks: localNumberFormatter(currentEpochInfo.length - currentEpochInfo.index), + days: localNumberFormatter(epochs / BigInt(6)), }) } } diff --git a/packages/neuron-ui/src/components/NervosDAO/WithdrawDialog.tsx b/packages/neuron-ui/src/components/NervosDAO/WithdrawDialog.tsx index 010b57e644..77c77b2760 100644 --- a/packages/neuron-ui/src/components/NervosDAO/WithdrawDialog.tsx +++ b/packages/neuron-ui/src/components/NervosDAO/WithdrawDialog.tsx @@ -1,16 +1,45 @@ import React, { useState, useEffect } from 'react' import { Dialog, DialogFooter, DefaultButton, PrimaryButton, DialogType } from 'office-ui-fabric-react' import { useTranslation } from 'react-i18next' -import { shannonToCKBFormatter } from 'utils/formatters' +import { shannonToCKBFormatter, localNumberFormatter } from 'utils/formatters' import { ckbCore } from 'services/chain' +import calculateTargetEpochNumber from 'utils/calculateClaimEpochNumber' +import { epochParser } from 'utils/parsers' -const WithdrawDialog = ({ onDismiss, onSubmit, record, tipBlockHash }: any) => { +const WithdrawDialog = ({ + onDismiss, + onSubmit, + record, + tipBlockHash, + currentEpoch, +}: { + onDismiss: any + onSubmit: any + record: State.NervosDAORecord + tipBlockHash: string + currentEpoch: string +}) => { const [t] = useTranslation() + const [depositEpoch, setDepositEpoch] = useState('') const [withdrawValue, setWithdrawValue] = useState('') + useEffect(() => { + if (!record) { + return + } + ckbCore.rpc + .getBlock(record.blockHash) + .then(b => { + setDepositEpoch(b.header.epoch) + }) + .catch((err: Error) => { + console.error(err) + }) + }, [record]) useEffect(() => { if (!record || !tipBlockHash) { return } + ;(ckbCore.rpc as any) .calculateDaoMaximumWithdraw( { @@ -26,6 +55,16 @@ const WithdrawDialog = ({ onDismiss, onSubmit, record, tipBlockHash }: any) => { console.error(err) }) }, [record, tipBlockHash]) + + const depositEpochInfo = epochParser(depositEpoch) + const currentEpochInfo = epochParser(currentEpoch) + const targetEpochNumber = calculateTargetEpochNumber(depositEpochInfo, currentEpochInfo) + const epochs = targetEpochNumber - currentEpochInfo.number - BigInt(1) + const message = t('nervos-dao.notice-wait-time', { + epochs: localNumberFormatter(epochs), + blocks: localNumberFormatter(currentEpochInfo.length - currentEpochInfo.index), + days: localNumberFormatter(epochs / BigInt(6)), + }) return (