Browse Source

Fix serialize/deserialize

master
meriadec 7 years ago
parent
commit
d37f3a8c0d
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 14
      src/components/modals/AddAccount/index.js
  2. 8
      src/reducers/accounts.js

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

@ -270,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/reducers/accounts.js

@ -90,11 +90,15 @@ export function canCreateAccount(state: State): boolean {
return every(getAccounts(state), a => get(a, 'operations.length', 0) > 0)
}
export function serializeAccounts(accounts: Account[]) {
export function serializeAccounts(accounts: AccountRaw[]): 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: AccountRaw[]) {
export function deserializeAccounts(accounts: Account[]): AccountRaw[] {
return accounts.map(accountModel.encode)
}

Loading…
Cancel
Save