From 0792bf86bdd67005e7f760d89bd04793d8ce7265 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Thu, 11 May 2017 08:55:44 +0300 Subject: [PATCH] app config (wip) --- react/src/actions/actionCreators.js | 54 ++++++------ react/src/components/dashboard/navbar.js | 2 +- react/src/components/dashboard/sendCoin.js | 3 +- react/src/components/dashboard/settings.js | 96 ++++++++++++++++++++-- react/src/reducers/settings.js | 18 +++- react/src/util/cacheFormat.js | 4 +- 6 files changed, 142 insertions(+), 35 deletions(-) diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index af58301..e721fdb 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -53,6 +53,7 @@ export const LOAD_APP_CONFIG = 'LOAD_APP_CONFIG'; export const SAVE_APP_CONFIG = 'SAVE_APP_CONFIG'; export const SERVICE_ERROR = 'SERVICE_ERROR'; export const DASHBOARD_ACTIVE_ADDRESS = 'DASHBOARD_ACTIVE_ADDRESS'; +export const LOAD_APP_INFO = 'LOAD_APP_INFO'; var iguanaForks = {}; // forks in mem array @@ -2493,28 +2494,23 @@ export function edexGetTransaction(data) { }); } -/*export function saveAppConfig() { - const payload = { - 'herdname': target, - 'lastLines': linesCount - }; - +export function saveAppConfig(_payload) { return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/debuglog', { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/appconf', { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify(payload), + body: JSON.stringify(_payload), }) .catch(function(error) { console.log(error); - dispatch(triggerToaster(true, 'getDebugLog', 'Error', 'error')); + dispatch(triggerToaster(true, 'saveAppConfig', 'Error', 'error')); }) .then(response => response.json()) - .then(json => dispatch(getDebugLogState(json))) + .then(json => dispatch(getAppConfigState(json))) } -}*/ +} function getAppConfigState(json) { return { @@ -2622,16 +2618,26 @@ export function shepherdPostCoinList(data) { }); } -/*function Shepherd_SendPendValue() { - Shepherd_SysInfo().then(function(result){ - var ram_data = formatBytes(result.totalmem_bytes) - var pend_val = null; - if (ram_data.size === 'GB') { - if (ram_data.ramsize >= '63' ) { pend_val = 16; } - if (ram_data.ramsize >= '31' ) { pend_val = 8; } - if (ram_data.ramsize >= '15' ) { pend_val = 4; } - if (ram_data.ramsize <= '15' ) { pend_val = 1; } - } else { pend_val = 1; } - sessionStorage.setItem('IguanaPendValue', pend_val); - }) -}*/ \ No newline at end of file +function getAppInfoState(json) { + return { + type: LOAD_APP_INFO, + info: json, + } +} + +export function getAppInfo() { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/appinfo', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getAppInfo', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(getAppInfoState(json))) + } +} \ No newline at end of file diff --git a/react/src/components/dashboard/navbar.js b/react/src/components/dashboard/navbar.js index d817180..42e7dea 100644 --- a/react/src/components/dashboard/navbar.js +++ b/react/src/components/dashboard/navbar.js @@ -76,7 +76,7 @@ class Navbar extends React.Component { EasyDEX -
  • +
  • this.dashboardChangeSection('jumblr')}> Jumblr diff --git a/react/src/components/dashboard/sendCoin.js b/react/src/components/dashboard/sendCoin.js index 7cbbbc0..d4c5e22 100644 --- a/react/src/components/dashboard/sendCoin.js +++ b/react/src/components/dashboard/sendCoin.js @@ -288,6 +288,7 @@ class SendCoin extends React.Component { const utxoSet = (refreshData && refreshData.data) || (listunspentData && listunspentData.data); const _pubkey = this.props.Dashboard.activeHandle.pubkey; const forceUpdateCache = this._fetchNewUTXOData; + const _sendFrom = this.state.sendFrom; const sendData = { 'coin': this.props.ActiveCoin.coin, 'sendfrom': this.state.sendFrom, @@ -356,7 +357,7 @@ class SendCoin extends React.Component { getCacheFile(_pubkey) .then(function(result) { console.log('got cache file', result); - let saveThisData = edexRemoveTXID(result.result, txidListToRemove); + let saveThisData = edexRemoveTXID(result.result, _sendFrom, txidListToRemove); console.log('saveThisData', saveThisData); resolve(saveThisData); }); diff --git a/react/src/components/dashboard/settings.js b/react/src/components/dashboard/settings.js index 5ff81a1..0c9c7fb 100644 --- a/react/src/components/dashboard/settings.js +++ b/react/src/components/dashboard/settings.js @@ -8,7 +8,9 @@ import { getDebugLog, getPeersList, addPeerNode, - getAppConfig + getAppConfig, + saveAppConfig, + getAppInfo } from '../../actions/actionCreators'; import Store from '../../store'; import AddCoinOptionsCrypto from '../addcoin/addcoinOptionsCrypto'; @@ -30,6 +32,7 @@ class Settings extends React.Component { debugLinesCount: 10, debugTarget: 'iguana', activeTabHeight: '10px', + appSettings: [], }; this.exportWifKeys = this.exportWifKeys.bind(this); this.updateInput = this.updateInput.bind(this); @@ -44,12 +47,16 @@ class Settings extends React.Component { componentDidMount() { Store.dispatch(iguanaActiveHandle()); Store.dispatch(getAppConfig()); + Store.dispatch(getAppInfo()); + } + + _saveAppConfig() { + Store.dispatch(saveAppConfig); } openTab(elemId, tab) { - console.log(elemId); const _height = document.querySelector('#' + elemId + ' .panel-collapse .panel-body').clientHeight; - console.log(_height); + this.setState(Object.assign({}, this.state, { activeTab: tab, activeTabHeight: _height, @@ -112,6 +119,51 @@ class Settings extends React.Component { } } + renderConfigEditForm() { + console.log(this.props.Settings.appSettings); + let items = []; + const _appConfig = this.props.Settings.appSettings; + + for (let key in this.props.Settings.appSettings) { + if (Object.keys(this.props.Settings.appSettings[key]).length && key !== 'host') { + items.push( + + + {key} + + + + ); + + for (let _key in this.props.Settings.appSettings[key]) { + items.push( + + + {_key} + + + + + + ); + } + } else { + items.push( + + + {key} + + + + + + ); + } + } + + return items; + } + updateInput(e) { this.setState({ [e.target.name]: e.target.value, @@ -393,13 +445,45 @@ class Settings extends React.Component {
    this.openTab('AppSettings', 7)}> - - App Settings (config.json) + + App Config (config.json)
    -

    Manage app settings

    +

    Manage app config

    +

    + Most changes to app config require wallet restart! +

    +
    +
    +
    +
    +
    +
    + + + {this.renderConfigEditForm()} + +
    +
    +
    + +
    +
    +
    +
    +
    + +
    +
    this.openTab('AppInfo', 8)}> + + App Info + +
    +
    +
    +

    {translate('INDEX.DEBUG_LOG_DESC')}

    diff --git a/react/src/reducers/settings.js b/react/src/reducers/settings.js index d08740b..ca26b76 100644 --- a/react/src/reducers/settings.js +++ b/react/src/reducers/settings.js @@ -1,9 +1,17 @@ -import { GET_WIF_KEY, GET_PEERS_LIST, GET_DEBUG_LOG } from '../actions/actionCreators'; +import { + GET_WIF_KEY, + GET_PEERS_LIST, + GET_DEBUG_LOG, + LOAD_APP_CONFIG, + LOAD_APP_INFO +} from '../actions/actionCreators'; export function Settings(state = { wifkey: null, address: null, debugLog: null, + appSettings: null, + appInfo: null, }, action) { switch (action.type) { case GET_WIF_KEY: @@ -20,6 +28,14 @@ export function Settings(state = { return Object.assign({}, state, { debugLog: action.data, }); + case LOAD_APP_CONFIG: + return Object.assign({}, state, { + appSettings: action.config, + }); + case LOAD_APP_INFO: + return Object.assign({}, state, { + appInfo: action.info, + }); default: return state; } diff --git a/react/src/util/cacheFormat.js b/react/src/util/cacheFormat.js index 0ea9bfb..792d405 100644 --- a/react/src/util/cacheFormat.js +++ b/react/src/util/cacheFormat.js @@ -10,7 +10,7 @@ export function edexGetTxIDList(getTxData) { return getTxidList; } -export function edexRemoveTXID(_obj, txidArray) { +export function edexRemoveTXID(_obj, address, txidArray) { let txidToStr = ':' + txidArray.join(':') + ':'; console.log(txidToStr); @@ -21,7 +21,7 @@ export function edexRemoveTXID(_obj, txidArray) { } else { for (let key in _obj.basilisk) { for (let coinAddr in _obj.basilisk[key]) { - if (_obj.basilisk[key][coinAddr] !== 'addresses') { + if (_obj.basilisk[key][coinAddr] !== 'addresses' && coinAddr === address) { if (_obj.basilisk[key][coinAddr].refresh && _obj.basilisk[key][coinAddr].refresh.data && _obj.basilisk[key][coinAddr].refresh.data.length > 0) {