Skip to content

Commit

Permalink
feat(neuron-ui): use calculateGlobalAPC to update Nervos DAO APC
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Nov 14, 2019
1 parent b5d4b35 commit e96ca61
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
10 changes: 2 additions & 8 deletions packages/neuron-ui/src/components/CustomRows/DAORecordRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DefaultButton } from 'office-ui-fabric-react'
import { useTranslation } from 'react-i18next'
import { ckbCore, getBlockByNumber } from 'services/chain'
import { showMessage } from 'services/remote'
import calculateAPC from 'utils/calculateAPC'
import calculateGlobalAPC from 'utils/calculateGlobalAPC'
import { shannonToCKBFormatter, uniformTimeFormatter, localNumberFormatter } from 'utils/formatters'
import calculateClaimEpochNumber from 'utils/calculateClaimEpochNumber'
import { epochParser } from 'utils/parsers'
Expand Down Expand Up @@ -143,13 +143,7 @@ const DAORecord = ({
</div>
</div>
<div className={styles.secondaryInfo}>
<span>
{`APC: ~${calculateAPC(
compensation.toString(),
capacity,
`${Date.now() - +(depositTimestamp || timestamp)}`
)}%`}
</span>
<span>{`APC: ~${calculateGlobalAPC(+(depositTimestamp || timestamp))}%`}</span>
<span>{uniformTimeFormatter(+timestamp)}</span>
<span>{metaInfo}</span>
</div>
Expand Down
7 changes: 0 additions & 7 deletions packages/neuron-ui/src/utils/calculateAPC.ts

This file was deleted.

8 changes: 4 additions & 4 deletions packages/neuron-ui/src/utils/calculateGlobalAPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const PERIOD_LENGTH = DAYS_PER_PERIOD * MILLI_SECONDS_PER_DAY

let cachedGenesisTimestamp: number | undefined

export default async (now: number, initialTimestamp: number | undefined = cachedGenesisTimestamp) => {
export default async (checkPointTimestamp: number, initialTimestamp: number | undefined = cachedGenesisTimestamp) => {
let genesisTimestamp = initialTimestamp
if (genesisTimestamp === undefined) {
genesisTimestamp = await getBlockByNumber('0x0')
Expand All @@ -18,12 +18,12 @@ export default async (now: number, initialTimestamp: number | undefined = cached
})
.catch(() => undefined)
}
if (genesisTimestamp === undefined || now <= genesisTimestamp) {
if (genesisTimestamp === undefined || checkPointTimestamp <= genesisTimestamp) {
return 0
}

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

const realSecondaryOffer =
BigInt(4) * SECONDARY_OFFER * pastPeriods +
Expand Down

0 comments on commit e96ca61

Please sign in to comment.