Browse Source

Use common types for Account and Operation

master
meriadec 7 years ago
parent
commit
4a8edc53b8
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 7
      src/actions/accounts.js
  2. 2
      src/components/AccountPage/AccountHeader.js
  3. 3
      src/components/AccountPage/index.js
  4. 4
      src/components/BalanceSummary/index.js
  5. 3
      src/components/CalculateBalance.js
  6. 3
      src/components/DashboardPage/AccountCard.js
  7. 5
      src/components/DashboardPage/index.js
  8. 3
      src/components/DeviceMonit/index.js
  9. 3
      src/components/IsUnlocked.js
  10. 34
      src/components/OperationsList/index.js
  11. 10
      src/components/OperationsList/stories.js
  12. 3
      src/components/ReceiveBox.js
  13. 3
      src/components/RequestAmount/index.js
  14. 3
      src/components/SelectAccount/index.js
  15. 3
      src/components/SideBar/index.js
  16. 3
      src/components/modals/AddAccount/ImportAccounts.js
  17. 3
      src/components/modals/AddAccount/RestoreAccounts.js
  18. 3
      src/components/modals/AddAccount/index.js
  19. 8
      src/components/modals/OperationDetails.js
  20. 3
      src/components/modals/Receive/index.js
  21. 3
      src/components/modals/Send/01-step-amount.js
  22. 2
      src/components/modals/Send/02-step-connect-device.js
  23. 3
      src/components/modals/Send/Footer.js
  24. 3
      src/components/modals/Send/index.js
  25. 10
      src/components/modals/SettingsAccount.js
  26. 3
      src/helpers/balance.js
  27. 11
      src/helpers/btc.js
  28. 16
      src/reducers/accounts.js
  29. 3
      src/renderer/events.js
  30. 42
      src/types/common.js
  31. 3
      yarn.lock

7
src/actions/accounts.js

