From 6d1bb7d2364a37481bbc66019714f9d38e55eaa5 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Wed, 26 Jul 2017 06:29:53 -0700 Subject: [PATCH] reset settings to default --- react/src/actions/actions/settings.js | 43 ++++++++++++++++++- .../components/dashboard/settings/settings.js | 12 ++++-- .../dashboard/settings/settings.render.js | 6 ++- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/react/src/actions/actions/settings.js b/react/src/actions/actions/settings.js index e1aacb7..126f10b 100644 --- a/react/src/actions/actions/settings.js +++ b/react/src/actions/actions/settings.js @@ -376,7 +376,16 @@ export function saveAppConfig(_payload) { ); }) .then(response => response.json()) - .then(json => dispatch(getAppConfig())) + .then(json => { + dispatch(getAppConfig()); + dispatch( + triggerToaster( + 'Settings are saved', + translate('TOASTR.SETTINGS_NOTIFICATION'), + 'success' + ) + ); + }) } } @@ -408,4 +417,36 @@ export function getAppConfig() { .then(response => response.json()) .then(json => dispatch(getAppConfigState(json))) } +} + +export function resetAppConfig() { + return dispatch => { + return fetch(`http://127.0.0.1:${Config.agamaPort}/shepherd/appconf/reset`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch( + triggerToaster( + 'resetAppConfig', + 'Error', + 'error' + ) + ); + }) + .then(response => response.json()) + .then(json => { + dispatch(getAppConfig()); + dispatch( + triggerToaster( + 'Settings are reset to default', + translate('TOASTR.SETTINGS_NOTIFICATION'), + 'success' + ) + ); + }) + } } \ No newline at end of file diff --git a/react/src/components/dashboard/settings/settings.js b/react/src/components/dashboard/settings/settings.js index 109f936..c1031cf 100644 --- a/react/src/components/dashboard/settings/settings.js +++ b/react/src/components/dashboard/settings/settings.js @@ -11,10 +11,11 @@ import { addPeerNode, getAppConfig, saveAppConfig, + resetAppConfig, getAppInfo, shepherdCli, checkForUpdateUIPromise, - updateUIPromise + updateUIPromise, } from '../../../actions/actionCreators'; import Store from '../../../store'; @@ -72,6 +73,7 @@ class Settings extends React.Component { this.renderPeersList = this.renderPeersList.bind(this); this.renderSNPeersList = this.renderSNPeersList.bind(this); this._saveAppConfig = this._saveAppConfig.bind(this); + this._resetAppConfig = this._resetAppConfig.bind(this); this.exportWifKeysRaw = this.exportWifKeysRaw.bind(this); this.toggleSeedInputVisibility = this.toggleSeedInputVisibility.bind(this); this._checkForUpdateUIPromise = this._checkForUpdateUIPromise.bind(this); @@ -97,12 +99,16 @@ class Settings extends React.Component { } } + _resetAppConfig() { + Store.dispatch(resetAppConfig()); + } + resizeLoginTextarea() { // auto-size textarea setTimeout(() => { if (this.state.seedInputVisibility) { - document.querySelector('#wifkeysPassphraseTextarea').style.height = '1px'; - document.querySelector('#wifkeysPassphraseTextarea').style.height = `${(15 + document.querySelector('#wifkeysPassphraseTextarea').scrollHeight)}px`; + document.querySelector('#wifkeysPassphraseTextarea').style.height = '1px'; + document.querySelector('#wifkeysPassphraseTextarea').style.height = `${(15 + document.querySelector('#wifkeysPassphraseTextarea').scrollHeight)}px`; } }, 100); } diff --git a/react/src/components/dashboard/settings/settings.render.js b/react/src/components/dashboard/settings/settings.render.js index 47d4fd4..5988490 100644 --- a/react/src/components/dashboard/settings/settings.render.js +++ b/react/src/components/dashboard/settings/settings.render.js @@ -538,6 +538,10 @@ export const SettingsRender = function() { type="button" className="btn btn-primary waves-effect waves-light" onClick={ this._saveAppConfig }>{ translate('SETTINGS.SAVE_APP_CONFIG') } + @@ -570,7 +574,7 @@ export const SettingsRender = function() { name="cliCoin" id="settingsCliOptions" onChange={ this.updateInput }> - + { this.renderActiveCoinsList('native') }