Browse Source

Remove account ref in operations list

master
Loëck Vézien 7 years ago
parent
commit
276e645f79
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 5
      src/components/AccountPage/index.js
  2. 6
      src/components/DashboardPage/index.js
  3. 67
      src/components/OperationsList/index.js
  4. 35
      src/reducers/accounts.js

5
src/components/AccountPage/index.js

@ -157,9 +157,10 @@ class AccountPage extends PureComponent<Props, State> {
/> />
</Box> </Box>
<OperationsList <OperationsList
title={t('account:lastOperations')} account={account}
operations={account.operations}
minConfirmations={account.settings.minConfirmations} minConfirmations={account.settings.minConfirmations}
operations={account.operations}
title={t('account:lastOperations')}
/> />
</Box> </Box>
) )

6
src/components/DashboardPage/index.js

@ -191,10 +191,10 @@ class DashboardPage extends PureComponent<Props, State> {
</Box> </Box>
<OperationsList <OperationsList
canShowMore canShowMore
title={t('dashboard:recentActivity')}
withAccounts
operations={allOperations}
onAccountClick={account => push(`/account/${account.id}`)} onAccountClick={account => push(`/account/${account.id}`)}
operations={allOperations}
title={t('dashboard:recentActivity')}
withAccount
/> />
</Fragment> </Fragment>
)} )}

67
src/components/OperationsList/index.js