@ -1,11 +1,11 @@
// @flow // @flow
import sortBy from 'lodash/sortBy' import sortBy from 'lodash/sortBy'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import db from 'helpers/db' import db from 'helpers/db'
import type { Dispatch } from 'redux' import type { Dispatch } from 'redux'
import type { Account } from 'types/common'
import { fetchCounterValues } from 'actions/counterValues' import { fetchCounterValues } from 'actions/counterValues'
@ -44,10 +44,7 @@ export const updateOrderAccounts: UpdateOrderAccounts = (orderAccounts: string)
export type AddAccount = Account => (Function, Function) => void export type AddAccount = Account => (Function, Function) => void
export const addAccount: AddAccount = payload => (dispatch, getState) => { export const addAccount: AddAccount = payload => (dispatch, getState) => {
const { settings: { counterValue, orderAccounts }, accounts } = getState() const { settings: { counterValue, orderAccounts }, accounts } = getState()
dispatch({ dispatch({ type: 'ADD_ACCOUNT', payload })
type: 'ADD_ACCOUNT',
payload,
})
dispatch(updateOrderAccounts(orderAccounts)) dispatch(updateOrderAccounts(orderAccounts))
// Start sync accounts the first time you add an account // Start sync accounts the first time you add an account

2
src/components/AccountPage/AccountHeader.js

@ -4,7 +4,7 @@ import React, { PureComponent } from 'react'
import { getIconByCoinType } from '@ledgerhq/currencies/react' import { getIconByCoinType } from '@ledgerhq/currencies/react'
import styled from 'styled-components' import styled from 'styled-components'
import type { Account } from 'types/common' import type { Account } from '@ledgerhq/wallet-common/lib/types'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Text from 'components/base/Text' import Text from 'components/base/Text'

3
src/components/AccountPage/index.js

@ -6,10 +6,11 @@ import { connect } from 'react-redux'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import { Redirect } from 'react-router' import { Redirect } from 'react-router'
import styled from 'styled-components' import styled from 'styled-components'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import { MODAL_SEND, MODAL_RECEIVE, MODAL_SETTINGS_ACCOUNT } from 'config/constants' import { MODAL_SEND, MODAL_RECEIVE, MODAL_SETTINGS_ACCOUNT } from 'config/constants'
import type { T, Account } from 'types/common' import type { T } from 'types/common'
import { darken } from 'styles/helpers' import { darken } from 'styles/helpers'

4
src/components/BalanceSummary/index.js

@ -1,11 +1,9 @@
// @flow // @flow
import React, { Fragment } from 'react' import React, { Fragment } from 'react'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import { getFiatUnit } from '@ledgerhq/currencies' import { getFiatUnit } from '@ledgerhq/currencies'
import type { Account } from 'types/common'
import Chart from 'components/base/Chart' import Chart from 'components/base/Chart'
import Box, { Card } from 'components/base/Box' import Box, { Card } from 'components/base/Box'
import CalculateBalance from 'components/CalculateBalance' import CalculateBalance from 'components/CalculateBalance'

3
src/components/CalculateBalance.js

@ -2,8 +2,7 @@
import { PureComponent } from 'react' import { PureComponent } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { Account } from 'types/common'
import calculateBalance from 'helpers/balance' import calculateBalance from 'helpers/balance'

3
src/components/DashboardPage/AccountCard.js

@ -2,8 +2,7 @@
import React from 'react' import React from 'react'
import { getIconByCoinType } from '@ledgerhq/currencies/react' import { getIconByCoinType } from '@ledgerhq/currencies/react'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { Account } from 'types/common'
import Chart from 'components/base/Chart' import Chart from 'components/base/Chart'
import Bar from 'components/base/Bar' import Bar from 'components/base/Bar'

5
src/components/DashboardPage/index.js

@ -5,12 +5,13 @@ import { compose } from 'redux'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { push } from 'react-router-redux' import { push } from 'react-router-redux'
import type { Account, Operation } from '@ledgerhq/wallet-common/lib/types'
import chunk from 'lodash/chunk' import chunk from 'lodash/chunk'
import get from 'lodash/get' import get from 'lodash/get'
import sortBy from 'lodash/sortBy' import sortBy from 'lodash/sortBy'
import type { Account, Operation, T } from 'types/common' import type { T } from 'types/common'
import { getVisibleAccounts } from 'reducers/accounts' import { getVisibleAccounts } from 'reducers/accounts'
import { getCounterValue } from 'reducers/settings' import { getCounterValue } from 'reducers/settings'
@ -71,7 +72,7 @@ const getAllOperations = accounts => {
return result return result
}, []) }, [])
return sortBy(allOperations, t => t.receivedAt) return sortBy(allOperations, t => t.date)
.reverse() .reverse()
.slice(0, ALL_OPERATIONS_LIMIT) .slice(0, ALL_OPERATIONS_LIMIT)
} }

3
src/components/DeviceMonit/index.js

