From c48bd079e9a37d8fe9835b402220775d0a191b79 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Mon, 13 Nov 2017 01:37:04 +0300 Subject: [PATCH] remove coin extended --- react/src/actions/actions/addCoin.js | 2 +- react/src/actions/actions/coinList.js | 57 ++++++++++++++++++- react/src/components/addcoin/addcoin.js | 2 +- .../claimInterestModal/claimInterestModal.js | 4 +- .../dashboard/coinTile/coinTileItem.js | 32 +++++++++-- .../dashboard/coinTile/coinTileItem.render.js | 22 ++----- .../importKeyModal/importKeyModal.js | 4 +- .../importKeyModal/importKeyModal.render.js | 2 +- .../settings/settings.exportKeysPanel.js | 6 +- react/src/components/login/login.js | 28 +++++---- react/src/components/login/login.render.js | 6 +- react/src/components/overrides.scss | 1 + 12 files changed, 118 insertions(+), 48 deletions(-) diff --git a/react/src/actions/actions/addCoin.js b/react/src/actions/actions/addCoin.js index ab2e218..642631d 100644 --- a/react/src/actions/actions/addCoin.js +++ b/react/src/actions/actions/addCoin.js @@ -243,7 +243,7 @@ export function shepherdHerd(coin, mode, path, startupParams) { console.warn(acData); dispatch( triggerToaster( - `Error starting ${coin} daemon. Port ${acData.rpc} is already taken!`, // translate + translate('TOASTR.ERROR_STARTING_DAEMON', coin) + ' ' + translate('TOASTR.PORT_IS_TAKEN', acData.rpc), translate('TOASTR.SERVICE_NOTIFICATION'), 'error', false diff --git a/react/src/actions/actions/coinList.js b/react/src/actions/actions/coinList.js index c078fb0..7a69e19 100644 --- a/react/src/actions/actions/coinList.js +++ b/react/src/actions/actions/coinList.js @@ -1,6 +1,54 @@ import { triggerToaster } from '../actionCreators'; import Config from '../../config'; +export function shepherdElectrumLock() { + return new Promise((resolve, reject) => { + fetch(`http://127.0.0.1:${Config.agamaPort}/shepherd/electrum/lock`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: '', + }) + .catch((error) => { + console.log(error); + dispatch( + triggerToaster( + 'shepherdElectrumLock', + 'Error', + 'error' + ) + ); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }); +} + +export function shepherdElectrumLogout() { + return new Promise((resolve, reject) => { + fetch(`http://127.0.0.1:${Config.agamaPort}/shepherd/electrum/logout`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: '', + }) + .catch((error) => { + console.log(error); + dispatch( + triggerToaster( + 'shepherdElectrumLogout', + 'Error', + 'error' + ) + ); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }); +} + export function shepherdStopCoind(coin) { return new Promise((resolve, reject) => { fetch(`http://127.0.0.1:${Config.agamaPort}/shepherd/coind/stop`, { @@ -25,14 +73,19 @@ export function shepherdStopCoind(coin) { }); } -export function shepherdRemoveCoin(coin) { +export function shepherdRemoveCoin(coin, mode) { return new Promise((resolve, reject) => { fetch(`http://127.0.0.1:${Config.agamaPort}/shepherd/coins/remove`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: coin === 'KMD' ? '' : JSON.stringify({ chain: coin }), + body: JSON.stringify(coin === 'KMD' && mode === 'native' ? { + mode, + } : { + mode, + chain: coin, + }), }) .catch((error) => { console.log(error); diff --git a/react/src/components/addcoin/addcoin.js b/react/src/components/addcoin/addcoin.js index 56e9f57..43237f6 100644 --- a/react/src/components/addcoin/addcoin.js +++ b/react/src/components/addcoin/addcoin.js @@ -128,7 +128,7 @@ class AddCoin extends React.Component { addCoinProps.display !== this.state.display) { this.setState(Object.assign({}, this.state, { display: addCoinProps.display, - modalClassName: addCoinProps.display ? 'show fade' : 'show fade', + modalClassName: 'show fade', })); setTimeout(() => { diff --git a/react/src/components/dashboard/claimInterestModal/claimInterestModal.js b/react/src/components/dashboard/claimInterestModal/claimInterestModal.js index 13cff78..8fe21d3 100755 --- a/react/src/components/dashboard/claimInterestModal/claimInterestModal.js +++ b/react/src/components/dashboard/claimInterestModal/claimInterestModal.js @@ -35,7 +35,9 @@ class ClaimInterestModal extends React.Component { } componentWillMount() { - this.loadListUnspent(); + if (this.props.ActiveCoin.mode === 'native') { + this.loadListUnspent(); + } } loadListUnspent() { diff --git a/react/src/components/dashboard/coinTile/coinTileItem.js b/react/src/components/dashboard/coinTile/coinTileItem.js index e3d3e44..cbd3c64 100644 --- a/react/src/components/dashboard/coinTile/coinTileItem.js +++ b/react/src/components/dashboard/coinTile/coinTileItem.js @@ -30,7 +30,7 @@ import Config from '../../../config'; import CoinTileItemRender from './coinTileItem.render'; -const SPV_DASHBOARD_UPDATE_TIMEOUT = 60000; +const SPV_DASHBOARD_UPDATE_TIMEOUT = 10000; const ACTIVE_HANDLE_TIMEOUT_COIND_NATIVE = 15000; const COIND_DOWN_MODAL_FETCH_FAILURES_THRESHOLD = window.require('electron').remote.getCurrentWindow().appConfig.failedRPCAttemptsThreshold || 10; @@ -43,6 +43,28 @@ class CoinTileItem extends React.Component { this.autoSetActiveCoin = this.autoSetActiveCoin.bind(this); } + renderStopCoinButton() { + if (this.props.Main && + this.props.Main.coins && + this.props.Main.coins.native && + this.props.Main.coins.native.length) { + return true; + } + } + + renderRemoveCoinButton() { + if (this.props.Main && + this.props.Main.coins && + ((this.props.Main.coins.native && + this.props.Main.coins.native.length && + this.state.appConfig && + !this.state.appConfig.stopNativeDaemonsOnQuit) || + (this.props.Main.coins.spv && + this.props.Main.coins.spv.length))) { + return true; + } + } + autoSetActiveCoin() { const modes = [ 'native', @@ -97,8 +119,8 @@ class CoinTileItem extends React.Component { }); } - removeCoin(coin) { - shepherdRemoveCoin(coin) + removeCoin(coin, mode) { + shepherdRemoveCoin(coin, mode) .then((res) => { Store.dispatch( triggerToaster( @@ -189,9 +211,7 @@ class CoinTileItem extends React.Component { ) ); } - } - - if (mode === 'spv') { + } else if (mode === 'spv') { Store.dispatch(shepherdElectrumBalance(coin, this.props.Dashboard.electrumCoins[coin].pub)); Store.dispatch(shepherdElectrumTransactions(coin, this.props.Dashboard.electrumCoins[coin].pub)); } diff --git a/react/src/components/dashboard/coinTile/coinTileItem.render.js b/react/src/components/dashboard/coinTile/coinTileItem.render.js index f7b1117..08578f0 100644 --- a/react/src/components/dashboard/coinTile/coinTileItem.render.js +++ b/react/src/components/dashboard/coinTile/coinTileItem.render.js @@ -24,29 +24,17 @@ const CoinTileItemRender = function() { - { item.mode === 'native' && - this.props.Main && - this.props.Main.coins && - this.props.Main.coins.native && - this.props.Main.coins.native.length && - this.props.Main.coins.native.length > 1 && + { this.renderStopCoinButton() && this.stopCoind(item.coin) } + onClick={ () => this.stopCoind(item.coin, item.mode) } title="Stop" className="icon fa-stop-circle coind-stop-icon"> } - { item.mode === 'native' && - this.props.Main && - this.props.Main.coins && - this.props.Main.coins.native && - this.props.Main.coins.native.length && - this.props.Main.coins.native.length > 1 && - this.state.appConfig && - !this.state.appConfig.stopNativeDaemonsOnQuit && + { this.renderRemoveCoinButton() && this.removeCoin(item.coin) } + onClick={ () => this.removeCoin(item.coin, item.mode) } title="Remove" - className="icon fa-plus-circle coind-remove-icon"> + className={ 'icon fa-plus-circle ' + (item.mode === 'spv' ? 'coind-remove-icon coind-remove-icon-spv' : 'coind-remove-icon') }> } { this.props.Dashboard && this.props.Dashboard.electrumCoins && diff --git a/react/src/components/dashboard/importKeyModal/importKeyModal.js b/react/src/components/dashboard/importKeyModal/importKeyModal.js index e3a87e7..824f4b4 100755 --- a/react/src/components/dashboard/importKeyModal/importKeyModal.js +++ b/react/src/components/dashboard/importKeyModal/importKeyModal.js @@ -77,11 +77,11 @@ class ImportKeyModal extends React.Component { this.setState({ trimPassphraseTimer: _trimPassphraseTimer, - [e.target.name]: newValue, + [e.target.name === 'wifkeysPassphraseTextarea' ? 'wifkeysPassphrase' : e.target.name]: newValue, }); } else { this.setState({ - [e.target.name]: e.target.value, + [e.target.name === 'wifkeysPassphraseTextarea' ? 'wifkeysPassphrase' : e.target.name]: e.target.value, }); } } diff --git a/react/src/components/dashboard/importKeyModal/importKeyModal.render.js b/react/src/components/dashboard/importKeyModal/importKeyModal.render.js index 6fcfbdd..a130657 100644 --- a/react/src/components/dashboard/importKeyModal/importKeyModal.render.js +++ b/react/src/components/dashboard/importKeyModal/importKeyModal.render.js @@ -43,7 +43,7 @@ export const ImportKeyModalRender = function() { autoComplete="off" className={ this.state.seedInputVisibility ? 'form-control' : 'hide' } id="wifkeysPassphraseTextarea" - name="wifkeysPassphrase" + name="wifkeysPassphraseTextarea" ref="wifkeysPassphraseTextarea" onChange={ this.updateInput } value={ this.state.wifkeysPassphrase }> diff --git a/react/src/components/dashboard/settings/settings.exportKeysPanel.js b/react/src/components/dashboard/settings/settings.exportKeysPanel.js index 7b7cf16..6fcada6 100644 --- a/react/src/components/dashboard/settings/settings.exportKeysPanel.js +++ b/react/src/components/dashboard/settings/settings.exportKeysPanel.js @@ -125,11 +125,11 @@ class ExportKeysPanel extends React.Component { this.setState({ trimPassphraseTimer: _trimPassphraseTimer, - [e.target.name]: newValue, + [e.target.name === 'wifkeysPassphraseTextarea' ? 'wifkeysPassphrase' : e.target.name]: newValue, }); } else { this.setState({ - [e.target.name]: e.target.value, + [e.target.name === 'wifkeysPassphraseTextarea' ? 'wifkeysPassphrase' : e.target.name]: e.target.value, }); } } @@ -189,7 +189,7 @@ class ExportKeysPanel extends React.Component { autoComplete="off" id="wifkeysPassphraseTextarea" ref="wifkeysPassphraseTextarea" - name="wifkeysPassphrase" + name="wifkeysPassphraseTextarea" onChange={ this.updateInput } value={ this.state.wifkeysPassphrase }> this.handleKeydown(event) } autoComplete="off" @@ -63,8 +63,8 @@ const LoginRender = function () {