From 374bc2ebb6332e68be4288b8ee9fc8a885d1528b Mon Sep 17 00:00:00 2001 From: pbca26 Date: Tue, 5 Sep 2017 00:08:54 +0300 Subject: [PATCH] combined native dashboard update --- assets/mainWindow/js/loading.js | 12 +- react/src/actions/actionCreators.js | 1 + .../actions/actions/nativeDashboardUpdate.js | 66 +++++++++++ react/src/actions/storeType.js | 1 + .../dashboard/coinTile/coinTileItem.js | 17 ++- .../dashboard/walletsData/walletsData.js | 6 +- .../dashboard/walletsData/walletsData.scss | 3 + .../walletsNative/walletsNative.render.js | 2 +- .../walletsNativeSend/walletsNativeSend.js | 2 - .../walletsProgress/walletsProgress.render.js | 8 +- react/src/components/overrides.scss | 68 ++---------- react/src/reducers/activeCoin.js | 103 +++++++++++------- react/src/reducers/dashboard.js | 51 +++------ 13 files changed, 184 insertions(+), 156 deletions(-) create mode 100644 react/src/actions/actions/nativeDashboardUpdate.js diff --git a/assets/mainWindow/js/loading.js b/assets/mainWindow/js/loading.js index 4de0cca..012d984 100644 --- a/assets/mainWindow/js/loading.js +++ b/assets/mainWindow/js/loading.js @@ -22,7 +22,7 @@ function initSettingsForm() {
- +
`; } @@ -174,6 +174,8 @@ function closeMainWindow() { const remote = require('electron').remote; const window = remote.getCurrentWindow(); + disableModeButtons(); + window.createWindow('open'); window.hide(); } @@ -185,11 +187,19 @@ function quitApp() { window.forseCloseApp(); } +function disableModeButtons() { + $('#nativeOnlyBtn').attr('disabled', true); + $('#normalStartBtn').attr('disabled', true); + $('#settingsBtn').attr('disabled', true); +} + function normalStart() { const remote = require('electron').remote; let appConf = remote.getCurrentWindow().appConfig; appConf.iguanaLessMode = false; + disableModeButtons(); + // run iguana-less mode with no daemons startup if (appConf && appConf.iguanaLessMode) { diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index 77454f1..b278b7d 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -64,6 +64,7 @@ export * from './actions/cli'; export * from './actions/update'; export * from './actions/jumblr'; export * from './actions/interest'; +export * from './actions/nativeDashboardUpdate'; export function changeActiveAddress(address) { return { diff --git a/react/src/actions/actions/nativeDashboardUpdate.js b/react/src/actions/actions/nativeDashboardUpdate.js new file mode 100644 index 0000000..6af0940 --- /dev/null +++ b/react/src/actions/actions/nativeDashboardUpdate.js @@ -0,0 +1,66 @@ +import { + triggerToaster, +} from '../actionCreators'; +import Config from '../../config'; +import { DASHBOARD_UPDATE } from '../storeType'; + +export function getDashboardUpdate(coin, activeCoinProps) { + return dispatch => { + const _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ coin: coin }), + }; + + return fetch( + `http://127.0.0.1:${Config.agamaPort}/shepherd/native/dashboard/update`, + _fetchConfig + ) + .catch(function(error) { + console.log(error); + dispatch( + triggerToaster( + 'getDashboardUpdate', + 'Error', + 'error' + ) + ); + }) + .then(response => response.json()) + .then(json => { + dispatch(getDashboardUpdateState(json)); + + // dirty hack to trigger dashboard render + if (!activeCoinProps.balance && + !activeCoinProps.addresses) { + setTimeout(() => { + dispatch(getDashboardUpdateState(json)); + }, 100); + } + }) + } +} + +export function getDashboardUpdateState(json) { + let _listtransactions = json.result['listtransactions']; + + if (_listtransactions && + _listtransactions.error) { + _listtransactions = null; + } else if (_listtransactions && _listtransactions.result && _listtransactions.result.length) { + _listtransactions = _listtransactions.result; + } else if (!_listtransactions || (!_listtransactions.result || !_listtransactions.result.length)) { + _listtransactions = 'no data'; + } + + return { + type: DASHBOARD_UPDATE, + progress: json.result['getinfo'].result, + opids: json.result['z_getoperationstatus'].result, + txhistory: _listtransactions, + balance: json.result['z_gettotalbalance'].result, + addresses: json.result['addresses'], + }; +} \ No newline at end of file diff --git a/react/src/actions/storeType.js b/react/src/actions/storeType.js index 6438740..adb9141 100644 --- a/react/src/actions/storeType.js +++ b/react/src/actions/storeType.js @@ -30,6 +30,7 @@ export const DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS = 'DASHBOARD_ACTIVE_COIN_NATIVE_ export const DASHBOARD_ACTIVE_COIN_SENDTO = 'DASHBOARD_ACTIVE_COIN_SENDTO'; export const DASHBOARD_ACTIVE_COIN_GET_CACHE = 'DASHBOARD_ACTIVE_COIN_GET_CACHE'; export const DASHBOARD_ACTIVE_COIN_MAIN_BASILISK_ADDR = 'DASHBOARD_ACTIVE_COIN_MAIN_BASILISK_ADDR'; +export const DASHBOARD_UPDATE = 'DASHBOARD_UPDATE'; export const VIEW_CACHE_DATA = 'VIEW_CACHE_DATA'; export const SYNC_ONLY_MODAL_TOGGLE = 'SYNC_ONLY_MODAL_TOGGLE'; export const SYNC_ONLY_DATA = 'SYNC_ONLY_DATA'; diff --git a/react/src/components/dashboard/coinTile/coinTileItem.js b/react/src/components/dashboard/coinTile/coinTileItem.js index 08c0fab..83ea141 100644 --- a/react/src/components/dashboard/coinTile/coinTileItem.js +++ b/react/src/components/dashboard/coinTile/coinTileItem.js @@ -18,7 +18,8 @@ import { getNativeTxHistory, getKMDBalanceTotal, getSyncInfoNative, - getDebugLog + getDebugLog, + getDashboardUpdate } from '../../../actions/actionCreators'; import Store from '../../../store'; import Config from '../../../config'; @@ -42,8 +43,8 @@ class CoinTileItem extends React.Component { dispatchCoinActions(coin, mode) { if (mode === 'native') { Store.dispatch(iguanaActiveHandle(true)); - const _propsDashboard = this.props.Dashboard; - const syncPercentage = _propsDashboard && _propsDashboard.progress && (parseFloat(parseInt(_propsDashboard.progress.blocks, 10) * 100 / parseInt(this.props.Dashboard.progress.longestchain, 10)).toFixed(2)).replace('NaN', 0); + const _propsDashboard = this.props.ActiveCoin; + const syncPercentage = _propsDashboard && _propsDashboard.progress && (parseFloat(parseInt(_propsDashboard.progress.blocks, 10) * 100 / parseInt(_propsDashboard.progress.longestchain, 10)).toFixed(2)).replace('NaN', 0); if (syncPercentage < 100 && !this.props.Dashboard.displayCoindDownModal) { @@ -56,10 +57,7 @@ class CoinTileItem extends React.Component { syncPercentage && (Config.iguanaLessMode || syncPercentage >= NATIVE_MIN_SYNC_PERCENTAGE_THRESHOLD)) { Store.dispatch(getSyncInfoNative(coin, true)); - Store.dispatch(getKMDBalanceTotal(coin)); - Store.dispatch(getNativeTxHistory(coin)); - Store.dispatch(getKMDAddressesNative(coin, mode)); - Store.dispatch(getKMDOPID(null, coin)); + Store.dispatch(getDashboardUpdate(coin, _propsDashboard)); } else { Store.dispatch(getSyncInfoNative(coin)); } @@ -205,14 +203,15 @@ const mapStateToProps = (state) => { ActiveCoin: { coin: state.ActiveCoin.coin, addresses: state.ActiveCoin.addresses, - mainBasiliskAddress: state.ActiveCoin.mainBasiliskAddress + mainBasiliskAddress: state.ActiveCoin.mainBasiliskAddress, + progress: state.ActiveCoin.progress, }, Dashboard: state.Dashboard, Interval: { interval: state.Interval.interval } }; - + }; export default connect(mapStateToProps)(CoinTileItem); \ No newline at end of file diff --git a/react/src/components/dashboard/walletsData/walletsData.js b/react/src/components/dashboard/walletsData/walletsData.js index 56463f3..a317b2b 100644 --- a/react/src/components/dashboard/walletsData/walletsData.js +++ b/react/src/components/dashboard/walletsData/walletsData.js @@ -385,20 +385,20 @@ class WalletsData extends React.Component { if (this.isFullySynced()) { return ( - { translate('INDEX.LOADING_HISTORY') }... + { translate('INDEX.LOADING_HISTORY') }... ); } else { return ( - { translate('INDEX.SYNC_IN_PROGRESS') }... + { translate('INDEX.SYNC_IN_PROGRESS') }... ); } } else if (this.state.itemsList === 'no data') { return ( - { translate('INDEX.NO_DATA') } + { translate('INDEX.NO_DATA') } ); } else if (this.state.itemsList) { diff --git a/react/src/components/dashboard/walletsData/walletsData.scss b/react/src/components/dashboard/walletsData/walletsData.scss index ab72b82..a03e870 100644 --- a/react/src/components/dashboard/walletsData/walletsData.scss +++ b/react/src/components/dashboard/walletsData/walletsData.scss @@ -86,4 +86,7 @@ padding: 38px; background: rgba(255, 255, 255, 0.85); } +} +.table-cell-offset-16 { + padding-left: 16px; } \ No newline at end of file diff --git a/react/src/components/dashboard/walletsNative/walletsNative.render.js b/react/src/components/dashboard/walletsNative/walletsNative.render.js index 580ae42..e5411f4 100644 --- a/react/src/components/dashboard/walletsNative/walletsNative.render.js +++ b/react/src/components/dashboard/walletsNative/walletsNative.render.js @@ -27,7 +27,7 @@ const WalletsNativeRender = function() { -
+
diff --git a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js index 5c30dad..7f6a850 100644 --- a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js +++ b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js @@ -430,8 +430,6 @@ class WalletsNativeSend extends React.Component { valid = false; } - valid = false; - return valid; } diff --git a/react/src/components/dashboard/walletsProgress/walletsProgress.render.js b/react/src/components/dashboard/walletsProgress/walletsProgress.render.js index d1b19cc..a2c11a2 100644 --- a/react/src/components/dashboard/walletsProgress/walletsProgress.render.js +++ b/react/src/components/dashboard/walletsProgress/walletsProgress.render.js @@ -56,15 +56,13 @@ export const CoinIsBusyRender = function() { export const ChainActivationNotificationRender = function() { return ( -
+
-

- { translate('INDEX.ACTIVATING_CHAIN') } - { this.renderActivatingBestChainProgress() } +

{ translate('INDEX.ACTIVATING_CHAIN') } { this.renderActivatingBestChainProgress() }

{ this.renderLB('INDEX.KMD_STARTED') }

@@ -75,7 +73,7 @@ export const WalletsProgressRender = function() { return (