Browse Source

Fix import in internal

master
Loëck Vézien 7 years ago
parent
commit
f1c13bf3b3
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 44
      src/helpers/db.js
  2. 2
      src/internals/usb/wallet/accounts.js
  3. 42
      src/reducers/accounts.js

44
src/helpers/db.js

@ -4,9 +4,7 @@ import Store from 'electron-store'
import set from 'lodash/set'
import get from 'lodash/get'
import { getDefaultUnitByCoinType, getCurrencyByCoinType } from '@ledgerhq/currencies'
import type { Accounts } from 'types/common'
import { serializeAccounts, deserializeAccounts } from 'reducers/accounts'
type DBKey = 'settings' | 'accounts'
@ -25,46 +23,6 @@ export function setEncryptionKey(key: DBKey, value?: string) {
encryptionKey[key] = value
}
export function serializeAccounts(accounts: Array<Object>) {
return accounts.map((account, key) => {
const a = {
id: account.id,
address: account.address,
addresses: account.addresses,
balance: account.balance,
coinType: account.coinType,
currency: getCurrencyByCoinType(account.coinType),
index: account.index,
name: account.name || `${key}`,
path: account.path,
unit: account.unit || getDefaultUnitByCoinType(account.coinType),
}
return {
...a,
transactions: account.transactions.map(t => ({
...t,
account: a,
})),
}
})
}
export function deserializeAccounts(accounts: Accounts) {
return accounts.map(account => ({
id: account.id,
address: account.address,
addresses: account.addresses,
balance: account.balance,
coinType: account.coinType,
index: account.index,
name: account.name,
path: account.path,
transactions: account.transactions.map(({ account, ...t }) => t),
unit: account.unit,
}))
}
function middleware(type, key, data: any) {
if (key === 'accounts') {
if (type === 'get') {

2
src/internals/usb/wallet/accounts.js

@ -7,7 +7,7 @@ import bs58check from 'bs58check'
import Btc from '@ledgerhq/hw-app-btc'
import { getAccount, getHDNode, networks } from 'helpers/btc'
import { serializeAccounts } from 'helpers/db'
import { serializeAccounts } from 'reducers/accounts'
type CoinType = 0 | 1

42
src/reducers/accounts.js

@ -6,6 +6,8 @@ import every from 'lodash/every'
import get from 'lodash/get'
import reduce from 'lodash/reduce'
import { getDefaultUnitByCoinType, getCurrencyByCoinType } from '@ledgerhq/currencies'
import type { State } from 'reducers'
import type { Account, Accounts } from 'types/common'
@ -96,4 +98,44 @@ export function canCreateAccount(state: State): boolean {
return every(getAccounts(state), a => get(a, 'transactions.length', 0) > 0)
}
export function serializeAccounts(accounts: Array<Object>) {
return accounts.map((account, key) => {
const a = {
id: account.id,
address: account.address,
addresses: account.addresses,
balance: account.balance,
coinType: account.coinType,
currency: getCurrencyByCoinType(account.coinType),
index: account.index,
name: account.name || `${key}`,
path: account.path,
unit: account.unit || getDefaultUnitByCoinType(account.coinType),
}
return {
...a,
transactions: account.transactions.map(t => ({
...t,
account: a,
})),
}
})
}
export function deserializeAccounts(accounts: Accounts) {
return accounts.map(account => ({
id: account.id,
address: account.address,
addresses: account.addresses,
balance: account.balance,
coinType: account.coinType,
index: account.index,
name: account.name,
path: account.path,
transactions: account.transactions.map(({ account, ...t }) => t),
unit: account.unit,
}))
}
export default handleActions(handlers, state)

Loading…
Cancel
Save