@ -9,7 +9,7 @@ import noop from 'lodash/noop'
import isEqual from 'lodash/isEqual' import isEqual from 'lodash/isEqual'
import { getIconByCoinType } from '@ledgerhq/currencies/react' import { getIconByCoinType } from '@ledgerhq/currencies/react'
import type { Operation as OperationType, T } from 'types/common' import type { Account, Operation as OperationType, T } from 'types/common'
import IconAngleDown from 'icons/AngleDown' import IconAngleDown from 'icons/AngleDown'
import Box, { Card } from 'components/base/Box' import Box, { Card } from 'components/base/Box'
@ -98,18 +98,21 @@ const ShowMore = styled(Box).attrs({
` `
const Operation = ({ const Operation = ({
account,
t, t,
onAccountClick, onAccountClick,
tx, tx,
withAccounts, withAccount,
minConfirmations, minConfirmations,
}: { }: {
account: Account | null,
t: T, t: T,
onAccountClick?: Function, onAccountClick?: Function,
tx: OperationType, tx: OperationType,
withAccounts?: boolean, withAccount?: boolean,
minConfirmations: number, minConfirmations: number,
}) => { }) => {
const acc = account || tx.account
const time = moment(tx.receivedAt) const time = moment(tx.receivedAt)
const Icon = getIconByCoinType(get(tx, 'account.currency.coinType')) const Icon = getIconByCoinType(get(tx, 'account.currency.coinType'))
return ( return (
@ -120,24 +123,20 @@ const Operation = ({
<Hour>{time.format('HH:mm')}</Hour> <Hour>{time.format('HH:mm')}</Hour>
</Box> </Box>
</Cell> </Cell>
{withAccounts && {withAccount &&
tx.account && ( acc && (
<Cell <Cell
size={ACCOUNT_COL_SIZE} size={ACCOUNT_COL_SIZE}
horizontal horizontal
flow={2} flow={2}
style={{ cursor: 'pointer' }} style={{ cursor: 'pointer' }}
onClick={() => onAccountClick && onAccountClick(tx.account)} onClick={() => onAccountClick && onAccountClick(acc)}
> >
<Box <Box alignItems="center" justifyContent="center" style={{ color: acc.currency.color }}>
alignItems="center"
justifyContent="center"
style={{ color: tx.account.currency.color }}
>
{Icon && <Icon size={16} />} {Icon && <Icon size={16} />}
</Box> </Box>
<Box ff="Open Sans|SemiBold" fontSize={4} color="dark"> <Box ff="Open Sans|SemiBold" fontSize={4} color="dark">
{tx.account.name} {acc.name}
</Box> </Box>
</Cell> </Cell>
)} )}
@ -166,13 +165,7 @@ const Operation = ({
</Box> </Box>
</Cell> </Cell>
<Cell size={AMOUNT_COL_SIZE} justifyContent="flex-end"> <Cell size={AMOUNT_COL_SIZE} justifyContent="flex-end">
<FormattedVal <FormattedVal val={tx.amount} unit={acc && acc.unit} showCode fontSize={4} alwaysShowSign />
val={tx.amount}
unit={get(tx, 'account.unit')}
showCode
fontSize={4}
alwaysShowSign
/>
</Cell> </Cell>
<Cell size={CONFIRMATION_COL_SIZE} px={0} align="center" justify="flex-start"> <Cell size={CONFIRMATION_COL_SIZE} px={0} align="center" justify="flex-start">
<ConfirmationCheck <ConfirmationCheck
@ -187,23 +180,25 @@ const Operation = ({
Operation.defaultProps = { Operation.defaultProps = {
onAccountClick: noop, onAccountClick: noop,
withAccounts: false, withAccount: false,
} }
type Props = { type Props = {
t: T, account: Account | null,
canShowMore: boolean,
minConfirmations: number,
onAccountClick?: Function, onAccountClick?: Function,
operations: OperationType[], operations: OperationType[],
withAccounts?: boolean, t: T,
minConfirmations: number,
title?: string, title?: string,
canShowMore: boolean, withAccount?: boolean,
} }
class OperationsList extends Component<Props> { class OperationsList extends Component<Props> {
static defaultProps = { static defaultProps = {
account: null,
onAccountClick: noop, onAccountClick: noop,
withAccounts: false, withAccount: false,
minConfirmations: 2, minConfirmations: 2,
canShowMore: false, canShowMore: false,
} }
@ -230,13 +225,14 @@ class OperationsList extends Component<Props> {
render() { render() {
const { const {
operations, account,
title,
withAccounts,
onAccountClick,
minConfirmations,
canShowMore, canShowMore,
minConfirmations,
onAccountClick,
operations,
t, t,
title,
withAccount,
} = this.props } = this.props
this._hashCache = this.getHashCache(operations) this._hashCache = this.getHashCache(operations)
@ -246,7 +242,7 @@ class OperationsList extends Component<Props> {
<Card flow={1} title={title} p={0}> <Card flow={1} title={title} p={0}>
<Box horizontal pt={4}> <Box horizontal pt={4}>
<HeaderCol size={DATE_COL_SIZE}>{t('operationsList:date')}</HeaderCol> <HeaderCol size={DATE_COL_SIZE}>{t('operationsList:date')}</HeaderCol>
{withAccounts && ( {withAccount && (
<HeaderCol size={ACCOUNT_COL_SIZE}>{t('operationsList:account')}</HeaderCol> <HeaderCol size={ACCOUNT_COL_SIZE}>{t('operationsList:account')}</HeaderCol>
)} )}
<HeaderCol grow>{t('operationsList:address')}</HeaderCol> <HeaderCol grow>{t('operationsList:address')}</HeaderCol>
@ -257,14 +253,15 @@ class OperationsList extends Component<Props> {
</Box> </Box>
<Box> <Box>
{operations.map(trans => ( {operations.map(tx => (
<Operation <Operation
account={account}
t={t} t={t}
key={`{${trans.hash}-${trans.account ? trans.account.id : ''}`} key={`{${tx.hash}${tx.account ? `-${tx.account.id}` : ''}`}
withAccounts={withAccounts} withAccount={withAccount}
onAccountClick={onAccountClick} onAccountClick={onAccountClick}
minConfirmations={minConfirmations} minConfirmations={minConfirmations}
tx={trans} tx={tx}
/> />
))} ))}
</Box> </Box>

35
src/reducers/accounts.js

@ -99,31 +99,12 @@ export function canCreateAccount(state: State): boolean {
} }
export function serializeAccounts(accounts: Array<Object>) { export function serializeAccounts(accounts: Array<Object>) {
return accounts.map((account, key) => { return accounts.map((account, key) => ({
const a = { ...account,
id: account.id, currency: getCurrencyByCoinType(account.coinType),
address: account.address, name: account.name || `${key}`,
addresses: account.addresses, unit: account.unit || getDefaultUnitByCoinType(account.coinType),
balance: account.balance, }))
balanceByDay: account.balanceByDay,
coinType: account.coinType,
currency: getCurrencyByCoinType(account.coinType),
index: account.index,
name: account.name || `${key}`,
path: account.path,
rootPath: account.rootPath,
unit: account.unit || getDefaultUnitByCoinType(account.coinType),
settings: account.settings,
}
return {
...a,
operations: account.operations.map(t => ({
...t,
account: a,
})),
}
})
} }
export function deserializeAccounts(accounts: Account[]) { export function deserializeAccounts(accounts: Account[]) {
@ -136,11 +117,11 @@ export function deserializeAccounts(accounts: Account[]) {
coinType: account.coinType, coinType: account.coinType,
index: account.index, index: account.index,
name: account.name, name: account.name,
operations: account.operations,
path: account.path, path: account.path,
rootPath: account.rootPath, rootPath: account.rootPath,
operations: account.operations.map(({ account, ...t }) => t),
unit: account.unit,
settings: account.settings, settings: account.settings,
unit: account.unit,
})) }))
} }

Loading…
Cancel
Save