Skip to content

Commit

Permalink
fix(add coinify sell trades to metadata)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed Jul 2, 2018
1 parent 9d50125 commit bb45df5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
7 changes: 3 additions & 4 deletions packages/blockchain-wallet-v4/src/redux/data/coinify/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,8 @@ export default ({ api, options }) => {
const coinifyObj = yield call(getCoinify)
yield put(A.fetchTrades(coinifyObj))

// save trades to metadata
const kvTrades = yield select(buySellSelectors.getCoinifyTrades)
const newTrades = prepend(buyResult, kvTrades.getOrElse([]))
yield put(buySellA.setCoinifyTradesBuySell(newTrades))
// save trade to metadata
yield put(buySellA.addCoinifyTradeBuySell(buyResult))

yield call(labelAddressForBuy, buyResult, addressData)
return buyResult
Expand Down Expand Up @@ -276,6 +274,7 @@ export default ({ api, options }) => {
yield put(A.handleTradeSuccess(sellResult))
yield put(A.fetchTrades())
yield call(getCoinify)
yield put(buySellA.addCoinifyTradeBuySell(sellResult))
return sellResult
} catch (e) {
yield put(A.handleTradeFailure(e))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export const SET_SFOX_TRADES_BUYSELL = '@CORE.SET_SFOX_TRADES_BUYSELL'
export const UPDATE_METADATA_BUYSELL = '@CORE.UPDATE_METADATA_BUYSELL'

export const SET_COINIFY_TRADES_BUYSELL = '@CORE.SET_COINIFY_TRADES_BUYSELL'
export const ADD_COINIFY_TRADE_BUYSELL = '@CORE.ADD_COINIFY_TRADE_BUYSELL'
// FETCH_METADATA_BUYSELL
export const FETCH_METADATA_BUYSELL = '@CORE.FETCH_METADATA_BUYSELL'
export const FETCH_METADATA_BUYSELL_LOADING = '@CORE.FETCH_METADATA_BUYSELL_LOADING'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as AT from './actionTypes'
export const setSfoxTradesBuySell = (payload) => ({ type: AT.SET_SFOX_TRADES_BUYSELL, payload })
export const updateMetadataBuySell = (payload = {}) => ({ type: AT.UPDATE_METADATA_BUYSELL, payload })

export const setCoinifyTradesBuySell = (payload) => ({ type: AT.SET_COINIFY_TRADES_BUYSELL, payload })
export const addCoinifyTradeBuySell = (payload) => ({ type: AT.ADD_COINIFY_TRADE_BUYSELL, payload })

// FETCH_METADATA_BUYSELL
export const fetchMetadataBuySell = () => ({ type: AT.FETCH_METADATA_BUYSELL })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { over, set, mapped } from 'ramda-lens'
import { assocPath, compose } from 'ramda'
import { assocPath, compose, lensPath, prepend } from 'ramda'
import { KVStoreEntry } from '../../../types'
import * as AT from './actionTypes'
import Remote from '../../../remote'
Expand All @@ -19,10 +19,9 @@ export default (state = INITIAL_STATE, action) => {
let setTrades = assocPath(['sfox', 'trades'], payload)
return over(valueLens, setTrades, state)
}
case AT.SET_COINIFY_TRADES_BUYSELL: {
let valueLens = compose(mapped, KVStoreEntry.value)
let setTrades = assocPath(['coinify', 'trades'], payload)
return over(valueLens, setTrades, state)
case AT.ADD_COINIFY_TRADE_BUYSELL: {
let valueLens = compose(mapped, KVStoreEntry.value, lensPath(['coinify', 'trades']))
return over(valueLens, prepend(payload), state)
}
case AT.FETCH_METADATA_BUYSELL_LOADING: {
return Remote.Loading
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assoc, assocPath, compose, set } from 'ramda'
import { assoc, assocPath, compose, lensPath, prepend, set } from 'ramda'
import { mapped, over } from 'ramda-lens'
import Remote from '../../../remote'
import { KVStoreEntry } from '../../../types'
Expand Down Expand Up @@ -69,11 +69,11 @@ describe('kvStore buysell reducers', () => {
expect(reducer(buySellMetadataSuccess, action)).toEqual(expectedState)
})

it('should handle SET_COINIFY_TRADES_BUYSELL true', () => {
const trades = [5, 4, 0]
const action = actions.setCoinifyTradesBuySell(trades)
const setCoinifyTrades = assocPath(['coinify', 'trades'], trades)
const expectedState = over(valueLens, setCoinifyTrades, buySellMetadataSuccess)
it('should handle ADD_COINIFY_TRADE_BUYSELL true', () => {
const newTrade = 5
const action = actions.addCoinifyTradeBuySell(newTrade)
const tradesLens = compose(valueLens, lensPath(['coinify', 'trades']))
const expectedState = over(tradesLens, prepend(newTrade), buySellMetadataSuccess)
expect(reducer(buySellMetadataSuccess, action)).toEqual(expectedState)
})

Expand Down

0 comments on commit bb45df5

Please sign in to comment.