Skip to content

Commit e27bfb4

Browse files
authored
Merge pull request #1073 from nervosnetwork/rc/v0.24.3
[ᚬmaster] Rc/v0.24.3
2 parents 57b1a03 + 5efec50 commit e27bfb4

File tree

20 files changed

+157
-68
lines changed

20 files changed

+157
-68
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
## [0.24.3](https://github.com/nervosnetwork/neuron/compare/v0.24.2...v0.24.3) (2019-11-11)
2+
3+
4+
### Bug Fixes
5+
6+
* **neuron-ui:** fix the address prefix on tx view according to the chain type. ([ffedca7](https://github.com/nervosnetwork/neuron/commit/ffedca7))
7+
* **neuron-wallet:** order inputs in a tx ([b0e3855](https://github.com/nervosnetwork/neuron/commit/b0e3855))
8+
* I18n for pending confirmations count ([2990891](https://github.com/nervosnetwork/neuron/commit/2990891))
9+
* input capacity can be null ([2d80fa8](https://github.com/nervosnetwork/neuron/commit/2d80fa8))
10+
11+
12+
### Features
13+
14+
* **neuron-ui:** remove input truncation on importing keystore. ([#1068](https://github.com/nervosnetwork/neuron/issues/1068)) ([2d6283d](https://github.com/nervosnetwork/neuron/commit/2d6283d))
15+
* **neuron-ui:** show local error message ahead of remote error message ([21fd5b1](https://github.com/nervosnetwork/neuron/commit/21fd5b1))
16+
* **neuron-ui:** show the error message from api controller on send view. ([7bf6dbc](https://github.com/nervosnetwork/neuron/commit/7bf6dbc))
17+
* **neuron-wallet:** trim the keywords on searching txs ([8ed5501](https://github.com/nervosnetwork/neuron/commit/8ed5501))
18+
* strengthen address validation ([1bc213a](https://github.com/nervosnetwork/neuron/commit/1bc213a))
19+
* **neuron-ui:** update the explorer url according to chain type. ([67aceb8](https://github.com/nervosnetwork/neuron/commit/67aceb8))
20+
* Finalize testnet explorer URL ([848fe7b](https://github.com/nervosnetwork/neuron/commit/848fe7b))
21+
* **neuron-ui:** adjust the layout of receive view to vertical aglinment. ([8d58abc](https://github.com/nervosnetwork/neuron/commit/8d58abc))
22+
* **neuron-ui:** only addresses start with 0x0100 are valid ([67be688](https://github.com/nervosnetwork/neuron/commit/67be688))
23+
24+
25+
126
## [0.24.2](https://github.com/nervosnetwork/neuron/compare/v0.24.1...v0.24.2) (2019-11-08)
227

328

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.2",
5+
"version": "0.24.3",
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.2",
5+
"version": "0.24.3",
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.24.2",
3+
"version": "0.24.3",
44
"private": true,
55
"author": {
66
"name": "Nervos Core Dev",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { StateWithDispatch } from 'states/stateProvider/reducer'
2020
import { useLocalDescription } from 'utils/hooks'
2121
import { localNumberFormatter, shannonToCKBFormatter } from 'utils/formatters'
2222
import { onRenderRow } from 'utils/fabricUIRender'
23+
import { MAINNET_TAG } from 'utils/const'
2324

2425
const Addresses = ({
2526
app: {
@@ -30,8 +31,7 @@ const Addresses = ({
3031
settings: { networks = [] },
3132
dispatch,
3233
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps>) => {
33-
const isMainnet =
34-
(networks.find(n => n.id === networkID) || {}).chain === (process.env.REACT_APP_MAINNET_TAG || 'ckb')
34+
const isMainnet = (networks.find(n => n.id === networkID) || {}).chain === MAINNET_TAG
3535
const [showMainnetAddress, setShowMainnetAddress] = useState(false)
3636
const [t] = useTranslation()
3737

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ const ImportKeystore = (props: React.PropsWithoutRef<StateWithDispatch & RouteCo
9898
placeholder={t(`import-keystore.placeholder.${key}`)}
9999
type={key === 'password' ? 'password' : 'text'}
100100
readOnly={key === 'path'}
101-
maxLength={maxLength}
102101
value={value}
103102
validateOnLoad={false}
104103
onGetErrorMessage={(text?: string) => {
@@ -108,6 +107,13 @@ const ImportKeystore = (props: React.PropsWithoutRef<StateWithDispatch & RouteCo
108107
if (key === 'name' && isNameUsed) {
109108
return t(`messages.codes.${ErrorCode.FieldUsed}`, { fieldName: `name`, fieldValue: text })
110109
}
110+
if (text && maxLength && text.length > maxLength) {
111+
return t(`messages.codes.${ErrorCode.FieldTooLong}`, {
112+
fieldName: key,
113+
fieldValue: key === 'password' ? '' : text,
114+
length: maxLength,
115+
})
116+
}
111117
return ''
112118
}}
113119
onChange={(_e: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, newValue?: string) => {

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

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useCallback, useMemo } from 'react'
22
import { RouteComponentProps } from 'react-router-dom'
33
import { useTranslation } from 'react-i18next'
4-
import { Stack, Text, TextField, TooltipHost, Modal, FontSizes, IconButton } from 'office-ui-fabric-react'
4+
import { Stack, Text, TextField, TooltipHost, Modal, IconButton } from 'office-ui-fabric-react'
55

66
import { StateWithDispatch } from 'states/stateProvider/reducer'
77
import QRCode from 'widgets/QRCode'
@@ -28,35 +28,43 @@ const Receive = ({
2828
addPopup('addr-copied')(dispatch)
2929
}, [accountAddress, dispatch])
3030

31+
const Address = useMemo(
32+
() => (
33+
<Stack styles={{ root: { flex: 1, minWidth: 500 } }}>
34+
<TooltipHost content={t('receive.click-to-copy')} calloutProps={{ gapSpace: 0 }}>
35+
<Stack horizontal horizontalAlign="stretch" tokens={{ childrenGap: 15 }}>
36+
<TextField
37+
styles={{
38+
root: {
39+
flex: 1,
40+
color: '#888',
41+
},
42+
fieldGroup: {
43+
borderColor: '#eee!important',
44+
},
45+
}}
46+
readOnly
47+
placeholder={accountAddress}
48+
onClick={copyAddress}
49+
/>
50+
<IconButton iconProps={{ iconName: 'Copy' }} onClick={copyAddress} />
51+
</Stack>
52+
</TooltipHost>
53+
</Stack>
54+
),
55+
[copyAddress, accountAddress, t]
56+
)
57+
3158
if (!accountAddress) {
3259
return <div>{t('receive.address-not-found')}</div>
3360
}
3461

3562
return (
3663
<>
37-
<Stack horizontal tokens={{ childrenGap: 40, padding: '20px 0 0 0' }} horizontalAlign="space-between">
38-
<Stack styles={{ root: { flex: 1 } }}>
39-
<TooltipHost content={t('receive.click-to-copy')} calloutProps={{ gapSpace: 0 }}>
40-
<Stack horizontal horizontalAlign="stretch" tokens={{ childrenGap: 15 }}>
41-
<TextField
42-
styles={{
43-
root: {
44-
flex: 1,
45-
},
46-
description: {
47-
fontSize: FontSizes.medium,
48-
},
49-
}}
50-
readOnly
51-
placeholder={accountAddress}
52-
onClick={copyAddress}
53-
description={t('receive.prompt')}
54-
/>
55-
<IconButton iconProps={{ iconName: 'Copy' }} onClick={copyAddress} />
56-
</Stack>
57-
</TooltipHost>
58-
</Stack>
59-
64+
<Stack tokens={{ childrenGap: 10 }} horizontalAlign="center">
65+
<Text as="p" variant="medium">
66+
{`${t('receive.address', { network: accountAddress.startsWith('ckb') ? 'CKB Mainnet' : 'CKB Testnet' })}`}
67+
</Text>
6068
<Stack style={{ alignSelf: 'center' }}>
6169
<QRCode
6270
value={accountAddress}
@@ -65,8 +73,12 @@ const Receive = ({
6573
exportable
6674
includeMargin
6775
dispatch={dispatch}
76+
remark={Address}
6877
/>
6978
</Stack>
79+
<Text as="p" variant="medium">
80+
{t('receive.prompt')}
81+
</Text>
7082
</Stack>
7183

7284
<Modal isOpen={showLargeQRCode} onDismiss={() => setShowLargeQRCode(false)}>

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ const useOnTransactionChange = (
5252
items: TransactionOutput[],
5353
price: string,
5454
dispatch: StateDispatch,
55-
setIsTransactionValid: Function,
56-
setTotalAmount: Function
55+
setTotalAmount: Function,
56+
setErrorMessage: Function
5757
) => {
5858
useEffect(() => {
5959
clearTimeout(generateTxTimer)
60+
setErrorMessage('')
6061
generateTxTimer = setTimeout(() => {
6162
dispatch({
6263
type: AppActions.UpdateGeneratedTx,
6364
payload: null,
6465
})
6566
if (verifyTransactionOutputs(items)) {
66-
setIsTransactionValid(true)
6767
const totalAmount = outputsToTotalAmount(items)
6868
setTotalAmount(totalAmount)
6969
const realParams = {
@@ -81,16 +81,25 @@ const useOnTransactionChange = (
8181
type: AppActions.UpdateGeneratedTx,
8282
payload: res.result,
8383
})
84+
} else {
85+
throw new Error(res.message.content)
8486
}
8587
})
8688
.catch((err: Error) => {
87-
console.error(err)
89+
dispatch({
90+
type: AppActions.UpdateGeneratedTx,
91+
payload: '',
92+
})
93+
setErrorMessage(err.message)
8894
})
8995
} else {
90-
setIsTransactionValid(false)
96+
dispatch({
97+
type: AppActions.UpdateGeneratedTx,
98+
payload: '',
99+
})
91100
}
92101
}, 300)
93-
}, [walletID, items, price, dispatch, setIsTransactionValid, setTotalAmount])
102+
}, [walletID, items, price, dispatch, setTotalAmount, setErrorMessage])
94103
}
95104

96105
const useOnSubmit = (items: TransactionOutput[], dispatch: StateDispatch) =>
@@ -176,8 +185,8 @@ export const useInitialize = (
176185
) => {
177186
const fee = useMemo(() => calculateFee(generatedTx), [generatedTx])
178187

179-
const [isTransactionValid, setIsTransactionValid] = useState(false)
180188
const [totalAmount, setTotalAmount] = useState('0')
189+
const [errorMessage, setErrorMessage] = useState('')
181190

182191
const updateTransactionOutput = useUpdateTransactionOutput(dispatch)
183192
const onItemChange = useOnItemChange(updateTransactionOutput)
@@ -235,8 +244,6 @@ export const useInitialize = (
235244
fee,
236245
totalAmount,
237246
setTotalAmount,
238-
isTransactionValid,
239-
setIsTransactionValid,
240247
useOnTransactionChange,
241248
onItemChange,
242249
addTransactionOutput,
@@ -247,6 +254,8 @@ export const useInitialize = (
247254
onGetAmountErrorMessage,
248255
onSubmit,
249256
onClear,
257+
errorMessage,
258+
setErrorMessage,
250259
}
251260
}
252261

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ const Send = ({
4545
fee,
4646
totalAmount,
4747
setTotalAmount,
48-
isTransactionValid,
49-
setIsTransactionValid,
5048
useOnTransactionChange,
5149
onItemChange,
5250
onSubmit,
@@ -57,12 +55,16 @@ const Send = ({
5755
onGetAddressErrorMessage,
5856
onGetAmountErrorMessage,
5957
onClear,
58+
errorMessage,
59+
setErrorMessage,
6060
} = useInitialize(walletID, send.outputs, send.generatedTx, dispatch, t)
61-
useOnTransactionChange(walletID, send.outputs, send.price, dispatch, setIsTransactionValid, setTotalAmount)
61+
useOnTransactionChange(walletID, send.outputs, send.price, dispatch, setTotalAmount, setErrorMessage)
6262
const leftStackWidth = '70%'
6363
const labelWidth = '140px'
6464

65-
const isAffordable = verifyTotalAmount(totalAmount, fee, balance)
65+
const errorMessageUnderTotal = verifyTotalAmount(totalAmount, fee, balance)
66+
? errorMessage
67+
: t(`messages.codes.${ErrorCode.AmountNotEnough}`)
6668

6769
return (
6870
<Stack verticalFill tokens={{ childrenGap: 15, padding: '20px 0 0 0' }}>
@@ -178,7 +180,7 @@ const Send = ({
178180
styles={{
179181
root: {
180182
width: leftStackWidth,
181-
display: send.outputs.length > 1 || !isAffordable ? 'flex' : 'none',
183+
display: send.outputs.length > 1 || errorMessageUnderTotal ? 'flex' : 'none',
182184
},
183185
}}
184186
tokens={{ childrenGap: 20 }}
@@ -192,7 +194,7 @@ const Send = ({
192194
alt={t('send.total-amount')}
193195
value={`${shannonToCKBFormatter(totalAmount)} CKB`}
194196
readOnly
195-
errorMessage={isAffordable ? '' : t(`messages.codes.${ErrorCode.AmountNotEnough}`)}
197+
errorMessage={errorMessageUnderTotal}
196198
/>
197199
</Stack.Item>
198200
</Stack>
@@ -232,7 +234,7 @@ const Send = ({
232234
<PrimaryButton
233235
type="submit"
234236
onClick={onSubmit(walletID)}
235-
disabled={sending || !isTransactionValid || !isAffordable || !send.generatedTx}
237+
disabled={sending || !!errorMessageUnderTotal || !send.generatedTx}
236238
text={t('send.send')}
237239
/>
238240
)}

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ckbCore } from 'services/chain'
88
import { transactionState } from 'states/initStates/chain'
99

1010
import { localNumberFormatter, uniformTimeFormatter, shannonToCKBFormatter } from 'utils/formatters'
11-
import { ErrorCode } from 'utils/const'
11+
import { ErrorCode, MAINNET_TAG } from 'utils/const'
1212
import { explorerNavButton } from './style.module.scss'
1313

1414
const MIN_CELL_WIDTH = 70
@@ -30,9 +30,11 @@ const CompactAddress = ({ address }: { address: string }) => (
3030
const Transaction = () => {
3131
const [t] = useTranslation()
3232
const [transaction, setTransaction] = useState(transactionState)
33-
const [addressPrefix, setAddressPrefix] = useState(ckbCore.utils.AddressPrefix.Mainnet)
33+
const [isMainnet, setIsMainnet] = useState(false)
3434
const [error, setError] = useState({ code: '', message: '' })
3535

36+
const addressPrefix = isMainnet ? ckbCore.utils.AddressPrefix.Mainnet : ckbCore.utils.AddressPrefix.Testnet
37+
3638
const inputColumns: IColumn[] = useMemo(
3739
() =>
3840
[
@@ -198,11 +200,7 @@ const Transaction = () => {
198200
throw new Error('Cannot find current network in the network list')
199201
}
200202

201-
setAddressPrefix(
202-
network.chain === process.env.REACT_APP_MAINNET_TAG
203-
? ckbCore.utils.AddressPrefix.Mainnet
204-
: ckbCore.utils.AddressPrefix.Testnet
205-
)
203+
setIsMainnet(network.chain === MAINNET_TAG)
206204
}
207205
})
208206
.catch(err => console.warn(err))
@@ -246,10 +244,10 @@ const Transaction = () => {
246244
})
247245
}, [])
248246

249-
// TODO: add conditional branch on mainnet and testnet
250247
const onExplorerBtnClick = useCallback(() => {
251-
openExternal(`https://explorer.nervos.org/transaction/${transaction.hash}`)
252-
}, [transaction.hash])
248+
const explorerUrl = isMainnet ? 'https://explorer.nervos.org' : 'https://explorer.nervos.org/testnet'
249+
openExternal(`${explorerUrl}/transaction/${transaction.hash}`)
250+
}, [transaction.hash, isMainnet])
253251

254252
const basicInfoItems = useMemo(
255253
() => [

0 commit comments

Comments
 (0)