#73 Fixing Flow errors

This commit is contained in:
apanizo 2018-10-30 13:10:11 +01:00
parent a2892ea4eb
commit 9235cd2990
10 changed files with 32 additions and 26 deletions

View File

@ -28,6 +28,7 @@ type State = {
orderBy: string,
orderProp: boolean,
rowsPerPage: number,
fixed: boolean,
}
const styles = {

View File

@ -1,10 +1,12 @@
// @flow
export const FIXED = 'fixed'
export type SortRow = {
[FIXED]: boolean,
type Fixed = {
fixed?: boolean,
}
export type SortRow<T> = T & Fixed
export const buildOrderFieldFrom = (attr: string) => `${attr}Order`
@ -21,9 +23,10 @@ const desc = (a: Object, b: Object, orderBy: string, orderProp: boolean) => {
return 0
}
export const stableSort = (array: any, cmp: any, fixed: boolean) => {
const fixedElems = fixed ? array.filter(elem => elem[FIXED]) : []
const data = fixed ? array.filter(elem => !elem[FIXED]) : array
// eslint-disable-next-line
export const stableSort = <SortRow>(array: Array<SortRow>, cmp: any, fixed: boolean): Array<SortRow> => {
const fixedElems: Array<SortRow> = fixed ? array.filter((elem: any) => elem.fixed) : []
const data: Array<SortRow> = fixed ? array.filter((elem: any) => !elem[FIXED]) : array
const stabilizedThis = data.map((el, index) => [el, index])
stabilizedThis.sort((a, b) => {
@ -35,7 +38,7 @@ export const stableSort = (array: any, cmp: any, fixed: boolean) => {
return a[1] - b[1]
})
const sortedElems = stabilizedThis.map(el => el[0])
const sortedElems: Array<SortRow> = stabilizedThis.map(el => el[0])
return fixedElems.concat(sortedElems)
}

View File

@ -7,12 +7,13 @@ export const BALANCE_TABLE_ASSET_ID = 'asset'
export const BALANCE_TABLE_BALANCE_ID = 'balance'
export const BALANCE_TABLE_VALUE_ID = 'value'
export type BalanceRow = SortRow & {
type BalanceData = {
asset: string,
balance: string,
value: string,
}
export type BalanceRow = SortRow<BalanceData>
export const getBalanceData = (): Array<BalanceRow> => [
{
[BALANCE_TABLE_ASSET_ID]: 'CVL Journalism',

View File

@ -23,6 +23,8 @@ import Receive from './Receive'
type State = {
hideZero: boolean,
showToken: boolean,
showReceive: boolean,
showSend: boolean,
}
const styles = theme => ({

View File

@ -6,7 +6,7 @@ import { makeOwner, type Owner } from '~/routes/safe/store/model/owner'
export const ADD_SAFE = 'ADD_SAFE'
export const buildOwnersFrom = (names: string[], addresses: string[]) => {
export const buildOwnersFrom = (names: Array<string>, addresses: Array<string>) => {
const owners = names.map((name: string, index: number) => makeOwner({ name, address: addresses[index] }))
return List(owners)

View File

@ -2,7 +2,8 @@
import { Map } from 'immutable'
import { handleActions, type ActionType } from 'redux-actions'
import addSafe, { ADD_SAFE, buildOwnersFrom } from '~/routes/safe/store/actions/addSafe'
import { type Safe, makeSafe } from '~/routes/safe/store/model/safe'
import { type Safe, type SafeProps, makeSafe } from '~/routes/safe/store/model/safe'
import { type OwnerProps } from '~/routes/safe/store/model/owner'
import { saveSafes, setOwners, load, SAFES_KEY } from '~/utils/localStorage'
import updateSafe, { UPDATE_SAFE } from '~/routes/safe/store/actions/updateSafe'
@ -11,10 +12,9 @@ export const SAFE_REDUCER_ID = 'safes'
export type State = Map<string, Safe>
export const buildSafe = (storedSafe: SafeProps) => {
const owners = buildOwnersFrom(
storedSafe.owners.map((owner: OwnerProps) => owner.name),
storedSafe.owners.map((owner: OwnerProps) => owner.address),
)
const names = storedSafe.owners.map((owner: OwnerProps) => owner.name)
const addresses = storedSafe.owners.map((owner: OwnerProps) => owner.address)
const owners = buildOwnersFrom(names.toIndexedSeq().toArray(), addresses.toIndexedSeq().toArray())
const safe: SafeProps = {
address: storedSafe.address,
@ -26,8 +26,8 @@ export const buildSafe = (storedSafe: SafeProps) => {
return makeSafe(safe)
}
const buildSafesFrom = (loadedSafes: Object): Promise<Map<string, Safe>> => {
const safes = Map()
const buildSafesFrom = (loadedSafes: Object): Map<string, Safe> => {
const safes: Map<string, Safe> = Map()
const keys = Object.keys(loadedSafes)
try {

View File

@ -1,6 +1,6 @@
// @flow
import { makeSafe, type Safe } from '~/routes/safe/store/model/safe'
import { buildOwnersFrom } from '~/routes/safe/store/actions'
import { buildOwnersFrom } from '~/routes/safe/store/actions/addSafe'
class SafeBuilder {
safe: Safe

View File

@ -1,10 +1,9 @@
// @flow
import { makeSafe, type Safe } from '~/routes/safe/store/model/safe'
import { buildOwnersFrom } from '~/routes/safe/store/actions'
import addSafe, { buildOwnersFrom } from '~/routes/safe/store/actions/addSafe'
import { FIELD_NAME, FIELD_CONFIRMATIONS, FIELD_OWNERS, getOwnerNameBy, getOwnerAddressBy } from '~/routes/open/components/fields'
import { getWeb3, getProviderInfo } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import addSafe from '~/routes/safe/store/actions/addSafe'
import { createSafe, type OpenState } from '~/routes/open/container/Open'
import { type GlobalState } from '~/store/index'
import { makeProvider } from '~/logic/wallets/store/model/provider'

View File

@ -120,7 +120,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
await assureThresholdIs(gnosisSafe, 1)
await assureOwnersAre(gnosisSafe, accounts[2], accounts[0], accounts[1])
await store.dispatch(fetchSafe(safe))
await store.dispatch(fetchSafe(safe.get('address')))
safe = getSafeFrom(store.getState(), address)
expect(safe.get('owners').count()).toBe(3)
await assureOwnersAre(gnosisSafe, ...getAddressesFrom(safe))
@ -149,7 +149,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
await assureThresholdIs(gnosisSafe, 2)
await assureOwnersAre(gnosisSafe, accounts[2], accounts[0], accounts[1])
await store.dispatch(fetchSafe(safe))
await store.dispatch(fetchSafe(safe.get('address')))
safe = getSafeFrom(store.getState(), address)
expect(safe.get('owners').count()).toBe(3)
await assureOwnersAre(gnosisSafe, ...getAddressesFrom(safe))
@ -179,7 +179,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
await assureThresholdIs(gnosisSafe, 1)
await assureOwnersAre(gnosisSafe, accounts[0])
await store.dispatch(fetchSafe(safe))
await store.dispatch(fetchSafe(safe.get('address')))
safe = getSafeFrom(store.getState(), address)
expect(safe.get('owners').count()).toBe(1)
await assureOwnersAre(gnosisSafe, ...getAddressesFrom(safe))
@ -204,7 +204,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
await assureThresholdIs(gnosisSafe, 1)
await assureOwnersAre(gnosisSafe, accounts[0], accounts[1])
await store.dispatch(fetchSafe(safe))
await store.dispatch(fetchSafe(safe.get('address')))
safe = getSafeFrom(store.getState(), address)
expect(safe.get('owners').count()).toBe(2)
await assureOwnersAre(gnosisSafe, ...getAddressesFrom(safe))
@ -230,7 +230,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
await assureThresholdIs(gnosisSafe, 2)
await assureOwnersAre(gnosisSafe, accounts[0], accounts[1])
await store.dispatch(fetchSafe(safe))
await store.dispatch(fetchSafe(safe.get('address')))
safe = getSafeFrom(store.getState(), address)
expect(safe.get('owners').count()).toBe(2)
await assureOwnersAre(gnosisSafe, ...getAddressesFrom(safe))

View File

@ -36,12 +36,12 @@ describe('Transactions Suite', () => {
const executor = accounts[0]
const nonce = await gnosisSafe.nonce()
const firstTxHash = await createTransaction(safe, 'Add Owner Second account', safeAddress, 0, nonce, executor, firstTxData)
await store.dispatch(fetchSafe(safe))
await store.dispatch(fetchSafe(safe.get('address')))
safe = getSafeFrom(store.getState(), safeAddress)
const secondTxData = gnosisSafe.contract.addOwnerWithThreshold.getData(accounts[2], 2)
const secondTxHash = await createTransaction(safe, 'Add Owner Third account', safeAddress, 0, nonce + 100, executor, secondTxData)
await store.dispatch(fetchSafe(safe))
await store.dispatch(fetchSafe(safe.get('address')))
safe = getSafeFrom(store.getState(), safeAddress)
// WHEN