From e2a000a97a63a6cb5cb64301cd6b5c9651654658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Fri, 2 Mar 2018 17:56:32 +0100 Subject: [PATCH] Fix counterValues --- src/actions/counterValues.js | 13 +++++++----- src/components/DashboardPage/AccountCard.js | 2 +- src/components/base/Chart/index.js | 2 +- src/components/modals/AddAccount/index.js | 23 +++++++-------------- src/renderer/init.js | 2 +- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/actions/counterValues.js b/src/actions/counterValues.js index abb31731..3d604a82 100644 --- a/src/actions/counterValues.js +++ b/src/actions/counterValues.js @@ -20,7 +20,7 @@ export const updateCounterValues: UpdateCounterValues = payload => ({ payload, }) -type FetchCounterValues = (?number) => (Dispatch<*>, Function) => void +type FetchCounterValues = (?number) => (Dispatch<*>, Function) => Promise export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, getState) => { const { accounts, counterValues } = getState() @@ -39,7 +39,7 @@ export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, get const todayCounterValues = get(counterValues, `${code}-USD.${today}`, null) if (todayCounterValues !== null) { - return {} + return null } return axios @@ -56,13 +56,16 @@ export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, get })) } - Promise.all(coinTypes.map(fetchCounterValuesByCoinType)).then(result => { + return Promise.all(coinTypes.map(fetchCounterValuesByCoinType)).then(result => { const newCounterValues = result.reduce((r, v) => { - if (v.symbol) { + if (v !== null) { r[v.symbol] = v.values } return r }, {}) - dispatch(updateCounterValues(newCounterValues)) + + if (Object.keys(newCounterValues).length !== 0) { + dispatch(updateCounterValues(newCounterValues)) + } }) } diff --git a/src/components/DashboardPage/AccountCard.js b/src/components/DashboardPage/AccountCard.js index f41e69c7..f3c0d658 100644 --- a/src/components/DashboardPage/AccountCard.js +++ b/src/components/DashboardPage/AccountCard.js @@ -86,7 +86,7 @@ const AccountCard = ({ color={account.currency.color} height={52} id={`account-chart-${account.id}`} - linearGradient={[[5, 0.2], [75, 0]]} + linearGradient={[[5, 0.2], [100, 0]]} simple strokeWidth={1.5} /> diff --git a/src/components/base/Chart/index.js b/src/components/base/Chart/index.js index 1830990d..66f6633e 100644 --- a/src/components/base/Chart/index.js +++ b/src/components/base/Chart/index.js @@ -206,7 +206,7 @@ export class AreaChart extends PureComponent { static defaultProps = { height: 100, id: 'chart', - linearGradient: [[5, 0.2], [50, 0]], + linearGradient: [[5, 0.2], [100, 0]], strokeWidth: 2, renderLabels: (d: Object) => d.y, renderTickX: (t: any) => t, diff --git a/src/components/modals/AddAccount/index.js b/src/components/modals/AddAccount/index.js index b6b57efb..5b17078b 100644 --- a/src/components/modals/AddAccount/index.js +++ b/src/components/modals/AddAccount/index.js @@ -171,25 +171,11 @@ class AddAccountModal extends PureComponent { } componentWillReceiveProps(nextProps) { - const { fetchingCounterValues, currency } = this.state - if (nextProps.accounts) { this.setState(prev => ({ accounts: differenceBy(prev.accounts, nextProps.accounts, 'id'), })) } - - if (currency !== null && fetchingCounterValues) { - const { code } = getDefaultUnitByCoinType(currency.coinType) - const symbol = `${code.toString()}-USD` - - if (nextProps.counterValues[symbol]) { - this.setState({ - fetchingCounterValues: false, - step: 'connectDevice', - }) - } - } } componentDidUpdate() { @@ -297,7 +283,7 @@ class AddAccountModal extends PureComponent { handleChangeCurrency = (currency: Currency) => this.setState({ currency }) - handleSubmit = (e: SyntheticEvent) => { + handleSubmit = async (e: SyntheticEvent) => { e.preventDefault() const { fetchCounterValues } = this.props @@ -308,7 +294,12 @@ class AddAccountModal extends PureComponent { fetchingCounterValues: true, }) - fetchCounterValues(currency.coinType) + await fetchCounterValues(currency.coinType) + + this.setState({ + fetchingCounterValues: false, + step: 'connectDevice', + }) } } diff --git a/src/renderer/init.js b/src/renderer/init.js index 59bf5154..74233997 100644 --- a/src/renderer/init.js +++ b/src/renderer/init.js @@ -29,8 +29,8 @@ const history = createHistory() const store = createStore(history) const rootNode = document.getElementById('app') -store.dispatch(initCounterValues()) store.dispatch(fetchSettings()) +store.dispatch(initCounterValues()) const state = store.getState() || {} const language = getLanguage(state)