@ -14,6 +14,8 @@ import { MODAL_SETTINGS_ACCOUNT } from 'config/constants'
import { updateAccount , removeAccount } from 'actions/accounts'
import { updateAccount , removeAccount } from 'actions/accounts'
import { setDataModal } from 'reducers/modals'
import { setDataModal } from 'reducers/modals'
import { getBridgeForCurrency } from 'bridge'
import Spoiler from 'components/base/Spoiler'
import Spoiler from 'components/base/Spoiler'
import CryptoCurrencyIcon from 'components/CryptoCurrencyIcon'
import CryptoCurrencyIcon from 'components/CryptoCurrencyIcon'
import Box from 'components/base/Box'
import Box from 'components/base/Box'
@ -30,9 +32,11 @@ import {
} from 'components/base/Modal'
} from 'components/base/Modal'
type State = {
type State = {
accountName : string | null ,
accountName : ? string ,
accountUnit : Unit | null ,
accountUnit : ? Unit ,
endpointConfig : ? string ,
accountNameError : boolean ,
accountNameError : boolean ,
endpointConfigError : ? Error ,
isRemoveAccountModalOpen : boolean ,
isRemoveAccountModalOpen : boolean ,
}
}
@ -45,6 +49,8 @@ type Props = {
data : any ,
data : any ,
}
}
const canConfigureEndpointConfig = account => account . currency . id === 'ripple'
const unitGetOptionValue = unit => unit . magnitude
const unitGetOptionValue = unit => unit . magnitude
const renderUnitItemCode = item => item . data . code
const renderUnitItemCode = item => item . data . code
@ -57,7 +63,9 @@ const mapDispatchToProps = {
const defaultState = {
const defaultState = {
accountName : null ,
accountName : null ,
accountUnit : null ,
accountUnit : null ,
endpointConfig : null ,
accountNameError : false ,
accountNameError : false ,
endpointConfigError : null ,
isRemoveAccountModalOpen : false ,
isRemoveAccountModalOpen : false ,
}
}
@ -66,7 +74,12 @@ class HelperComp extends PureComponent<Props, State> {
... defaultState ,
... defaultState ,
}
}
componentWillUnmount ( ) {
this . handleChangeEndpointConfig_id ++
}
getAccount ( data : Object ) : Account {
getAccount ( data : Object ) : Account {
// FIXME this should be a selector
const { accountName } = this . state
const { accountName } = this . state
const account = get ( data , 'account' , { } )
const account = get ( data , 'account' , { } )
@ -80,6 +93,31 @@ class HelperComp extends PureComponent<Props, State> {
}
}
}
}
handleChangeEndpointConfig_id = 0
handleChangeEndpointConfig = async ( endpointConfig : string ) => {
const bridge = getBridgeForCurrency ( this . getAccount ( this . props . data ) . currency )
this . handleChangeEndpointConfig_id ++
const { handleChangeEndpointConfig_id } = this
this . setState ( {
endpointConfig ,
endpointConfigError : null ,
} )
try {
if ( bridge . validateEndpointConfig ) {
await bridge . validateEndpointConfig ( endpointConfig )
}
if ( handleChangeEndpointConfig_id === this . handleChangeEndpointConfig_id ) {
this . setState ( {
endpointConfigError : null ,
} )
}
} catch ( endpointConfigError ) {
if ( handleChangeEndpointConfig_id === this . handleChangeEndpointConfig_id ) {
this . setState ( { endpointConfigError } )
}
}
}
handleChangeName = ( value : string ) =>
handleChangeName = ( value : string ) =>
this . setState ( {
this . setState ( {
accountName : value ,
accountName : value ,
@ -91,7 +129,7 @@ class HelperComp extends PureComponent<Props, State> {
e . preventDefault ( )
e . preventDefault ( )
const { updateAccount , setDataModal } = this . props
const { updateAccount , setDataModal } = this . props
const { accountName , accountUnit } = this . state
const { accountName , accountUnit , endpointConfig , endpointConfigError } = this . state
const sanitizedAccountName = accountName ? accountName . replace ( /\s+/g , ' ' ) . trim ( ) : null
const sanitizedAccountName = accountName ? accountName . replace ( /\s+/g , ' ' ) . trim ( ) : null
if ( account . name || sanitizedAccountName ) {
if ( account . name || sanitizedAccountName ) {
@ -100,6 +138,9 @@ class HelperComp extends PureComponent<Props, State> {
unit : accountUnit || account . unit ,
unit : accountUnit || account . unit ,
name : sanitizedAccountName || account . name ,
name : sanitizedAccountName || account . name ,
}
}
if ( endpointConfig && ! endpointConfigError ) {
account . endpointConfig = endpointConfig
}
updateAccount ( account )
updateAccount ( account )
setDataModal ( MODAL_SETTINGS_ACCOUNT , { account } )
setDataModal ( MODAL_SETTINGS_ACCOUNT , { account } )
onClose ( )
onClose ( )
@ -123,7 +164,9 @@ class HelperComp extends PureComponent<Props, State> {
handleChangeUnit = ( value : Unit ) => {
handleChangeUnit = ( value : Unit ) => {
this . setState ( { accountUnit : value } )
this . setState ( { accountUnit : value } )
}
}
handleOpenRemoveAccountModal = ( ) => this . setState ( { isRemoveAccountModalOpen : true } )
handleOpenRemoveAccountModal = ( ) => this . setState ( { isRemoveAccountModalOpen : true } )
handleCloseRemoveAccountModal = ( ) => this . setState ( { isRemoveAccountModalOpen : false } )
handleCloseRemoveAccountModal = ( ) => this . setState ( { isRemoveAccountModalOpen : false } )
handleRemoveAccount = ( account : Account ) => {
handleRemoveAccount = ( account : Account ) => {
@ -134,10 +177,17 @@ class HelperComp extends PureComponent<Props, State> {
}
}
render ( ) {
render ( ) {
const { accountUnit , accountNameError , isRemoveAccountModalOpen } = this . state
const {
accountUnit ,
endpointConfig ,
accountNameError ,
isRemoveAccountModalOpen ,
endpointConfigError ,
} = this . state
const { t , onClose , data } = this . props
const { t , onClose , data } = this . props
const account = this . getAccount ( data )
const account = this . getAccount ( data )
const bridge = getBridgeForCurrency ( account . currency )
const usefulData = {
const usefulData = {
xpub : account . xpub || undefined ,
xpub : account . xpub || undefined ,
@ -184,6 +234,29 @@ class HelperComp extends PureComponent<Props, State> {
/ >
/ >
< / B o x >
< / B o x >
< / C o n t a i n e r >
< / C o n t a i n e r >
{ canConfigureEndpointConfig ( account ) ? (
< Container >
< Box >
< OptionRowTitle > { t ( 'app:account.settings.endpointConfig.title' ) } < / O p t i o n R o w T i t l e >
< OptionRowDesc > { t ( 'app:account.settings.endpointConfig.desc' ) } < / O p t i o n R o w D e s c >
< / B o x >
< Box >
< Input
value = {
endpointConfig ||
account . endpointConfig ||
( bridge . getDefaultEndpointConfig && bridge . getDefaultEndpointConfig ( ) ) ||
''
}
onChange = { this . handleChangeEndpointConfig }
onFocus = { e => this . handleFocus ( e , 'endpointConfig' ) }
error = {
endpointConfigError ? t ( 'app:account.settings.endpointConfig.error' ) : false
}
/ >
< / B o x >
< / C o n t a i n e r >
) : null }
< Spoiler title = { t ( 'app:account.settings.advancedLogs' ) } >
< Spoiler title = { t ( 'app:account.settings.advancedLogs' ) } >
< textarea
< textarea
readOnly
readOnly