Skip to content

Commit 53b13da

Browse files
authored
Merge pull request #1129 from nervosnetwork/rc/v0.25.0
[ᚬmaster] Rc/v0.25.0
2 parents df7f4db + c8a4132 commit 53b13da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+780
-485
lines changed

CHANGELOG.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
1+
# [0.25.0](https://github.com/nervosnetwork/neuron/compare/v0.24.5...v0.25.0) (2019-11-16)
2+
3+
4+
### Bug Fixes
5+
6+
* capacity null when calculate bytes ([97ee2a1](https://github.com/nervosnetwork/neuron/commit/97ee2a1))
7+
* update tx and its outputs in different sqls ([b8fe366](https://github.com/nervosnetwork/neuron/commit/b8fe366))
8+
* **neuron:** use deposit timestamp to calculate phase2 dao cell apc ([abdab3f](https://github.com/nervosnetwork/neuron/commit/abdab3f))
9+
* **neuron-ui:** cache the genesis block timestamp in the nervos dao component instead of in global ([5274edd](https://github.com/nervosnetwork/neuron/commit/5274edd))
10+
* **neuron-ui:** fix the missing field in error message. ([a7dc73b](https://github.com/nervosnetwork/neuron/commit/a7dc73b))
11+
* **neuron-ui:** fix the missing of password request dialog ([19d07bd](https://github.com/nervosnetwork/neuron/commit/19d07bd))
12+
* **neuron-ui:** fix the missing word in i18n ([952ae72](https://github.com/nervosnetwork/neuron/commit/952ae72))
13+
* **neuron-ui:** hide the countdown if the current epoch number is greater than the target epoch number. ([2cded1c](https://github.com/nervosnetwork/neuron/commit/2cded1c))
14+
* add typeHash when generate dao tx ([ce5e264](https://github.com/nervosnetwork/neuron/commit/ce5e264))
15+
* **neuron-ui:** remove sort of dao cells ([e501072](https://github.com/nervosnetwork/neuron/commit/e501072))
16+
* next address order ([fffd2f0](https://github.com/nervosnetwork/neuron/commit/fffd2f0))
17+
18+
19+
### Features
20+
21+
* Always load genesis hash and chain info when ([761a4a8](https://github.com/nervosnetwork/neuron/commit/761a4a8))
22+
* ChainInfo delegates Networks Service to get current chain ([0673343](https://github.com/nervosnetwork/neuron/commit/0673343))
23+
* If genesis hash doesn't match do not proceed to sync ([bd8e4e4](https://github.com/nervosnetwork/neuron/commit/bd8e4e4))
24+
* Remove ChainInfo moving its feature into NetworksService ([81f1eff](https://github.com/nervosnetwork/neuron/commit/81f1eff))
25+
* **neuron-ui:** add a guide bubble in connection status ([59f2dd5](https://github.com/nervosnetwork/neuron/commit/59f2dd5))
26+
* **neuron-ui:** add a guide link to run a ckb mainnet node. ([89aa04c](https://github.com/nervosnetwork/neuron/commit/89aa04c))
27+
* **neuron-ui:** add difficulty formatter ([#1105](https://github.com/nervosnetwork/neuron/issues/1105)) ([98ba68d](https://github.com/nervosnetwork/neuron/commit/98ba68d))
28+
* **neuron-ui:** add hint for synchronization not started. ([7d0cc67](https://github.com/nervosnetwork/neuron/commit/7d0cc67))
29+
* **neuron-ui:** hide the general settings and redirect to wallets setting ([b3e3d0e](https://github.com/nervosnetwork/neuron/commit/b3e3d0e))
30+
* **neuron-ui:** limit the times of guide bubble to 3 ([9b85589](https://github.com/nervosnetwork/neuron/commit/9b85589))
31+
* **neuron-ui:** update chain types on launch ([2cb5047](https://github.com/nervosnetwork/neuron/commit/2cb5047))
32+
* **neuron-ui:** update the hint of withdraw dialog ([0bec01e](https://github.com/nervosnetwork/neuron/commit/0bec01e))
33+
* **neuron-ui:** update the warning in withdraw dialog. ([e819439](https://github.com/nervosnetwork/neuron/commit/e819439))
34+
* add depositTimestamp ([108d5b1](https://github.com/nervosnetwork/neuron/commit/108d5b1))
35+
* Do not allow importing keystore from cli ([1b66ea3](https://github.com/nervosnetwork/neuron/commit/1b66ea3))
36+
* If chain info couldn't be fetched set as ckb_dev ([17c1715](https://github.com/nervosnetwork/neuron/commit/17c1715))
37+
* Let addresses regeneration happen before sync task starts ([a52a531](https://github.com/nervosnetwork/neuron/commit/a52a531))
38+
* Prefer network's chain and genesis hash when syncing ([9b5b52c](https://github.com/nervosnetwork/neuron/commit/9b5b52c))
39+
* Preset mainnet network configuration ([1979e8a](https://github.com/nervosnetwork/neuron/commit/1979e8a))
40+
* Set current wallet to null if it's undefined ([6c7117f](https://github.com/nervosnetwork/neuron/commit/6c7117f))
41+
* Update all networks' chain and genesis hash when NetworkService ([a3ccf2d](https://github.com/nervosnetwork/neuron/commit/a3ccf2d))
42+
* **neuron-ui:** use calculateGlobalAPC to update Nervos DAO APC ([e96ca61](https://github.com/nervosnetwork/neuron/commit/e96ca61))
43+
* verify address according to chain type ([2026921](https://github.com/nervosnetwork/neuron/commit/2026921))
44+
45+
46+
147
## [0.24.5](https://github.com/nervosnetwork/neuron/compare/v0.24.4...v0.24.5) (2019-11-14)
248

349

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"packages": [
33
"packages/*"
44
],
5-
"version": "0.24.5",
5+
"version": "0.25.0",
66
"npmClient": "yarn",
77
"useWorkspaces": true
88
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "neuron",
33
"productName": "Neuron",
44
"description": "CKB Neuron Wallet",
5-
"version": "0.24.5",
5+
"version": "0.25.0",
66
"private": true,
77
"author": {
88
"name": "Nervos Core Dev",

packages/neuron-ui/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "neuron-ui",
3-
"version": "0.24.5",
3+
"version": "0.25.0",
44
"private": true,
55
"author": {
66
"name": "Nervos Core Dev",
@@ -17,7 +17,7 @@
1717
"scripts": {
1818
"start": "react-app-rewired start",
1919
"lint": "eslint --fix --ext .tsx,.ts,.js src",
20-
"test": "react-app-rewired test --env=jsdom --color --watchAll=false",
20+
"test": "react-app-rewired test --env=jsdom --watchAll=false",
2121
"build": "react-app-rewired build",
2222
"clean": "rimraf build/*",
2323
"precommit": "lint-staged",

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { useEffect, useState, useMemo } from 'react'
22
import { DefaultButton } from 'office-ui-fabric-react'
33
import { useTranslation } from 'react-i18next'
4-
import { ckbCore, getBlockByNumber } from 'services/chain'
4+
import { ckbCore, getHeaderByNumber } 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'
@@ -19,6 +19,8 @@ const DAORecord = ({
1919
actionLabel,
2020
onClick,
2121
timestamp,
22+
genesisBlockTimestamp,
23+
depositTimestamp,
2224
depositOutPoint,
2325
epoch,
2426
withdraw,
@@ -29,35 +31,43 @@ const DAORecord = ({
2931
tipBlockNumber: string
3032
epoch: string
3133
withdraw: string | null
34+
genesisBlockTimestamp: number | undefined
3235
connectionStatus: 'online' | 'offline'
3336
}) => {
3437
const [t] = useTranslation()
3538
const [withdrawingEpoch, setWithdrawingEpoch] = useState('')
3639
const [depositEpoch, setDepositEpoch] = useState('')
40+
const [apc, setApc] = useState(0)
41+
42+
useEffect(() => {
43+
calculateGlobalAPC(+(depositTimestamp || timestamp), genesisBlockTimestamp).then(res => {
44+
setApc(res)
45+
})
46+
}, [depositTimestamp, timestamp, genesisBlockTimestamp])
3747

3848
useEffect(() => {
3949
if (!depositOutPoint) {
40-
getBlockByNumber(BigInt(blockNumber))
41-
.then(b => {
42-
setDepositEpoch(b.header.epoch)
50+
getHeaderByNumber(BigInt(blockNumber))
51+
.then(header => {
52+
setDepositEpoch(header.epoch)
4353
})
4454
.catch((err: Error) => {
4555
console.error(err)
4656
})
4757
return
4858
}
4959
const depositBlockNumber = ckbCore.utils.bytesToHex(ckbCore.utils.hexToBytes(daoData).reverse())
50-
getBlockByNumber(BigInt(depositBlockNumber))
51-
.then(b => {
52-
setDepositEpoch(b.header.epoch)
60+
getHeaderByNumber(BigInt(depositBlockNumber))
61+
.then(header => {
62+
setDepositEpoch(header.epoch)
5363
})
5464
.catch((err: Error) => {
5565
console.error(err)
5666
})
5767

58-
getBlockByNumber(BigInt(blockNumber))
59-
.then(b => {
60-
setWithdrawingEpoch(b.header.epoch)
68+
getHeaderByNumber(BigInt(blockNumber))
69+
.then(header => {
70+
setWithdrawingEpoch(header.epoch)
6171
})
6272
.catch((err: Error) => {
6373
console.error(err)
@@ -142,7 +152,7 @@ const DAORecord = ({
142152
</div>
143153
</div>
144154
<div className={styles.secondaryInfo}>
145-
<span>{`APC: ~${calculateAPC(compensation.toString(), capacity, `${Date.now() - +timestamp}`)}%`}</span>
155+
<span>{`APC: ~${apc}%`}</span>
146156
<span>{uniformTimeFormatter(+timestamp)}</span>
147157
<span>{metaInfo}</span>
148158
</div>

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,20 @@ const WithdrawDialog = ({
6060
const currentEpochInfo = epochParser(currentEpoch)
6161
const targetEpochNumber = calculateTargetEpochNumber(depositEpochInfo, currentEpochInfo)
6262
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-
})
63+
const message =
64+
epochs >= BigInt(0)
65+
? t('nervos-dao.notice-wait-time', {
66+
epochs: localNumberFormatter(epochs),
67+
blocks: localNumberFormatter(currentEpochInfo.length - currentEpochInfo.index),
68+
days: localNumberFormatter(epochs / BigInt(6)),
69+
})
70+
: ''
6871

6972
const alert =
70-
epochs <= BigInt(5)
73+
epochs <= BigInt(5) && epochs >= BigInt(0)
7174
? t('nervos-dao.withdraw-alert', {
7275
epochs,
73-
nextLeftEpochs: epochs + BigInt(180),
76+
hours: epochs * BigInt(4),
7477
days: (epochs + BigInt(180)) / BigInt(6),
7578
})
7679
: ''

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { updateNervosDaoData, clearNervosDaoData } from 'states/stateProvider/ac
1111
import calculateGlobalAPC from 'utils/calculateGlobalAPC'
1212
import calculateFee from 'utils/calculateFee'
1313
import { shannonToCKBFormatter, CKBToShannonFormatter } from 'utils/formatters'
14-
import { MIN_DEPOSIT_AMOUNT, MEDIUM_FEE_RATE, SHANNON_CKB_RATIO, CapacityUnit } from 'utils/const'
14+
import { MIN_DEPOSIT_AMOUNT, MEDIUM_FEE_RATE, SHANNON_CKB_RATIO, MAX_DECIMAL_DIGITS, CapacityUnit } from 'utils/const'
1515
import { verifyAmount } from 'utils/validators'
1616

1717
import { generateDepositTx, generateWithdrawTx, generateClaimTx } from 'services/remote'
18-
import { ckbCore } from 'services/chain'
18+
import { ckbCore, getHeaderByNumber } from 'services/chain'
1919
import { epochParser } from 'utils/parsers'
2020

2121
import DAORecord from 'components/CustomRows/DAORecordRow'
@@ -46,6 +46,7 @@ const NervosDAO = ({
4646
const [errorMessage, setErrorMessage] = useState('')
4747
const [withdrawList, setWithdrawList] = useState<(string | null)[]>([])
4848
const [globalAPC, setGlobalAPC] = useState(0)
49+
const [genesisBlockTimestamp, setGenesisBlockTimestamp] = useState<number | undefined>(undefined)
4950

5051
const clearGeneratedTx = useCallback(() => {
5152
dispatch({
@@ -66,7 +67,7 @@ const NervosDAO = ({
6667

6768
const verifyRes = verifyAmount(value)
6869
if (verifyRes !== true) {
69-
setErrorMessage(t(`messages.codes.${verifyRes.code}`, { fieldName: 'deposit' }))
70+
setErrorMessage(t(`messages.codes.${verifyRes.code}`, { fieldName: 'deposit', length: MAX_DECIMAL_DIGITS }))
7071
return
7172
}
7273

@@ -98,6 +99,9 @@ const NervosDAO = ({
9899
useEffect(() => {
99100
updateNervosDaoData({ walletID: wallet.id })(dispatch)
100101
updateDepositValue(`${MIN_DEPOSIT_AMOUNT}`)
102+
getHeaderByNumber('0x0')
103+
.then(header => setGenesisBlockTimestamp(+header.timestamp))
104+
.catch(err => console.error(err))
101105
return () => {
102106
clearNervosDaoData()(dispatch)
103107
clearGeneratedTx()
@@ -106,11 +110,13 @@ const NervosDAO = ({
106110

107111
useEffect(() => {
108112
if (tipBlockTimestamp) {
109-
calculateGlobalAPC(tipBlockTimestamp).then(apc => {
110-
setGlobalAPC(apc)
111-
})
113+
calculateGlobalAPC(tipBlockTimestamp, genesisBlockTimestamp)
114+
.then(apc => {
115+
setGlobalAPC(apc)
116+
})
117+
.catch(err => console.error(err))
112118
}
113-
}, [tipBlockTimestamp])
119+
}, [tipBlockTimestamp, genesisBlockTimestamp])
114120

115121
const onDepositDialogDismiss = () => {
116122
setShowDepositDialog(false)
@@ -276,14 +282,15 @@ const NervosDAO = ({
276282
onClick={onActionClick}
277283
tipBlockNumber={tipBlockNumber}
278284
epoch={epoch}
285+
genesisBlockTimestamp={genesisBlockTimestamp}
279286
connectionStatus={connectionStatus}
280287
/>
281288
)
282289
})}
283290
</Stack>
284291
</>
285292
)
286-
}, [records, withdrawList, t, onActionClick, tipBlockNumber, epoch, connectionStatus])
293+
}, [records, withdrawList, t, onActionClick, tipBlockNumber, epoch, connectionStatus, genesisBlockTimestamp])
287294

288295
const free = BigInt(wallet.balance)
289296
const locked = withdrawList.reduce((acc, w) => acc + BigInt(w || 0), BigInt(0))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import PropertyList, { Property } from 'widgets/PropertyList'
77
import { StateWithDispatch } from 'states/stateProvider/reducer'
88
import { updateTransactionList } from 'states/stateProvider/actionCreators'
99

10-
import { localNumberFormatter, shannonToCKBFormatter } from 'utils/formatters'
10+
import { localNumberFormatter, shannonToCKBFormatter, difficultyFormatter } from 'utils/formatters'
1111
import { epochParser } from 'utils/parsers'
1212
import { PAGE_SIZE, Routes, CONFIRMATION_THRESHOLD } from 'utils/const'
1313
import { backToTop } from 'utils/animations'
@@ -104,7 +104,7 @@ const Overview = ({
104104
},
105105
{
106106
label: t('overview.difficulty'),
107-
value: localNumberFormatter(+difficulty),
107+
value: difficultyFormatter(difficulty),
108108
},
109109
],
110110
[t, chain, epoch, difficulty, tipBlockNumber]

packages/neuron-ui/src/components/Send/hooks.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,17 @@ export const useInitialize = (
201201
clear(dispatch)
202202
}, [walletID, dispatch])
203203

204-
const onGetAddressErrorMessage = useCallback(
205-
(addr: string) => {
204+
const onGetAddressErrorMessage: (isMainnet: boolean) => (addr: string) => string = useCallback(
205+
(isMainnet: boolean) => (addr: string) => {
206206
if (addr === '') {
207207
return t(`messages.codes.${ErrorCode.AddressIsEmpty}`)
208208
}
209+
if (isMainnet && !addr.startsWith('ckb')) {
210+
return t(`messages.mainnet-address-required`)
211+
}
212+
if (!isMainnet && !addr.startsWith('ckt')) {
213+
return t(`messages.testnet-address-required`)
214+
}
209215
if (!verifyAddress(addr)) {
210216
return t(`messages.codes.${ErrorCode.FieldInvalid}`, {
211217
fieldName: 'address',

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import QRScanner from 'widgets/QRScanner'
2020
import { StateWithDispatch } from 'states/stateProvider/reducer'
2121
import appState from 'states/initStates/app'
2222

23-
import { PlaceHolders, CapacityUnit, ErrorCode } from 'utils/const'
23+
import { PlaceHolders, CapacityUnit, ErrorCode, MAINNET_TAG } from 'utils/const'
2424
import { shannonToCKBFormatter } from 'utils/formatters'
2525

2626
import { verifyTotalAmount } from 'utils/validators'
@@ -38,7 +38,8 @@ const Send = ({
3838
loadings: { sending = false },
3939
},
4040
wallet: { id: walletID = '', balance = '' },
41-
chain: { connectionStatus },
41+
chain: { networkID, connectionStatus },
42+
settings: { networks = [] },
4243
dispatch,
4344
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps<{ address: string }>>) => {
4445
const { t } = useTranslation()
@@ -66,6 +67,8 @@ const Send = ({
6667
const errorMessageUnderTotal = verifyTotalAmount(totalAmount, fee, balance)
6768
? errorMessage
6869
: t(`messages.codes.${ErrorCode.AmountNotEnough}`)
70+
const network = networks.find(n => n.id === networkID)
71+
const isMainnet = (network && network.chain === MAINNET_TAG) || false
6972

7073
return (
7174
<Stack verticalFill tokens={{ childrenGap: 15, padding: '20px 0 0 0' }}>
@@ -97,7 +100,7 @@ const Send = ({
97100
onChange={onItemChange}
98101
required
99102
validateOnLoad={false}
100-
onGetErrorMessage={onGetAddressErrorMessage}
103+
onGetErrorMessage={onGetAddressErrorMessage(isMainnet)}
101104
/>
102105
</Stack.Item>
103106
<Stack styles={{ root: { width: '48px' } }} verticalAlign="start">

0 commit comments

Comments
 (0)