Skip to content

Commit e96ca61

Browse files
committed
feat(neuron-ui): use calculateGlobalAPC to update Nervos DAO APC
1 parent b5d4b35 commit e96ca61

3 files changed

Lines changed: 6 additions & 19 deletions

File tree

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DefaultButton } from 'office-ui-fabric-react'
33
import { useTranslation } from 'react-i18next'
44
import { ckbCore, getBlockByNumber } from 'services/chain'
55
import { showMessage } from 'services/remote'
6-
import calculateAPC from 'utils/calculateAPC'
6+
import calculateGlobalAPC from 'utils/calculateGlobalAPC'
77
import { shannonToCKBFormatter, uniformTimeFormatter, localNumberFormatter } from 'utils/formatters'
88
import calculateClaimEpochNumber from 'utils/calculateClaimEpochNumber'
99
import { epochParser } from 'utils/parsers'
@@ -143,13 +143,7 @@ const DAORecord = ({
143143
</div>
144144
</div>
145145
<div className={styles.secondaryInfo}>
146-
<span>
147-
{`APC: ~${calculateAPC(
148-
compensation.toString(),
149-
capacity,
150-
`${Date.now() - +(depositTimestamp || timestamp)}`
151-
)}%`}
152-
</span>
146+
<span>{`APC: ~${calculateGlobalAPC(+(depositTimestamp || timestamp))}%`}</span>
153147
<span>{uniformTimeFormatter(+timestamp)}</span>
154148
<span>{metaInfo}</span>
155149
</div>

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

Lines changed: 0 additions & 7 deletions
This file was deleted.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const PERIOD_LENGTH = DAYS_PER_PERIOD * MILLI_SECONDS_PER_DAY
88

99
let cachedGenesisTimestamp: number | undefined
1010

11-
export default async (now: number, initialTimestamp: number | undefined = cachedGenesisTimestamp) => {
11+
export default async (checkPointTimestamp: number, initialTimestamp: number | undefined = cachedGenesisTimestamp) => {
1212
let genesisTimestamp = initialTimestamp
1313
if (genesisTimestamp === undefined) {
1414
genesisTimestamp = await getBlockByNumber('0x0')
@@ -18,12 +18,12 @@ export default async (now: number, initialTimestamp: number | undefined = cached
1818
})
1919
.catch(() => undefined)
2020
}
21-
if (genesisTimestamp === undefined || now <= genesisTimestamp) {
21+
if (genesisTimestamp === undefined || checkPointTimestamp <= genesisTimestamp) {
2222
return 0
2323
}
2424

25-
const pastPeriods = BigInt(now - genesisTimestamp) / BigInt(PERIOD_LENGTH)
26-
const pastDays = Math.ceil(((now - genesisTimestamp) % PERIOD_LENGTH) / MILLI_SECONDS_PER_DAY)
25+
const pastPeriods = BigInt(checkPointTimestamp - genesisTimestamp) / BigInt(PERIOD_LENGTH)
26+
const pastDays = Math.ceil(((checkPointTimestamp - genesisTimestamp) % PERIOD_LENGTH) / MILLI_SECONDS_PER_DAY)
2727

2828
const realSecondaryOffer =
2929
BigInt(4) * SECONDARY_OFFER * pastPeriods +

0 commit comments

Comments
 (0)