@ -7,9 +7,16 @@ import Store from '../../store';
class WalletsNativeTxHistory extends React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
itemsPerPage : 10 ,
activePage : 1 ,
itemsList : null ,
} ;
this . updateInput = this . updateInput . bind ( this ) ;
}
// TODO: implement sorting and pagination
// TODO: implement sorting
// implement pagination past X items should call listtransactions to get new chunk of data
// z transactions
// filter based on addr
@ -17,6 +24,17 @@ class WalletsNativeTxHistory extends React.Component {
Store . dispatch ( toggleDashboardTxInfoModal ( display , txIndex ) ) ;
}
updateInput ( e ) {
let historyToSplit = this . props . ActiveCoin . txhistory ;
historyToSplit = historyToSplit . slice ( 0 , e . target . value ) ;
this . setState ( {
[ e . target . name ] : e . target . value ,
activePage : 1 ,
itemsList : historyToSplit ,
} ) ;
}
renderTxType ( category ) {
if ( category === 'send' ) {
return (
@ -60,9 +78,92 @@ class WalletsNativeTxHistory extends React.Component {
}
}
componentWillReceiveProps ( props ) {
if ( ! this . state . itemsList || ( this . state . itemsList && ! this . state . itemsList . length ) ) {
let historyToSplit = this . props . ActiveCoin . txhistory ;
historyToSplit = historyToSplit . slice ( ( this . state . activePage - 1 ) * this . state . itemsPerPage , this . state . activePage * this . state . itemsPerPage ) ;
this . setState ( Object . assign ( { } , this . state , {
itemsList : historyToSplit ,
} ) ) ;
}
}
updateCurrentPage ( page ) {
let historyToSplit = this . props . ActiveCoin . txhistory ;
historyToSplit = historyToSplit . slice ( ( page - 1 ) * this . state . itemsPerPage , page * this . state . itemsPerPage ) ;
this . setState ( Object . assign ( { } , this . state , {
activePage : page ,
itemsList : historyToSplit ,
} ) ) ;
}
renderPaginationItems ( ) {
let items = [ ] ;
for ( let i = 0 ; i <= Math . floor ( this . props . ActiveCoin . txhistory . length / this . state . itemsPerPage ) ; i ++ ) {
items . push (
< li className = { this . state . activePage === i + 1 ? 'paginate_button active' : 'paginate_button' } >
< a aria - controls = "kmd-tx-history-tbl" data - dt - idx = "1" tabIndex = "0" key = { i + '-pagination' } onClick = { this . state . activePage !== ( i + 1 ) ? ( ) => this . updateCurrentPage ( i + 1 ) : null } > { i + 1 } < / a >
< / l i >
) ;
}
return items ;
}
renderPaginationItemsPerPageSelector ( ) {
if ( this . props . ActiveCoin . txhistory . length > 10 ) {
return (
< div className = "dataTables_length" id = "kmd-tx-history-tbl_length" >
< label >
Show & nbsp ;
< select name = "itemsPerPage" aria - controls = "kmd-tx-history-tbl" className = "form-control input-sm" onChange = { this . updateInput } >
< option value = "10" > 10 < / o p t i o n >
< option value = "25" > 25 < / o p t i o n >
< option value = "50" > 50 < / o p t i o n >
< option value = "100" > 100 < / o p t i o n >
< / s e l e c t > & n b s p ;
entries
< / l a b e l >
< / d i v >
) ;
} else {
return null ;
}
}
renderPagination ( ) {
if ( this . props . ActiveCoin . txhistory . length > 10 ) {
return (
< div className = "row unselectable" >
< div className = "col-sm-5" >
< div className = "dataTables_info" id = "kmd-tx-history-tbl_info" role = "status" aria - live = "polite" > Showing { ( ( this . state . activePage - 1 ) * this . state . itemsPerPage ) + 1 } to { this . state . activePage * this . state . itemsPerPage } of { this . props . ActiveCoin . txhistory . length } entries < / d i v >
< / d i v >
< div className = "col-sm-7" >
< div className = "dataTables_paginate paging_simple_numbers" id = "kmd-tx-history-tbl_paginate" >
< ul className = "pagination" >
< li className = { this . state . activePage === 1 ? 'paginate_button previous disabled' : 'paginate_button previous' } id = "kmd-tx-history-tbl_previous" >
< a aria - controls = "kmd-tx-history-tbl" data - dt - idx = "0" tabIndex = "0" onClick = { ( ) => this . updateCurrentPage ( this . state . activePage - 1 ) } > Previous < / a >
< / l i >
{ this . renderPaginationItems ( ) }
< li className = { this . state . activePage === Math . floor ( this . props . ActiveCoin . txhistory . length / this . state . itemsPerPage ) ? 'paginate_button next disabled' : 'paginate_button next' } id = "kmd-tx-history-tbl_next" >
< a aria - controls = "kmd-tx-history-tbl" data - dt - idx = "2" tabIndex = "0" onClick = { ( ) => this . updateCurrentPage ( this . state . activePage + 1 ) } > Next < / a >
< / l i >
< / u l >
< / d i v >
< / d i v >
< / d i v >
) ;
} else {
return null ;
}
}
renderTxHistoryList ( ) {
if ( this . props . ActiveCoin . txhistory && this . props . ActiveCoin . txhistory . length && this . props . ActiveCoin . nativeActiveSection === 'default' ) {
return this . props . ActiveCoin . txhistory . map ( ( tx , index ) =>
if ( this . state . itemsList && this . state . itemsList . length && this . props . ActiveCoin . nativeActiveSection === 'default' ) {
return this . state . itemsList . map ( ( tx , index ) =>
< tr key = { tx . txid + tx . amount } >
< td >
< span className = "label label-default" >
@ -98,33 +199,48 @@ class WalletsNativeTxHistory extends React.Component {
< h3 className = "panel-title" > { translate ( 'INDEX.TRANSACTION_HISTORY' ) } < / h 3 >
< / h e a d e r >
< div className = "panel-body" >
< table className = "table table-hover dataTable table-striped" data - extcoin = "COIN" id = "kmd-tx-history-tbl" width = "100%" >
< thead >
< tr >
< th > { translate ( 'INDEX.TYPE' ) } < / t h >
< th > { translate ( 'INDEX.DIRECTION' ) } < / t h >
< th > { translate ( 'INDEX.CONFIRMATIONS' ) } < / t h >
< th > { translate ( 'INDEX.AMOUNT' ) } < / t h >
< th > { translate ( 'INDEX.TIME' ) } < / t h >
< th > { translate ( 'INDEX.DEST_ADDRESS' ) } < / t h >
< th > { translate ( 'INDEX.TX_DETAIL' ) } < / t h >
< / t r >
< / t h e a d >
< tbody >
{ this . renderTxHistoryList ( ) }
< / t b o d y >
< tfoot >
< tr >
< th > { translate ( 'INDEX.TYPE' ) } < / t h >
< th > { translate ( 'INDEX.DIRECTION' ) } < / t h >
< th > { translate ( 'INDEX.CONFIRMATIONS' ) } < / t h >
< th > { translate ( 'INDEX.AMOUNT' ) } < / t h >
< th > { translate ( 'INDEX.TIME' ) } < / t h >
< th > { translate ( 'INDEX.DEST_ADDRESS' ) } < / t h >
< th > { translate ( 'INDEX.TX_DETAIL' ) } < / t h >
< / t r >
< / t f o o t >
< / t a b l e >
< div className = "row" >
< div className = "col-sm-6" >
{ this . renderPaginationItemsPerPageSelector ( ) }
< / d i v >
< div className = "col-sm-6" >
< div id = "kmd-tx-history-tbl_filter" className = "dataTables_filter" >
< label >
Search : < input type = "search" className = "form-control input-sm" placeholder = "" aria - controls = "kmd-tx-history-tbl" disabled = "true" / >
< / l a b e l >
< / d i v >
< / d i v >
< / d i v >
< div className = "row" >
< table className = "table table-hover dataTable table-striped" data - extcoin = "COIN" id = "kmd-tx-history-tbl" width = "100%" >
< thead >
< tr >
< th > { translate ( 'INDEX.TYPE' ) } < / t h >
< th > { translate ( 'INDEX.DIRECTION' ) } < / t h >
< th > { translate ( 'INDEX.CONFIRMATIONS' ) } < / t h >
< th > { translate ( 'INDEX.AMOUNT' ) } < / t h >
< th > { translate ( 'INDEX.TIME' ) } < / t h >
< th > { translate ( 'INDEX.DEST_ADDRESS' ) } < / t h >
< th > { translate ( 'INDEX.TX_DETAIL' ) } < / t h >
< / t r >
< / t h e a d >
< tbody >
{ this . renderTxHistoryList ( ) }
< / t b o d y >
< tfoot >
< tr >
< th > { translate ( 'INDEX.TYPE' ) } < / t h >
< th > { translate ( 'INDEX.DIRECTION' ) } < / t h >
< th > { translate ( 'INDEX.CONFIRMATIONS' ) } < / t h >
< th > { translate ( 'INDEX.AMOUNT' ) } < / t h >
< th > { translate ( 'INDEX.TIME' ) } < / t h >
< th > { translate ( 'INDEX.DEST_ADDRESS' ) } < / t h >
< th > { translate ( 'INDEX.TX_DETAIL' ) } < / t h >
< / t r >
< / t f o o t >
< / t a b l e >
< / d i v >
{ this . renderPagination ( ) }
< / d i v >
< / d i v >
< / d i v >