Browse Source

Ability to restore an archived account

master
meriadec 7 years ago
parent
commit
60d378a2a7
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 3
      src/components/base/CheckBox/index.js
  2. 35
      src/components/modals/AddAccount/RestoreAccounts.js
  3. 18
      src/components/modals/AddAccount/index.js
  4. 4
      src/reducers/accounts.js

3
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

35
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 (
<Box borderWidth={1} borderColor="grenade">
<Text fontSize={3} fontWeight="bold">
{'Restore account'}
</Text>
{archivedAccounts.map(account => (
<Box key={account.id} horizontal flow={2} align="center">
<Text>{account.name}</Text>
<Button primary onClick={() => updateAccount({ ...account, archived: false })}>
{'restore'}
</Button>
</Box>
))}
</Box>
)
}
export default RestoreAccounts

18
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 = {
</Box>
),
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 (
<Box flow={10}>
<ImportAccounts {...props} accounts={existingAccounts} />
{!!archivedAccounts.length && <RestoreAccounts {...props} accounts={archivedAccounts} />}
{canCreateAccount ? (
<CreateAccount {...props} account={newAccount} />
) : (
@ -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<Props, State> {
@ -184,7 +190,7 @@ class AddAccountModal extends PureComponent<Props, State> {
}
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, State> {
...props(step === 'listAccounts', {
t,
accounts,
archivedAccounts,
canCreateAccount,
updateAccount,
onAddAccount: this.handleAddAccount,
onImportAccounts: this.handleImportAccounts,
}),

4
src/reducers/accounts.js

@ -110,6 +110,10 @@ export function getAccounts(state: { accounts: AccountsState }): Array<Account>
return state.accounts
}
export function getArchivedAccounts(state: { accounts: AccountsState }): Array<Account> {
return state.accounts.filter(acc => acc.archived === true)
}
export function getVisibleAccounts(state: { accounts: AccountsState }): Array<Account> {
return getAccounts(state).filter(account => account.archived !== true)
}

Loading…
Cancel
Save