Skip to content

Commit 1bbec7a

Browse files
authored
Merge pull request #891 from nervosnetwork/rc/v0.18.0-beta.1
[ᚬmaster] Rc/v0.18.0 beta.1
2 parents a8c9543 + 8df64c7 commit 1bbec7a

File tree

81 files changed

+2351
-512
lines changed

Some content is hidden

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

81 files changed

+2351
-512
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ node_modules
88
# testing
99
/coverage
1010
*.snap
11+
/packages/neuron-wallet/tests-e2e/errors
1112

1213
# production
1314
build

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
# [0.18.0-beta.1](https://github.com/nervosnetwork/neuron/compare/v0.18.0-beta.0...v0.18.0-beta.1) (2019-08-22)
2+
3+
4+
### Bug Fixes
5+
6+
* remove hash_type=Type in test ([9340e41](https://github.com/nervosnetwork/neuron/commit/9340e41))
7+
* **neuron-ui:** fix the color of pagination ([3ffed72](https://github.com/nervosnetwork/neuron/commit/3ffed72))
8+
* **neuron-ui:** fix the i18n text of pagination ([c779a20](https://github.com/nervosnetwork/neuron/commit/c779a20))
9+
* address service test ([f743a06](https://github.com/nervosnetwork/neuron/commit/f743a06))
10+
* don't restart when generate new address in normal sync ([66b6810](https://github.com/nervosnetwork/neuron/commit/66b6810))
11+
* minBlockNumber select error ([acbafd0](https://github.com/nervosnetwork/neuron/commit/acbafd0))
12+
* using appendLockHashInfos ([342061d](https://github.com/nervosnetwork/neuron/commit/342061d))
13+
* **e2e:** Make sure to exit server ([559a11e](https://github.com/nervosnetwork/neuron/commit/559a11e))
14+
* **neuron-ui:** disable the submit button when it's sending ([9fc7b7d](https://github.com/nervosnetwork/neuron/commit/9fc7b7d))
15+
* **neuron-ui:** use the create api for creating wallets ([49edee8](https://github.com/nervosnetwork/neuron/commit/49edee8))
16+
* only check success txs ([2ec2529](https://github.com/nervosnetwork/neuron/commit/2ec2529))
17+
* reset when import wallet ([6be360e](https://github.com/nervosnetwork/neuron/commit/6be360e))
18+
19+
20+
### Features
21+
22+
* **neuron-ui:** add more detailed error messages of the amount field ([a2503ff](https://github.com/nervosnetwork/neuron/commit/a2503ff))
23+
* **neuron-ui:** add verification on updating amounts ([46ae8c1](https://github.com/nervosnetwork/neuron/commit/46ae8c1))
24+
* check tx success regular intervals ([a1203da](https://github.com/nervosnetwork/neuron/commit/a1203da))
25+
* not start from zero in indexer when create wallet ([25ed522](https://github.com/nervosnetwork/neuron/commit/25ed522))
26+
* not start from zero in normal sync when create wallet ([50a3c73](https://github.com/nervosnetwork/neuron/commit/50a3c73))
27+
* **neuron-ui:** fill the address field automatically on QR Code recognized as a valid address ([c8a6689](https://github.com/nervosnetwork/neuron/commit/c8a6689))
28+
* **neuron-ui:** update the cycles on the outputs changing ([01d02e0](https://github.com/nervosnetwork/neuron/commit/01d02e0))
29+
* **neuron-ui:** use real cycles ([874e781](https://github.com/nervosnetwork/neuron/commit/874e781))
30+
* auto switch indexer or common sync ([ece382f](https://github.com/nervosnetwork/neuron/commit/ece382f))
31+
* compute cycles ([2be05b3](https://github.com/nervosnetwork/neuron/commit/2be05b3))
32+
* impl sync by indexer RPCs ([16fa2a4](https://github.com/nervosnetwork/neuron/commit/16fa2a4))
33+
* Update Electron to v6 ([0977897](https://github.com/nervosnetwork/neuron/commit/0977897))
34+
* **neuron-ui:** use the same naming strategy as importing mnemonic words ([694ac98](https://github.com/nervosnetwork/neuron/commit/694ac98))
35+
* process fork in indexer mode ([a7ad2d5](https://github.com/nervosnetwork/neuron/commit/a7ad2d5))
36+
37+
38+
139
# [0.18.0-beta.0](https://github.com/nervosnetwork/neuron/compare/v0.18.0-alpha.1...v0.18.0-beta.0) (2019-08-16)
240

341

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.18.0-beta.0",
5+
"version": "0.18.0-beta.1",
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.18.0-beta.0",
5+
"version": "0.18.0-beta.1",
66
"private": true,
77
"author": {
88
"name": "Nervos Core Dev",

packages/neuron-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "neuron-ui",
3-
"version": "0.18.0-beta.0",
3+
"version": "0.18.0-beta.1",
44
"private": true,
55
"author": {
66
"name": "Nervos Core Dev",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const History = ({
6262
nextPageAriaLabel={t('pagination.next-page')}
6363
firstPageAriaLabel={t('pagination.first-page')}
6464
lastPageAriaLabel={t('pagination.last-page')}
65-
pageAriaLabel={t('pagination-page')}
66-
selectedAriaLabel={t('pagination-selected')}
65+
pageAriaLabel={t('pagination.page')}
66+
selectedAriaLabel={t('pagination.selected')}
6767
firstPageIconProps={{ iconName: 'FirstPage' }}
6868
previousPageIconProps={{ iconName: 'PrevPage' }}
6969
nextPageIconProps={{ iconName: 'NextPage' }}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React, { useState, useCallback, useMemo } from 'react'
1+
import React, { useState, useCallback, useMemo, useEffect } from 'react'
22
import { RouteComponentProps } from 'react-router-dom'
33
import { Stack, DefaultButton, PrimaryButton, TextField } from 'office-ui-fabric-react'
44
import { useTranslation } from 'react-i18next'
55
import { showOpenDialog } from 'services/remote'
66
import { importWalletWithKeystore } from 'states/stateProvider/actionCreators'
77
import { StateWithDispatch } from 'states/stateProvider/reducer'
88
import { useGoBack } from 'utils/hooks'
9+
import generateWalletName from 'utils/generateWalletName'
910

1011
const defaultFields = {
1112
path: '',
@@ -23,6 +24,16 @@ const ImportKeystore = (props: React.PropsWithoutRef<StateWithDispatch & RouteCo
2324
const [fields, setFields] = useState(defaultFields)
2425
const goBack = useGoBack(history)
2526

27+
useEffect(() => {
28+
if (fields.name === '') {
29+
const name = generateWalletName(wallets, wallets.length + 1, t)
30+
setFields({
31+
...fields,
32+
name,
33+
})
34+
}
35+
}, [wallets, fields, setFields, t])
36+
2637
const exsitingNames = useMemo(() => {
2738
return wallets.map(w => w.name)
2839
}, [wallets])
@@ -39,11 +50,9 @@ const ImportKeystore = (props: React.PropsWithoutRef<StateWithDispatch & RouteCo
3950
return
4051
}
4152
const filePath = filePaths[0]
42-
const filename = filePath.split('/').pop() || 'Imported wallet'
4353
setFields({
4454
...fields,
4555
path: filePath,
46-
name: filename,
4756
})
4857
},
4958
})

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { priceToFee, CKBToShannonFormatter } from 'utils/formatters'
88

99
const PasswordRequest = ({
1010
app: {
11-
send: { txID, outputs, description, price, cycles },
11+
send: { txID, outputs, description, price, cycles, loading: isSending },
1212
passwordRequest: { walletID = '', actionType = null, password = '' },
1313
},
1414
settings: { wallets = [] },
@@ -27,6 +27,9 @@ const PasswordRequest = ({
2727
const onConfirm = useCallback(() => {
2828
switch (actionType) {
2929
case 'send': {
30+
if (isSending) {
31+
break
32+
}
3033
sendTransaction({
3134
id: txID,
3235
walletID,
@@ -58,7 +61,7 @@ const PasswordRequest = ({
5861
break
5962
}
6063
}
61-
}, [dispatch, walletID, password, actionType, txID, description, outputs, cycles, price, history])
64+
}, [dispatch, walletID, password, actionType, txID, description, outputs, cycles, price, history, isSending])
6265

6366
const onChange = useCallback(
6467
(_e, value?: string) => {
@@ -100,7 +103,7 @@ const PasswordRequest = ({
100103
<TextField value={password} type="password" onChange={onChange} autoFocus onKeyPress={onKeyPress} />
101104
<Stack horizontalAlign="end" horizontal tokens={{ childrenGap: 15 }}>
102105
<DefaultButton onClick={onDismiss}>{t('common.cancel')}</DefaultButton>
103-
<PrimaryButton onClick={onConfirm} disabled={!password}>
106+
<PrimaryButton onClick={onConfirm} disabled={!password || (actionType === 'send' && isSending)}>
104107
{t('common.confirm')}
105108
</PrimaryButton>
106109
</Stack>

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

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,62 @@ import React, { useCallback, useEffect } from 'react'
22
import { IDropdownOption } from 'office-ui-fabric-react'
33

44
import { AppActions, StateDispatch } from 'states/stateProvider/reducer'
5+
import { calculateCycles } from 'services/remote/wallets'
56

6-
import { Message } from 'utils/const'
7+
import { Message, MAX_DECIMAL_DIGITS } from 'utils/const'
78
import { verifyAddress, verifyAmountRange } from 'utils/validators'
9+
import { outputsToTotalCapacity } from 'utils/formatters'
810
import { TransactionOutput } from '.'
911

10-
const validateTransactionParams = ({ items, dispatch }: { items: TransactionOutput[]; dispatch: StateDispatch }) => {
12+
let cyclesTimer: ReturnType<typeof setTimeout>
13+
14+
const validateTransactionParams = ({ items, dispatch }: { items: TransactionOutput[]; dispatch?: StateDispatch }) => {
1115
const errorAction = {
1216
type: AppActions.AddNotification,
1317
payload: {
1418
type: 'warning',
1519
timestamp: Date.now(),
1620
content: Message.AtLeastOneAddressNeeded,
21+
meta: {},
1722
},
1823
}
1924
if (!items.length || !items[0].address) {
20-
dispatch(errorAction)
25+
if (dispatch) {
26+
dispatch(errorAction)
27+
}
2128
return false
2229
}
2330
const invalid = items.some(
2431
(item): boolean => {
25-
if (!verifyAddress(item.address)) {
32+
const isAddressValid = verifyAddress(item.address)
33+
if (typeof isAddressValid === 'string') {
2634
errorAction.payload.content = Message.InvalidAddress
35+
errorAction.payload.meta = { address: item.address }
2736
return true
2837
}
2938
if (Number.isNaN(+item.amount) || +item.amount < 0) {
3039
errorAction.payload.content = Message.InvalidAmount
40+
errorAction.payload.meta = { amount: item.amount }
3141
return true
3242
}
33-
if (!verifyAmountRange(item.amount)) {
34-
errorAction.payload.content = Message.AmountTooSmall
43+
const [, decimal = ''] = item.amount.split('.')
44+
if (decimal.length > MAX_DECIMAL_DIGITS) {
45+
errorAction.payload.content = Message.DecimalExceed
46+
errorAction.payload.meta = { amount: item.amount }
3547
return true
3648
}
37-
const [, decimal = ''] = item.amount.split('.')
38-
if (decimal.length > 8) {
39-
errorAction.payload.content = Message.InvalidAmount
49+
if (!verifyAmountRange(item.amount)) {
50+
errorAction.payload.content = Message.AmountTooSmall
51+
errorAction.payload.meta = { amount: item.amount }
4052
return true
4153
}
4254
return false
4355
}
4456
)
4557
if (invalid) {
46-
dispatch(errorAction)
58+
if (dispatch) {
59+
dispatch(errorAction)
60+
}
4761
return false
4862
}
4963
return true
@@ -84,6 +98,39 @@ const useRemoveTransactionOutput = (dispatch: StateDispatch) =>
8498
[dispatch]
8599
)
86100

101+
const useOnTransactionChange = (walletID: string, items: TransactionOutput[], dispatch: StateDispatch) => {
102+
useEffect(() => {
103+
clearTimeout(cyclesTimer)
104+
cyclesTimer = setTimeout(() => {
105+
if (validateTransactionParams({ items })) {
106+
calculateCycles({
107+
walletID,
108+
capacities: outputsToTotalCapacity(items),
109+
})
110+
.then(response => {
111+
if (response.status) {
112+
if (Number.isNaN(+response.result)) {
113+
throw new Error('Invalid Cycles')
114+
}
115+
dispatch({
116+
type: AppActions.UpdateSendCycles,
117+
payload: response.result,
118+
})
119+
} else {
120+
throw new Error('Cycles Not Calculated')
121+
}
122+
})
123+
.catch(() => {
124+
dispatch({
125+
type: AppActions.UpdateSendCycles,
126+
payload: '0',
127+
})
128+
})
129+
}
130+
}, 300)
131+
}, [walletID, items, dispatch])
132+
}
133+
87134
const useOnSubmit = (items: TransactionOutput[], dispatch: StateDispatch) =>
88135
useCallback(
89136
(walletID: string = '') => () => {
@@ -111,7 +158,14 @@ const useOnItemChange = (updateTransactionOutput: Function) =>
111158
value?: string
112159
) => {
113160
if (undefined !== value) {
114-
updateTransactionOutput(field)(idx)(value)
161+
if (field === 'amount') {
162+
if (Number.isNaN(+value) || /[^\d.]/.test(value)) {
163+
return
164+
}
165+
updateTransactionOutput(field)(idx)(value)
166+
} else {
167+
updateTransactionOutput(field)(idx)(value)
168+
}
115169
}
116170
},
117171
[updateTransactionOutput]
@@ -131,9 +185,10 @@ const useUpdateTransactionPrice = (dispatch: StateDispatch) =>
131185
useCallback(
132186
(_e: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, value?: string) => {
133187
if (undefined !== value) {
188+
const price = value.replace(/[^\d]/g, '')
134189
dispatch({
135190
type: AppActions.UpdateSendPrice,
136-
payload: value.trim(),
191+
payload: price,
137192
})
138193
}
139194
},
@@ -188,6 +243,7 @@ export const useInitialize = (
188243
}, [address, dispatch, history, updateTransactionOutput])
189244

190245
return {
246+
useOnTransactionChange,
191247
updateTransactionOutput,
192248
onItemChange,
193249
onCapacityUnitChange,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const Send = ({
4545
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps<{ address: string }>>) => {
4646
const { t } = useTranslation()
4747
const {
48+
useOnTransactionChange,
4849
updateTransactionOutput,
4950
onItemChange,
5051
onSubmit,
@@ -54,6 +55,7 @@ const Send = ({
5455
onDescriptionChange,
5556
onClear,
5657
} = useInitialize(address, send.outputs, dispatch, history)
58+
useOnTransactionChange(walletID, send.outputs, dispatch)
5759
const leftStackWidth = '70%'
5860
const labelWidth = '140px'
5961
const actionSpacer = (

0 commit comments

Comments
 (0)