Skip to content

Commit 3b72042

Browse files
committed
feat(neuron-ui): update i18n of nervos dao
1 parent ca46665 commit 3b72042

6 files changed

Lines changed: 79 additions & 23 deletions

File tree

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { useTranslation } from 'react-i18next'
44
import { ckbCore, getBlockByNumber } from 'services/chain'
55
import calculateAPY from 'utils/calculateAPY'
66
import { shannonToCKBFormatter, uniformTimeFormatter, localNumberFormatter } from 'utils/formatters'
7+
import calculateClaimEpochNumber from 'utils/calculateClaimEpochNumber'
78
import { epochParser } from 'utils/parsers'
8-
import { WITHDRAW_EPOCHS } from 'utils/const'
9+
// import { WITHDRAW_EPOCHS } from 'utils/const'
910

1011
import * as styles from './daoRecordRow.module.scss'
1112

@@ -74,24 +75,16 @@ const DAORecord = ({
7475
} else {
7576
const depositEpochInfo = epochParser(depositEpoch)
7677
const currentEpochInfo = epochParser(epoch)
77-
78-
let depositedEpochs = currentEpochInfo.number - depositEpochInfo.number
79-
const depositEpochFraction = depositEpochInfo.index * currentEpochInfo.length
80-
const currentEpochFraction = currentEpochInfo.index * depositEpochInfo.length
81-
if (currentEpochFraction > depositEpochFraction) {
82-
depositedEpochs += BigInt(1)
83-
}
84-
const minLockEpochs =
85-
((depositedEpochs + BigInt(WITHDRAW_EPOCHS - 1)) / BigInt(WITHDRAW_EPOCHS)) * BigInt(WITHDRAW_EPOCHS)
86-
const targetEpochNumber = depositEpochInfo.number + minLockEpochs
87-
78+
const targetEpochNumber = calculateClaimEpochNumber(depositEpochInfo, currentEpochInfo)
8879
if (targetEpochNumber < currentEpochInfo.number + BigInt(1) && targetEpochNumber >= currentEpochInfo.number) {
8980
metaInfo = 'Ready'
9081
ready = true
9182
} else {
83+
const epochs = targetEpochNumber - currentEpochInfo.number - BigInt(1)
9284
metaInfo = t('nervos-dao.blocks-left', {
93-
epochs: localNumberFormatter(targetEpochNumber - currentEpochInfo.number - BigInt(1)),
94-
blocks: currentEpochInfo.length - currentEpochInfo.index,
85+
epochs: localNumberFormatter(epochs),
86+
blocks: localNumberFormatter(currentEpochInfo.length - currentEpochInfo.index),
87+
days: localNumberFormatter(epochs / BigInt(6)),
9588
})
9689
}
9790
}

packages/neuron-ui/src/components/NervosDAO/WithdrawDialog.tsx

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
import React, { useState, useEffect } from 'react'
22
import { Dialog, DialogFooter, DefaultButton, PrimaryButton, DialogType } from 'office-ui-fabric-react'
33
import { useTranslation } from 'react-i18next'
4-
import { shannonToCKBFormatter } from 'utils/formatters'
4+
import { shannonToCKBFormatter, localNumberFormatter } from 'utils/formatters'
55
import { ckbCore } from 'services/chain'
6+
import calculateTargetEpochNumber from 'utils/calculateClaimEpochNumber'
7+
import { epochParser } from 'utils/parsers'
68

7-
const WithdrawDialog = ({ onDismiss, onSubmit, record, tipBlockHash }: any) => {
9+
const WithdrawDialog = ({
10+
onDismiss,
11+
onSubmit,
12+
record,
13+
tipBlockHash,
14+
currentEpoch,
15+
}: {
16+
onDismiss: any
17+
onSubmit: any
18+
record: State.NervosDAORecord
19+
tipBlockHash: string
20+
currentEpoch: string
21+
}) => {
822
const [t] = useTranslation()
23+
const [depositEpoch, setDepositEpoch] = useState('')
924
const [withdrawValue, setWithdrawValue] = useState('')
25+
useEffect(() => {
26+
if (!record) {
27+
return
28+
}
29+
ckbCore.rpc
30+
.getBlock(record.blockHash)
31+
.then(b => {
32+
setDepositEpoch(b.header.epoch)
33+
})
34+
.catch((err: Error) => {
35+
console.error(err)
36+
})
37+
}, [record])
1038
useEffect(() => {
1139
if (!record || !tipBlockHash) {
1240
return
1341
}
42+
1443
;(ckbCore.rpc as any)
1544
.calculateDaoMaximumWithdraw(
1645
{
@@ -26,6 +55,16 @@ const WithdrawDialog = ({ onDismiss, onSubmit, record, tipBlockHash }: any) => {
2655
console.error(err)
2756
})
2857
}, [record, tipBlockHash])
58+
59+
const depositEpochInfo = epochParser(depositEpoch)
60+
const currentEpochInfo = epochParser(currentEpoch)
61+
const targetEpochNumber = calculateTargetEpochNumber(depositEpochInfo, currentEpochInfo)
62+
const epochs = targetEpochNumber - currentEpochInfo.number - BigInt(1)
63+
const message = t('nervos-dao.notice-wait-time', {
64+
epochs: localNumberFormatter(epochs),
65+
blocks: localNumberFormatter(currentEpochInfo.length - currentEpochInfo.index),
66+
days: localNumberFormatter(epochs / BigInt(6)),
67+
})
2968
return (
3069
<Dialog
3170
hidden={!record}
@@ -39,17 +78,20 @@ const WithdrawDialog = ({ onDismiss, onSubmit, record, tipBlockHash }: any) => {
3978
{record ? (
4079
<>
4180
<div>
42-
<span>{`${t('nervos-dao.deposit')}:`}</span>
81+
<span>{`${t('nervos-dao.deposit')}: `}</span>
4382
<span>{`${shannonToCKBFormatter(record.capacity)} CKB`}</span>
4483
</div>
4584
<div>
46-
<span>{`${t('nervos-dao.interest')}:`}</span>
85+
<span>{`${t('nervos-dao.interest')}: `}</span>
4786
<span>
4887
{withdrawValue
4988
? `${shannonToCKBFormatter((BigInt(withdrawValue) - BigInt(record.capacity)).toString())} CKB`
5089
: ''}
5190
</span>
5291
</div>
92+
<div>
93+
<span>{message}</span>
94+
</div>
5395
</>
5496
) : null}
5597
<DialogFooter>

packages/neuron-ui/src/components/NervosDAO/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const NervosDAO = ({
7777
}, 500)
7878
setDepositValue(value)
7979
},
80-
[clearGeneratedTx, dispatch, wallet.id]
80+
[clearGeneratedTx, dispatch, wallet.id, t]
8181
)
8282

8383
useEffect(() => {
@@ -282,6 +282,7 @@ const NervosDAO = ({
282282
onDismiss={onWithdrawDialogDismiss}
283283
onSubmit={onWithdrawDialogSubmit}
284284
tipBlockHash={tipBlockHash}
285+
currentEpoch={epoch}
285286
/>
286287
) : null}
287288
</>

packages/neuron-ui/src/locales/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,13 @@
325325
"deposit-value": "Deposit",
326326
"interest": "Interest",
327327
"yield": "Yield",
328-
"notice-wait-time": "Notice: You need to wait {{epochs}} epochs {{blocks}} blocks(~days) to claim the saving.",
328+
"notice-wait-time": "Notice: You need to wait {{epochs}} epochs {{blocks}} blocks(~{{days}} days) to claim the saving.",
329329
"deposit-terms": "Nervos DAO is a system layer decentralized infrastructure. Your saving here is secure.\nAccording to the Nervos DAO protocol, you need at least 180 epochs to withdraw your deposit",
330330
"deposited-action-label": "Withdraw",
331331
"withdrawing-action-label": "Claim",
332332
"minimal-fee-required": "The minimum deposit capacity is {{minimal}} CKB",
333333
"interest-accumulated": "{{blockNumber}} blocks interest accumulated",
334-
"blocks-left": "{{epochs}} epochs {{blocks}} blocks left"
334+
"blocks-left": "{{epochs}} epochs {{blocks}} blocks left(~{{days}} days)"
335335
}
336336
}
337337
}

packages/neuron-ui/src/locales/zh.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,13 @@
325325
"deposit-value": "存款",
326326
"interest": "利息",
327327
"yield": "Yield",
328-
"notice-wait-time": "注意: 您需要等待 {{epochs}} epochs {{blocks}} 区块完成最终取款",
328+
"notice-wait-time": "注意: 您需要等待 {{epochs}} epochs {{blocks}} 区块(~{{days}}天)完成最终取款",
329329
"deposit-terms": "Nervos DAO is a system layer decentralized infrastructure. Your saving here is secure.\nAccording to the Nervos DAO protocol, you need at least 180 epochs to withdraw your deposit",
330330
"deposited-action-label": "Withdraw",
331331
"withdrawing-action-label": "Claim",
332332
"minimal-fee-required": "存入金额应不少于 {{minimal}} CKB",
333333
"interest-accumulated": "已累计 {{blockNumber}} 个块的利息",
334-
"blocks-left": " 还需等待 {{epochs}} epochs {{blocks}} 个块"
334+
"blocks-left": " 还需等待 {{epochs}} epochs {{blocks}} 个块(~{{days}} 天)"
335335
}
336336
}
337337
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { WITHDRAW_EPOCHS } from 'utils/const'
2+
3+
interface EpochInfo {
4+
index: bigint
5+
number: bigint
6+
length: bigint
7+
}
8+
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
13+
if (currentEpochFraction > depositEpochFraction) {
14+
depositedEpochs += BigInt(1)
15+
}
16+
const minLockEpochs =
17+
((depositedEpochs + BigInt(WITHDRAW_EPOCHS - 1)) / BigInt(WITHDRAW_EPOCHS)) * BigInt(WITHDRAW_EPOCHS)
18+
const targetEpochNumber = depositEpochInfo.number + minLockEpochs
19+
return targetEpochNumber
20+
}

0 commit comments

Comments
 (0)