From 60d378a2a7f8a5d615492d0e6b0c76c6927fcaba Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 7 Feb 2018 17:56:48 +0100 Subject: [PATCH] Ability to restore an archived account --- src/components/base/CheckBox/index.js | 3 +- .../modals/AddAccount/RestoreAccounts.js | 35 +++++++++++++++++++ src/components/modals/AddAccount/index.js | 18 +++++++--- src/reducers/accounts.js | 4 +++ 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 src/components/modals/AddAccount/RestoreAccounts.js diff --git a/src/components/base/CheckBox/index.js b/src/components/base/CheckBox/index.js index c2c7ed46..966b1be5 100644 --- a/src/components/base/CheckBox/index.js +++ b/src/components/base/CheckBox/index.js @@ -1,6 +1,7 @@ // @flow import React from 'react' +import noop from 'lodash/noop' import styled, { keyframes } from 'styled-components' import { Tabbable } from 'components/base/Box' @@ -60,7 +61,7 @@ function CheckBox(props: Props) { } CheckBox.defaultProps = { - onChange: null, + onChange: noop, } export default CheckBox diff --git a/src/components/modals/AddAccount/RestoreAccounts.js b/src/components/modals/AddAccount/RestoreAccounts.js new file mode 100644 index 00000000..1a81a11f --- /dev/null +++ b/src/components/modals/AddAccount/RestoreAccounts.js @@ -0,0 +1,35 @@ +// @flow + +import React from 'react' + +import Box from 'components/base/Box' +import Button from 'components/base/Button' +import Text from 'components/base/Text' + +import type { Accounts } from 'types/common' + +type Props = { + archivedAccounts: Accounts, + updateAccount: Function, +} + +function RestoreAccounts(props: Props) { + const { archivedAccounts, updateAccount } = props + return ( + + + {'Restore account'} + + {archivedAccounts.map(account => ( + + {account.name} + + + ))} + + ) +} + +export default RestoreAccounts diff --git a/src/components/modals/AddAccount/index.js b/src/components/modals/AddAccount/index.js index 1c75ddd2..01096df3 100644 --- a/src/components/modals/AddAccount/index.js +++ b/src/components/modals/AddAccount/index.js @@ -13,11 +13,11 @@ import type { MapStateToProps } from 'react-redux' import type { Accounts, Device, T } from 'types/common' import { closeModal } from 'reducers/modals' -import { canCreateAccount, getAccounts } from 'reducers/accounts' +import { canCreateAccount, getAccounts, getArchivedAccounts } from 'reducers/accounts' import { getCurrentDevice } from 'reducers/devices' import { sendEvent } from 'renderer/events' -import { addAccount } from 'actions/accounts' +import { addAccount, updateAccount } from 'actions/accounts' import Box from 'components/base/Box' import Text from 'components/base/Text' @@ -28,6 +28,7 @@ import Select from 'components/base/Select' import CreateAccount from './CreateAccount' import ImportAccounts from './ImportAccounts' +import RestoreAccounts from './RestoreAccounts' const currencies = [ { @@ -75,7 +76,7 @@ const Steps = { ), listAccounts: (props: Object) => { - const { accounts } = props + const { accounts, archivedAccounts } = props const emptyAccounts = accounts.filter(account => account.transactions.length === 0) const existingAccounts = accounts.filter(account => account.transactions.length > 0) const canCreateAccount = props.canCreateAccount && emptyAccounts.length === 1 @@ -83,6 +84,7 @@ const Steps = { return ( + {!!archivedAccounts.length && } {canCreateAccount ? ( ) : ( @@ -102,7 +104,9 @@ type Step = 'chooseWallet' | 'connectDevice' | 'inProgress' | 'listAccounts' type Props = { t: T, accounts: Accounts, + archivedAccounts: Accounts, addAccount: Function, + updateAccount: Function, canCreateAccount: boolean, closeModal: Function, currentDevice: Device | null, @@ -117,12 +121,14 @@ type State = { const mapStateToProps: MapStateToProps<*, *, *> = state => ({ accounts: getAccounts(state), + archivedAccounts: getArchivedAccounts(state), canCreateAccount: canCreateAccount(state), currentDevice: getCurrentDevice(state), }) const mapDispatchToProps = { addAccount, + updateAccount, closeModal, } @@ -132,7 +138,7 @@ const defaultState = { }, accounts: [], progress: null, - step: 'chooseWallet', + step: 'listAccounts', } class AddAccountModal extends PureComponent { @@ -184,7 +190,7 @@ class AddAccountModal extends PureComponent { } getStepProps() { - const { currentDevice, canCreateAccount, t } = this.props + const { currentDevice, archivedAccounts, canCreateAccount, updateAccount, t } = this.props const { inputValue, step, progress, accounts } = this.state const props = (predicate, props) => (predicate ? props : {}) @@ -208,7 +214,9 @@ class AddAccountModal extends PureComponent { ...props(step === 'listAccounts', { t, accounts, + archivedAccounts, canCreateAccount, + updateAccount, onAddAccount: this.handleAddAccount, onImportAccounts: this.handleImportAccounts, }), diff --git a/src/reducers/accounts.js b/src/reducers/accounts.js index d21c7bd8..9ef973b7 100644 --- a/src/reducers/accounts.js +++ b/src/reducers/accounts.js @@ -110,6 +110,10 @@ export function getAccounts(state: { accounts: AccountsState }): Array return state.accounts } +export function getArchivedAccounts(state: { accounts: AccountsState }): Array { + return state.accounts.filter(acc => acc.archived === true) +} + export function getVisibleAccounts(state: { accounts: AccountsState }): Array { return getAccounts(state).filter(account => account.archived !== true) }