Skip to content

Commit

Permalink
refactor(improve use of ramda)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed Jun 27, 2018
1 parent b63aaef commit f0267f7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { concat, curry, equals, keys, keysIn, filter, not, lift, map, path, prop } from 'ramda'
import { concat, curry, equals, keys, keysIn, filter, not, lift, map, path, prop, values } from 'ramda'
import { BCH } from '../config'
import { kvStorePath } from '../../paths'
import * as walletSelectors from '../../wallet/selectors'
Expand All @@ -18,7 +18,7 @@ export const getAccounts = state => getMetadata(state).map(path(['value', 'accou
// This one returns an array of accounts
export const getAccountsList = state => {
const accountsObj = getAccounts(state)
return lift(a => map(key => a[key], keys(a)))(accountsObj)
return lift(values)(accountsObj)
}

export const getContext = createDeepEqualSelector(
Expand Down
19 changes: 11 additions & 8 deletions packages/blockchain-wallet-v4/src/redux/kvStore/middleware.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mapObjIndexed, any, identity, values, sequence } from 'ramda'
import { mapObjIndexed, any, equals, identity, values, sequence } from 'ramda'
import Task from 'data.task'

// import { Wallet, KVStoreEntry } from '../../types'
Expand All @@ -22,13 +22,16 @@ const kvStoreMiddleware = ({ isAuthenticated, api } = {}) => (store) => (next) =

switch (true) {
case (wasAuth && isAuth &&
action.type !== T.root.FETCH_METADATA_ROOT_SUCCESS &&
action.type !== T.whatsNew.FETCH_METADATA_WHATSNEW_SUCCESS &&
action.type !== T.buySell.FETCH_METADATA_BUYSELL_SUCCESS &&
action.type !== T.contacts.FETCH_METADATA_CONTACTS_SUCCESS &&
action.type !== T.ethereum.FETCH_METADATA_ETHEREUM_SUCCESS &&
action.type !== T.shapeShift.FETCH_METADATA_SHAPESHIFT_SUCCESS &&
action.type !== T.bch.FETCH_METADATA_BCH_SUCCESS &&
!any(equals(action.type),
[
T.root.FETCH_METADATA_ROOT_SUCCESS,
T.whatsNew.FETCH_METADATA_WHATSNEW_SUCCESS,
T.buySell.FETCH_METADATA_BUYSELL_SUCCESS,
T.contacts.FETCH_METADATA_CONTACTS_SUCCESS,
T.ethereum.FETCH_METADATA_ETHEREUM_SUCCESS,
T.shapeShift.FETCH_METADATA_SHAPESHIFT_SUCCESS,
T.bch.FETCH_METADATA_BCH_SUCCESS
]) &&
any(identity, values(changes))):

const actionCreators = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { compose, curry, filter, head, path, reverse } from 'ramda'
import { compose, curry, equals, filter, head, path, reverse } from 'ramda'
import { SHAPESHIFT } from '../config'
import { kvStorePath } from '../../paths'

export const getMetadata = path([kvStorePath, SHAPESHIFT])
export const getUsState = state => getMetadata(state).map(path(['value', 'USAState']))
export const getTrades = state => getMetadata(state).map(path(['value', 'trades'])).map(trades => reverse(trades))
export const getTrades = state => getMetadata(state).map(compose(reverse, path(['value', 'trades'])))
export const getTrade = curry((address, state) => getTrades(state)
.map(compose(head, filter(x => path(['quote', 'deposit'], x) === address))))
.map(compose(head, filter(x => equals(path(['quote', 'deposit'], x), address)))))

0 comments on commit f0267f7

Please sign in to comment.