Browse Source

Fetch counterValues before connectDevice step, add translations

master
Loëck Vézien 7 years ago
parent
commit
aae84e5286
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 4
      src/actions/counterValues.js
  2. 2
      src/components/AccountPage/index.js
  3. 20
      src/components/BalanceSummary/BalanceInfos.js
  4. 1
      src/components/DashboardPage/index.js
  5. 6
      src/components/base/GrowScroll/index.js
  6. 65
      src/components/modals/AddAccount/index.js
  7. 1
      static/i18n/en/dashboard.yml
  8. 2
      static/i18n/en/time.yml

4
src/actions/counterValues.js

@ -58,7 +58,9 @@ export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, get
Promise.all(coinTypes.map(fetchCounterValuesByCoinType)).then(result => { Promise.all(coinTypes.map(fetchCounterValuesByCoinType)).then(result => {
const newCounterValues = result.reduce((r, v) => { const newCounterValues = result.reduce((r, v) => {
r[v.symbol] = v.values if (v.symbol) {
r[v.symbol] = v.values
}
return r return r
}, {}) }, {})
dispatch(updateCounterValues(newCounterValues)) dispatch(updateCounterValues(newCounterValues))

2
src/components/AccountPage/index.js

@ -131,12 +131,14 @@ class AccountPage extends PureComponent<Props, State> {
</Box> </Box>
<Box horizontal justifyContent="center" flow={7}> <Box horizontal justifyContent="center" flow={7}>
<BalanceSincePercent <BalanceSincePercent
t={t}
alignItems="center" alignItems="center"
totalBalance={totalBalance} totalBalance={totalBalance}
sinceBalance={sinceBalance} sinceBalance={sinceBalance}
since={selectedTime} since={selectedTime}
/> />
<BalanceSinceDiff <BalanceSinceDiff
t={t}
fiat="USD" fiat="USD"
alignItems="center" alignItems="center"
totalBalance={totalBalance} totalBalance={totalBalance}

20
src/components/BalanceSummary/BalanceInfos.js

@ -4,6 +4,7 @@ import React from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import type { Unit } from '@ledgerhq/currencies' import type { Unit } from '@ledgerhq/currencies'
import type { T } from 'types/common'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Text from 'components/base/Text' import Text from 'components/base/Text'
@ -13,12 +14,15 @@ const Sub = styled(Text).attrs({
ff: 'Open Sans', ff: 'Open Sans',
color: 'warnGrey', color: 'warnGrey',
fontSize: 4, fontSize: 4,
})`` })`
text-transform: lowercase;
`
type BalanceSinceProps = { type BalanceSinceProps = {
since: string, since: string,
totalBalance: number, totalBalance: number,
sinceBalance: number, sinceBalance: number,
t: T,
} }
type BalanceTotalProps = { type BalanceTotalProps = {
@ -33,7 +37,7 @@ type Props = {
} & BalanceSinceProps } & BalanceSinceProps
export function BalanceSincePercent(props: BalanceSinceProps) { export function BalanceSincePercent(props: BalanceSinceProps) {
const { totalBalance, sinceBalance, since, ...otherProps } = props const { t, totalBalance, sinceBalance, since, ...otherProps } = props
return ( return (
<Box {...otherProps}> <Box {...otherProps}>
<FormattedVal <FormattedVal
@ -42,13 +46,13 @@ export function BalanceSincePercent(props: BalanceSinceProps) {
alwaysShowSign alwaysShowSign
fontSize={7} fontSize={7}
/> />
<Sub>since one {since}</Sub> <Sub>{t('time:since', { since: t(`time:${since}`) })}</Sub>
</Box> </Box>
) )
} }
export function BalanceSinceDiff(props: Props) { export function BalanceSinceDiff(props: Props) {
const { totalBalance, sinceBalance, since, fiat, ...otherProps } = props const { t, totalBalance, sinceBalance, since, fiat, ...otherProps } = props
return ( return (
<Box {...otherProps}> <Box {...otherProps}>
<FormattedVal <FormattedVal
@ -58,7 +62,7 @@ export function BalanceSinceDiff(props: Props) {
val={totalBalance - sinceBalance} val={totalBalance - sinceBalance}
fontSize={7} fontSize={7}
/> />
<Sub>since one {since}</Sub> <Sub>{t('time:since', { since: t(`time:${since}`) })}</Sub>
</Box> </Box>
) )
} }
@ -89,17 +93,18 @@ BalanceTotal.defaultProps = {
} }
function BalanceInfos(props: Props) { function BalanceInfos(props: Props) {
const { fiat, totalBalance, since, sinceBalance } = props const { t, fiat, totalBalance, since, sinceBalance } = props
return ( return (
<Box horizontal alignItems="flex-end" flow={7}> <Box horizontal alignItems="flex-end" flow={7}>
<BalanceTotal fiat={fiat} totalBalance={totalBalance}> <BalanceTotal fiat={fiat} totalBalance={totalBalance}>
<Sub>{'Total balance'}</Sub> <Sub>{t('dashboard:totalBalance')}</Sub>
</BalanceTotal> </BalanceTotal>
<BalanceSincePercent <BalanceSincePercent
alignItems="flex-end" alignItems="flex-end"
totalBalance={totalBalance} totalBalance={totalBalance}
sinceBalance={sinceBalance} sinceBalance={sinceBalance}
since={since} since={since}
t={t}
/> />
<BalanceSinceDiff <BalanceSinceDiff
fiat="USD" fiat="USD"
@ -107,6 +112,7 @@ function BalanceInfos(props: Props) {
totalBalance={totalBalance} totalBalance={totalBalance}
sinceBalance={sinceBalance} sinceBalance={sinceBalance}
since={since} since={since}
t={t}
/> />
</Box> </Box>
) )

1
src/components/DashboardPage/index.js

@ -139,6 +139,7 @@ class DashboardPage extends PureComponent<Props, State> {
daysCount={daysCount} daysCount={daysCount}
renderHeader={({ totalBalance, selectedTime, sinceBalance }) => ( renderHeader={({ totalBalance, selectedTime, sinceBalance }) => (
<BalanceInfos <BalanceInfos
t={t}
fiat="USD" fiat="USD"
totalBalance={totalBalance} totalBalance={totalBalance}
since={selectedTime} since={selectedTime}

6
src/components/base/GrowScroll/index.js

@ -28,7 +28,7 @@ class GrowScroll extends PureComponent<Props> {
this.handleUpdate(this.props) this.handleUpdate(this.props)
if (this._scrollbar) { if (this._scrollbar) {
this._scrollbar.addListener(this.handleScroll) this._scrollbar.addListener(this.props.onScroll)
} }
} }
@ -38,7 +38,7 @@ class GrowScroll extends PureComponent<Props> {
componentWillUnmount() { componentWillUnmount() {
if (this._scrollbar) { if (this._scrollbar) {
this._scrollbar.removeListener(this.handleScroll) this._scrollbar.removeListener(this.props.onScroll)
} }
} }
@ -48,8 +48,6 @@ class GrowScroll extends PureComponent<Props> {
} }
} }
handleScroll = this.props.onScroll
_scrollbar = undefined _scrollbar = undefined
render() { render() {

65
src/components/modals/AddAccount/index.js

@ -21,6 +21,7 @@ import { getCurrentDevice } from 'reducers/devices'
import { sendEvent } from 'renderer/events' import { sendEvent } from 'renderer/events'
import { addAccount, updateAccount } from 'actions/accounts' import { addAccount, updateAccount } from 'actions/accounts'
import { fetchCounterValues } from 'actions/counterValues'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Button from 'components/base/Button' import Button from 'components/base/Button'
@ -55,9 +56,13 @@ const Steps = {
/> />
</Box> </Box>
<Box horizontal justifyContent="flex-end"> <Box horizontal justifyContent="flex-end">
<Button primary type="submit"> {props.fetchingCounterValues ? (
{props.t('addAccount:title')} 'Fetching counterValues...'
</Button> ) : (
<Button primary type="submit">
{props.t('addAccount:title')}
</Button>
)}
</Box> </Box>
</Box> </Box>
</form> </form>
@ -113,41 +118,47 @@ const Steps = {
type Step = 'chooseCurrency' | 'connectDevice' | 'inProgress' | 'listAccounts' type Step = 'chooseCurrency' | 'connectDevice' | 'inProgress' | 'listAccounts'
type Props = { type Props = {
t: T,
accounts: Accounts, accounts: Accounts,
archivedAccounts: Accounts,
addAccount: Function, addAccount: Function,
updateAccount: Function, archivedAccounts: Accounts,
canCreateAccount: boolean, canCreateAccount: boolean,
closeModal: Function, closeModal: Function,
counterValues: Object,
currentDevice: Device | null, currentDevice: Device | null,
fetchCounterValues: Function,
t: T,
updateAccount: Function,
} }
type State = { type State = {
step: Step,
currency: Currency | null,
accounts: Accounts, accounts: Accounts,
currency: Currency | null,
fetchingCounterValues: boolean,
progress: null | Object, progress: null | Object,
step: Step,
} }
const mapStateToProps: MapStateToProps<*, *, *> = state => ({ const mapStateToProps: MapStateToProps<*, *, *> = state => ({
accounts: getAccounts(state), accounts: getAccounts(state),
archivedAccounts: getArchivedAccounts(state), archivedAccounts: getArchivedAccounts(state),
canCreateAccount: canCreateAccount(state), canCreateAccount: canCreateAccount(state),
counterValues: state.counterValues,
currentDevice: getCurrentDevice(state), currentDevice: getCurrentDevice(state),
}) })
const mapDispatchToProps = { const mapDispatchToProps = {
addAccount, addAccount,
updateAccount,
closeModal, closeModal,
fetchCounterValues,
updateAccount,
} }
const defaultState = { const defaultState = {
step: 'chooseCurrency',
progress: null,
fetchingCounterValues: false,
currency: null, currency: null,
accounts: [], accounts: [],
progress: null,
step: 'chooseCurrency',
} }
class AddAccountModal extends PureComponent<Props, State> { class AddAccountModal extends PureComponent<Props, State> {
@ -160,11 +171,25 @@ class AddAccountModal extends PureComponent<Props, State> {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const { fetchingCounterValues, currency } = this.state
if (nextProps.accounts) { if (nextProps.accounts) {
this.setState(prev => ({ this.setState(prev => ({
accounts: differenceBy(prev.accounts, nextProps.accounts, 'id'), 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() { componentDidUpdate() {
@ -200,16 +225,17 @@ class AddAccountModal extends PureComponent<Props, State> {
getStepProps() { getStepProps() {
const { currentDevice, archivedAccounts, canCreateAccount, updateAccount, t } = this.props 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 : {}) const props = (predicate, props) => (predicate ? props : {})
return { return {
...props(step === 'chooseCurrency', { ...props(step === 'chooseCurrency', {
t,
currency, currency,
fetchingCounterValues,
onChangeCurrency: this.handleChangeCurrency, onChangeCurrency: this.handleChangeCurrency,
onSubmit: this.handleSubmit, onSubmit: this.handleSubmit,
t,
}), }),
...props(step === 'connectDevice', { ...props(step === 'connectDevice', {
t, t,
@ -274,9 +300,16 @@ class AddAccountModal extends PureComponent<Props, State> {
handleSubmit = (e: SyntheticEvent<HTMLFormElement>) => { handleSubmit = (e: SyntheticEvent<HTMLFormElement>) => {
e.preventDefault() e.preventDefault()
this.setState({ const { fetchCounterValues } = this.props
step: 'connectDevice', const { currency } = this.state
})
if (currency !== null) {
this.setState({
fetchingCounterValues: true,
})
fetchCounterValues(currency.coinType)
}
} }
handleClose = () => { handleClose = () => {

1
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' summary_plural: 'here is the summary of your {{count}} accounts'
noAccounts: no accounts noAccounts: no accounts
recentActivity: Recent activity recentActivity: Recent activity
totalBalance: Total balance

2
static/i18n/en/time.yml

@ -2,3 +2,5 @@ day: Day
week: Week week: Week
month: Month month: Month
year: Year year: Year
since: since one {{since}}

Loading…
Cancel
Save