Skip to content

Commit

Permalink
Merge pull request #1129 from nervosnetwork/rc/v0.25.0
Browse files Browse the repository at this point in the history
[ᚬmaster] Rc/v0.25.0
  • Loading branch information
ashchan committed Nov 15, 2019
2 parents df7f4db + c8a4132 commit 53b13da
Show file tree
Hide file tree
Showing 71 changed files with 780 additions and 485 deletions.
46 changes: 46 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,49 @@
# [0.25.0](https://github.com/nervosnetwork/neuron/compare/v0.24.5...v0.25.0) (2019-11-16)


### Bug Fixes

* capacity null when calculate bytes ([97ee2a1](https://github.com/nervosnetwork/neuron/commit/97ee2a1))
* update tx and its outputs in different sqls ([b8fe366](https://github.com/nervosnetwork/neuron/commit/b8fe366))
* **neuron:** use deposit timestamp to calculate phase2 dao cell apc ([abdab3f](https://github.com/nervosnetwork/neuron/commit/abdab3f))
* **neuron-ui:** cache the genesis block timestamp in the nervos dao component instead of in global ([5274edd](https://github.com/nervosnetwork/neuron/commit/5274edd))
* **neuron-ui:** fix the missing field in error message. ([a7dc73b](https://github.com/nervosnetwork/neuron/commit/a7dc73b))
* **neuron-ui:** fix the missing of password request dialog ([19d07bd](https://github.com/nervosnetwork/neuron/commit/19d07bd))
* **neuron-ui:** fix the missing word in i18n ([952ae72](https://github.com/nervosnetwork/neuron/commit/952ae72))
* **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))
* add typeHash when generate dao tx ([ce5e264](https://github.com/nervosnetwork/neuron/commit/ce5e264))
* **neuron-ui:** remove sort of dao cells ([e501072](https://github.com/nervosnetwork/neuron/commit/e501072))
* next address order ([fffd2f0](https://github.com/nervosnetwork/neuron/commit/fffd2f0))


### Features

* Always load genesis hash and chain info when ([761a4a8](https://github.com/nervosnetwork/neuron/commit/761a4a8))
* ChainInfo delegates Networks Service to get current chain ([0673343](https://github.com/nervosnetwork/neuron/commit/0673343))
* If genesis hash doesn't match do not proceed to sync ([bd8e4e4](https://github.com/nervosnetwork/neuron/commit/bd8e4e4))
* Remove ChainInfo moving its feature into NetworksService ([81f1eff](https://github.com/nervosnetwork/neuron/commit/81f1eff))
* **neuron-ui:** add a guide bubble in connection status ([59f2dd5](https://github.com/nervosnetwork/neuron/commit/59f2dd5))
* **neuron-ui:** add a guide link to run a ckb mainnet node. ([89aa04c](https://github.com/nervosnetwork/neuron/commit/89aa04c))
* **neuron-ui:** add difficulty formatter ([#1105](https://github.com/nervosnetwork/neuron/issues/1105)) ([98ba68d](https://github.com/nervosnetwork/neuron/commit/98ba68d))
* **neuron-ui:** add hint for synchronization not started. ([7d0cc67](https://github.com/nervosnetwork/neuron/commit/7d0cc67))
* **neuron-ui:** hide the general settings and redirect to wallets setting ([b3e3d0e](https://github.com/nervosnetwork/neuron/commit/b3e3d0e))
* **neuron-ui:** limit the times of guide bubble to 3 ([9b85589](https://github.com/nervosnetwork/neuron/commit/9b85589))
* **neuron-ui:** update chain types on launch ([2cb5047](https://github.com/nervosnetwork/neuron/commit/2cb5047))
* **neuron-ui:** update the hint of withdraw dialog ([0bec01e](https://github.com/nervosnetwork/neuron/commit/0bec01e))
* **neuron-ui:** update the warning in withdraw dialog. ([e819439](https://github.com/nervosnetwork/neuron/commit/e819439))
* add depositTimestamp ([108d5b1](https://github.com/nervosnetwork/neuron/commit/108d5b1))
* Do not allow importing keystore from cli ([1b66ea3](https://github.com/nervosnetwork/neuron/commit/1b66ea3))
* If chain info couldn't be fetched set as ckb_dev ([17c1715](https://github.com/nervosnetwork/neuron/commit/17c1715))
* Let addresses regeneration happen before sync task starts ([a52a531](https://github.com/nervosnetwork/neuron/commit/a52a531))
* Prefer network's chain and genesis hash when syncing ([9b5b52c](https://github.com/nervosnetwork/neuron/commit/9b5b52c))
* Preset mainnet network configuration ([1979e8a](https://github.com/nervosnetwork/neuron/commit/1979e8a))
* Set current wallet to null if it's undefined ([6c7117f](https://github.com/nervosnetwork/neuron/commit/6c7117f))
* Update all networks' chain and genesis hash when NetworkService ([a3ccf2d](https://github.com/nervosnetwork/neuron/commit/a3ccf2d))
* **neuron-ui:** use calculateGlobalAPC to update Nervos DAO APC ([e96ca61](https://github.com/nervosnetwork/neuron/commit/e96ca61))
* verify address according to chain type ([2026921](https://github.com/nervosnetwork/neuron/commit/2026921))



## [0.24.5](https://github.com/nervosnetwork/neuron/compare/v0.24.4...v0.24.5) (2019-11-14)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.24.5",
"version": "0.25.0",
"npmClient": "yarn",
"useWorkspaces": true
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "neuron",
"productName": "Neuron",
"description": "CKB Neuron Wallet",
"version": "0.24.5",
"version": "0.25.0",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "neuron-ui",
"version": "0.24.5",
"version": "0.25.0",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand All @@ -17,7 +17,7 @@
"scripts": {
"start": "react-app-rewired start",
"lint": "eslint --fix --ext .tsx,.ts,.js src",
"test": "react-app-rewired test --env=jsdom --color --watchAll=false",
"test": "react-app-rewired test --env=jsdom --watchAll=false",
"build": "react-app-rewired build",
"clean": "rimraf build/*",
"precommit": "lint-staged",
Expand Down
34 changes: 22 additions & 12 deletions packages/neuron-ui/src/components/CustomRows/DAORecordRow.tsx
@@ -1,9 +1,9 @@
import React, { useEffect, useState, useMemo } from 'react'
import { DefaultButton } from 'office-ui-fabric-react'
import { useTranslation } from 'react-i18next'
import { ckbCore, getBlockByNumber } from 'services/chain'
import { ckbCore, getHeaderByNumber } 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 All @@ -19,6 +19,8 @@ const DAORecord = ({
actionLabel,
onClick,
timestamp,
genesisBlockTimestamp,
depositTimestamp,
depositOutPoint,
epoch,
withdraw,
Expand All @@ -29,35 +31,43 @@ const DAORecord = ({
tipBlockNumber: string
epoch: string
withdraw: string | null
genesisBlockTimestamp: number | undefined
connectionStatus: 'online' | 'offline'
}) => {
const [t] = useTranslation()
const [withdrawingEpoch, setWithdrawingEpoch] = useState('')
const [depositEpoch, setDepositEpoch] = useState('')
const [apc, setApc] = useState(0)

useEffect(() => {
calculateGlobalAPC(+(depositTimestamp || timestamp), genesisBlockTimestamp).then(res => {
setApc(res)
})
}, [depositTimestamp, timestamp, genesisBlockTimestamp])

useEffect(() => {
if (!depositOutPoint) {
getBlockByNumber(BigInt(blockNumber))
.then(b => {
setDepositEpoch(b.header.epoch)
getHeaderByNumber(BigInt(blockNumber))
.then(header => {
setDepositEpoch(header.epoch)
})
.catch((err: Error) => {
console.error(err)
})
return
}
const depositBlockNumber = ckbCore.utils.bytesToHex(ckbCore.utils.hexToBytes(daoData).reverse())
getBlockByNumber(BigInt(depositBlockNumber))
.then(b => {
setDepositEpoch(b.header.epoch)
getHeaderByNumber(BigInt(depositBlockNumber))
.then(header => {
setDepositEpoch(header.epoch)
})
.catch((err: Error) => {
console.error(err)
})

getBlockByNumber(BigInt(blockNumber))
.then(b => {
setWithdrawingEpoch(b.header.epoch)
getHeaderByNumber(BigInt(blockNumber))
.then(header => {
setWithdrawingEpoch(header.epoch)
})
.catch((err: Error) => {
console.error(err)
Expand Down Expand Up @@ -142,7 +152,7 @@ const DAORecord = ({
</div>
</div>
<div className={styles.secondaryInfo}>
<span>{`APC: ~${calculateAPC(compensation.toString(), capacity, `${Date.now() - +timestamp}`)}%`}</span>
<span>{`APC: ~${apc}%`}</span>
<span>{uniformTimeFormatter(+timestamp)}</span>
<span>{metaInfo}</span>
</div>
Expand Down
17 changes: 10 additions & 7 deletions packages/neuron-ui/src/components/NervosDAO/WithdrawDialog.tsx
Expand Up @@ -60,17 +60,20 @@ const WithdrawDialog = ({
const currentEpochInfo = epochParser(currentEpoch)
const targetEpochNumber = calculateTargetEpochNumber(depositEpochInfo, currentEpochInfo)
const epochs = targetEpochNumber - currentEpochInfo.number - BigInt(1)
const message = t('nervos-dao.notice-wait-time', {
epochs: localNumberFormatter(epochs),
blocks: localNumberFormatter(currentEpochInfo.length - currentEpochInfo.index),
days: localNumberFormatter(epochs / BigInt(6)),
})
const message =
epochs >= BigInt(0)
? t('nervos-dao.notice-wait-time', {
epochs: localNumberFormatter(epochs),
blocks: localNumberFormatter(currentEpochInfo.length - currentEpochInfo.index),
days: localNumberFormatter(epochs / BigInt(6)),
})
: ''

const alert =
epochs <= BigInt(5)
epochs <= BigInt(5) && epochs >= BigInt(0)
? t('nervos-dao.withdraw-alert', {
epochs,
nextLeftEpochs: epochs + BigInt(180),
hours: epochs * BigInt(4),
days: (epochs + BigInt(180)) / BigInt(6),
})
: ''
Expand Down
23 changes: 15 additions & 8 deletions packages/neuron-ui/src/components/NervosDAO/index.tsx
Expand Up @@ -11,11 +11,11 @@ import { updateNervosDaoData, clearNervosDaoData } from 'states/stateProvider/ac
import calculateGlobalAPC from 'utils/calculateGlobalAPC'
import calculateFee from 'utils/calculateFee'
import { shannonToCKBFormatter, CKBToShannonFormatter } from 'utils/formatters'
import { MIN_DEPOSIT_AMOUNT, MEDIUM_FEE_RATE, SHANNON_CKB_RATIO, CapacityUnit } from 'utils/const'
import { MIN_DEPOSIT_AMOUNT, MEDIUM_FEE_RATE, SHANNON_CKB_RATIO, MAX_DECIMAL_DIGITS, CapacityUnit } from 'utils/const'
import { verifyAmount } from 'utils/validators'

import { generateDepositTx, generateWithdrawTx, generateClaimTx } from 'services/remote'
import { ckbCore } from 'services/chain'
import { ckbCore, getHeaderByNumber } from 'services/chain'
import { epochParser } from 'utils/parsers'

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

const clearGeneratedTx = useCallback(() => {
dispatch({
Expand All @@ -66,7 +67,7 @@ const NervosDAO = ({

const verifyRes = verifyAmount(value)
if (verifyRes !== true) {
setErrorMessage(t(`messages.codes.${verifyRes.code}`, { fieldName: 'deposit' }))
setErrorMessage(t(`messages.codes.${verifyRes.code}`, { fieldName: 'deposit', length: MAX_DECIMAL_DIGITS }))
return
}

Expand Down Expand Up @@ -98,6 +99,9 @@ const NervosDAO = ({
useEffect(() => {
updateNervosDaoData({ walletID: wallet.id })(dispatch)
updateDepositValue(`${MIN_DEPOSIT_AMOUNT}`)
getHeaderByNumber('0x0')
.then(header => setGenesisBlockTimestamp(+header.timestamp))
.catch(err => console.error(err))
return () => {
clearNervosDaoData()(dispatch)
clearGeneratedTx()
Expand All @@ -106,11 +110,13 @@ const NervosDAO = ({

useEffect(() => {
if (tipBlockTimestamp) {
calculateGlobalAPC(tipBlockTimestamp).then(apc => {
setGlobalAPC(apc)
})
calculateGlobalAPC(tipBlockTimestamp, genesisBlockTimestamp)
.then(apc => {
setGlobalAPC(apc)
})
.catch(err => console.error(err))
}
}, [tipBlockTimestamp])
}, [tipBlockTimestamp, genesisBlockTimestamp])

const onDepositDialogDismiss = () => {
setShowDepositDialog(false)
Expand Down Expand Up @@ -276,14 +282,15 @@ const NervosDAO = ({
onClick={onActionClick}
tipBlockNumber={tipBlockNumber}
epoch={epoch}
genesisBlockTimestamp={genesisBlockTimestamp}
connectionStatus={connectionStatus}
/>
)
})}
</Stack>
</>
)
}, [records, withdrawList, t, onActionClick, tipBlockNumber, epoch, connectionStatus])
}, [records, withdrawList, t, onActionClick, tipBlockNumber, epoch, connectionStatus, genesisBlockTimestamp])

const free = BigInt(wallet.balance)
const locked = withdrawList.reduce((acc, w) => acc + BigInt(w || 0), BigInt(0))
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/components/Overview/index.tsx
Expand Up @@ -7,7 +7,7 @@ import PropertyList, { Property } from 'widgets/PropertyList'
import { StateWithDispatch } from 'states/stateProvider/reducer'
import { updateTransactionList } from 'states/stateProvider/actionCreators'

import { localNumberFormatter, shannonToCKBFormatter } from 'utils/formatters'
import { localNumberFormatter, shannonToCKBFormatter, difficultyFormatter } from 'utils/formatters'
import { epochParser } from 'utils/parsers'
import { PAGE_SIZE, Routes, CONFIRMATION_THRESHOLD } from 'utils/const'
import { backToTop } from 'utils/animations'
Expand Down Expand Up @@ -104,7 +104,7 @@ const Overview = ({
},
{
label: t('overview.difficulty'),
value: localNumberFormatter(+difficulty),
value: difficultyFormatter(difficulty),
},
],
[t, chain, epoch, difficulty, tipBlockNumber]
Expand Down
10 changes: 8 additions & 2 deletions packages/neuron-ui/src/components/Send/hooks.ts
Expand Up @@ -201,11 +201,17 @@ export const useInitialize = (
clear(dispatch)
}, [walletID, dispatch])

const onGetAddressErrorMessage = useCallback(
(addr: string) => {
const onGetAddressErrorMessage: (isMainnet: boolean) => (addr: string) => string = useCallback(
(isMainnet: boolean) => (addr: string) => {
if (addr === '') {
return t(`messages.codes.${ErrorCode.AddressIsEmpty}`)
}
if (isMainnet && !addr.startsWith('ckb')) {
return t(`messages.mainnet-address-required`)
}
if (!isMainnet && !addr.startsWith('ckt')) {
return t(`messages.testnet-address-required`)
}
if (!verifyAddress(addr)) {
return t(`messages.codes.${ErrorCode.FieldInvalid}`, {
fieldName: 'address',
Expand Down
9 changes: 6 additions & 3 deletions packages/neuron-ui/src/components/Send/index.tsx
Expand Up @@ -20,7 +20,7 @@ import QRScanner from 'widgets/QRScanner'
import { StateWithDispatch } from 'states/stateProvider/reducer'
import appState from 'states/initStates/app'

import { PlaceHolders, CapacityUnit, ErrorCode } from 'utils/const'
import { PlaceHolders, CapacityUnit, ErrorCode, MAINNET_TAG } from 'utils/const'
import { shannonToCKBFormatter } from 'utils/formatters'

import { verifyTotalAmount } from 'utils/validators'
Expand All @@ -38,7 +38,8 @@ const Send = ({
loadings: { sending = false },
},
wallet: { id: walletID = '', balance = '' },
chain: { connectionStatus },
chain: { networkID, connectionStatus },
settings: { networks = [] },
dispatch,
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps<{ address: string }>>) => {
const { t } = useTranslation()
Expand Down Expand Up @@ -66,6 +67,8 @@ const Send = ({
const errorMessageUnderTotal = verifyTotalAmount(totalAmount, fee, balance)
? errorMessage
: t(`messages.codes.${ErrorCode.AmountNotEnough}`)
const network = networks.find(n => n.id === networkID)
const isMainnet = (network && network.chain === MAINNET_TAG) || false

return (
<Stack verticalFill tokens={{ childrenGap: 15, padding: '20px 0 0 0' }}>
Expand Down Expand Up @@ -97,7 +100,7 @@ const Send = ({
onChange={onItemChange}
required
validateOnLoad={false}
onGetErrorMessage={onGetAddressErrorMessage}
onGetErrorMessage={onGetAddressErrorMessage(isMainnet)}
/>
</Stack.Item>
<Stack styles={{ root: { width: '48px' } }} verticalAlign="start">
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/Settings/index.tsx
Expand Up @@ -13,7 +13,7 @@ import { WalletWizardPath } from 'components/WalletWizard'
import { Routes } from 'utils/const'

const pivotItems = [
{ label: 'settings.setting-tabs.general', url: Routes.SettingsGeneral },
// { label: 'settings.setting-tabs.general', url: Routes.SettingsGeneral },
{ label: 'settings.setting-tabs.wallets', url: Routes.SettingsWallets },
{ label: 'settings.setting-tabs.network', url: Routes.SettingsNetworks },
]
Expand Down

0 comments on commit 53b13da

Please sign in to comment.