From ced18c4b3368f82158684c05ad73a4824d02a5ee Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sat, 29 Jul 2017 20:58:57 +0300 Subject: [PATCH] walletsData add/remove sockets --- react/src/actions/actionCreators.js | 3 -- react/src/actions/actions/addressBalance.js | 34 ++++++++++--------- .../components/dashboard/qrModal/qrModal.js | 8 ++--- .../receiveCoin/receiveCoin.render.js | 13 +++---- .../dashboard/settings/settings.render.js | 2 +- .../dashboard/walletsData/walletsData.js | 21 ++++++++++-- react/src/translate/translate.js | 8 ++--- 7 files changed, 48 insertions(+), 41 deletions(-) diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index f785cd6..69d451c 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -322,7 +322,6 @@ export function setBasiliskMainAddress(json, coin, mode) { } export function getNativeTxHistoryState(json) { - console.log('getNativeTxHistoryState', json.result.length); if (json && json.error) { json = null; @@ -332,8 +331,6 @@ export function getNativeTxHistoryState(json) { json = 'no data'; } - console.log('getNativeTxHistoryState', json); - return { type: DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY, txhistory: json, diff --git a/react/src/actions/actions/addressBalance.js b/react/src/actions/actions/addressBalance.js index 5f16784..e0acd18 100644 --- a/react/src/actions/actions/addressBalance.js +++ b/react/src/actions/actions/addressBalance.js @@ -249,25 +249,27 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { for (let a = 0; a < result.length; a++) { newAddressArray[a] = []; - for (let b = 0; b < result[a].length; b++) { - let filteredArray; + if (result[a]) { + for (let b = 0; b < result[a].length; b++) { + let filteredArray; + + if (mode === 'basilisk') { + filteredArray = json.map(res => res.amount); + } else { + filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount); + } - if (mode === 'basilisk') { - filteredArray = json.map(res => res.amount); - } else { - filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount); - } + let sum = 0; + for (let i = 0; i < filteredArray.length; i++) { + sum += filteredArray[i]; + } - let sum = 0; - for (let i = 0; i < filteredArray.length; i++) { - sum += filteredArray[i]; + newAddressArray[a][b] = { + address: result[a][b], + amount: currentAddress === result[a][b] || mode === 'native' ? sum : 'N/A', + type: a === 0 ? 'public': 'private', + }; } - - newAddressArray[a][b] = { - address: result[a][b], - amount: currentAddress === result[a][b] || mode === 'native' ? sum : 'N/A', - type: a === 0 ? 'public': 'private', - }; } } diff --git a/react/src/components/dashboard/qrModal/qrModal.js b/react/src/components/dashboard/qrModal/qrModal.js index 0866cc9..eea82dd 100755 --- a/react/src/components/dashboard/qrModal/qrModal.js +++ b/react/src/components/dashboard/qrModal/qrModal.js @@ -19,14 +19,14 @@ class QRModal extends React.Component { this.closeModal = this.closeModal.bind(this); this.handleScan = this.handleScan.bind(this); this.handleError = this.handleError.bind(this); - document.body.addEventListener('click', this.closeModal); } handleScan(data) { if (data !== null) { if (this.props.mode === 'scan') { - this.props.setRecieverFromScan(data) + this.props.setRecieverFromScan(data); } + this.closeModal(); } } @@ -60,10 +60,6 @@ class QRModal extends React.Component { this.setState({ modalIsOpen: false, }); - - if (this.props.mode === 'scan') { - ReactDOM.unmountComponentAtNode(document.getElementById('webcam')); - } } render() { diff --git a/react/src/components/dashboard/receiveCoin/receiveCoin.render.js b/react/src/components/dashboard/receiveCoin/receiveCoin.render.js index 108fb88..0894f8d 100644 --- a/react/src/components/dashboard/receiveCoin/receiveCoin.render.js +++ b/react/src/components/dashboard/receiveCoin/receiveCoin.render.js @@ -26,9 +26,7 @@ export const AddressActionsBasiliskModeRender = function(address) { onClick={ () => this._validateAddressBasilisk(address) }> - + ); }; @@ -45,9 +43,7 @@ export const AddressActionsNonBasiliskModeRender = function(address, type) { onClick={ () => this._copyCoinAddress(address) }> { translate('INDEX.COPY') } - + ); }; @@ -76,8 +72,9 @@ export const ReceiveCoinRender = function() {
{this.isNativeMode() &&
-
+
{ translate('INDEX.GET_NEW_ADDRESS') } diff --git a/react/src/components/dashboard/settings/settings.render.js b/react/src/components/dashboard/settings/settings.render.js index ebf4d97..aa17e53 100644 --- a/react/src/components/dashboard/settings/settings.render.js +++ b/react/src/components/dashboard/settings/settings.render.js @@ -593,7 +593,7 @@ export const SettingsRender = function() { diff --git a/react/src/components/dashboard/walletsData/walletsData.js b/react/src/components/dashboard/walletsData/walletsData.js index 84dc35d..74fe8f3 100644 --- a/react/src/components/dashboard/walletsData/walletsData.js +++ b/react/src/components/dashboard/walletsData/walletsData.js @@ -64,7 +64,6 @@ class WalletsData extends React.Component { this.basiliskRefreshActionOne = this.basiliskRefreshActionOne.bind(this); this.handleClickOutside = this.handleClickOutside.bind(this); this.refreshTxHistory = this.refreshTxHistory.bind(this); - socket.on('messages', msg => this.updateSocketsData(msg)); } componentWillMount() { @@ -73,6 +72,14 @@ class WalletsData extends React.Component { this.handleClickOutside, false ); + + setTimeout(() => { + if (this.props.ActiveCoin.mode === 'basilisk') { + socket.on('messages', msg => this.updateSocketsData(msg)); + } else { + socket.removeAllListeners('messages'); + } + }, 100); } componentWillUnmount() { @@ -81,6 +88,8 @@ class WalletsData extends React.Component { this.handleClickOutside, false ); + + socket.removeAllListeners('messages'); } handleClickOutside(e) { @@ -576,8 +585,14 @@ class WalletsData extends React.Component { if (this.props && this.props.ActiveCoin && this.props.ActiveCoin.coin && - !this.props.ActiveCoin.send && - !this.props.ActiveCoin.receive) { + ( + this.props.ActiveCoin.mode !== 'native' && + !this.props.ActiveCoin.send && + !this.props.ActiveCoin.receive + ) || ( + this.props.ActiveCoin.mode === 'native' && + this.props.ActiveCoin.nativeActiveSection === 'default' + )) { return WalletsDataRender.call(this); } else { return null; diff --git a/react/src/translate/translate.js b/react/src/translate/translate.js index 060f05d..631141b 100644 --- a/react/src/translate/translate.js +++ b/react/src/translate/translate.js @@ -13,13 +13,13 @@ export function translate(langID) { _lang[defaultLang][langIDComponents[0]][langIDComponents[1]]) { return _lang[defaultLang][langIDComponents[0]][langIDComponents[1]]; } else { - console.warn('Missing translation in js/' + defaultLang.toLowerCase() + '.js ' + langID); - return '--> ' + langID + ' <--'; + console.warn(`Missing translation ${langID} in js/${defaultLang.toLowerCase()}.js`); + return `--> ${langID} <--`; } } else { if (langID.length) { - console.warn('Missing translation in js/' + defaultLang.toLowerCase() + '.js ' + langID); - return '--> ' + langID + ' <--'; + console.warn(`Missing translation ${langID} in js/${defaultLang.toLowerCase()}.js`); + return `--> ${langID} <--`; } } } \ No newline at end of file