From 62678af9f7b3fe73b0b6e6da40e8a499ce2c66c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Sat, 16 Jun 2018 11:23:23 +0200 Subject: [PATCH 1/2] No countervalues to load if there is no accounts --- src/helpers/countervalues.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/helpers/countervalues.js b/src/helpers/countervalues.js index 41e509a9..a6671bcf 100644 --- a/src/helpers/countervalues.js +++ b/src/helpers/countervalues.js @@ -18,15 +18,17 @@ const pairsSelector = createSelector( counterValueExchangeSelector, state => state, (currencies, counterValueCurrency, counterValueExchange, state) => - [ - { from: intermediaryCurrency, to: counterValueCurrency, exchange: counterValueExchange }, - ].concat( - currencies.filter(c => c.ticker !== intermediaryCurrency.ticker).map(currency => ({ - from: currency, - to: intermediaryCurrency, - exchange: currencySettingsSelector(state, { currency }).exchange, - })), - ), + currencies.length === 0 + ? [] + : [ + { from: intermediaryCurrency, to: counterValueCurrency, exchange: counterValueExchange }, + ].concat( + currencies.filter(c => c.ticker !== intermediaryCurrency.ticker).map(currency => ({ + from: currency, + to: intermediaryCurrency, + exchange: currencySettingsSelector(state, { currency }).exchange, + })), + ), ) const addExtraPollingHooks = (schedulePoll, cancelPoll) => { From 4149185d71ea981bef97169d619597a6c46a11af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Sat, 16 Jun 2018 11:33:02 +0200 Subject: [PATCH 2/2] also hide the ActivityIndicator if no accounts + some perf optim --- src/components/TopBar/ActivityIndicator.js | 76 +++++++++++++--------- src/reducers/accounts.js | 2 + 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/components/TopBar/ActivityIndicator.js b/src/components/TopBar/ActivityIndicator.js index a606ce93..a2c9ff31 100644 --- a/src/components/TopBar/ActivityIndicator.js +++ b/src/components/TopBar/ActivityIndicator.js @@ -1,6 +1,6 @@ // @flow -import React, { Component, Fragment } from 'react' +import React, { PureComponent, Fragment } from 'react' import { compose } from 'redux' import { connect } from 'react-redux' import { createStructuredSelector } from 'reselect' @@ -10,6 +10,7 @@ import type { T } from 'types/common' import type { AsyncState } from 'reducers/bridgeSync' import { globalSyncStateSelector } from 'reducers/bridgeSync' +import { hasAccountsSelector } from 'reducers/accounts' import { BridgeSyncConsumer } from 'bridge/BridgeSyncContext' import CounterValues from 'helpers/countervalues' @@ -20,7 +21,10 @@ import IconExclamationCircle from 'icons/ExclamationCircle' import IconCheckCircle from 'icons/CheckCircle' import ItemContainer from './ItemContainer' -const mapStateToProps = createStructuredSelector({ globalSyncState: globalSyncStateSelector }) +const mapStateToProps = createStructuredSelector({ + globalSyncState: globalSyncStateSelector, + hasAccounts: hasAccountsSelector, +}) type Props = { // FIXME: eslint should see that it is used in static method @@ -28,8 +32,9 @@ type Props = { isPending: boolean, isError: boolean, - onClick: void => void, t: T, + cvPoll: *, + setSyncBehavior: *, } type State = { @@ -38,7 +43,7 @@ type State = { isFirstSync: boolean, } -class ActivityIndicatorInner extends Component { +class ActivityIndicatorInner extends PureComponent { state = { hasClicked: false, isFirstSync: true, @@ -61,10 +66,14 @@ class ActivityIndicatorInner extends Component { return nextState } + onClick = () => { + this.props.cvPoll() + this.props.setSyncBehavior({ type: 'SYNC_ALL_ACCOUNTS', priority: 5 }) + } + handleRefresh = () => { - const { onClick } = this.props this.setState({ hasClicked: true }) - onClick() + this.onClick() } render() { @@ -119,30 +128,37 @@ class ActivityIndicatorInner extends Component { } } -const ActivityIndicator = ({ globalSyncState, t }: { globalSyncState: AsyncState, t: T }) => ( - - {setSyncBehavior => ( - - {cvPolling => { - const isPending = cvPolling.pending || globalSyncState.pending - const isError = cvPolling.error || globalSyncState.error - return ( - { - cvPolling.poll() - setSyncBehavior({ type: 'SYNC_ALL_ACCOUNTS', priority: 5 }) - }} - /> - ) - }} - - )} - -) +const ActivityIndicator = ({ + globalSyncState, + hasAccounts, + t, +}: { + globalSyncState: AsyncState, + hasAccounts: boolean, + t: T, +}) => + !hasAccounts ? null : ( + + {setSyncBehavior => ( + + {cvPolling => { + const isPending = cvPolling.pending || globalSyncState.pending + const isError = cvPolling.error || globalSyncState.error + return ( + + ) + }} + + )} + + ) export default compose( translate(), diff --git a/src/reducers/accounts.js b/src/reducers/accounts.js index 99cdee31..9dc42c87 100644 --- a/src/reducers/accounts.js +++ b/src/reducers/accounts.js @@ -62,6 +62,8 @@ const handlers: Object = { export const accountsSelector = (state: { accounts: AccountsState }): Account[] => state.accounts +export const hasAccountsSelector = createSelector(accountsSelector, accounts => accounts.length > 0) + export const currenciesSelector = createSelector(accountsSelector, accounts => [...new Set(accounts.map(a => a.currency))].sort((a, b) => a.name.localeCompare(b.name)), )