Skip to content

Commit 1c19582

Browse files
committed
fix(neuron-ui): fix the minimal withdraw epoch number
1 parent f1ad76b commit 1c19582

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

packages/neuron-ui/src/components/CustomRows/DAORecordRow.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const DAORecord = ({
3131
}) => {
3232
const [t] = useTranslation()
3333
const [withdrawValue, setWithdrawValue] = useState('')
34+
const [withdrawingEpoch, setWithdrawingEpoch] = useState('')
3435
const [depositEpoch, setDepositEpoch] = useState('')
3536

3637
useEffect(() => {
@@ -69,7 +70,15 @@ const DAORecord = ({
6970
.catch((err: Error) => {
7071
console.error(err)
7172
})
72-
}, [daoData, depositOutPoint])
73+
74+
getBlockByNumber(BigInt(blockNumber))
75+
.then(b => {
76+
setWithdrawingEpoch(b.header.epoch)
77+
})
78+
.catch((err: Error) => {
79+
console.error(err)
80+
})
81+
}, [daoData, depositOutPoint, blockNumber])
7382

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

@@ -83,7 +92,8 @@ const DAORecord = ({
8392
} else {
8493
const depositEpochInfo = epochParser(depositEpoch)
8594
const currentEpochInfo = epochParser(epoch)
86-
const targetEpochNumber = calculateClaimEpochNumber(depositEpochInfo, currentEpochInfo)
95+
const withdrawingEpochInfo = epochParser(withdrawingEpoch)
96+
const targetEpochNumber = calculateClaimEpochNumber(depositEpochInfo, withdrawingEpochInfo)
8797
if (targetEpochNumber <= currentEpochInfo.number) {
8898
metaInfo = 'Ready'
8999
ready = true

packages/neuron-ui/src/utils/calculateClaimEpochNumber.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ interface EpochInfo {
66
length: bigint
77
}
88

9-
export default (depositEpochInfo: EpochInfo, currentEpochInfo: EpochInfo) => {
10-
let depositedEpochs = currentEpochInfo.number - depositEpochInfo.number
11-
const depositEpochFraction = depositEpochInfo.index * currentEpochInfo.length
12-
const currentEpochFraction = currentEpochInfo.index * depositEpochInfo.length
9+
export default (depositEpochInfo: EpochInfo, withdrawingEpochInfo: EpochInfo) => {
10+
let depositedEpochs = withdrawingEpochInfo.number - depositEpochInfo.number
11+
const depositEpochFraction = depositEpochInfo.index * withdrawingEpochInfo.length
12+
const currentEpochFraction = withdrawingEpochInfo.index * depositEpochInfo.length
1313
if (currentEpochFraction > depositEpochFraction) {
1414
depositedEpochs += BigInt(1)
1515
}

0 commit comments

Comments
 (0)