2019-03-25 17:13:23 +01:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-09-16 19:11:01 +02:00
|
|
|
import classnames from 'classnames'
|
2019-03-25 17:13:23 +01:00
|
|
|
import { exportAsFile } from '../../../helpers/utils/util'
|
2019-07-08 19:58:35 +02:00
|
|
|
import ToggleButton from '../../../components/ui/toggle-button'
|
2019-03-25 17:13:23 +01:00
|
|
|
import TextField from '../../../components/ui/text-field'
|
|
|
|
import Button from '../../../components/ui/button'
|
|
|
|
import { MOBILE_SYNC_ROUTE } from '../../../helpers/constants/routes'
|
|
|
|
|
|
|
|
export default class AdvancedTab extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
metricsEvent: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
2019-09-27 06:30:36 +02:00
|
|
|
setUseNonceField: PropTypes.func,
|
|
|
|
useNonceField: PropTypes.bool,
|
2019-03-25 17:13:23 +01:00
|
|
|
setHexDataFeatureFlag: PropTypes.func,
|
|
|
|
displayWarning: PropTypes.func,
|
|
|
|
showResetAccountConfirmationModal: PropTypes.func,
|
|
|
|
warning: PropTypes.string,
|
|
|
|
history: PropTypes.object,
|
|
|
|
sendHexData: PropTypes.bool,
|
|
|
|
setAdvancedInlineGasFeatureFlag: PropTypes.func,
|
|
|
|
advancedInlineGas: PropTypes.bool,
|
|
|
|
showFiatInTestnets: PropTypes.bool,
|
2019-05-08 20:57:21 +02:00
|
|
|
autoLogoutTimeLimit: PropTypes.number,
|
|
|
|
setAutoLogoutTimeLimit: PropTypes.func.isRequired,
|
2019-03-25 17:13:23 +01:00
|
|
|
setShowFiatConversionOnTestnetsPreference: PropTypes.func.isRequired,
|
2019-09-16 19:11:01 +02:00
|
|
|
threeBoxSyncingAllowed: PropTypes.bool.isRequired,
|
|
|
|
setThreeBoxSyncingPermission: PropTypes.func.isRequired,
|
|
|
|
threeBoxDisabled: PropTypes.bool.isRequired,
|
2019-12-12 20:28:07 +01:00
|
|
|
setIpfsGateway: PropTypes.func.isRequired,
|
|
|
|
ipfsGateway: PropTypes.string.isRequired,
|
2019-03-25 17:13:23 +01:00
|
|
|
}
|
|
|
|
|
2019-10-17 17:25:37 +02:00
|
|
|
state = {
|
|
|
|
autoLogoutTimeLimit: this.props.autoLogoutTimeLimit,
|
|
|
|
logoutTimeError: '',
|
2019-12-12 20:28:07 +01:00
|
|
|
ipfsGateway: this.props.ipfsGateway,
|
|
|
|
ipfsGatewayError: '',
|
2019-10-17 17:25:37 +02:00
|
|
|
}
|
2019-03-25 17:13:23 +01:00
|
|
|
|
|
|
|
renderMobileSync () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { history } = this.props
|
2019-07-31 22:17:11 +02:00
|
|
|
//
|
2019-03-25 17:13:23 +01:00
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ t('syncWithMobile') }</span>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<Button
|
2019-04-16 21:35:22 +02:00
|
|
|
type="secondary"
|
2019-03-25 17:13:23 +01:00
|
|
|
large
|
|
|
|
onClick={event => {
|
|
|
|
event.preventDefault()
|
|
|
|
history.push(MOBILE_SYNC_ROUTE)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{ t('syncWithMobile') }
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderStateLogs () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { displayWarning } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ t('stateLogs') }</span>
|
|
|
|
<span className="settings-page__content-description">
|
|
|
|
{ t('stateLogsDescription') }
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<Button
|
2019-04-16 21:35:22 +02:00
|
|
|
type="secondary"
|
2019-03-25 17:13:23 +01:00
|
|
|
large
|
|
|
|
onClick={() => {
|
|
|
|
window.logStateString((err, result) => {
|
|
|
|
if (err) {
|
|
|
|
displayWarning(t('stateLogError'))
|
|
|
|
} else {
|
2019-10-07 19:54:44 +02:00
|
|
|
exportAsFile(`${t('stateLogFileName')}.json`, result)
|
2019-03-25 17:13:23 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{ t('downloadStateLogs') }
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderResetAccount () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { showResetAccountConfirmationModal } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ t('resetAccount') }</span>
|
2019-12-12 16:40:30 +01:00
|
|
|
<span className="settings-page__content-description">
|
|
|
|
{ t('resetAccountDescription') }
|
|
|
|
</span>
|
2019-03-25 17:13:23 +01:00
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<Button
|
2019-04-16 21:35:22 +02:00
|
|
|
type="warning"
|
2019-03-25 17:13:23 +01:00
|
|
|
large
|
2019-12-12 21:33:05 +01:00
|
|
|
className="settings-tab__button--red"
|
2019-03-25 17:13:23 +01:00
|
|
|
onClick={event => {
|
|
|
|
event.preventDefault()
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Settings',
|
|
|
|
action: 'Reset Account',
|
|
|
|
name: 'Reset Account',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
showResetAccountConfirmationModal()
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{ t('resetAccount') }
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderHexDataOptIn () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { sendHexData, setHexDataFeatureFlag } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ t('showHexData') }</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{ t('showHexDataDescription') }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={sendHexData}
|
|
|
|
onToggle={value => setHexDataFeatureFlag(!value)}
|
2019-07-08 19:58:35 +02:00
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
2019-03-25 17:13:23 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderAdvancedGasInputInline () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { advancedInlineGas, setAdvancedInlineGasFeatureFlag } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ t('showAdvancedGasInline') }</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{ t('showAdvancedGasInlineDescription') }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={advancedInlineGas}
|
|
|
|
onToggle={value => setAdvancedInlineGasFeatureFlag(!value)}
|
2019-07-08 19:58:35 +02:00
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
2019-03-25 17:13:23 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderShowConversionInTestnets () {
|
|
|
|
const { t } = this.context
|
|
|
|
const {
|
|
|
|
showFiatInTestnets,
|
|
|
|
setShowFiatConversionOnTestnetsPreference,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ t('showFiatConversionInTestnets') }</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{ t('showFiatConversionInTestnetsDescription') }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={showFiatInTestnets}
|
|
|
|
onToggle={value => setShowFiatConversionOnTestnetsPreference(!value)}
|
2019-07-08 19:58:35 +02:00
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
2019-03-25 17:13:23 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-09-27 06:30:36 +02:00
|
|
|
renderUseNonceOptIn () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { useNonceField, setUseNonceField } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ this.context.t('nonceField') }</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{ t('nonceFieldDescription') }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={useNonceField}
|
|
|
|
onToggle={value => setUseNonceField(!value)}
|
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-17 17:25:37 +02:00
|
|
|
handleLogoutChange (time) {
|
|
|
|
const { t } = this.context
|
|
|
|
const autoLogoutTimeLimit = Math.max(Number(time), 0)
|
|
|
|
|
|
|
|
this.setState(() => {
|
|
|
|
let logoutTimeError = ''
|
|
|
|
|
|
|
|
if (autoLogoutTimeLimit > 10080) {
|
|
|
|
logoutTimeError = t('logoutTimeTooGreat')
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
autoLogoutTimeLimit,
|
|
|
|
logoutTimeError,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-08 20:57:21 +02:00
|
|
|
renderAutoLogoutTimeLimit () {
|
|
|
|
const { t } = this.context
|
2019-10-17 17:25:37 +02:00
|
|
|
const { logoutTimeError } = this.state
|
2019-05-08 20:57:21 +02:00
|
|
|
const {
|
|
|
|
autoLogoutTimeLimit,
|
|
|
|
setAutoLogoutTimeLimit,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ t('autoLogoutTimeLimit') }</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{ t('autoLogoutTimeLimitDescription') }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<TextField
|
|
|
|
type="number"
|
|
|
|
id="autoTimeout"
|
|
|
|
placeholder="5"
|
|
|
|
value={this.state.autoLogoutTimeLimit}
|
|
|
|
defaultValue={autoLogoutTimeLimit}
|
2019-10-17 17:25:37 +02:00
|
|
|
onChange={e => this.handleLogoutChange(e.target.value)}
|
|
|
|
error={logoutTimeError}
|
2019-05-08 20:57:21 +02:00
|
|
|
fullWidth
|
|
|
|
margin="dense"
|
|
|
|
min={0}
|
|
|
|
/>
|
2019-10-17 17:25:37 +02:00
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
className="settings-tab__rpc-save-button"
|
|
|
|
disabled={logoutTimeError !== ''}
|
2019-05-08 20:57:21 +02:00
|
|
|
onClick={() => {
|
|
|
|
setAutoLogoutTimeLimit(this.state.autoLogoutTimeLimit)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{ t('save') }
|
2019-10-17 17:25:37 +02:00
|
|
|
</Button>
|
2019-05-08 20:57:21 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-09-16 19:11:01 +02:00
|
|
|
renderThreeBoxControl () {
|
|
|
|
const { t } = this.context
|
|
|
|
const {
|
|
|
|
threeBoxSyncingAllowed,
|
|
|
|
setThreeBoxSyncingPermission,
|
|
|
|
threeBoxDisabled,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
let allowed = threeBoxSyncingAllowed
|
|
|
|
let description = t('syncWithThreeBoxDescription')
|
|
|
|
|
|
|
|
if (threeBoxDisabled) {
|
|
|
|
allowed = false
|
|
|
|
description = t('syncWithThreeBoxDisabled')
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ t('syncWithThreeBox') }</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{ description }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className={classnames('settings-page__content-item', {
|
|
|
|
'settings-page__content-item--disabled': threeBoxDisabled,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={allowed}
|
|
|
|
onToggle={value => {
|
|
|
|
if (!threeBoxDisabled) {
|
|
|
|
setThreeBoxSyncingPermission(!value)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-12-12 20:28:07 +01:00
|
|
|
handleIpfsGatewayChange (url) {
|
|
|
|
const { t } = this.context
|
|
|
|
|
|
|
|
this.setState(() => {
|
|
|
|
let ipfsGatewayError = ''
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const urlObj = new URL(addUrlProtocolPrefix(url))
|
|
|
|
if (!urlObj.host) {
|
|
|
|
throw new Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't allow the use of this gateway
|
|
|
|
if (urlObj.host === 'gateway.ipfs.io') {
|
|
|
|
throw new Error('Forbidden gateway')
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
ipfsGatewayError = (
|
|
|
|
error.message === 'Forbidden gateway'
|
|
|
|
? t('forbiddenIpfsGateway')
|
|
|
|
: t('invalidIpfsGateway')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
ipfsGateway: url,
|
|
|
|
ipfsGatewayError,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
handleIpfsGatewaySave () {
|
|
|
|
|
|
|
|
const url = new URL(addUrlProtocolPrefix(this.state.ipfsGateway))
|
|
|
|
const host = url.host
|
|
|
|
|
|
|
|
this.props.setIpfsGateway(host)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderIpfsGatewayControl () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { ipfsGatewayError } = this.state
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ t('ipfsGateway') }</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{ t('ipfsGatewayDescription') }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<TextField
|
|
|
|
type="text"
|
|
|
|
value={this.state.ipfsGateway}
|
|
|
|
onChange={e => this.handleIpfsGatewayChange(e.target.value)}
|
|
|
|
error={ipfsGatewayError}
|
|
|
|
fullWidth
|
|
|
|
margin="dense"
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
className="settings-tab__rpc-save-button"
|
|
|
|
disabled={Boolean(ipfsGatewayError)}
|
|
|
|
onClick={() => {
|
|
|
|
this.handleIpfsGatewaySave()
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{ t('save') }
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-03-25 17:13:23 +01:00
|
|
|
renderContent () {
|
2019-09-26 09:24:52 +02:00
|
|
|
const { warning } = this.props
|
2019-03-25 17:13:23 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__body">
|
|
|
|
{ warning && <div className="settings-tab__error">{ warning }</div> }
|
|
|
|
{ this.renderStateLogs() }
|
|
|
|
{ this.renderMobileSync() }
|
|
|
|
{ this.renderResetAccount() }
|
|
|
|
{ this.renderAdvancedGasInputInline() }
|
|
|
|
{ this.renderHexDataOptIn() }
|
|
|
|
{ this.renderShowConversionInTestnets() }
|
2019-09-27 06:30:36 +02:00
|
|
|
{ this.renderUseNonceOptIn() }
|
2019-05-08 20:57:21 +02:00
|
|
|
{ this.renderAutoLogoutTimeLimit() }
|
2019-09-26 09:24:52 +02:00
|
|
|
{ this.renderThreeBoxControl() }
|
2019-12-12 20:28:07 +01:00
|
|
|
{ this.renderIpfsGatewayControl() }
|
2019-03-25 17:13:23 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return this.renderContent()
|
|
|
|
}
|
|
|
|
}
|
2019-12-12 20:28:07 +01:00
|
|
|
|
|
|
|
function addUrlProtocolPrefix (urlString) {
|
|
|
|
if (!urlString.match(
|
|
|
|
/(^http:\/\/)|(^https:\/\/)/
|
|
|
|
)) {
|
|
|
|
return 'https://' + urlString
|
|
|
|
}
|
|
|
|
return urlString
|
|
|
|
}
|