Skip to content

Commit 1c4b38c

Browse files
author
ZengClaire
authored
Merge pull request #849 from nervosnetwork/rc/v0.18.0-alpha.0
[ᚬmaster] Rc/v0.18.0 alpha.0
2 parents a466a70 + 4d2aa93 commit 1c4b38c

File tree

22 files changed

+443
-142
lines changed

22 files changed

+443
-142
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ node_modules
77

88
# testing
99
/coverage
10+
*.snap
1011

1112
# production
1213
build

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# [0.18.0-alpha.0](https://github.com/nervosnetwork/neuron/compare/v0.17.0-alpha.9...v0.18.0-alpha.0) (2019-08-10)
2+
3+
4+
### Features
5+
6+
* **neuron-ui:** remove highlight on values in recent activities ([bc052ac](https://github.com/nervosnetwork/neuron/commit/bc052ac))
7+
* display recent activities in sentence style ([b1af1fb](https://github.com/nervosnetwork/neuron/commit/b1af1fb))
8+
9+
10+
111
# [0.17.0-alpha.9](https://github.com/nervosnetwork/neuron/compare/v0.17.0-alpha.8...v0.17.0-alpha.9) (2019-08-08)
212

313

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module.exports = {
77
verbose: true,
88
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
99
projects: [
10-
"<rootDir>/packages/neuron-wallet"
10+
"<rootDir>/packages/neuron-*",
1111
]
1212
};

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

packages/neuron-ui/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "neuron-ui",
3-
"version": "0.17.0-alpha.9",
3+
"version": "0.18.0-alpha.0",
44
"private": true,
55
"author": {
66
"name": "Nervos Core Dev",
@@ -43,7 +43,7 @@
4343
"last 2 chrome versions"
4444
],
4545
"dependencies": {
46-
"@nervosnetwork/ckb-sdk-core": "0.17.1",
46+
"@nervosnetwork/ckb-sdk-core": "0.18.0",
4747
"@uifabric/experiments": "7.10.0",
4848
"@uifabric/styling": "7.4.0",
4949
"canvg": "2.0.0",
@@ -62,6 +62,7 @@
6262
"@storybook/addon-actions": "5.1.9",
6363
"@storybook/addon-knobs": "5.1.9",
6464
"@storybook/addon-links": "5.1.9",
65+
"@storybook/addon-storyshots": "5.1.10",
6566
"@storybook/addon-viewport": "5.1.9",
6667
"@storybook/addons": "5.1.9",
6768
"@storybook/cli": "5.1.9",
@@ -74,6 +75,7 @@
7475
"@types/react-router-dom": "4.3.3",
7576
"@types/storybook-react-router": "1.0.0",
7677
"@types/storybook__addon-knobs": "5.0.3",
78+
"@types/storybook__addon-storyshots": "5.1.0",
7779
"@types/storybook__react": "4.0.2",
7880
"@types/styled-components": "4.1.16",
7981
"babel-jest": "24.8.0",
@@ -84,6 +86,7 @@
8486
"lint-staged": "9.2.0",
8587
"node-sass": "4.12.0",
8688
"react-app-rewired": "2.1.3",
89+
"react-test-renderer": "16.8.6",
8790
"rimraf": "2.6.3",
8891
"storybook-react-router": "1.0.5"
8992
}

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

Lines changed: 125 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
DefaultButton,
99
DetailsList,
1010
DetailsRow,
11+
Icon,
1112
IColumn,
1213
CheckboxVisibility,
1314
DetailsListLayoutMode,
@@ -24,66 +25,94 @@ import PropertyList, { Property } from 'widgets/PropertyList'
2425
import { StateWithDispatch } from 'states/stateProvider/reducer'
2526
import { updateTransactionList, addPopup } from 'states/stateProvider/actionCreators'
2627

27-
import { showErrorMessage } from 'services/remote'
28+
import { showTransactionDetails, showErrorMessage } from 'services/remote'
2829

2930
import { localNumberFormatter, shannonToCKBFormatter, uniformTimeFormatter as timeFormatter } from 'utils/formatters'
30-
import { PAGE_SIZE } from 'utils/const'
31+
import { PAGE_SIZE, Routes, CONFIRMATION_THRESHOLD } from 'utils/const'
3132

3233
const TITLE_FONT_SIZE = 'xxLarge'
34+
export type ActivityItem = State.Transaction & { confirmations: string; typeLabel: string }
35+
36+
const genTypeLabel = (type: 'send' | 'receive', confirmationCount: number) => {
37+
switch (type) {
38+
case 'send': {
39+
if (confirmationCount < CONFIRMATION_THRESHOLD) {
40+
return 'sending'
41+
}
42+
return 'sent'
43+
}
44+
case 'receive': {
45+
if (confirmationCount < CONFIRMATION_THRESHOLD) {
46+
return 'receiving'
47+
}
48+
return 'received'
49+
}
50+
default: {
51+
return type
52+
}
53+
}
54+
}
3355

3456
const ActivityList = ({
3557
columns,
3658
items,
59+
onGoToHistory,
60+
t,
3761
...props
3862
}: React.PropsWithoutRef<{
3963
columns: IColumn[]
4064
items: any
65+
onGoToHistory: any
66+
t: any
4167
isHeaderVisible?: boolean
4268
onRenderRow?: IRenderFunction<IDetailsRowProps>
4369
[index: string]: any
4470
}>) => (
45-
<DetailsList
46-
layoutMode={DetailsListLayoutMode.fixedColumns}
47-
checkboxVisibility={CheckboxVisibility.hidden}
48-
compact
49-
items={items}
50-
columns={columns}
51-
styles={{
52-
root: {
53-
backgroundColor: 'transparent',
54-
},
55-
headerWrapper: {
56-
selectors: {
57-
'.ms-DetailsHeader': {
58-
backgroundColor: 'transparent',
59-
},
60-
'.ms-DetailsHeader-cellName': {
61-
fontSize: FontSizes.xLarge,
62-
},
71+
<Stack>
72+
<DetailsList
73+
isHeaderVisible={false}
74+
layoutMode={DetailsListLayoutMode.justified}
75+
checkboxVisibility={CheckboxVisibility.hidden}
76+
compact
77+
items={items.slice(0, 10)}
78+
columns={columns}
79+
onItemInvoked={item => {
80+
showTransactionDetails(item.hash)
81+
}}
82+
styles={{
83+
root: {
84+
backgroundColor: 'transparent',
6385
},
64-
},
65-
contentWrapper: {
66-
selectors: {
67-
'.ms-DetailsRow': {
68-
backgroundColor: 'transparent',
69-
},
70-
'.ms-DetailsRow-cell': {
71-
fontSize: FontSizes.mediumPlus,
86+
contentWrapper: {
87+
selectors: {
88+
'.ms-DetailsRow': {
89+
backgroundColor: 'transparent',
90+
},
91+
'.ms-DetailsRow-cell': {
92+
fontSize: FontSizes.mediumPlus,
93+
},
7294
},
7395
},
74-
},
75-
}}
76-
{...props}
77-
/>
96+
}}
97+
{...props}
98+
/>
99+
{items.length > 10 ? (
100+
<ActionButton onClick={onGoToHistory} styles={{ root: { border: 'none' } }}>
101+
{t('overview.more')}
102+
</ActionButton>
103+
) : null}
104+
</Stack>
78105
)
79106
const Overview = ({
80107
dispatch,
81108
app: { tipBlockNumber, chain, epoch, difficulty },
82109
wallet: { id, name, balance = '', addresses = [] },
83110
chain: {
111+
tipBlockNumber: syncedBlockNumber,
84112
codeHash = '',
85113
transactions: { items = [] },
86114
},
115+
history,
87116
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps>) => {
88117
const [t] = useTranslation()
89118
const [displayBlockchainInfo, setDisplayBlockchainInfo] = useState(false)
@@ -100,6 +129,9 @@ const Overview = ({
100129
walletID: id,
101130
})(dispatch)
102131
}, [id, dispatch])
132+
const onGoToHistory = useCallback(() => {
133+
history.push(Routes.History)
134+
}, [history])
103135

104136
const onTransactionRowRender = useCallback((props?: IDetailsRowProps) => {
105137
if (props) {
@@ -108,29 +140,22 @@ const Overview = ({
108140
animationDuration: '0!important',
109141
},
110142
}
111-
if (props.item.status === 'failed') {
112-
customStyles.root = {
113-
animationDuration: '0!important',
114-
color: 'red',
115-
}
116-
}
117143
return <DetailsRow {...props} styles={customStyles} />
118144
}
119145
return null
120146
}, [])
121147

122-
const onTransactionTypeRender = useCallback((item?: any) => {
148+
const onTransactionActivityRender = useCallback((item?: ActivityItem) => {
123149
if (item) {
124150
return (
125-
<Text
126-
variant="mediumPlus"
127-
as="span"
128-
style={{
129-
color: item.type === 'receive' ? '#28b463' : '#e66465',
130-
}}
131-
>
132-
{item.type}
133-
</Text>
151+
<>
152+
<Text variant="mediumPlus" as="span" title={`${item.value} shannon`}>
153+
{`${item.typeLabel} ${shannonToCKBFormatter(item.value)} CKB`}
154+
</Text>
155+
<Text variant="mediumPlus" as="span" title={item.confirmations} styles={{ root: [{ paddingLeft: '5px' }] }}>
156+
{item.confirmations}
157+
</Text>
158+
</>
134159
)
135160
}
136161
return null
@@ -149,6 +174,24 @@ const Overview = ({
149174

150175
const activityColumns: IColumn[] = useMemo(() => {
151176
return [
177+
{
178+
key: 'status',
179+
name: t('overview.status'),
180+
minWidth: 20,
181+
maxWidth: 20,
182+
onRender: (item?: State.Transaction) => {
183+
if (!item) {
184+
return null
185+
}
186+
let iconName = 'TransactionPending'
187+
if (item.status === 'success') {
188+
iconName = 'TransactionSuccess'
189+
} else if (item.status === 'failed') {
190+
iconName = 'TransactionFailure'
191+
}
192+
return <Icon iconName={iconName} title={item.status} />
193+
},
194+
},
152195
{
153196
key: 'timestamp',
154197
name: t('overview.datetime'),
@@ -157,30 +200,11 @@ const Overview = ({
157200
onRender: onTimestampRender,
158201
},
159202
{
160-
key: 'type',
161-
name: t('overview.type'),
162-
minWidth: 100,
163-
maxWidth: 100,
164-
onRender: onTransactionTypeRender,
165-
},
166-
{
167-
key: 'status',
168-
name: t('overview.status'),
203+
key: 'activity',
204+
name: t('overview.activity'),
169205
minWidth: 100,
170-
maxWidth: 100,
171-
},
172-
{
173-
key: 'value',
174-
name: t('overview.amount'),
175-
title: 'value',
176-
minWidth: 100,
177-
maxWidth: 500,
178-
onRender: (item?: State.Transaction) => {
179-
if (item) {
180-
return <span title={`${item.value} shannon`}>{`${shannonToCKBFormatter(item.value)} CKB`}</span>
181-
}
182-
return '-'
183-
},
206+
maxWidth: 600,
207+
onRender: onTransactionActivityRender,
184208
},
185209
].map(
186210
(col): IColumn => ({
@@ -189,7 +213,7 @@ const Overview = ({
189213
...col,
190214
})
191215
)
192-
}, [t, onTimestampRender, onTransactionTypeRender])
216+
}, [t, onTimestampRender, onTransactionActivityRender])
193217

194218
const balanceProperties: Property[] = useMemo(
195219
() => [
@@ -249,6 +273,28 @@ const Overview = ({
249273
}
250274
}, [defaultAddress, t, hideMinerInfo, dispatch])
251275

276+
const activityItems = useMemo(
277+
() =>
278+
items.map(item => {
279+
let confirmations = '(-)'
280+
let typeLabel: string = item.type
281+
if (item.blockNumber !== undefined) {
282+
const confirmationCount = 1 + Math.max(+syncedBlockNumber, +tipBlockNumber) - +item.blockNumber
283+
typeLabel = genTypeLabel(item.type, confirmationCount)
284+
confirmations =
285+
confirmationCount > 1
286+
? `(${t('overview.confirmations', { confirmationCount: localNumberFormatter(confirmationCount) })})`
287+
: `(${t('overview.confirmation', { confirmationCount: localNumberFormatter(confirmationCount) })})`
288+
}
289+
return {
290+
...item,
291+
confirmations: item.status === 'success' ? confirmations : '',
292+
typeLabel: t(`overview.${typeLabel}`),
293+
}
294+
}),
295+
[items, t, syncedBlockNumber, tipBlockNumber]
296+
)
297+
252298
return (
253299
<Stack tokens={{ childrenGap: 15 }} verticalFill horizontalAlign="stretch">
254300
<Text as="h1" variant={TITLE_FONT_SIZE}>
@@ -273,7 +319,13 @@ const Overview = ({
273319
{t('overview.recent-activities')}
274320
</Text>
275321
{items.length ? (
276-
<ActivityList columns={activityColumns} items={items} onRenderRow={onTransactionRowRender} />
322+
<ActivityList
323+
columns={activityColumns}
324+
items={activityItems}
325+
onRenderRow={onTransactionRowRender}
326+
onGoToHistory={onGoToHistory}
327+
t={t}
328+
/>
277329
) : (
278330
<div>{t('overview.no-recent-activities')}</div>
279331
)}

0 commit comments

Comments
 (0)