From aae84e528662390428e67e7447ba6d063c17ce24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Fri, 2 Mar 2018 17:38:57 +0100 Subject: [PATCH] Fetch counterValues before connectDevice step, add translations --- src/actions/counterValues.js | 4 +- src/components/AccountPage/index.js | 2 + src/components/BalanceSummary/BalanceInfos.js | 20 ++++-- src/components/DashboardPage/index.js | 1 + src/components/base/GrowScroll/index.js | 6 +- src/components/modals/AddAccount/index.js | 65 ++++++++++++++----- static/i18n/en/dashboard.yml | 1 + static/i18n/en/time.yml | 2 + 8 files changed, 73 insertions(+), 28 deletions(-) diff --git a/src/actions/counterValues.js b/src/actions/counterValues.js index c30169bb..abb31731 100644 --- a/src/actions/counterValues.js +++ b/src/actions/counterValues.js @@ -58,7 +58,9 @@ export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, get Promise.all(coinTypes.map(fetchCounterValuesByCoinType)).then(result => { const newCounterValues = result.reduce((r, v) => { - r[v.symbol] = v.values + if (v.symbol) { + r[v.symbol] = v.values + } return r }, {}) dispatch(updateCounterValues(newCounterValues)) diff --git a/src/components/AccountPage/index.js b/src/components/AccountPage/index.js index 633930d0..7ea240ba 100644 --- a/src/components/AccountPage/index.js +++ b/src/components/AccountPage/index.js @@ -131,12 +131,14 @@ class AccountPage extends PureComponent { - since one {since} + {t('time:since', { since: t(`time:${since}`) })} ) } export function BalanceSinceDiff(props: Props) { - const { totalBalance, sinceBalance, since, fiat, ...otherProps } = props + const { t, totalBalance, sinceBalance, since, fiat, ...otherProps } = props return ( - since one {since} + {t('time:since', { since: t(`time:${since}`) })} ) } @@ -89,17 +93,18 @@ BalanceTotal.defaultProps = { } function BalanceInfos(props: Props) { - const { fiat, totalBalance, since, sinceBalance } = props + const { t, fiat, totalBalance, since, sinceBalance } = props return ( - {'Total balance'} + {t('dashboard:totalBalance')} ) diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index a53c6f41..ae066dbf 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -139,6 +139,7 @@ class DashboardPage extends PureComponent { daysCount={daysCount} renderHeader={({ totalBalance, selectedTime, sinceBalance }) => ( { this.handleUpdate(this.props) if (this._scrollbar) { - this._scrollbar.addListener(this.handleScroll) + this._scrollbar.addListener(this.props.onScroll) } } @@ -38,7 +38,7 @@ class GrowScroll extends PureComponent { componentWillUnmount() { if (this._scrollbar) { - this._scrollbar.removeListener(this.handleScroll) + this._scrollbar.removeListener(this.props.onScroll) } } @@ -48,8 +48,6 @@ class GrowScroll extends PureComponent { } } - handleScroll = this.props.onScroll - _scrollbar = undefined render() { diff --git a/src/components/modals/AddAccount/index.js b/src/components/modals/AddAccount/index.js index 251752cb..b6b57efb 100644 --- a/src/components/modals/AddAccount/index.js +++ b/src/components/modals/AddAccount/index.js @@ -21,6 +21,7 @@ import { getCurrentDevice } from 'reducers/devices' import { sendEvent } from 'renderer/events' import { addAccount, updateAccount } from 'actions/accounts' +import { fetchCounterValues } from 'actions/counterValues' import Box from 'components/base/Box' import Button from 'components/base/Button' @@ -55,9 +56,13 @@ const Steps = { /> - + {props.fetchingCounterValues ? ( + 'Fetching counterValues...' + ) : ( + + )} @@ -113,41 +118,47 @@ const Steps = { type Step = 'chooseCurrency' | 'connectDevice' | 'inProgress' | 'listAccounts' type Props = { - t: T, accounts: Accounts, - archivedAccounts: Accounts, addAccount: Function, - updateAccount: Function, + archivedAccounts: Accounts, canCreateAccount: boolean, closeModal: Function, + counterValues: Object, currentDevice: Device | null, + fetchCounterValues: Function, + t: T, + updateAccount: Function, } type State = { - step: Step, - currency: Currency | null, accounts: Accounts, + currency: Currency | null, + fetchingCounterValues: boolean, progress: null | Object, + step: Step, } const mapStateToProps: MapStateToProps<*, *, *> = state => ({ accounts: getAccounts(state), archivedAccounts: getArchivedAccounts(state), canCreateAccount: canCreateAccount(state), + counterValues: state.counterValues, currentDevice: getCurrentDevice(state), }) const mapDispatchToProps = { addAccount, - updateAccount, closeModal, + fetchCounterValues, + updateAccount, } const defaultState = { + step: 'chooseCurrency', + progress: null, + fetchingCounterValues: false, currency: null, accounts: [], - progress: null, - step: 'chooseCurrency', } class AddAccountModal extends PureComponent { @@ -160,11 +171,25 @@ 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() { @@ -200,16 +225,17 @@ class AddAccountModal extends PureComponent { getStepProps() { const { currentDevice, archivedAccounts, canCreateAccount, updateAccount, t } = this.props - const { currency, step, progress, accounts } = this.state + const { currency, step, progress, accounts, fetchingCounterValues } = this.state const props = (predicate, props) => (predicate ? props : {}) return { ...props(step === 'chooseCurrency', { - t, currency, + fetchingCounterValues, onChangeCurrency: this.handleChangeCurrency, onSubmit: this.handleSubmit, + t, }), ...props(step === 'connectDevice', { t, @@ -274,9 +300,16 @@ class AddAccountModal extends PureComponent { handleSubmit = (e: SyntheticEvent) => { e.preventDefault() - this.setState({ - step: 'connectDevice', - }) + const { fetchCounterValues } = this.props + const { currency } = this.state + + if (currency !== null) { + this.setState({ + fetchingCounterValues: true, + }) + + fetchCounterValues(currency.coinType) + } } handleClose = () => { diff --git a/static/i18n/en/dashboard.yml b/static/i18n/en/dashboard.yml index d2c3c88d..463f7daf 100644 --- a/static/i18n/en/dashboard.yml +++ b/static/i18n/en/dashboard.yml @@ -4,3 +4,4 @@ summary: here is the summary of your account summary_plural: 'here is the summary of your {{count}} accounts' noAccounts: no accounts recentActivity: Recent activity +totalBalance: Total balance diff --git a/static/i18n/en/time.yml b/static/i18n/en/time.yml index 4ed423da..2cf41275 100644 --- a/static/i18n/en/time.yml +++ b/static/i18n/en/time.yml @@ -2,3 +2,5 @@ day: Day week: Week month: Month year: Year + +since: since one {{since}}