From d37f3a8c0dfaee6e9cb071e541a341a3bf3d2c5c Mon Sep 17 00:00:00 2001 From: meriadec Date: Tue, 27 Mar 2018 14:08:16 +0200 Subject: [PATCH] Fix serialize/deserialize --- src/components/modals/AddAccount/index.js | 14 +++++++++++++- src/reducers/accounts.js | 8 ++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/modals/AddAccount/index.js b/src/components/modals/AddAccount/index.js index 11065cfd..5f48b22a 100644 --- a/src/components/modals/AddAccount/index.js +++ b/src/components/modals/AddAccount/index.js @@ -270,8 +270,20 @@ class AddAccountModal extends PureComponent { } 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', }) } diff --git a/src/reducers/accounts.js b/src/reducers/accounts.js index 636c3783..e49d04ba 100644 --- a/src/reducers/accounts.js +++ b/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) }