Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
#73 Fixing Flow errors
Browse files Browse the repository at this point in the history
  • Loading branch information
apanizo committed Oct 30, 2018
1 parent a2892ea commit 9235cd2
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/components/Table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type State = {
orderBy: string,
orderProp: boolean,
rowsPerPage: number,
fixed: boolean,
}

const styles = {
Expand Down
15 changes: 9 additions & 6 deletions src/components/Table/sorting.js
Original file line number Diff line number Diff line change
@@ -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`


Expand All @@ -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) => {
Expand All @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions src/routes/safe/component/Balances/dataFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions src/routes/safe/component/Balances/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import Receive from './Receive'
type State = {
hideZero: boolean,
showToken: boolean,
showReceive: boolean,
showSend: boolean,
}

const styles = theme => ({
Expand Down
2 changes: 1 addition & 1 deletion src/routes/safe/store/actions/addSafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions src/routes/safe/store/reducer/safe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/safe/store/test/builder/safe.builder.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/test/builder/safe.redux.builder.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
10 changes: 5 additions & 5 deletions src/test/safe.redux.owners.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/test/safe.redux.transactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9235cd2

Please sign in to comment.