@ -3,10 +3,11 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { ipcRenderer } from 'electron' import { ipcRenderer } from 'electron'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import { sendEvent } from 'renderer/events' import { sendEvent } from 'renderer/events'
import { getCurrentDevice } from 'reducers/devices' import { getCurrentDevice } from 'reducers/devices'
import type { Device, Account } from 'types/common' import type { Device } from 'types/common'
const mapStateToProps = state => ({ const mapStateToProps = state => ({
currentDevice: getCurrentDevice(state), currentDevice: getCurrentDevice(state),

3
src/components/IsUnlocked.js

@ -5,8 +5,9 @@ import { connect } from 'react-redux'
import { compose } from 'redux' import { compose } from 'redux'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import bcrypt from 'bcryptjs' import bcrypt from 'bcryptjs'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { Settings, Account, T } from 'types/common' import type { Settings, T } from 'types/common'
import get from 'lodash/get' import get from 'lodash/get'

34
src/components/OperationsList/index.js

@ -7,11 +7,12 @@ import { connect } from 'react-redux'
import { compose } from 'redux' import { compose } from 'redux'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import { getIconByCoinType } from '@ledgerhq/currencies/react' import { getIconByCoinType } from '@ledgerhq/currencies/react'
import type { Account, Operation as OperationType } from '@ledgerhq/wallet-common/lib/types'
import noop from 'lodash/noop' import noop from 'lodash/noop'
import isEqual from 'lodash/isEqual' import isEqual from 'lodash/isEqual'
import type { Account, Operation as OperationType, T } from 'types/common' import type { T } from 'types/common'
import { MODAL_OPERATION_DETAILS } from 'config/constants' import { MODAL_OPERATION_DETAILS } from 'config/constants'
@ -117,7 +118,7 @@ const Operation = ({
onAccountClick, onAccountClick,
onOperationClick, onOperationClick,
t, t,
tx, op,
withAccount, withAccount,
}: { }: {
account: Account, account: Account,
@ -125,21 +126,21 @@ const Operation = ({
onAccountClick: Function, onAccountClick: Function,
onOperationClick: Function, onOperationClick: Function,
t: T, t: T,
tx: OperationType, op: OperationType,
withAccount?: boolean, withAccount?: boolean,
}) => { }) => {
const { unit } = account const { unit } = account
const time = moment(tx.receivedAt) const time = moment(op.date)
const Icon = getIconByCoinType(account.currency.coinType) const Icon = getIconByCoinType(account.currency.coinType)
const type = tx.amount > 0 ? 'from' : 'to' const type = op.amount > 0 ? 'from' : 'to'
return ( return (
<OperationRaw onClick={() => onOperationClick({ operation: tx, account, type })}> <OperationRaw onClick={() => onOperationClick({ operation: op, account, type })}>
<Cell size={CONFIRMATION_COL_SIZE} align="center" justify="flex-start"> <Cell size={CONFIRMATION_COL_SIZE} align="center" justify="flex-start">
<ConfirmationCheck <ConfirmationCheck
type={type} type={type}
minConfirmations={minConfirmations} minConfirmations={minConfirmations}
confirmations={tx.confirmations} confirmations={op.confirmations}
t={t} t={t}
/> />
</Cell> </Cell>
@ -176,19 +177,19 @@ const Operation = ({
</Cell> </Cell>
)} )}
<Cell grow shrink style={{ display: 'block' }}> <Cell grow shrink style={{ display: 'block' }}>
<Address value={tx.address} /> <Address value={op.address} />
</Cell> </Cell>
<Cell size={AMOUNT_COL_SIZE}> <Cell size={AMOUNT_COL_SIZE}>
<Box alignItems="flex-end"> <Box alignItems="flex-end">
<FormattedVal <FormattedVal
val={tx.amount} val={op.amount}
unit={unit} unit={unit}
showCode showCode
fontSize={4} fontSize={4}
alwaysShowSign alwaysShowSign
color={tx.amount < 0 ? 'smoke' : 'positiveGreen'} color={op.amount < 0 ? 'smoke' : 'positiveGreen'}
/> />
<CounterValue color="grey" fontSize={3} time={time} unit={unit} value={tx.amount} /> <CounterValue color="grey" fontSize={3} time={time} unit={unit} value={op.amount} />
</Box> </Box>
</Cell> </Cell>
</OperationRaw> </OperationRaw>
@ -260,17 +261,18 @@ export class OperationsList extends Component<Props> {
<Box> <Box>
<Card flow={1} title={title} p={0}> <Card flow={1} title={title} p={0}>
<Box> <Box>
{operations.map(tx => { {operations.map(op => {
const acc = account || tx.account // $FlowFixMe
const acc = account || op.account
return ( return (
<Operation <Operation
account={acc} account={acc}
key={`${tx.id}${acc ? `-${acc.id}` : ''}`} key={`${op.id}${acc ? `-${acc.id}` : ''}`}
minConfirmations={acc.settings.minConfirmations} minConfirmations={acc.minConfirmations}
onAccountClick={onAccountClick} onAccountClick={onAccountClick}
onOperationClick={this.handleClickOperation} onOperationClick={this.handleClickOperation}
t={t} t={t}
tx={tx} op={op}
withAccount={withAccount} withAccount={withAccount}
/> />
) )

10
src/components/OperationsList/stories.js

@ -16,9 +16,7 @@ const unit = getDefaultUnitByCoinType(0)
const account = ({ name }) => ({ const account = ({ name }) => ({
...accounts[0], ...accounts[0],
settings: {
minConfirmations: 10, minConfirmations: 10,
},
currency: getCurrencyByCoinType(0), currency: getCurrencyByCoinType(0),
name, name,
coinType: 0, coinType: 0,
@ -39,7 +37,7 @@ const operations = [
address: '5c6ea1716520c7d6e038d36a3223faced3c', address: '5c6ea1716520c7d6e038d36a3223faced3c',
hash: '5c6ea1716520c7d6e038d36a3223faced3c4b8f7ffb69d9fb5bd527d562fdb62', hash: '5c6ea1716520c7d6e038d36a3223faced3c4b8f7ffb69d9fb5bd527d562fdb62',
amount: 130000000, amount: 130000000,
receivedAt: '2018-01-09T16:03:52Z', date: '2018-01-09T16:03:52Z',
confirmations: 1, confirmations: 1,
account: account({ account: account({
name: 'Account 1', name: 'Account 1',
@ -49,7 +47,7 @@ const operations = [
address: '5c6ea1716520c7d6e038d36a3223faced3c', address: '5c6ea1716520c7d6e038d36a3223faced3c',
hash: '5c6ea1716520c7d6e038d36a3223faced3c4b8f7ffb69d9fb5bd527d562fdb62', hash: '5c6ea1716520c7d6e038d36a3223faced3c4b8f7ffb69d9fb5bd527d562fdb62',
amount: 130000000, amount: 130000000,
receivedAt: '2018-01-09T16:03:52Z', date: '2018-01-09T16:03:52Z',
confirmations: 11, confirmations: 11,
account: account({ account: account({
name: 'Account 1', name: 'Account 1',
@ -59,7 +57,7 @@ const operations = [
address: '27416a48caab90fab053b507b8b6b9d4', address: '27416a48caab90fab053b507b8b6b9d4',
hash: '27416a48caab90fab053b507b8b6b9d48fba75421d3bfdbae4b85f64024bc9c4', hash: '27416a48caab90fab053b507b8b6b9d48fba75421d3bfdbae4b85f64024bc9c4',
amount: -65000000, amount: -65000000,
receivedAt: '2018-01-09T16:02:40Z', date: '2018-01-09T16:02:40Z',
confirmations: 11, confirmations: 11,
account: account({ account: account({
name: 'Account 2', name: 'Account 2',
@ -69,7 +67,7 @@ const operations = [
address: '27416a48caab90fab053b507b8b6b9d4', address: '27416a48caab90fab053b507b8b6b9d4',
hash: '27416a48caab90fab053b507b8b6b9d48fba75421d3bfdbae4b85f64024bc9c4', hash: '27416a48caab90fab053b507b8b6b9d48fba75421d3bfdbae4b85f64024bc9c4',
amount: -65000000, amount: -65000000,
receivedAt: '2018-01-09T16:02:40Z', date: '2018-01-09T16:02:40Z',
confirmations: 1, confirmations: 1,
account: account({ account: account({
name: 'Account 2', name: 'Account 2',

3
src/components/ReceiveBox.js

@ -4,8 +4,9 @@ import React, { PureComponent } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import styled from 'styled-components' import styled from 'styled-components'
import { ipcRenderer } from 'electron' import { ipcRenderer } from 'electron'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { Account, Device } from 'types/common' import type { Device } from 'types/common'
import { getCurrentDevice } from 'reducers/devices' import { getCurrentDevice } from 'reducers/devices'
import { sendEvent } from 'renderer/events' import { sendEvent } from 'renderer/events'

3
src/components/RequestAmount/index.js

@ -6,11 +6,12 @@ import { translate } from 'react-i18next'
import styled from 'styled-components' import styled from 'styled-components'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { getDefaultUnitByCoinType, getFiatUnit } from '@ledgerhq/currencies' import { getDefaultUnitByCoinType, getFiatUnit } from '@ledgerhq/currencies'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import isNaN from 'lodash/isNaN' import isNaN from 'lodash/isNaN'
import noop from 'lodash/noop' import noop from 'lodash/noop'
import type { T, Account } from 'types/common' import type { T } from 'types/common'
import { getCounterValue } from 'reducers/settings' import { getCounterValue } from 'reducers/settings'
import { getLastCounterValueBySymbol } from 'reducers/counterValues' import { getLastCounterValueBySymbol } from 'reducers/counterValues'

3
src/components/SelectAccount/index.js

@ -5,8 +5,9 @@ import { connect } from 'react-redux'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import noop from 'lodash/noop' import noop from 'lodash/noop'
import { getIconByCoinType } from '@ledgerhq/currencies/react' import { getIconByCoinType } from '@ledgerhq/currencies/react'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { T, Account } from 'types/common' import type { T } from 'types/common'
import { getVisibleAccounts } from 'reducers/accounts' import { getVisibleAccounts } from 'reducers/accounts'

3
src/components/SideBar/index.js

@ -6,10 +6,11 @@ import { translate } from 'react-i18next'
import styled from 'styled-components' import styled from 'styled-components'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { getIconByCoinType } from '@ledgerhq/currencies/react' import { getIconByCoinType } from '@ledgerhq/currencies/react'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import { MODAL_SEND, MODAL_RECEIVE, MODAL_ADD_ACCOUNT } from 'config/constants' import { MODAL_SEND, MODAL_RECEIVE, MODAL_ADD_ACCOUNT } from 'config/constants'
import type { Account, T } from 'types/common' import type { T } from 'types/common'
import { openModal } from 'reducers/modals' import { openModal } from 'reducers/modals'
import { getVisibleAccounts } from 'reducers/accounts' import { getVisibleAccounts } from 'reducers/accounts'

3
src/components/modals/AddAccount/ImportAccounts.js

@ -2,8 +2,9 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { T, Account } from 'types/common' import type { T } from 'types/common'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Button from 'components/base/Button' import Button from 'components/base/Button'

3
src/components/modals/AddAccount/RestoreAccounts.js

@ -2,13 +2,12 @@
import React from 'react' import React from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Button from 'components/base/Button' import Button from 'components/base/Button'
import Text from 'components/base/Text' import Text from 'components/base/Text'
import type { Account } from 'types/common'
const Container = styled(Box)` const Container = styled(Box)`
border: 1px solid ${p => p.theme.colors.alertRed}; border: 1px solid ${p => p.theme.colors.alertRed};
` `

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

@ -7,12 +7,13 @@ import { translate } from 'react-i18next'
import { ipcRenderer } from 'electron' import { ipcRenderer } from 'electron'
import differenceBy from 'lodash/differenceBy' import differenceBy from 'lodash/differenceBy'
import { listCurrencies, getDefaultUnitByCoinType } from '@ledgerhq/currencies' import { listCurrencies, getDefaultUnitByCoinType } from '@ledgerhq/currencies'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { Currency } from '@ledgerhq/currencies' import type { Currency } from '@ledgerhq/currencies'
import { MODAL_ADD_ACCOUNT } from 'config/constants' import { MODAL_ADD_ACCOUNT } from 'config/constants'
import type { Account, Device, T } from 'types/common' import type { Device, T } from 'types/common'
import { closeModal } from 'reducers/modals' import { closeModal } from 'reducers/modals'
import { canCreateAccount, getAccounts, getArchivedAccounts } from 'reducers/accounts' import { canCreateAccount, getAccounts, getArchivedAccounts } from 'reducers/accounts'

8
src/components/modals/OperationDetails.js

@ -54,8 +54,8 @@ const OperationDetails = ({ t }: { t: T }) => (
render={({ data, onClose }) => { render={({ data, onClose }) => {
const { operation, account, type } = data const { operation, account, type } = data
const { name, unit, settings: { minConfirmations } } = account const { name, unit, minConfirmations } = account
const { id, amount, confirmations, receivedAt, from, to } = operation const { id, amount, confirmations, date, from, to } = operation
const isConfirmed = confirmations >= minConfirmations const isConfirmed = confirmations >= minConfirmations
@ -90,7 +90,7 @@ const OperationDetails = ({ t }: { t: T }) => (
color="grey" color="grey"
fontSize={5} fontSize={5}
style={{ lineHeight: 1 }} style={{ lineHeight: 1 }}
time={receivedAt} time={date}
unit={unit} unit={unit}
value={amount} value={amount}
/> />
@ -104,7 +104,7 @@ const OperationDetails = ({ t }: { t: T }) => (
<B /> <B />
<Line> <Line>
<ColLeft>Date</ColLeft> <ColLeft>Date</ColLeft>
<ColRight>{moment(receivedAt).format('LLL')}</ColRight> <ColRight>{moment(date).format('LLL')}</ColRight>
</Line> </Line>
<B /> <B />
<Line> <Line>

3
src/components/modals/Receive/index.js

@ -2,6 +2,7 @@
import React, { PureComponent, Fragment } from 'react' import React, { PureComponent, Fragment } from 'react'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import type { Account as AccountType } from '@ledgerhq/wallet-common/lib/types'
import get from 'lodash/get' import get from 'lodash/get'
@ -15,7 +16,7 @@ import ReceiveBox from 'components/ReceiveBox'
import RequestAmount from 'components/RequestAmount' import RequestAmount from 'components/RequestAmount'
import SelectAccount from 'components/SelectAccount' import SelectAccount from 'components/SelectAccount'
import type { Account as AccountType, T } from 'types/common' import type { T } from 'types/common'
type Props = { type Props = {
t: T, t: T,

3
src/components/modals/Send/01-step-amount.js

@ -1,9 +1,10 @@
// @flow // @flow
import React, { Fragment } from 'react' import React, { Fragment } from 'react'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { Unit } from '@ledgerhq/currencies' import type { Unit } from '@ledgerhq/currencies'
import type { Account, T } from 'types/common' import type { T } from 'types/common'
import type { DoubleVal } from 'components/RequestAmount' import type { DoubleVal } from 'components/RequestAmount'
import Box from 'components/base/Box' import Box from 'components/base/Box'

2
src/components/modals/Send/02-step-connect-device.js

@ -1,9 +1,9 @@
// @flow // @flow
import React from 'react' import React from 'react'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import DeviceMonit from 'components/DeviceMonit' import DeviceMonit from 'components/DeviceMonit'
import type { Account } from 'types/common'
type Props = { type Props = {
account: Account | null, account: Account | null,

3
src/components/modals/Send/Footer.js

@ -1,8 +1,9 @@
// @flow // @flow
import React from 'react' import React from 'react'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { T, Account } from 'types/common' import type { T } from 'types/common'
import type { DoubleVal } from 'components/RequestAmount' import type { DoubleVal } from 'components/RequestAmount'
import { ModalFooter } from 'components/base/Modal' import { ModalFooter } from 'components/base/Modal'

3
src/components/modals/Send/index.js

@ -5,9 +5,10 @@ import { compose } from 'redux'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import get from 'lodash/get' import get from 'lodash/get'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { Unit } from '@ledgerhq/currencies' import type { Unit } from '@ledgerhq/currencies'
import type { T, Account } from 'types/common' import type { T } from 'types/common'
import type { DoubleVal } from 'components/RequestAmount' import type { DoubleVal } from 'components/RequestAmount'
import { MODAL_SEND } from 'config/constants' import { MODAL_SEND } from 'config/constants'

10
src/components/modals/SettingsAccount.js

@ -4,11 +4,10 @@ import React, { PureComponent } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import get from 'lodash/get' import get from 'lodash/get'
import { push } from 'react-router-redux' import { push } from 'react-router-redux'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import { MODAL_SETTINGS_ACCOUNT } from 'config/constants' import { MODAL_SETTINGS_ACCOUNT } from 'config/constants'
import type { Account } from 'types/common'
import { updateAccount, removeAccount } from 'actions/accounts' import { updateAccount, removeAccount } from 'actions/accounts'
import { setDataModal, closeModal } from 'reducers/modals' import { setDataModal, closeModal } from 'reducers/modals'
@ -73,7 +72,7 @@ class SettingsAccount extends PureComponent<Props, State> {
: {}), : {}),
settings: { settings: {
...account.settings, ...account.settings,
minConfirmations: minConfirmations || account.settings.minConfirmations, minConfirmations: minConfirmations || account.minConfirmations,
}, },
} }
} }
@ -89,10 +88,7 @@ class SettingsAccount extends PureComponent<Props, State> {
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
updateAccount({ updateAccount({
...account, ...account,
settings: {
...account.settings,
minConfirmations: Number(minConfirmations), minConfirmations: Number(minConfirmations),
},
}) })
}) })
} }
@ -205,7 +201,7 @@ class SettingsAccount extends PureComponent<Props, State> {
type="number" type="number"
min={1} min={1}
max={100} max={100}
value={account.settings.minConfirmations} value={account.minConfirmations}
onChange={this.handleChangeMinConfirmations(account)} onChange={this.handleChangeMinConfirmations(account)}
/> />
</Box> </Box>

3
src/helpers/balance.js

@ -2,14 +2,13 @@
import moment from 'moment' import moment from 'moment'
import { getDefaultUnitByCoinType } from '@ledgerhq/currencies' import { getDefaultUnitByCoinType } from '@ledgerhq/currencies'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import find from 'lodash/find' import find from 'lodash/find'
import first from 'lodash/first' import first from 'lodash/first'
import isUndefined from 'lodash/isUndefined' import isUndefined from 'lodash/isUndefined'
import last from 'lodash/last' import last from 'lodash/last'
import type { Account } from 'types/common'
type DateInterval = { type DateInterval = {
start: string, start: string,
end: string, end: string,

11
src/helpers/btc.js

@ -2,13 +2,12 @@
import ledger from 'ledger-test-library' import ledger from 'ledger-test-library'
import bitcoin from 'bitcoinjs-lib' import bitcoin from 'bitcoinjs-lib'
import type { Operation } from '@ledgerhq/wallet-common/lib/types'
import groupBy from 'lodash/groupBy' import groupBy from 'lodash/groupBy'
import noop from 'lodash/noop' import noop from 'lodash/noop'
import uniqBy from 'lodash/uniqBy' import uniqBy from 'lodash/uniqBy'
import type { Operation } from 'types/common'
const GAP_LIMIT_ADDRESSES = 20 const GAP_LIMIT_ADDRESSES = 20
export const networks = [ export const networks = [
@ -31,21 +30,25 @@ export function computeOperation(addresses: Array<string>) {
.filter(i => addresses.includes(i.address)) .filter(i => addresses.includes(i.address))
.reduce((acc, cur) => acc + cur.value, 0) .reduce((acc, cur) => acc + cur.value, 0)
const amount = outputVal - inputVal const amount = outputVal - inputVal
console.warn('assiging a fake account id and blockHeight to operation')
return { return {
id: t.hash, id: t.hash,
hash: t.hash,
address: t.amount > 0 ? t.inputs[0].address : t.outputs[0].address, address: t.amount > 0 ? t.inputs[0].address : t.outputs[0].address,
from: t.inputs.map(t => t.address), from: t.inputs.map(t => t.address),
to: t.outputs.map(t => t.address), to: t.outputs.map(t => t.address),
amount, amount,
confirmations: t.confirmations, confirmations: t.confirmations,
receivedAt: t.received_at, date: t.received_at,
accountId: 'abcd',
blockHeight: 0,
} }
} }
} }
export function getBalanceByDay(operations: Operation[]) { export function getBalanceByDay(operations: Operation[]) {
const txsByDate = groupBy(operations, tx => { const txsByDate = groupBy(operations, tx => {
const [date] = new Date(tx.receivedAt).toISOString().split('T') const [date] = new Date(tx.date).toISOString().split('T')
return date return date
}) })

16
src/reducers/accounts.js

@ -5,38 +5,29 @@ import { handleActions } from 'redux-actions'
import every from 'lodash/every' import every from 'lodash/every'
import get from 'lodash/get' import get from 'lodash/get'
import reduce from 'lodash/reduce' import reduce from 'lodash/reduce'
import defaultsDeep from 'lodash/defaultsDeep' import type { Account, AccountRaw } from '@ledgerhq/wallet-common/lib/types'
import { getDefaultUnitByCoinType, getCurrencyByCoinType } from '@ledgerhq/currencies' import { getDefaultUnitByCoinType, getCurrencyByCoinType } from '@ledgerhq/currencies'
import type { State } from 'reducers' import type { State } from 'reducers'
import type { Account } from 'types/common'
export type AccountsState = Account[] export type AccountsState = Account[]
const state: AccountsState = [] const state: AccountsState = []
function orderAccountsOperations(account: Account) { function orderAccountsOperations(account: Account) {
const { operations } = account const { operations } = account
operations.sort((a, b) => new Date(b.receivedAt) - new Date(a.receivedAt)) operations.sort((a, b) => new Date(b.date) - new Date(a.date))
return { return {
...account, ...account,
operations, operations,
} }
} }
function applyDefaults(account) {
return defaultsDeep(account, {
settings: {
minConfirmations: 2,
},
})
}
const handlers: Object = { const handlers: Object = {
SET_ACCOUNTS: ( SET_ACCOUNTS: (
state: AccountsState, state: AccountsState,
{ payload: accounts }: { payload: Account[] }, { payload: accounts }: { payload: Account[] },
): AccountsState => accounts.map(applyDefaults), ): AccountsState => accounts,
ADD_ACCOUNT: ( ADD_ACCOUNT: (
state: AccountsState, state: AccountsState,
@ -120,7 +111,6 @@ export function deserializeAccounts(accounts: Account[]) {
operations: account.operations, operations: account.operations,
path: account.path, path: account.path,
rootPath: account.rootPath, rootPath: account.rootPath,
settings: account.settings,
unit: account.unit, unit: account.unit,
})) }))
} }

3
src/renderer/events.js

@ -4,8 +4,7 @@ import { ipcRenderer } from 'electron'
import objectPath from 'object-path' import objectPath from 'object-path'
import debug from 'debug' import debug from 'debug'
import { getDefaultUnitByCoinType } from '@ledgerhq/currencies' import { getDefaultUnitByCoinType } from '@ledgerhq/currencies'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { Account } from 'types/common'
import { CHECK_UPDATE_DELAY, SYNC_ACCOUNT_DELAY, SYNC_COUNTER_VALUES_DELAY } from 'config/constants' import { CHECK_UPDATE_DELAY, SYNC_ACCOUNT_DELAY, SYNC_COUNTER_VALUES_DELAY } from 'config/constants'

42
src/types/common.js

@ -1,7 +1,5 @@
// @flow // @flow
import type { Unit, Currency } from '@ledgerhq/currencies'
export type Device = { export type Device = {
vendorId: string, vendorId: string,
productId: string, productId: string,
@ -10,43 +8,6 @@ export type Device = {
export type Devices = Array<Device> export type Devices = Array<Device>
// -------------------- Operations
export type Operation = {
id: string,
account?: Account,
address: string,
from: Array<string>,
to: Array<string>,
amount: number,
receivedAt: string,
confirmations: number,
}
// -------------------- Accounts
export type AccountSettings = {
minConfirmations: number,
}
export type Account = {
address: string,
addresses: Array<string>,
archived?: boolean,
balance: number,
balanceByDay: Object,
coinType: number,
currency: Currency,
id: string,
index: number,
name: string,
path: string,
rootPath: string,
operations: Operation[],
unit: Unit,
settings: AccountSettings,
}
// -------------------- Settings // -------------------- Settings
export type SettingsProfile = { export type SettingsProfile = {
@ -55,12 +16,15 @@ export type SettingsProfile = {
value: string, value: string,
}, },
} }
export type SettingsDisplay = { export type SettingsDisplay = {
language: string, language: string,
} }
export type SettingsMoney = { export type SettingsMoney = {
counterValue: string, counterValue: string,
} }
export type Settings = SettingsProfile & SettingsDisplay & SettingsMoney export type Settings = SettingsProfile & SettingsDisplay & SettingsMoney
export type T = (string, ?Object) => string export type T = (string, ?Object) => string

3
yarn.lock

@ -7969,9 +7969,6 @@ ledger-test-library@KhalilBellakrid/ledger-test-library-nodejs#7d37482:
dependencies: dependencies:
axios "^0.17.1" axios "^0.17.1"
bindings "^1.3.0" bindings "^1.3.0"
electron "^1.8.2"
electron-builder "^20.0.4"
electron-rebuild "^1.7.3"
nan "^2.6.2" nan "^2.6.2"
prebuild-install "^2.2.2" prebuild-install "^2.2.2"

Loading…
Cancel
Save