Browse Source

Merge pull request #250 from meriadec/common-attempt-2

Use types, decode, encode from wallet-common
master
Loëck Vézien 7 years ago
committed by GitHub
parent
commit
64e0e8e66c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      package.json
  2. 7
      src/actions/accounts.js
  3. 2
      src/components/AccountPage/AccountHeader.js
  4. 3
      src/components/AccountPage/index.js
  5. 4
      src/components/BalanceSummary/index.js
  6. 3
      src/components/CalculateBalance.js
  7. 3
      src/components/DashboardPage/AccountCard.js
  8. 5
      src/components/DashboardPage/index.js
  9. 3
      src/components/DeviceMonit/index.js
  10. 3
      src/components/IsUnlocked.js
  11. 34
      src/components/OperationsList/index.js
  12. 12
      src/components/OperationsList/stories.js
  13. 3
      src/components/ReceiveBox.js
  14. 3
      src/components/RequestAmount/index.js
  15. 3
      src/components/SelectAccount/index.js
  16. 3
      src/components/SideBar/index.js
  17. 3
      src/components/modals/AddAccount/ImportAccounts.js
  18. 3
      src/components/modals/AddAccount/RestoreAccounts.js
  19. 17
      src/components/modals/AddAccount/index.js
  20. 8
      src/components/modals/OperationDetails.js
  21. 3
      src/components/modals/Receive/index.js
  22. 3
      src/components/modals/Send/01-step-amount.js
  23. 2
      src/components/modals/Send/02-step-connect-device.js
  24. 3
      src/components/modals/Send/Footer.js
  25. 3
      src/components/modals/Send/index.js
  26. 12
      src/components/modals/SettingsAccount.js
  27. 3
      src/helpers/balance.js
  28. 15
      src/helpers/btc.js
  29. 52
      src/reducers/accounts.js
  30. 3
      src/renderer/events.js
  31. 42
      src/types/common.js
  32. 85
      yarn.lock

1
package.json

@ -48,6 +48,7 @@
"@ledgerhq/hw-app-eth": "^4.7.3",
"@ledgerhq/hw-transport": "^4.7.3",
"@ledgerhq/hw-transport-node-hid": "^4.7.3",
"@ledgerhq/wallet-common": "^0.6.0",
"axios": "^0.18.0",
"bcryptjs": "^2.4.3",
"bitcoinjs-lib": "^3.3.2",

7
src/actions/accounts.js

@ -1,11 +1,11 @@
// @flow
import sortBy from 'lodash/sortBy'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import db from 'helpers/db'
import type { Dispatch } from 'redux'
import type { Account } from 'types/common'
import { fetchCounterValues } from 'actions/counterValues'
@ -44,10 +44,7 @@ export const updateOrderAccounts: UpdateOrderAccounts = (orderAccounts: string)
export type AddAccount = Account => (Function, Function) => void
export const addAccount: AddAccount = payload => (dispatch, getState) => {
const { settings: { counterValue, orderAccounts }, accounts } = getState()
dispatch({
type: 'ADD_ACCOUNT',
payload,
})
dispatch({ type: 'ADD_ACCOUNT', payload })
dispatch(updateOrderAccounts(orderAccounts))
// 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 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 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 { Redirect } from 'react-router'
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 type { T, Account } from 'types/common'
import type { T } from 'types/common'
import { darken } from 'styles/helpers'

4
src/components/BalanceSummary/index.js

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

3
src/components/CalculateBalance.js

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

3
src/components/DashboardPage/AccountCard.js

@ -2,8 +2,7 @@
import React from 'react'
import { getIconByCoinType } from '@ledgerhq/currencies/react'
import type { Account } from 'types/common'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import Chart from 'components/base/Chart'
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 { connect } from 'react-redux'
import { push } from 'react-router-redux'
import type { Account, Operation } from '@ledgerhq/wallet-common/lib/types'
import chunk from 'lodash/chunk'
import get from 'lodash/get'
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 { getCounterValue } from 'reducers/settings'
@ -71,7 +72,7 @@ const getAllOperations = accounts => {
return result
}, [])
return sortBy(allOperations, t => t.receivedAt)
return sortBy(allOperations, t => t.date)
.reverse()
.slice(0, ALL_OPERATIONS_LIMIT)
}

