Skip to content

Commit

Permalink
fix(neuron-ui): fix the minimal withdraw epoch number
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Nov 11, 2019
1 parent f1ad76b commit 1c19582
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions packages/neuron-ui/src/components/CustomRows/DAORecordRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const DAORecord = ({
}) => {
const [t] = useTranslation()
const [withdrawValue, setWithdrawValue] = useState('')
const [withdrawingEpoch, setWithdrawingEpoch] = useState('')
const [depositEpoch, setDepositEpoch] = useState('')

useEffect(() => {
Expand Down Expand Up @@ -69,7 +70,15 @@ const DAORecord = ({
.catch((err: Error) => {
console.error(err)
})
}, [daoData, depositOutPoint])

getBlockByNumber(BigInt(blockNumber))
.then(b => {
setWithdrawingEpoch(b.header.epoch)
})
.catch((err: Error) => {
console.error(err)
})
}, [daoData, depositOutPoint, blockNumber])

const interest = BigInt(withdrawValue) - BigInt(capacity)

Expand All @@ -83,7 +92,8 @@ const DAORecord = ({
} else {
const depositEpochInfo = epochParser(depositEpoch)
const currentEpochInfo = epochParser(epoch)
const targetEpochNumber = calculateClaimEpochNumber(depositEpochInfo, currentEpochInfo)
const withdrawingEpochInfo = epochParser(withdrawingEpoch)
const targetEpochNumber = calculateClaimEpochNumber(depositEpochInfo, withdrawingEpochInfo)
if (targetEpochNumber <= currentEpochInfo.number) {
metaInfo = 'Ready'
ready = true
Expand Down
8 changes: 4 additions & 4 deletions packages/neuron-ui/src/utils/calculateClaimEpochNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ interface EpochInfo {
length: bigint
}

export default (depositEpochInfo: EpochInfo, currentEpochInfo: EpochInfo) => {
let depositedEpochs = currentEpochInfo.number - depositEpochInfo.number
const depositEpochFraction = depositEpochInfo.index * currentEpochInfo.length
const currentEpochFraction = currentEpochInfo.index * depositEpochInfo.length
export default (depositEpochInfo: EpochInfo, withdrawingEpochInfo: EpochInfo) => {
let depositedEpochs = withdrawingEpochInfo.number - depositEpochInfo.number
const depositEpochFraction = depositEpochInfo.index * withdrawingEpochInfo.length
const currentEpochFraction = withdrawingEpochInfo.index * depositEpochInfo.length
if (currentEpochFraction > depositEpochFraction) {
depositedEpochs += BigInt(1)
}
Expand Down

0 comments on commit 1c19582

Please sign in to comment.