Browse Source

Simplify flow annotation for arrays

master
meriadec 7 years ago
parent
commit
787426ddac
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 4
      src/components/BalanceSummary/index.js
  2. 4
      src/components/CalculateBalance.js
  3. 6
      src/components/DashboardPage/index.js
  4. 4
      src/components/IsUnlocked.js
  5. 4
      src/components/OperationsList/index.js
  6. 4
      src/components/SelectAccount/index.js
  7. 4
      src/components/SideBar/index.js
  8. 4
      src/components/modals/AddAccount/ImportAccounts.js
  9. 4
      src/components/modals/AddAccount/RestoreAccounts.js
  10. 8
      src/components/modals/AddAccount/index.js
  11. 6
      src/helpers/balance.js
  12. 4
      src/helpers/btc.js
  13. 15
      src/reducers/accounts.js
  14. 6
      src/renderer/events.js
  15. 6
      src/types/common.js

4
src/components/BalanceSummary/index.js

@ -4,7 +4,7 @@ import React, { Fragment } from 'react'
import { getFiatUnit } from '@ledgerhq/currencies'
import type { Accounts } from 'types/common'
import type { Account } from 'types/common'
import Chart from 'components/base/NewChart'
import Box, { Card } from 'components/base/Box'
@ -15,7 +15,7 @@ type Props = {
counterValue: string,
chartColor: string,
chartId: string,
accounts: Accounts,
accounts: Account[],
selectedTime: string,
daysCount: number,
renderHeader: null | Function,

4
src/components/CalculateBalance.js

@ -3,7 +3,7 @@
import { PureComponent } from 'react'
import { connect } from 'react-redux'
import type { Accounts } from 'types/common'
import type { Account } from 'types/common'
import calculateBalance from 'helpers/balance'
@ -12,7 +12,7 @@ const mapStateToProps = state => ({
})
type Props = {
accounts: Accounts,
accounts: Account[],
counterValues: Object,
daysCount: number,
render: Function,

6
src/components/DashboardPage/index.js

@ -10,7 +10,7 @@ import chunk from 'lodash/chunk'
import get from 'lodash/get'
import sortBy from 'lodash/sortBy'
import type { Account, Accounts, Operations, T } from 'types/common'
import type { Account, Operation, T } from 'types/common'
import { getVisibleAccounts } from 'reducers/accounts'
import { getCounterValue } from 'reducers/settings'
@ -41,14 +41,14 @@ const mapDispatchToProps = {
type Props = {
t: T,
accounts: Accounts,
accounts: Account[],
push: Function,
counterValue: string,
}
type State = {
accountsChunk: Array<Array<Account | null>>,
allOperations: Operations,
allOperations: Operation[],
selectedTime: string,
daysCount: number,
}

4
src/components/IsUnlocked.js

@ -6,7 +6,7 @@ import { compose } from 'redux'
import { translate } from 'react-i18next'
import bcrypt from 'bcryptjs'
import type { Settings, Accounts, T } from 'types/common'
import type { Settings, Account, T } from 'types/common'
import get from 'lodash/get'
@ -31,7 +31,7 @@ type InputValue = {
}
type Props = {
accounts: Accounts,
accounts: Account[],
children: any,
counterValue: string,
fetchAccounts: Function,

4
src/components/OperationsList/index.js

@ -193,7 +193,7 @@ Operation.defaultProps = {
type Props = {
t: T,
onAccountClick?: Function,
operations: Array<OperationType>,
operations: OperationType[],
withAccounts?: boolean,
minConfirmations: number,
title?: string,
@ -224,7 +224,7 @@ class OperationsList extends Component<Props> {
return !isEqual(this._hashCache, this.getHashCache(nextProps.operations))
}
getHashCache = (operations: Array<OperationType>) => operations.map(t => t.hash)
getHashCache = (operations: OperationType[]) => operations.map(t => t.hash)
_hashCache = null

4
src/components/SelectAccount/index.js

@ -6,7 +6,7 @@ import { translate } from 'react-i18next'
import noop from 'lodash/noop'
import { getIconByCoinType } from '@ledgerhq/currencies/react'
import type { T, Accounts, Account } from 'types/common'
import type { T, Account } from 'types/common'
import { getVisibleAccounts } from 'reducers/accounts'
@ -42,7 +42,7 @@ const renderItem = a => {
}
type Props = {
accounts: Accounts,
accounts: Account[],
onChange?: () => Account | void,
value?: Account | null,
t: T,

4
src/components/SideBar/index.js

@ -9,7 +9,7 @@ import { getIconByCoinType } from '@ledgerhq/currencies/react'
import { MODAL_SEND, MODAL_RECEIVE, MODAL_ADD_ACCOUNT } from 'constants'
import type { Accounts, T } from 'types/common'
import type { Account, T } from 'types/common'
import { openModal } from 'reducers/modals'
import { getVisibleAccounts } from 'reducers/accounts'
@ -52,7 +52,7 @@ const PlusBtn = styled(Tabbable).attrs({
type Props = {
t: T,
accounts: Accounts,
accounts: Account[],
openModal: Function,
}

4
src/components/modals/AddAccount/ImportAccounts.js

@ -3,7 +3,7 @@
import React, { PureComponent } from 'react'
import { translate } from 'react-i18next'
import type { T, Accounts } from 'types/common'
import type { T, Account } from 'types/common'
import Box from 'components/base/Box'
import Button from 'components/base/Button'
@ -13,7 +13,7 @@ import Input from 'components/base/Input'
type Props = {
t: T,
accounts: Accounts,
accounts: Account[],
onImportAccounts: Function,
}

4
src/components/modals/AddAccount/RestoreAccounts.js

@ -7,14 +7,14 @@ import Box from 'components/base/Box'
import Button from 'components/base/Button'
import Text from 'components/base/Text'
import type { Accounts } from 'types/common'
import type { Account } from 'types/common'
const Container = styled(Box)`
border: 1px solid ${p => p.theme.colors.alertRed};
`
type Props = {
archivedAccounts: Accounts,
archivedAccounts: Account[],
updateAccount: Function,
}

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

@ -12,7 +12,7 @@ import type { Currency } from '@ledgerhq/currencies'
import { MODAL_ADD_ACCOUNT } from 'constants'
import type { Accounts, Device, T } from 'types/common'
import type { Account, Device, T } from 'types/common'
import { closeModal } from 'reducers/modals'
import { canCreateAccount, getAccounts, getArchivedAccounts } from 'reducers/accounts'
@ -117,9 +117,9 @@ const Steps = {
type Step = 'chooseCurrency' | 'connectDevice' | 'inProgress' | 'listAccounts'
type Props = {
accounts: Accounts,
accounts: Account[],
addAccount: Function,
archivedAccounts: Accounts,
archivedAccounts: Account[],
canCreateAccount: boolean,
closeModal: Function,
counterValues: Object,
@ -130,7 +130,7 @@ type Props = {
}
type State = {
accounts: Accounts,
accounts: Account[],
currency: Currency | null,
fetchingCounterValues: boolean,
progress: null | Object,

6
src/helpers/balance.js

@ -8,7 +8,7 @@ import first from 'lodash/first'
import isUndefined from 'lodash/isUndefined'
import last from 'lodash/last'
import type { Accounts, Account } from 'types/common'
import type { Account } from 'types/common'
type DateInterval = {
start: string,
@ -21,7 +21,7 @@ type BalanceHistoryDay = {
}
type CalculateBalance = {
accounts: Accounts,
accounts: Account[],
counterValue: string,
counterValues: Object,
daysCount: number,
@ -100,7 +100,7 @@ export function getBalanceHistoryForAccounts({
interval,
}: {
counterValue: string,
accounts: Accounts,
accounts: Account[],
counterValues: Object,
interval: DateInterval,
}): Array<BalanceHistoryDay> {

4
src/helpers/btc.js

@ -7,7 +7,7 @@ import groupBy from 'lodash/groupBy'
import noop from 'lodash/noop'
import uniqBy from 'lodash/uniqBy'
import type { Operations } from 'types/common'
import type { Operation } from 'types/common'
const GAP_LIMIT_ADDRESSES = 20
@ -42,7 +42,7 @@ export function computeOperation(addresses: Array<string>) {
}
}
export function getBalanceByDay(operations: Operations) {
export function getBalanceByDay(operations: Operation[]) {
const txsByDate = groupBy(operations, tx => {
const [date] = new Date(tx.receivedAt).toISOString().split('T')
return date

15
src/reducers/accounts.js

@ -10,10 +10,9 @@ import defaultsDeep from 'lodash/defaultsDeep'
import { getDefaultUnitByCoinType, getCurrencyByCoinType } from '@ledgerhq/currencies'
import type { State } from 'reducers'
import type { Account, Accounts } from 'types/common'
export type AccountsState = Accounts
import type { Account } from 'types/common'
export type AccountsState = Account[]
const state: AccountsState = []
function orderAccountsOperations(account: Account) {
@ -36,7 +35,7 @@ function applyDefaults(account) {
const handlers: Object = {
SET_ACCOUNTS: (
state: AccountsState,
{ payload: accounts }: { payload: Accounts },
{ payload: accounts }: { payload: Account[] },
): AccountsState => accounts.map(applyDefaults),
ADD_ACCOUNT: (
@ -78,15 +77,15 @@ export function getTotalBalance(state: { accounts: AccountsState }) {
)
}
export function getAccounts(state: { accounts: AccountsState }): Array<Account> {
export function getAccounts(state: { accounts: AccountsState }): Account[] {
return state.accounts
}
export function getArchivedAccounts(state: { accounts: AccountsState }): Array<Account> {
export function getArchivedAccounts(state: { accounts: AccountsState }): Account[] {
return state.accounts.filter(acc => acc.archived === true)
}
export function getVisibleAccounts(state: { accounts: AccountsState }): Array<Account> {
export function getVisibleAccounts(state: { accounts: AccountsState }): Account[] {
return getAccounts(state).filter(account => account.archived !== true)
}
@ -127,7 +126,7 @@ export function serializeAccounts(accounts: Array<Object>) {
})
}
export function deserializeAccounts(accounts: Accounts) {
export function deserializeAccounts(accounts: Account[]) {
return accounts.map(account => ({
id: account.id,
address: account.address,

6
src/renderer/events.js

@ -5,7 +5,7 @@ import objectPath from 'object-path'
import debug from 'debug'
import { getDefaultUnitByCoinType } from '@ledgerhq/currencies'
import type { Accounts } from 'types/common'
import type { Account } from 'types/common'
import { CHECK_UPDATE_DELAY, SYNC_ACCOUNT_DELAY, SYNC_COUNTER_VALUES_DELAY } from 'constants'
@ -52,7 +52,7 @@ export function sendSyncEvent(channel: string, msgType: string, data: any): any
})
}
export function startSyncAccounts(accounts: Accounts) {
export function startSyncAccounts(accounts: Account[]) {
d.sync('Sync accounts - start')
syncAccountsInProgress = true
sendEvent('accounts', 'sync.all', {
@ -76,7 +76,7 @@ export function stopSyncAccounts() {
clearTimeout(syncAccountsTimeout)
}
export function startSyncCounterValues(counterValue: string, accounts: Accounts) {
export function startSyncCounterValues(counterValue: string, accounts: Account[]) {
d.sync('Sync counterValues - start')
sendEvent('msg', 'counterValues.sync', {

6
src/types/common.js

@ -22,8 +22,6 @@ export type Operation = {
confirmations: number,
}
export type Operations = Array<Operation>
// -------------------- Accounts
export type AccountSettings = {
@ -43,13 +41,11 @@ export type Account = {
name: string,
path: string,
rootPath: string,
operations: Operations,
operations: Operation[],
unit: Unit,
settings: AccountSettings,
}
export type Accounts = Array<Account>
// -------------------- Settings
export type SettingsProfile = {

Loading…
Cancel
Save