Prevent Logout Timer that's longer than a week. (#7253)

feature/default_network_editable
Thomas Huang 5 years ago committed by Mark Stacey
parent 3d1f214cb0
commit 9d9f3685bb
  1. 3
      app/_locales/en/messages.json
  2. 35
      ui/app/pages/settings/advanced-tab/advanced-tab.component.js
  3. 2
      ui/app/pages/settings/advanced-tab/tests/advanced-tab-component.test.js

@ -741,6 +741,9 @@
"logout": {
"message": "Log out"
},
"logoutTimeTooGreat": {
"message": "Logout time is too great"
},
"mainnet": {
"message": "Main Ethereum Network"
},

@ -34,7 +34,10 @@ export default class AdvancedTab extends PureComponent {
threeBoxDisabled: PropTypes.bool.isRequired,
}
state = { autoLogoutTimeLimit: this.props.autoLogoutTimeLimit }
state = {
autoLogoutTimeLimit: this.props.autoLogoutTimeLimit,
logoutTimeError: '',
}
renderMobileSync () {
const { t } = this.context
@ -240,8 +243,27 @@ export default class AdvancedTab extends PureComponent {
)
}
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,
}
})
}
renderAutoLogoutTimeLimit () {
const { t } = this.context
const { logoutTimeError } = this.state
const {
autoLogoutTimeLimit,
setAutoLogoutTimeLimit,
@ -263,19 +285,22 @@ export default class AdvancedTab extends PureComponent {
placeholder="5"
value={this.state.autoLogoutTimeLimit}
defaultValue={autoLogoutTimeLimit}
onChange={e => this.setState({ autoLogoutTimeLimit: Math.max(Number(e.target.value), 0) })}
onChange={e => this.handleLogoutChange(e.target.value)}
error={logoutTimeError}
fullWidth
margin="dense"
min={0}
/>
<button
className="button btn-primary settings-tab__rpc-save-button"
<Button
type="primary"
className="settings-tab__rpc-save-button"
disabled={logoutTimeError !== ''}
onClick={() => {
setAutoLogoutTimeLimit(this.state.autoLogoutTimeLimit)
}}
>
{ t('save') }
</button>
</Button>
</div>
</div>
</div>

@ -38,7 +38,7 @@ describe('AdvancedTab Component', () => {
textField.props().onChange({ target: { value: 1440 } })
assert.equal(root.state().autoLogoutTimeLimit, 1440)
autoTimeout.find('button').simulate('click')
autoTimeout.find('.settings-tab__rpc-save-button').simulate('click')
assert.equal(setAutoLogoutTimeLimitSpy.args[0][0], 1440)
})
})

Loading…
Cancel
Save