3
src/components/DeviceMonit/index.js

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

3
src/components/IsUnlocked.js

@ -5,8 +5,9 @@ import { connect } from 'react-redux'
import { compose } from 'redux'
import { translate } from 'react-i18next'
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'

34
src/components/OperationsList/index.js

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

12
src/components/OperationsList/stories.js

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

3
src/components/ReceiveBox.js

@ -4,8 +4,9 @@ import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import styled from 'styled-components'
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 { 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 { connect } from 'react-redux'
import { getDefaultUnitByCoinType, getFiatUnit } from '@ledgerhq/currencies'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import isNaN from 'lodash/isNaN'
import noop from 'lodash/noop'
import type { T, Account } from 'types/common'
import type { T } from 'types/common'
import { getCounterValue } from 'reducers/settings'
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 noop from 'lodash/noop'
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'

3
src/components/SideBar/index.js

@ -6,10 +6,11 @@ import { translate } from 'react-i18next'
import styled from 'styled-components'
import { connect } from 'react-redux'
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 type { Account, T } from 'types/common'
import type { T } from 'types/common'
import { openModal } from 'reducers/modals'
import { getVisibleAccounts } from 'reducers/accounts'

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

@ -2,8 +2,9 @@
import React, { PureComponent } from 'react'
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 Button from 'components/base/Button'

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

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

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

@ -7,12 +7,13 @@ import { translate } from 'react-i18next'
import { ipcRenderer } from 'electron'
import differenceBy from 'lodash/differenceBy'
import { listCurrencies, getDefaultUnitByCoinType } from '@ledgerhq/currencies'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { Currency } from '@ledgerhq/currencies'
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 { canCreateAccount, getAccounts, getArchivedAccounts } from 'reducers/accounts'
@ -269,8 +270,20 @@ class AddAccountModal extends PureComponent<Props, State> {
}
if (type === 'wallet.getAccounts.success') {
// As data is passed inside electron event system,
// dates are converted to their string equivalent
//
// so, quick & dirty way to put back Date objects
const parsedData = data.map(account => ({
...account,
operations: account.operations.map(op => ({
...op,
date: new Date(op.date),
})),
}))
this.setState({
accounts: data,
accounts: parsedData,
step: 'listAccounts',
})
}

8
src/components/modals/OperationDetails.js

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

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

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

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

@ -1,9 +1,10 @@
// @flow
import React, { Fragment } from 'react'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
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 Box from 'components/base/Box'

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

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

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

@ -1,8 +1,9 @@
// @flow
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 { 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 { translate } from 'react-i18next'
import get from 'lodash/get'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
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 { MODAL_SEND } from 'config/constants'

12
src/components/modals/SettingsAccount.js

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

3
src/helpers/balance.js

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

15
src/helpers/btc.js

@ -2,13 +2,12 @@
import ledger from 'ledger-test-library'
import bitcoin from 'bitcoinjs-lib'
import type { OperationRaw } from '@ledgerhq/wallet-common/lib/types'
import groupBy from 'lodash/groupBy'
import noop from 'lodash/noop'
import uniqBy from 'lodash/uniqBy'
import type { Operation } from 'types/common'
const GAP_LIMIT_ADDRESSES = 20
export const networks = [
@ -31,21 +30,25 @@ export function computeOperation(addresses: Array<string>) {
.filter(i => addresses.includes(i.address))
.reduce((acc, cur) => acc + cur.value, 0)
const amount = outputVal - inputVal
console.warn('assiging a fake account id and blockHeight to operation') // eslint-disable-line no-console
return {
id: t.hash,
hash: t.hash,
address: t.amount > 0 ? t.inputs[0].address : t.outputs[0].address,
from: t.inputs.map(t => t.address),
to: t.outputs.map(t => t.address),
amount,
confirmations: t.confirmations,
receivedAt: t.received_at,
date: t.received_at,
accountId: 'abcd',
blockHeight: 0,
}
}
}
export function getBalanceByDay(operations: Operation[]) {
export function getBalanceByDay(operations: OperationRaw[]) {
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
})
@ -89,7 +92,7 @@ export async function getAccount({
network: Object,
asyncDelay?: number,
onProgress?: Function,
}) {
}): Promise<any> {
const script = segwit ? parseInt(network.scriptHash, 10) : parseInt(network.pubKeyHash, 10)
let balance = 0

52
src/reducers/accounts.js

@ -1,42 +1,34 @@
// @flow
import { handleActions } from 'redux-actions'
import { createAccountModel } from '@ledgerhq/wallet-common/lib/models/account'
import every from 'lodash/every'
import get from 'lodash/get'
import reduce from 'lodash/reduce'
import defaultsDeep from 'lodash/defaultsDeep'
import { getDefaultUnitByCoinType, getCurrencyByCoinType } from '@ledgerhq/currencies'
import type { Account } from '@ledgerhq/wallet-common/lib/types'
import type { State } from 'reducers'
import type { Account } from 'types/common'
export type AccountsState = Account[]
const state: AccountsState = []
const accountModel = createAccountModel()
function orderAccountsOperations(account: Account) {
const { operations } = account
operations.sort((a, b) => new Date(b.receivedAt) - new Date(a.receivedAt))
operations.sort((a, b) => b.date - a.date)
return {
...account,
operations,
}
}
function applyDefaults(account) {
return defaultsDeep(account, {
settings: {
minConfirmations: 2,
},
})
}
const handlers: Object = {
SET_ACCOUNTS: (
state: AccountsState,
{ payload: accounts }: { payload: Account[] },
): AccountsState => accounts.map(applyDefaults),
): AccountsState => accounts,
ADD_ACCOUNT: (
state: AccountsState,
@ -98,31 +90,19 @@ export function canCreateAccount(state: State): boolean {
return every(getAccounts(state), a => get(a, 'operations.length', 0) > 0)
}
export function serializeAccounts(accounts: Array<Object>) {
return accounts.map((account, key) => ({
...account,
currency: getCurrencyByCoinType(account.coinType),
name: account.name || `${key}`,
unit: account.unit || getDefaultUnitByCoinType(account.coinType),
}))
// Yeah. `any` should be `AccountRaw[]` but it can also be a map
// of wrapped accounts. And as flow is apparently incapable of doing
// such a simple thing, let's put any, right? I don't care.
export function serializeAccounts(accounts: any): Account[] {
// ensure that accounts are always wrapped in data key
if (accounts.length && !accounts[0].data) {
accounts = accounts.map(account => ({ data: account }))
}
return accounts.map(accountModel.decode)
}
export function deserializeAccounts(accounts: Account[]) {
return accounts.map(account => ({
id: account.id,
address: account.address,
addresses: account.addresses,
balance: account.balance,
balanceByDay: account.balanceByDay,
coinType: account.coinType,
index: account.index,
name: account.name,
operations: account.operations,
path: account.path,
rootPath: account.rootPath,
settings: account.settings,
unit: account.unit,
}))
return accounts.map(accountModel.encode)
}
export default handleActions(handlers, state)

3
src/renderer/events.js

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

42
src/types/common.js

@ -1,7 +1,5 @@
// @flow
import type { Unit, Currency } from '@ledgerhq/currencies'
export type Device = {
vendorId: string,
productId: string,
@ -10,43 +8,6 @@ export type 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
export type SettingsProfile = {
@ -55,12 +16,15 @@ export type SettingsProfile = {
value: string,
},
}
export type SettingsDisplay = {
language: string,
}
export type SettingsMoney = {
counterValue: string,
}
export type Settings = SettingsProfile & SettingsDisplay & SettingsMoney
export type T = (string, ?Object) => string

85
yarn.lock

@ -913,7 +913,7 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"
"@ledgerhq/currencies@^4.7.3":
"@ledgerhq/currencies@^4.7.1", "@ledgerhq/currencies@^4.7.3":
version "4.7.3"
resolved "https://registry.yarnpkg.com/@ledgerhq/currencies/-/currencies-4.7.3.tgz#0e28c0f1c74cf00b990be6865fbec374f808b71f"
dependencies:
@ -947,6 +947,19 @@
dependencies:
events "^2.0.0"
"@ledgerhq/wallet-common@^0.6.0":
version "0.6.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/wallet-common/-/wallet-common-0.6.0.tgz#e6a77fada1e3eaef4d6e59f3ea5cebaf0a276a63"
dependencies:
"@ledgerhq/currencies" "^4.7.1"
axios "^0.18.0"
babel-jest "^23.0.0-alpha.0"
invariant "^2.2.2"
lodash "^4.17.4"
prando "^3.0.1"
react "^16.0.0"
timemachine "^0.3.0"
"@posthtml/esm@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@posthtml/esm/-/esm-1.0.0.tgz#09bcb28a02438dcee22ad1970ca1d85a000ae0cf"
@ -1889,6 +1902,13 @@ babel-jest@^22.4.3:
babel-plugin-istanbul "^4.1.5"
babel-preset-jest "^22.4.3"
babel-jest@^23.0.0-alpha.0:
version "23.0.0-alpha.4"
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-23.0.0-alpha.4.tgz#e3bb1e486f4178b381cc7b37e6cafb1af3a9d1bf"
dependencies:
babel-plugin-istanbul "^4.1.6"
babel-preset-jest "^23.0.0-alpha.4"
babel-loader@^7.1.2:
version "7.1.3"
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-7.1.3.tgz#ff5b440da716e9153abb946251a9ab7670037b16"
@ -1939,10 +1959,23 @@ babel-plugin-istanbul@^4.1.5:
istanbul-lib-instrument "^1.7.5"
test-exclude "^4.1.1"
babel-plugin-istanbul@^4.1.6:
version "4.1.6"
resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-4.1.6.tgz#36c59b2192efce81c5b378321b74175add1c9a45"
dependencies:
babel-plugin-syntax-object-rest-spread "^6.13.0"
find-up "^2.1.0"
istanbul-lib-instrument "^1.10.1"
test-exclude "^4.2.1"
babel-plugin-jest-hoist@^22.4.3:
version "22.4.3"
resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-22.4.3.tgz#7d8bcccadc2667f96a0dcc6afe1891875ee6c14a"
babel-plugin-jest-hoist@^23.0.0-alpha.4:
version "23.0.0-alpha.4"
resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-23.0.0-alpha.4.tgz#3f32715d54640e37cc62a84a9d3d7eada6a067fc"
babel-plugin-minify-builtins@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/babel-plugin-minify-builtins/-/babel-plugin-minify-builtins-0.2.0.tgz#317f824b0907210b6348671bb040ca072e2e0c82"
@ -2542,6 +2575,13 @@ babel-preset-jest@^22.4.3:
babel-plugin-jest-hoist "^22.4.3"
babel-plugin-syntax-object-rest-spread "^6.13.0"
babel-preset-jest@^23.0.0-alpha.4:
version "23.0.0-alpha.4"
resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-23.0.0-alpha.4.tgz#d3080507330e6d23c47dcc366d69f7a330174f70"
dependencies:
babel-plugin-jest-hoist "^23.0.0-alpha.4"
babel-plugin-syntax-object-rest-spread "^6.13.0"
babel-preset-minify@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/babel-preset-minify/-/babel-preset-minify-0.2.0.tgz#006566552d9b83834472273f306c0131062a0acc"
@ -4817,7 +4857,7 @@ electron-builder-lib@~20.6.2:
semver "^5.5.0"
temp-file "^3.1.1"
electron-builder@^20.0.4, electron-builder@^20.8.0:
electron-builder@^20.8.0:
version "20.8.0"
resolved "https://registry.yarnpkg.com/electron-builder/-/electron-builder-20.8.0.tgz#9f7067dc8a3aa9451d08e0231066556d39d0ffef"
dependencies:
@ -4997,7 +5037,7 @@ electron-webpack@^2.0.1:
webpack-merge "^4.1.2"
yargs "^11.1.0"
electron@1.8.4, electron@^1.8.2:
electron@1.8.4:
version "1.8.4"
resolved "https://registry.yarnpkg.com/electron/-/electron-1.8.4.tgz#cca8d0e6889f238f55b414ad224f03e03b226a38"
dependencies:
@ -7244,12 +7284,28 @@ istanbul-lib-coverage@^1.1.1, istanbul-lib-coverage@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-1.1.2.tgz#4113c8ff6b7a40a1ef7350b01016331f63afde14"
istanbul-lib-coverage@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-1.2.0.tgz#f7d8f2e42b97e37fe796114cb0f9d68b5e3a4341"
istanbul-lib-hook@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/istanbul-lib-hook/-/istanbul-lib-hook-1.1.0.tgz#8538d970372cb3716d53e55523dd54b557a8d89b"
dependencies:
append-transform "^0.4.0"
istanbul-lib-instrument@^1.10.1:
version "1.10.1"
resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.10.1.tgz#724b4b6caceba8692d3f1f9d0727e279c401af7b"
dependencies:
babel-generator "^6.18.0"
babel-template "^6.16.0"
babel-traverse "^6.18.0"
babel-types "^6.18.0"
babylon "^6.18.0"
istanbul-lib-coverage "^1.2.0"
semver "^5.3.0"
istanbul-lib-instrument@^1.7.5, istanbul-lib-instrument@^1.8.0, istanbul-lib-instrument@^1.9.2:
version "1.9.2"
resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.9.2.tgz#84905bf47f7e0b401d6b840da7bad67086b4aab6"
@ -7969,9 +8025,6 @@ ledger-test-library@KhalilBellakrid/ledger-test-library-nodejs#7d37482:
dependencies:
axios "^0.17.1"
bindings "^1.3.0"
electron "^1.8.2"
electron-builder "^20.0.4"
electron-rebuild "^1.7.3"
nan "^2.6.2"
prebuild-install "^2.2.2"
@ -9721,6 +9774,10 @@ posthtml@^0.11.2, posthtml@^0.11.3:
posthtml-parser "^0.3.3"
posthtml-render "^1.1.0"
prando@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/prando/-/prando-3.0.1.tgz#8fa6d856277fad738e50f3e550b702380ad52d6e"
prebuild-install@^2.2.2:
version "2.5.1"
resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-2.5.1.tgz#0f234140a73760813657c413cdccdda58296b1da"
@ -10274,7 +10331,7 @@ react-treebeard@^2.1.0:
shallowequal "^0.2.2"
velocity-react "^1.3.1"
react@^16.2.0:
react@^16.0.0, react@^16.2.0:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.2.0.tgz#a31bd2dab89bff65d42134fa187f24d054c273ba"
dependencies:
@ -11820,6 +11877,16 @@ test-exclude@^4.1.1:
read-pkg-up "^1.0.1"
require-main-filename "^1.0.1"
test-exclude@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-4.2.1.tgz#dfa222f03480bca69207ca728b37d74b45f724fa"
dependencies:
arrify "^1.0.1"
micromatch "^3.1.8"
object-assign "^4.1.0"
read-pkg-up "^1.0.1"
require-main-filename "^1.0.1"
text-table@^0.2.0, text-table@~0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
@ -11866,6 +11933,10 @@ timed-out@4.0.1, timed-out@^4.0.0, timed-out@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"
timemachine@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/timemachine/-/timemachine-0.3.0.tgz#83e2eb696cbfe4696c1708e6a3700df4e62fc525"
timers-browserify@^2.0.4:
version "2.0.6"
resolved "https://registry.yarnpkg.com/timers-browserify/-/timers-browserify-2.0.6.tgz#241e76927d9ca05f4d959819022f5b3664b64bae"

Loading…
Cancel
Save