From af916ce6e7ec63ca806d96e6c2fa9f6323b21e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Sat, 2 Jun 2018 16:19:24 +0200 Subject: [PATCH] remove archived flag. future impl will differ --- package.json | 2 +- src/bridge/EthereumJSBridge.js | 2 -- src/bridge/RippleJSBridge.js | 1 - src/bridge/makeMockBridge.js | 1 - src/components/AccountPage/index.js | 4 +-- src/components/DashboardPage/index.js | 11 ++++---- src/components/QRCodeExporter.js | 4 +-- src/components/SelectAccount/index.js | 7 +++-- src/components/SideBar/index.js | 6 ++-- src/components/modals/ImportAccounts/index.js | 9 +++--- src/components/modals/Send/SendModalBody.js | 4 +-- src/reducers/accounts.js | 28 +------------------ src/reducers/bridgeSync.js | 4 +-- yarn.lock | 6 ++-- 14 files changed, 31 insertions(+), 58 deletions(-) diff --git a/package.json b/package.json index c5e620f1..d445f66c 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@ledgerhq/hw-transport": "^4.12.0", "@ledgerhq/hw-transport-node-hid": "^4.12.0", "@ledgerhq/ledger-core": "1.4.1", - "@ledgerhq/live-common": "2.23.0", + "@ledgerhq/live-common": "2.24.0", "axios": "^0.18.0", "babel-runtime": "^6.26.0", "bcryptjs": "^2.4.3", diff --git a/src/bridge/EthereumJSBridge.js b/src/bridge/EthereumJSBridge.js index 634b73ab..e8dba565 100644 --- a/src/bridge/EthereumJSBridge.js +++ b/src/bridge/EthereumJSBridge.js @@ -146,7 +146,6 @@ const EthereumBridge: WalletBridge = { name: 'New Account', balance, blockHeight: currentBlock.height, - archived: false, index, currency, operations: [], @@ -171,7 +170,6 @@ const EthereumBridge: WalletBridge = { name: address.slice(32), balance, blockHeight: currentBlock.height, - archived: false, index, currency, operations: [], diff --git a/src/bridge/RippleJSBridge.js b/src/bridge/RippleJSBridge.js index 131d764b..5c98e0ce 100644 --- a/src/bridge/RippleJSBridge.js +++ b/src/bridge/RippleJSBridge.js @@ -254,7 +254,6 @@ const RippleJSBridge: WalletBridge = { operations: [], pendingOperations: [], unit: currency.units[0], - archived: false, lastSyncDate: new Date(), } account.operations = transactions.map(txToOperation(account)) diff --git a/src/bridge/makeMockBridge.js b/src/bridge/makeMockBridge.js index af28a275..eb41396d 100644 --- a/src/bridge/makeMockBridge.js +++ b/src/bridge/makeMockBridge.js @@ -91,7 +91,6 @@ function makeMockBridge(opts?: Opts): WalletBridge<*> { currency, }) account.unit = currency.units[0] - account.archived = false if (!unsubscribed) next(account) } if (!unsubscribed) complete() diff --git a/src/components/AccountPage/index.js b/src/components/AccountPage/index.js index ac2965c7..a57f54e6 100644 --- a/src/components/AccountPage/index.js +++ b/src/components/AccountPage/index.js @@ -14,7 +14,7 @@ import type { T } from 'types/common' import { darken } from 'styles/helpers' -import { getAccountById } from 'reducers/accounts' +import { accountSelector } from 'reducers/accounts' import { counterValueCurrencySelector, localeSelector } from 'reducers/settings' import { openModal } from 'reducers/modals' @@ -50,7 +50,7 @@ const ButtonSettings = styled(Button).attrs({ ` const mapStateToProps = (state, props) => ({ - account: getAccountById(state, props.match.params.id), + account: accountSelector(state, { accountId: props.match.params.id }), counterValue: counterValueCurrencySelector(state), settings: localeSelector(state), }) diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index fc7b970c..00ecfead 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -6,13 +6,14 @@ import { translate } from 'react-i18next' import { connect } from 'react-redux' import { push } from 'react-router-redux' import chunk from 'lodash/chunk' +import { createStructuredSelector } from 'reselect' import type { Account, Currency } from '@ledgerhq/live-common/lib/types' import type { T } from 'types/common' import { colors } from 'styles/theme' -import { getVisibleAccounts } from 'reducers/accounts' +import { accountsSelector } from 'reducers/accounts' import { counterValueCurrencySelector, localeSelector } from 'reducers/settings' import { updateOrderAccounts } from 'actions/accounts' @@ -30,10 +31,10 @@ import AccountCard from './AccountCard' import AccountsOrder from './AccountsOrder' import EmptyState from './EmptyState' -const mapStateToProps = state => ({ - accounts: getVisibleAccounts(state), - counterValue: counterValueCurrencySelector(state), - locale: localeSelector(state), +const mapStateToProps = createStructuredSelector({ + accounts: accountsSelector, + counterValue: counterValueCurrencySelector, + locale: localeSelector, }) const mapDispatchToProps = { diff --git a/src/components/QRCodeExporter.js b/src/components/QRCodeExporter.js index 3a4a3510..2fc2d14e 100644 --- a/src/components/QRCodeExporter.js +++ b/src/components/QRCodeExporter.js @@ -4,7 +4,7 @@ import React, { PureComponent } from 'react' import { connect } from 'react-redux' import type { State } from 'reducers' -import { getVisibleAccounts } from 'reducers/accounts' +import { accountsSelector } from 'reducers/accounts' import QRCode from './base/QRCode' // encode the app state to export into an array of chunks for the mobile app to understand. @@ -15,7 +15,7 @@ function makeChunks(state: State): Array { const desktopVersion = __APP_VERSION__ const data = [ ['meta', chunksFormatVersion, 'desktop', desktopVersion], - ...getVisibleAccounts(state).map(account => [ + ...accountsSelector(state).map(account => [ 'account', account.id, account.name, diff --git a/src/components/SelectAccount/index.js b/src/components/SelectAccount/index.js index 37bb60b3..28584255 100644 --- a/src/components/SelectAccount/index.js +++ b/src/components/SelectAccount/index.js @@ -4,20 +4,21 @@ import React from 'react' import { connect } from 'react-redux' import { translate } from 'react-i18next' import { getCryptoCurrencyIcon } from '@ledgerhq/live-common/lib/react' +import { createStructuredSelector } from 'reselect' import type { Account } from '@ledgerhq/live-common/lib/types' import type { T } from 'types/common' import type { Option } from 'components/base/Select' -import { getVisibleAccounts } from 'reducers/accounts' +import { accountsSelector } from 'reducers/accounts' import Select from 'components/base/Select' import FormattedVal from 'components/base/FormattedVal' import Box from 'components/base/Box' import Text from 'components/base/Text' -const mapStateToProps = state => ({ - accounts: getVisibleAccounts(state), +const mapStateToProps = createStructuredSelector({ + accounts: accountsSelector, }) const renderOption = a => { diff --git a/src/components/SideBar/index.js b/src/components/SideBar/index.js index 34a6e2a3..cbc64845 100644 --- a/src/components/SideBar/index.js +++ b/src/components/SideBar/index.js @@ -13,7 +13,7 @@ import { MODAL_SEND, MODAL_RECEIVE } from 'config/constants' import type { T } from 'types/common' import { openModal } from 'reducers/modals' -import { getVisibleAccounts } from 'reducers/accounts' +import { accountsSelector } from 'reducers/accounts' import { getUpdateStatus } from 'reducers/update' import type { UpdateStatus } from 'reducers/update' @@ -62,7 +62,7 @@ type Props = { } const mapStateToProps = state => ({ - accounts: getVisibleAccounts(state), + accounts: accountsSelector(state), updateStatus: getUpdateStatus(state), }) @@ -125,7 +125,7 @@ class SideBar extends PureComponent { } const AccountsList = connect(state => ({ - accounts: getVisibleAccounts(state), + accounts: accountsSelector(state), }))(({ accounts }: { accounts: Account[] }) => ( {accounts.map(account => { diff --git a/src/components/modals/ImportAccounts/index.js b/src/components/modals/ImportAccounts/index.js index e680a571..0774bc6f 100644 --- a/src/components/modals/ImportAccounts/index.js +++ b/src/components/modals/ImportAccounts/index.js @@ -4,13 +4,14 @@ import React, { PureComponent } from 'react' import { compose } from 'redux' import { connect } from 'react-redux' import { translate } from 'react-i18next' +import { createStructuredSelector } from 'reselect' import type { Currency, Account } from '@ledgerhq/live-common/lib/types' import type { T, Device } from 'types/common' import { getCurrentDevice } from 'reducers/devices' -import { getAccounts } from 'reducers/accounts' +import { accountsSelector } from 'reducers/accounts' import { addAccount } from 'actions/accounts' import { closeModal } from 'reducers/modals' @@ -100,9 +101,9 @@ export type StepProps = { err: ?Error, } -const mapStateToProps = state => ({ - currentDevice: getCurrentDevice(state), - existingAccounts: getAccounts(state), +const mapStateToProps = createStructuredSelector({ + currentDevice: getCurrentDevice, + existingAccounts: accountsSelector, }) const mapDispatchToProps = { diff --git a/src/components/modals/Send/SendModalBody.js b/src/components/modals/Send/SendModalBody.js index 567a207f..7620f454 100644 --- a/src/components/modals/Send/SendModalBody.js +++ b/src/components/modals/Send/SendModalBody.js @@ -11,7 +11,7 @@ import type { T, Device } from 'types/common' import type { WalletBridge } from 'bridge/types' import { getBridgeForCurrency } from 'bridge' -import { getVisibleAccounts } from 'reducers/accounts' +import { accountsSelector } from 'reducers/accounts' import { updateAccountWithUpdater } from 'actions/accounts' import Breadcrumb from 'components/Breadcrumb' @@ -53,7 +53,7 @@ type Step = { } const mapStateToProps = createStructuredSelector({ - accounts: getVisibleAccounts, + accounts: accountsSelector, }) const mapDispatchToProps = { diff --git a/src/reducers/accounts.js b/src/reducers/accounts.js index d30e644b..5e12bd16 100644 --- a/src/reducers/accounts.js +++ b/src/reducers/accounts.js @@ -51,15 +51,7 @@ export function accountsSelector(state: { accounts: AccountsState }): Account[] return state.accounts } -export const archivedAccountsSelector = createSelector(accountsSelector, accounts => - accounts.filter(acc => acc.archived), -) - -export const visibleAccountsSelector = createSelector(accountsSelector, accounts => - accounts.filter(acc => !acc.archived), -) - -export const currenciesSelector = createSelector(visibleAccountsSelector, accounts => +export const currenciesSelector = createSelector(accountsSelector, accounts => [...new Set(accounts.map(a => a.currency))].sort((a, b) => a.name.localeCompare(b.name)), ) @@ -69,24 +61,6 @@ export const accountSelector = createSelector( (accounts, accountId) => accounts.find(a => a.id === accountId), ) -// TODO remove deprecated selectors - -export function getAccounts(state: { accounts: AccountsState }): Account[] { - return state.accounts -} - -export function getArchivedAccounts(state: { accounts: AccountsState }): Account[] { - return state.accounts.filter(acc => acc.archived === true) -} - -export function getVisibleAccounts(state: { accounts: AccountsState }): Account[] { - return getAccounts(state).filter(account => account.archived !== true) -} - -export function getAccountById(state: { accounts: AccountsState }, id: string): ?Account { - return getAccounts(state).find(account => account.id === id) -} - export function decodeAccount(account: AccountRaw): Account { return accountModel.decode({ data: account, diff --git a/src/reducers/bridgeSync.js b/src/reducers/bridgeSync.js index 66468a63..8f32aedd 100644 --- a/src/reducers/bridgeSync.js +++ b/src/reducers/bridgeSync.js @@ -3,7 +3,7 @@ import { createSelector } from 'reselect' import { handleActions } from 'redux-actions' import type { State } from 'reducers' -import { getAccounts } from './accounts' +import { accountsSelector } from './accounts' export type AsyncState = { pending: boolean, @@ -62,7 +62,7 @@ export const pullMoreStateLocalSelector = ( ) => bridgeSync.pullMores[accountId] || nothingState export const globalSyncStateSelector = createSelector( - getAccounts, + accountsSelector, bridgeSyncSelector, (accounts, bridgeSync) => { const globalSyncState: AsyncState = { diff --git a/yarn.lock b/yarn.lock index 39061848..d0e3b30c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1495,9 +1495,9 @@ npm "^5.7.1" prebuild-install "^2.2.2" -"@ledgerhq/live-common@2.23.0": - version "2.23.0" - resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.23.0.tgz#c039bbb444ceb909fa9c7f17645c39d9c3ce125e" +"@ledgerhq/live-common@2.24.0": + version "2.24.0" + resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.24.0.tgz#0b2f3e5856708b86e0d42e248aab2721d900f42d" dependencies: axios "^0.18.0" invariant "^2.2.2"