From 9d9f3685bb58cd7b134345318aed10511df94920 Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Thu, 17 Oct 2019 08:25:37 -0700 Subject: [PATCH] Prevent Logout Timer that's longer than a week. (#7253) --- app/_locales/en/messages.json | 3 ++ .../advanced-tab/advanced-tab.component.js | 35 ++++++++++++++++--- .../tests/advanced-tab-component.test.js | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 89bef5997..4fe04674b 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -741,6 +741,9 @@ "logout": { "message": "Log out" }, + "logoutTimeTooGreat": { + "message": "Logout time is too great" + }, "mainnet": { "message": "Main Ethereum Network" }, diff --git a/ui/app/pages/settings/advanced-tab/advanced-tab.component.js b/ui/app/pages/settings/advanced-tab/advanced-tab.component.js index cfc896139..5df85c027 100644 --- a/ui/app/pages/settings/advanced-tab/advanced-tab.component.js +++ b/ui/app/pages/settings/advanced-tab/advanced-tab.component.js @@ -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} /> - + diff --git a/ui/app/pages/settings/advanced-tab/tests/advanced-tab-component.test.js b/ui/app/pages/settings/advanced-tab/tests/advanced-tab-component.test.js index 760f62e54..924602ace 100644 --- a/ui/app/pages/settings/advanced-tab/tests/advanced-tab-component.test.js +++ b/ui/app/pages/settings/advanced-tab/tests/advanced-tab-component.test.js @@ -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) }) })