@ -10,6 +10,10 @@ import {
getDashboardUpdate ,
shepherdElectrumTransactions ,
toggleClaimInterestModal ,
shepherdElectrumCheckServerConnection ,
shepherdElectrumSetServer ,
electrumServerChanged ,
triggerToaster ,
} from '../../../actions/actionCreators' ;
import Store from '../../../store' ;
import {
@ -25,6 +29,7 @@ import {
WalletsDataRender ,
} from './walletsData.render' ;
import { secondsToString } from '../../../util/time' ;
import getRandomElectrumServer from '../../../util/serverRandom' ;
/ * i m p o r t { S o c k e t P r o v i d e r } f r o m ' s o c k e t . i o - r e a c t ' ;
import io from 'socket.io-client' ;
@ -52,12 +57,14 @@ class WalletsData extends React.Component {
coin : null ,
txhistory : null ,
loading : false ,
reconnectInProgress : false ,
} ;
this . openDropMenu = this . openDropMenu . bind ( this ) ;
this . handleClickOutside = this . handleClickOutside . bind ( this ) ;
this . refreshTxHistory = this . refreshTxHistory . bind ( this ) ;
this . openClaimInterestModal = this . openClaimInterestModal . bind ( this ) ;
this . displayClaimInterestUI = this . displayClaimInterestUI . bind ( this ) ;
this . spvAutoReconnect = this . spvAutoReconnect . bind ( this ) ;
}
componentWillMount ( ) {
@ -294,6 +301,7 @@ class WalletsData extends React.Component {
txhistory : this . props . ActiveCoin . txhistory ,
showPagination : this . props . ActiveCoin . txhistory && this . props . ActiveCoin . txhistory . length >= this . state . defaultPageSize ,
itemsListColumns : this . generateItemsListColumns ( this . props . ActiveCoin . txhistory . length ) ,
reconnectInProgress : false ,
} ) ;
}
@ -301,21 +309,62 @@ class WalletsData extends React.Component {
this . props . ActiveCoin . txhistory === 'no data' ) {
_ stateChange = Object . assign ( { } , _ stateChange , {
itemsList : 'no data' ,
reconnectInProgress : false ,
} ) ;
} else if ( this . props . ActiveCoin . txhistory && this . props . ActiveCoin . txhistory === 'loading' ) {
_ stateChange = Object . assign ( { } , _ stateChange , {
itemsList : 'loading' ,
reconnectInProgress : false ,
} ) ;
} else if ( ( this . props . ActiveCoin . txhistory && this . props . ActiveCoin . txhistory === 'connection error or incomplete data' ) ||
( this . props . ActiveCoin . txhistory && this . props . ActiveCoin . txhistory === 'cant get current height' ) ) {
_ stateChange = Object . assign ( { } , _ stateChange , {
itemsList : 'connection error' ,
reconnectInProgress : this . props . Dashboard . electrumCoins [ this . props . ActiveCoin . coin ] . serverList !== 'none' ? true : false ,
} ) ;
if ( ! this . state . reconnectInProgress ) {
this . spvAutoReconnect ( ) ;
}
}
this . setState ( Object . assign ( { } , _ stateChange ) ) ;
}
spvAutoReconnect ( ) {
let _ spvServers = this . props . Dashboard . electrumCoins [ this . props . ActiveCoin . coin ] . serverList ;
let _ server = [
this . props . Dashboard . electrumCoins [ this . props . ActiveCoin . coin ] . server . ip ,
this . props . Dashboard . electrumCoins [ this . props . ActiveCoin . coin ] . server . port
] ;
const _ randomServer = getRandomElectrumServer ( _ spvServers , _ server . join ( ':' ) ) ;
shepherdElectrumCheckServerConnection ( _ randomServer . ip , _ randomServer . port )
. then ( ( res ) => {
if ( res . result ) {
shepherdElectrumSetServer ( this . props . ActiveCoin . coin , _ randomServer . ip , _ randomServer . port )
. then ( ( serverSetRes ) => {
Store . dispatch (
triggerToaster (
` ${ this . props . ActiveCoin . coin } SPV server set to ${ _ randomServer . ip } : ${ _ randomServer . port } ` ,
translate ( 'TOASTR.WALLET_NOTIFICATION' ) ,
'success'
)
) ;
Store . dispatch ( electrumServerChanged ( true ) ) ;
} ) ;
} else {
Store . dispatch (
triggerToaster (
` ${ this . props . ActiveCoin . coin } SPV server ${ _ randomServer . ip } : ${ _ randomServer . port } is unreachable! ` ,
translate ( 'TOASTR.WALLET_NOTIFICATION' ) ,
'error'
)
) ;
}
} ) ;
}
isFullySynced ( ) {
const _ progress = this . props . ActiveCoin . progress ;
@ -362,12 +411,16 @@ class WalletsData extends React.Component {
< tr className = "hover--none" >
< td
colSpan = "7"
className = "table-cell-offset-16 color-warning" >
{ translate ( 'DASHBOARD.SPV_CONN_ERROR' ) }
< span className = { this . props . Dashboard . electrumCoins [ this . props . ActiveCoin . coin ] . serverList !== 'none' ? '' : 'hide' } >
< br / > { translate ( 'DASHBOARD.SPV_CONN_ERROR_P1' ) }
< br / > { translate ( 'DASHBOARD.SPV_CONN_ERROR_P2' ) }
< / s p a n >
className = "table-cell-offset-16" >
< div className = "color-warning" >
{ translate ( 'DASHBOARD.SPV_CONN_ERROR' ) }
< / d i v >
< div className = { this . props . Dashboard . electrumCoins [ this . props . ActiveCoin . coin ] . serverList !== 'none' ? '' : 'hide' } >
< div className = "color-warning" > Trying to switch to another server ... < / d i v >
< br / >
< strong > How to switch manually : < / s t r o n g >
< br / > { translate ( 'DASHBOARD.SPV_CONN_ERROR_P1' ) }
< / d i v >
< / t d >
< / t r >
) ;