diff --git a/src/components/DashboardPage/AccountCard.js b/src/components/DashboardPage/AccountCard.js index 4a6c8b9a..1aa61b95 100644 --- a/src/components/DashboardPage/AccountCard.js +++ b/src/components/DashboardPage/AccountCard.js @@ -1,6 +1,6 @@ // @flow -import React from 'react' +import React, { PureComponent } from 'react' import styled from 'styled-components' import type { Account, Currency } from '@ledgerhq/live-common/lib/types' @@ -20,80 +20,83 @@ const Wrapper = styled(Card).attrs({ cursor: ${p => (p.onClick ? 'pointer' : 'default')}; ` -const AccountCard = ({ - counterValue, - account, - onClick, - daysCount, - ...props -}: { +class AccountCard extends PureComponent<{ counterValue: Currency, account: Account, - onClick?: () => void, + onClick?: Account => void, daysCount: number, -}) => ( - - - - - - - - - {account.unit.code} - - - {account.name} - - - - - - - - - - {({ isAvailable, balanceHistory, balanceStart, balanceEnd }) => ( +}> { + render() { + const { counterValue, account, onClick, daysCount, ...props } = this.props + return ( + onClick(account) : null} {...props}> - - - {isAvailable ? ( - - ) : null} + + + - - {balanceStart && isAvailable ? ( - - ) : null} + + + {account.unit.code} + + + {account.name} + - + + + + - )} - - -) + + {({ isAvailable, balanceHistory, balanceStart, balanceEnd }) => ( + + + + {isAvailable ? ( + + ) : null} + + + {balanceStart && isAvailable ? ( + + ) : null} + + + + + )} + + + ) + } +} export default AccountCard diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index c71e797f..eea708a7 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -5,7 +5,6 @@ import { compose } from 'redux' import { translate } from 'react-i18next' import { connect } from 'react-redux' import { push } from 'react-router-redux' -import chunk from 'lodash/chunk' import { createStructuredSelector } from 'reselect' import type { Account, Currency } from '@ledgerhq/live-common/lib/types' @@ -51,36 +50,17 @@ type Props = { } type State = { - accountsChunk: Array>, selectedTime: string, daysCount: number, } -const ACCOUNTS_BY_LINE = 3 - -const getAccountsChunk = accounts => { - // create shallow copy of accounts, to be mutated - const listAccounts = [...accounts] - - while (listAccounts.length % ACCOUNTS_BY_LINE !== 0) listAccounts.push(null) - - return chunk(listAccounts, ACCOUNTS_BY_LINE) -} - class DashboardPage extends PureComponent { state = { - accountsChunk: getAccountsChunk(this.props.accounts), selectedTime: 'week', daysCount: 7, } - componentWillReceiveProps(nextProps) { - if (nextProps.accounts !== this.props.accounts) { - this.setState({ - accountsChunk: getAccountsChunk(nextProps.accounts), - }) - } - } + onAccountClick = account => this.props.push(`/account/${account.id}`) handleGreeting = () => { const localTimeHour = new Date().getHours() @@ -104,8 +84,8 @@ class DashboardPage extends PureComponent { _cacheBalance = null render() { - const { push, accounts, t, counterValue } = this.props - const { accountsChunk, selectedTime, daysCount } = this.state + const { accounts, t, counterValue } = this.props + const { selectedTime, daysCount } = this.state const timeFrame = this.handleGreeting() const totalAccounts = accounts.length @@ -161,31 +141,24 @@ class DashboardPage extends PureComponent { - - {accountsChunk.map((accountsByLine, i) => ( - - {accountsByLine.map( - (account: any, j) => - account === null ? ( - - ) : ( - push(`/account/${account.id}`)} - /> - ), - )} + + {accounts.concat(Array(3 - accounts.length % 3).fill(null)).map((account, i) => ( + + {account ? ( + + ) : null} ))} @@ -193,7 +166,7 @@ class DashboardPage extends PureComponent { {displayOperations && ( push(`/account/${account.id}`)} + onAccountClick={this.onAccountClick} accounts={accounts} title={t('dashboard:recentActivity')} withAccount diff --git a/src/components/base/Box/index.js b/src/components/base/Box/index.js index f961388c..679c167c 100644 --- a/src/components/base/Box/index.js +++ b/src/components/base/Box/index.js @@ -8,6 +8,7 @@ import { boxShadow, color, flex, + flexWrap, fontSize, justifyContent, space, @@ -34,6 +35,7 @@ const Box = styled.div` ${boxShadow}; ${color}; ${flex}; + ${flexWrap}; ${fontFamily}; ${fontSize}; ${justifyContent}; diff --git a/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap b/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap index 6d59e715..03d6d3b1 100644 --- a/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap +++ b/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap @@ -2,7 +2,7 @@ exports[`components FormattedVal renders a formatted val 1`] = `
4 @@ -11,7 +11,7 @@ exports[`components FormattedVal renders a formatted val 1`] = ` exports[`components FormattedVal renders a percent 1`] = `
30 % @@ -20,7 +20,7 @@ exports[`components FormattedVal renders a percent 1`] = ` exports[`components FormattedVal shows code 1`] = `
BTC 4 @@ -29,7 +29,7 @@ exports[`components FormattedVal shows code 1`] = ` exports[`components FormattedVal shows sign 1`] = `
+ 4 @@ -38,7 +38,7 @@ exports[`components FormattedVal shows sign 1`] = ` exports[`components FormattedVal shows sign 2`] = `
- 4