Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8d58abc
feat(neuron-ui): adjust the layout of receive view to vertical aglinm…
Keith-CY Nov 8, 2019
4d9caae
Merge pull request #1061 from Keith-CY/adjust-layout-of-receive
ashchan Nov 8, 2019
da1bfc3
Merge remote-tracking branch 'origin/master' into develop
ashchan Nov 8, 2019
2990891
fix: I18n for pending confirmations count
ashchan Nov 8, 2019
67be688
feat(neuron-ui): only addresses start with 0x0100 are valid
Keith-CY Nov 8, 2019
2d80fa8
fix: input capacity can be null
classicalliu Nov 8, 2019
fe62f7c
Merge pull request #1062 from Keith-CY/verify-address-in-ui
Keith-CY Nov 8, 2019
22ab3d8
Merge pull request #1063 from nervosnetwork/fix-input-capacities
Keith-CY Nov 8, 2019
b0e3855
fix(neuron-wallet): order inputs in a tx
Keith-CY Nov 8, 2019
15d1ec6
Merge pull request #1064 from Keith-CY/order-inputs-in-tx
Keith-CY Nov 9, 2019
848fe7b
feat: Finalize testnet explorer URL
ashchan Nov 9, 2019
ffedca7
fix(neuron-ui): fix the address prefix on tx view according to the ch…
Keith-CY Nov 10, 2019
8f71903
Merge branch 'fix-addr-prefix-in-tx-detail' into testnet-explorer-url
Keith-CY Nov 10, 2019
67aceb8
feat(neuron-ui): update the explorer url according to chain type.
Keith-CY Nov 10, 2019
1bc213a
feat: strengthen address validation
Keith-CY Nov 10, 2019
8ed5501
feat(neuron-wallet): trim the keywords on searching txs
Keith-CY Nov 10, 2019
7bf6dbc
feat(neuron-ui): show the error message from api controller on send v…
Keith-CY Nov 10, 2019
21fd5b1
feat(neuron-ui): show local error message ahead of remote error message
Keith-CY Nov 11, 2019
8686707
Merge pull request #1067 from Keith-CY/strengthen-address-validation
Keith-CY Nov 11, 2019
2d6283d
feat(neuron-ui): remove input truncation on importing keystore. (#1068)
Keith-CY Nov 11, 2019
d943fcf
Merge pull request #1069 from Keith-CY/trim-keywords
ashchan Nov 11, 2019
19c511f
Merge pull request #1070 from Keith-CY/show-error-message-from-api-on…
ashchan Nov 11, 2019
3b5545e
Merge pull request #1065 from nervosnetwork/testnet-explorer-url
ashchan Nov 11, 2019
43cb7a6
chore: Bump to v0.24.3
ashchan Nov 11, 2019
5efec50
docs: Update changelog for v0.24.3
ashchan Nov 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
## [0.24.3](https://github.com/nervosnetwork/neuron/compare/v0.24.2...v0.24.3) (2019-11-11)


### Bug Fixes

* **neuron-ui:** fix the address prefix on tx view according to the chain type. ([ffedca7](https://github.com/nervosnetwork/neuron/commit/ffedca7))
* **neuron-wallet:** order inputs in a tx ([b0e3855](https://github.com/nervosnetwork/neuron/commit/b0e3855))
* I18n for pending confirmations count ([2990891](https://github.com/nervosnetwork/neuron/commit/2990891))
* input capacity can be null ([2d80fa8](https://github.com/nervosnetwork/neuron/commit/2d80fa8))


### Features

* **neuron-ui:** remove input truncation on importing keystore. ([#1068](https://github.com/nervosnetwork/neuron/issues/1068)) ([2d6283d](https://github.com/nervosnetwork/neuron/commit/2d6283d))
* **neuron-ui:** show local error message ahead of remote error message ([21fd5b1](https://github.com/nervosnetwork/neuron/commit/21fd5b1))
* **neuron-ui:** show the error message from api controller on send view. ([7bf6dbc](https://github.com/nervosnetwork/neuron/commit/7bf6dbc))
* **neuron-wallet:** trim the keywords on searching txs ([8ed5501](https://github.com/nervosnetwork/neuron/commit/8ed5501))
* strengthen address validation ([1bc213a](https://github.com/nervosnetwork/neuron/commit/1bc213a))
* **neuron-ui:** update the explorer url according to chain type. ([67aceb8](https://github.com/nervosnetwork/neuron/commit/67aceb8))
* Finalize testnet explorer URL ([848fe7b](https://github.com/nervosnetwork/neuron/commit/848fe7b))
* **neuron-ui:** adjust the layout of receive view to vertical aglinment. ([8d58abc](https://github.com/nervosnetwork/neuron/commit/8d58abc))
* **neuron-ui:** only addresses start with 0x0100 are valid ([67be688](https://github.com/nervosnetwork/neuron/commit/67be688))



## [0.24.2](https://github.com/nervosnetwork/neuron/compare/v0.24.1...v0.24.2) (2019-11-08)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.24.2",
"version": "0.24.3",
"npmClient": "yarn",
"useWorkspaces": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "neuron",
"productName": "Neuron",
"description": "CKB Neuron Wallet",
"version": "0.24.2",
"version": "0.24.3",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "neuron-ui",
"version": "0.24.2",
"version": "0.24.3",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/components/Addresses/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { StateWithDispatch } from 'states/stateProvider/reducer'
import { useLocalDescription } from 'utils/hooks'
import { localNumberFormatter, shannonToCKBFormatter } from 'utils/formatters'
import { onRenderRow } from 'utils/fabricUIRender'
import { MAINNET_TAG } from 'utils/const'

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

Expand Down
8 changes: 7 additions & 1 deletion packages/neuron-ui/src/components/ImportKeystore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ const ImportKeystore = (props: React.PropsWithoutRef<StateWithDispatch & RouteCo
placeholder={t(`import-keystore.placeholder.${key}`)}
type={key === 'password' ? 'password' : 'text'}
readOnly={key === 'path'}
maxLength={maxLength}
value={value}
validateOnLoad={false}
onGetErrorMessage={(text?: string) => {
Expand All @@ -108,6 +107,13 @@ const ImportKeystore = (props: React.PropsWithoutRef<StateWithDispatch & RouteCo
if (key === 'name' && isNameUsed) {
return t(`messages.codes.${ErrorCode.FieldUsed}`, { fieldName: `name`, fieldValue: text })
}
if (text && maxLength && text.length > maxLength) {
return t(`messages.codes.${ErrorCode.FieldTooLong}`, {
fieldName: key,
fieldValue: key === 'password' ? '' : text,
length: maxLength,
})
}
return ''
}}
onChange={(_e: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, newValue?: string) => {
Expand Down
60 changes: 36 additions & 24 deletions packages/neuron-ui/src/components/Receive/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useCallback, useMemo } from 'react'
import { RouteComponentProps } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Stack, Text, TextField, TooltipHost, Modal, FontSizes, IconButton } from 'office-ui-fabric-react'
import { Stack, Text, TextField, TooltipHost, Modal, IconButton } from 'office-ui-fabric-react'

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

const Address = useMemo(
() => (
<Stack styles={{ root: { flex: 1, minWidth: 500 } }}>
<TooltipHost content={t('receive.click-to-copy')} calloutProps={{ gapSpace: 0 }}>
<Stack horizontal horizontalAlign="stretch" tokens={{ childrenGap: 15 }}>
<TextField
styles={{
root: {
flex: 1,
color: '#888',
},
fieldGroup: {
borderColor: '#eee!important',
},
}}
readOnly
placeholder={accountAddress}
onClick={copyAddress}
/>
<IconButton iconProps={{ iconName: 'Copy' }} onClick={copyAddress} />
</Stack>
</TooltipHost>
</Stack>
),
[copyAddress, accountAddress, t]
)

if (!accountAddress) {
return <div>{t('receive.address-not-found')}</div>
}

return (
<>
<Stack horizontal tokens={{ childrenGap: 40, padding: '20px 0 0 0' }} horizontalAlign="space-between">
<Stack styles={{ root: { flex: 1 } }}>
<TooltipHost content={t('receive.click-to-copy')} calloutProps={{ gapSpace: 0 }}>
<Stack horizontal horizontalAlign="stretch" tokens={{ childrenGap: 15 }}>
<TextField
styles={{
root: {
flex: 1,
},
description: {
fontSize: FontSizes.medium,
},
}}
readOnly
placeholder={accountAddress}
onClick={copyAddress}
description={t('receive.prompt')}
/>
<IconButton iconProps={{ iconName: 'Copy' }} onClick={copyAddress} />
</Stack>
</TooltipHost>
</Stack>

<Stack tokens={{ childrenGap: 10 }} horizontalAlign="center">
<Text as="p" variant="medium">
{`${t('receive.address', { network: accountAddress.startsWith('ckb') ? 'CKB Mainnet' : 'CKB Testnet' })}`}
</Text>
<Stack style={{ alignSelf: 'center' }}>
<QRCode
value={accountAddress}
Expand All @@ -65,8 +73,12 @@ const Receive = ({
exportable
includeMargin
dispatch={dispatch}
remark={Address}
/>
</Stack>
<Text as="p" variant="medium">
{t('receive.prompt')}
</Text>
</Stack>

<Modal isOpen={showLargeQRCode} onDismiss={() => setShowLargeQRCode(false)}>
Expand Down
27 changes: 18 additions & 9 deletions packages/neuron-ui/src/components/Send/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ const useOnTransactionChange = (
items: TransactionOutput[],
price: string,
dispatch: StateDispatch,
setIsTransactionValid: Function,
setTotalAmount: Function
setTotalAmount: Function,
setErrorMessage: Function
) => {
useEffect(() => {
clearTimeout(generateTxTimer)
setErrorMessage('')
generateTxTimer = setTimeout(() => {
dispatch({
type: AppActions.UpdateGeneratedTx,
payload: null,
})
if (verifyTransactionOutputs(items)) {
setIsTransactionValid(true)
const totalAmount = outputsToTotalAmount(items)
setTotalAmount(totalAmount)
const realParams = {
Expand All @@ -81,16 +81,25 @@ const useOnTransactionChange = (
type: AppActions.UpdateGeneratedTx,
payload: res.result,
})
} else {
throw new Error(res.message.content)
}
})
.catch((err: Error) => {
console.error(err)
dispatch({
type: AppActions.UpdateGeneratedTx,
payload: '',
})
setErrorMessage(err.message)
})
} else {
setIsTransactionValid(false)
dispatch({
type: AppActions.UpdateGeneratedTx,
payload: '',
})
}
}, 300)
}, [walletID, items, price, dispatch, setIsTransactionValid, setTotalAmount])
}, [walletID, items, price, dispatch, setTotalAmount, setErrorMessage])
}

const useOnSubmit = (items: TransactionOutput[], dispatch: StateDispatch) =>
Expand Down Expand Up @@ -176,8 +185,8 @@ export const useInitialize = (
) => {
const fee = useMemo(() => calculateFee(generatedTx), [generatedTx])

const [isTransactionValid, setIsTransactionValid] = useState(false)
const [totalAmount, setTotalAmount] = useState('0')
const [errorMessage, setErrorMessage] = useState('')

const updateTransactionOutput = useUpdateTransactionOutput(dispatch)
const onItemChange = useOnItemChange(updateTransactionOutput)
Expand Down Expand Up @@ -235,8 +244,6 @@ export const useInitialize = (
fee,
totalAmount,
setTotalAmount,
isTransactionValid,
setIsTransactionValid,
useOnTransactionChange,
onItemChange,
addTransactionOutput,
Expand All @@ -247,6 +254,8 @@ export const useInitialize = (
onGetAmountErrorMessage,
onSubmit,
onClear,
errorMessage,
setErrorMessage,
}
}

Expand Down
16 changes: 9 additions & 7 deletions packages/neuron-ui/src/components/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ const Send = ({
fee,
totalAmount,
setTotalAmount,
isTransactionValid,
setIsTransactionValid,
useOnTransactionChange,
onItemChange,
onSubmit,
Expand All @@ -57,12 +55,16 @@ const Send = ({
onGetAddressErrorMessage,
onGetAmountErrorMessage,
onClear,
errorMessage,
setErrorMessage,
} = useInitialize(walletID, send.outputs, send.generatedTx, dispatch, t)
useOnTransactionChange(walletID, send.outputs, send.price, dispatch, setIsTransactionValid, setTotalAmount)
useOnTransactionChange(walletID, send.outputs, send.price, dispatch, setTotalAmount, setErrorMessage)
const leftStackWidth = '70%'
const labelWidth = '140px'

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

return (
<Stack verticalFill tokens={{ childrenGap: 15, padding: '20px 0 0 0' }}>
Expand Down Expand Up @@ -178,7 +180,7 @@ const Send = ({
styles={{
root: {
width: leftStackWidth,
display: send.outputs.length > 1 || !isAffordable ? 'flex' : 'none',
display: send.outputs.length > 1 || errorMessageUnderTotal ? 'flex' : 'none',
},
}}
tokens={{ childrenGap: 20 }}
Expand All @@ -192,7 +194,7 @@ const Send = ({
alt={t('send.total-amount')}
value={`${shannonToCKBFormatter(totalAmount)} CKB`}
readOnly
errorMessage={isAffordable ? '' : t(`messages.codes.${ErrorCode.AmountNotEnough}`)}
errorMessage={errorMessageUnderTotal}
/>
</Stack.Item>
</Stack>
Expand Down Expand Up @@ -232,7 +234,7 @@ const Send = ({
<PrimaryButton
type="submit"
onClick={onSubmit(walletID)}
disabled={sending || !isTransactionValid || !isAffordable || !send.generatedTx}
disabled={sending || !!errorMessageUnderTotal || !send.generatedTx}
text={t('send.send')}
/>
)}
Expand Down
18 changes: 8 additions & 10 deletions packages/neuron-ui/src/components/Transaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ckbCore } from 'services/chain'
import { transactionState } from 'states/initStates/chain'

import { localNumberFormatter, uniformTimeFormatter, shannonToCKBFormatter } from 'utils/formatters'
import { ErrorCode } from 'utils/const'
import { ErrorCode, MAINNET_TAG } from 'utils/const'
import { explorerNavButton } from './style.module.scss'

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

const addressPrefix = isMainnet ? ckbCore.utils.AddressPrefix.Mainnet : ckbCore.utils.AddressPrefix.Testnet

const inputColumns: IColumn[] = useMemo(
() =>
[
Expand Down Expand Up @@ -198,11 +200,7 @@ const Transaction = () => {
throw new Error('Cannot find current network in the network list')
}

setAddressPrefix(
network.chain === process.env.REACT_APP_MAINNET_TAG
? ckbCore.utils.AddressPrefix.Mainnet
: ckbCore.utils.AddressPrefix.Testnet
)
setIsMainnet(network.chain === MAINNET_TAG)
}
})
.catch(err => console.warn(err))
Expand Down Expand Up @@ -246,10 +244,10 @@ const Transaction = () => {
})
}, [])

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

const basicInfoItems = useMemo(
() => [
Expand Down
4 changes: 3 additions & 1 deletion packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"click-to-copy": "Click to copy the address",
"address-not-found": "Address not found",
"prompt": "Neuron picks a new receiving address for better privacy. Please go to the Address Book if you want to use a previously used receiving address.",
"address-qrcode": "Address QR Code"
"address-qrcode": "Address QR Code",
"address": "{{network}} Address"
},
"history": {
"meta": "Meta",
Expand Down Expand Up @@ -258,6 +259,7 @@
"fields": {
"wallet": "Wallet",
"name": "Name",
"password": "Password",
"remote": "RPC URL",
"network": "Network",
"address": "Address",
Expand Down
Loading