1- import React , { useEffect } from 'react'
1+ import React , { useEffect , useMemo } from 'react'
22import { RouteComponentProps } from 'react-router-dom'
33import { useTranslation } from 'react-i18next'
4- import { Stack , DetailsList , DetailsListLayoutMode , CheckboxVisibility , IColumn } from 'office-ui-fabric-react'
4+ import { Stack , DetailsList , Text , DetailsListLayoutMode , CheckboxVisibility , IColumn } from 'office-ui-fabric-react'
55
66import { AppActions , StateWithDispatch } from 'states/stateProvider/reducer'
77import actionCreators from 'states/stateProvider/actionCreators'
88import chainState from 'states/initStates/chain'
99
1010import { localNumberFormatter } from 'utils/formatters'
1111
12+ const MIN_CELL_WIDTH = 70
13+
1214const inputColumns : IColumn [ ] = [
1315 {
14- ariaLabel : 'lock hash' ,
1516 key : 'lockHash' ,
1617 name : 'Lock Hash' ,
17- fieldName : 'lockHash' ,
18- minWidth : 70 ,
19- isResizable : true ,
20- isCollapsable : false ,
18+ maxWidth : 300 ,
2119 } ,
2220 {
23- ariaLabel : 'outpoint block hash' ,
2421 key : 'outPointBlockHash' ,
2522 name : 'OutPoint BlockHash' ,
23+ maxWidth : 300 ,
2624 onRender : ( item : any ) => < span > { item . previousOutput . blockHash || 'none' } </ span > ,
27- minWidth : 70 ,
28- isResizable : true ,
29- isCollapsable : false ,
3025 } ,
3126 {
32- ariaLabel : 'outpoint cell' ,
3327 key : 'outPointCell' ,
3428 name : 'OutPoint Cell' ,
3529 onRender : ( item : any ) => (
3630 < span >
3731 { item . previousOutput . cell ? `${ item . previousOutput . cell . txHash } [${ item . previousOutput . cell . index } ]` : 'none' }
3832 </ span >
3933 ) ,
40- minWidth : 70 ,
41- isResizable : true ,
42- isCollapsable : false ,
4334 } ,
4435 {
45- ariaLabel : 'capacity' ,
4636 key : 'capacity' ,
4737 name : 'Capacity' ,
48- fieldName : 'capacity' ,
49- minWidth : 70 ,
38+ } ,
39+ ] . map (
40+ ( col ) : IColumn => ( {
41+ minWidth : MIN_CELL_WIDTH ,
5042 isResizable : true ,
5143 isCollapsable : false ,
52- } ,
53- ]
54- const outputColumns = [
44+ ariaLabel : col . name ,
45+ fieldName : col . key ,
46+ ...col ,
47+ } )
48+ )
49+ const outputColumns : IColumn [ ] = [
5550 {
56- ariaLabel : 'index' ,
5751 key : 'index' ,
5852 name : 'Index' ,
59- fieldName : 'index' ,
60- minWidth : 10 ,
61- maxWidth : 30 ,
62- isResizable : true ,
63- isCollapsable : false ,
53+ minWidth : 80 ,
54+ maxWidth : 150 ,
6455 } ,
6556 {
66- ariaLabel : 'lock hash' ,
6757 key : 'lockHash' ,
6858 name : 'Lock Hash' ,
69- fieldName : 'lockHash' ,
7059 minWidth : 70 ,
71- isResizable : true ,
72- isCollapsable : false ,
60+ maxWidth : 300 ,
7361 } ,
7462 {
75- ariaLabel : 'capacity' ,
7663 key : 'capacity' ,
7764 name : 'Capacity' ,
78- fieldName : 'capacity' ,
79- minWidth : 70 ,
65+ minWidth : 150 ,
66+ } ,
67+ ] . map ( col => ( {
68+ isResizable : true ,
69+ isCollapsable : false ,
70+ ariaLabel : col . name ,
71+ fieldName : col . key ,
72+ ...col ,
73+ } ) )
74+
75+ const basicInfoColumns : IColumn [ ] = [
76+ {
77+ key : 'label' ,
78+ name : 'Label' ,
79+ } ,
80+ {
81+ key : 'value' ,
82+ name : 'value' ,
83+ minWidth : 450 ,
84+ } ,
85+ ] . map (
86+ ( col ) : IColumn => ( {
8087 isResizable : true ,
8188 isCollapsable : false ,
82- } ,
83- ]
89+ minWidth : MIN_CELL_WIDTH ,
90+ ariaLabel : col . name ,
91+ fieldName : col . key ,
92+ ...col ,
93+ } )
94+ )
8495const Transaction = ( {
8596 wallet : { id : walletID = '' } ,
8697 chain : { transaction = chainState . transaction } ,
@@ -97,48 +108,70 @@ const Transaction = ({
97108 dispatch ( actionCreators . getTransaction ( walletID , match . params . hash ) )
98109 } , [ match . params . hash , dispatch , walletID ] )
99110
111+ const basicInfoItems = useMemo (
112+ ( ) => [
113+ { label : t ( 'history.transaction-hash' ) , value : transaction . hash || 'none' } ,
114+ {
115+ label : t ( 'history.date' ) ,
116+ value : + ( transaction . timestamp || transaction . createdAt )
117+ ? new Date ( + transaction . timestamp || + transaction . createdAt ) . toLocaleString ( )
118+ : 'none' ,
119+ } ,
120+ {
121+ label : t ( 'history.blockNumber' ) ,
122+ value : localNumberFormatter ( transaction . blockNumber ) || 'none' ,
123+ } ,
124+ {
125+ label : t ( 'history.amount' ) ,
126+ value : transaction . value ,
127+ } ,
128+ ] ,
129+ [ t , transaction ]
130+ )
131+
100132 return (
101- < Stack >
102- < Stack . Item >
103- < b > { `${ t ( 'history.transaction-hash' ) } : ` } </ b >
104- { transaction . hash }
105- </ Stack . Item >
106- < Stack . Item >
107- < div >
108- < b > { `${ t ( 'history.date' ) } : ` } </ b >
109- { + transaction . timestamp ? new Date ( + transaction . timestamp ) . toLocaleString ( ) : null }
110- </ div >
111- < div >
112- < b > { `${ t ( 'history.blockNumber' ) } : ` } </ b >
113- { localNumberFormatter ( transaction . blockNumber ) }
114- </ div >
115- < div >
116- < b > { `${ t ( 'history.amount' ) } : ` } </ b >
117- { transaction . value }
118- </ div >
119- < div >
120- < b > Inputs</ b >
133+ < Stack tokens = { { childrenGap : 15 } } >
134+ < Stack tokens = { { childrenGap : 15 } } >
135+ < Text variant = "xLarge" as = "h1" >
136+ { t ( 'history.basic-information' ) }
137+ </ Text >
138+ < DetailsList
139+ columns = { basicInfoColumns }
140+ items = { basicInfoItems }
141+ layoutMode = { DetailsListLayoutMode . justified }
142+ checkboxVisibility = { CheckboxVisibility . hidden }
143+ compact
144+ isHeaderVisible = { false }
145+ />
146+ </ Stack >
147+ < Stack tokens = { { childrenGap : 15 } } >
148+ < Stack . Item >
149+ < Text variant = "xLarge" as = "h1" >
150+ Inputs
151+ </ Text >
121152 < DetailsList
122- checkboxVisibility = { CheckboxVisibility . hidden }
123153 items = { transaction . inputs }
124- compact
125- isHeaderVisible
126154 layoutMode = { DetailsListLayoutMode . justified }
127155 columns = { inputColumns }
156+ checkboxVisibility = { CheckboxVisibility . hidden }
157+ compact
158+ isHeaderVisible
128159 />
129- </ div >
130- < div >
131- < b > Outputs</ b >
160+ </ Stack . Item >
161+ < Stack . Item >
162+ < Text variant = "xLarge" as = "h1" >
163+ Outputs
164+ </ Text >
132165 < DetailsList
133166 items = { transaction . outputs . map ( ( output , index ) => ( { ...output , index } ) ) }
167+ layoutMode = { DetailsListLayoutMode . justified }
168+ columns = { outputColumns }
134169 checkboxVisibility = { CheckboxVisibility . hidden }
135170 compact
136171 isHeaderVisible
137- layoutMode = { DetailsListLayoutMode . justified }
138- columns = { outputColumns }
139172 />
140- </ div >
141- </ Stack . Item >
173+ </ Stack . Item >
174+ </ Stack >
142175 </ Stack >
143176 )
144177}
0 commit comments