Skip to content

Commit

Permalink
feat(Coinify): redux setup for subscriptions; refactor order history …
Browse files Browse the repository at this point in the history
…selector and pass subscriptions to template
  • Loading branch information
Philip Welber committed Jun 5, 2018
1 parent 3a4b41a commit cef87f7
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 13 deletions.
Expand Up @@ -17,6 +17,7 @@ class CoinifyBuyContainer extends React.Component {
this.props.coinifyActions.initializeCheckoutForm('buy')
this.props.coinifyDataActions.fetchTrades()
this.props.coinifyDataActions.getKycs()
this.props.coinifyDataActions.fetchSubscriptions()
if (this.props.step === 'isx') this.props.coinifyActions.coinifyNextCheckoutStep('checkout')
}

Expand Down
Expand Up @@ -16,6 +16,14 @@ export const getTrades = (state) => {
}
}

export const getSubscriptions = (state) => {
try {
return selectors.core.data.coinify.getSubscriptions(state).data
} catch (e) {
return null
}
}

export const getRateQuote = (state) => {
try {
return selectors.core.data.coinify.getRateQuote(state)
Expand Down Expand Up @@ -63,6 +71,7 @@ export const getData = (state) => ({
buyQuoteR: getQuote(state),
rateQuoteR: getRateQuote(state),
trades: getTrades(state),
subscriptions: getSubscriptions(state),
trade: getTrade(state),
errors: getErrors(state),
currency: formValueSelector('coinifyCheckoutBuy')(state, 'currency'),
Expand Down
Expand Up @@ -2,9 +2,10 @@ import React from 'react'
import { actions } from 'data'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { getData } from './selectors'
import { getData, getTrade } from './selectors'
import Success from './template.success.js'
import Loading from 'components/BuySell/Loading'
import { path } from 'ramda'

class OrderHistoryContainer extends React.Component {
componentDidMount () {
Expand All @@ -26,7 +27,7 @@ class OrderHistoryContainer extends React.Component {

return data.cata({
Success: (value) => <Success
trades={value}
value={value}
showModal={showModal}
finishTrade={finishTrade}
trade={trade}
Expand All @@ -44,7 +45,13 @@ class OrderHistoryContainer extends React.Component {
}
}

const mapStateToProps = state => getData(state)
const mapStateToProps = state => ({
data: getData(state),
trade: getTrade(state),
step: path(['coinify', 'checkoutStep'], state),
busy: path(['coinify', 'coinifyBusy'], state),
cancelTradeId: path(['coinify', 'cancelTradeId'], state)
})

const mapDispatchToProps = (dispatch) => ({
coinifyDataActions: bindActionCreators(actions.core.data.coinify, dispatch),
Expand Down
@@ -1,5 +1,6 @@
import { selectors } from 'data'
import { path } from 'ramda'
import { lift } from 'ramda'
import { createDeepEqualSelector } from 'services/ReselectHelper'

export const getTrade = (state) => {
try {
Expand All @@ -9,11 +10,64 @@ export const getTrade = (state) => {
}
}

export const getData = (state) => ({
data: selectors.core.data.coinify.getTrades(state),
canTrade: selectors.core.data.coinify.canTrade(state).getOrElse(true),
trade: getTrade(state),
step: path(['coinify', 'checkoutStep'], state),
busy: path(['coinify', 'coinifyBusy'], state),
cancelTradeId: path(['coinify', 'cancelTradeId'], state)
})
export const getData = createDeepEqualSelector(
[
selectors.core.data.coinify.getTrades,
selectors.core.data.coinify.getSubscriptions
],
(tradesR, subscriptionsR, tradeR) => {
const transform = (trades, subscriptions) => {
return {
trades,
subscriptions
}
}
console.log('order history selector', tradesR, subscriptionsR)
return lift(transform)(tradesR, subscriptionsR)
}
)

// export const getData = (state) => ({
// data: selectors.core.data.coinify.getTrades(state),
// canTrade: selectors.core.data.coinify.canTrade(state).getOrElse(true),
// trade: getTrade(state),
// step: path(['coinify', 'checkoutStep'], state),
// busy: path(['coinify', 'coinifyBusy'], state),
// cancelTradeId: path(['coinify', 'cancelTradeId'], state)
// })



// import { lift } from 'ramda'
// import { selectors } from 'data'
// import { createDeepEqualSelector } from 'services/ReselectHelper'

// export const getData = createDeepEqualSelector(
// [
// selectors.core.data.coinify.getProfile,
// selectors.core.data.coinify.getLimits,
// selectors.core.data.coinify.getLevel,
// selectors.core.data.coinify.getMediums,
// selectors.core.data.coinify.getKycs
// ],
// (profileR, limitsR, levelR, mediumsR, kycsR) => {
// const transform = (profile, limits, level, mediums, kycs) => {
// return {
// profile,
// limits,
// level,
// mediums,
// kycs
// }
// }
// return lift(transform)(profileR, limitsR, levelR, mediumsR, kycsR)
// }
// )
//
// export const getQuote = createDeepEqualSelector(
// [selectors.core.data.coinify.getQuote],
// (quoteR) => {
// const transform = quote => quote
// return lift(transform)(quoteR)
// }
// )
Expand Up @@ -26,8 +26,10 @@ const isPending = (t) => t.state === 'processing' || t.state === 'awaiting_trans
const isCompleted = (t) => contains(t.state, ['completed', 'rejected', 'cancelled', 'expired'])

const OrderHistory = (props) => {
const { showModal, finishTrade, cancelTrade, trades, step, trade, status, cancelTradeId, changeTab, canTrade } = props
const { showModal, finishTrade, cancelTrade, step, status, cancelTradeId, trade, changeTab, canTrade, value } = props
const { trades, subscriptions } = value
const pendingTrades = filter(isPending, trades)
console.log('OrderHistory template', props)
if (step === 'isx') {
return (
<ISignThis
Expand Down
Expand Up @@ -16,6 +16,11 @@ export const COINIFY_FETCH_TRADES_LOADING = '@CORE.COINIFY_FETCH_TRADES_LOADING'
export const COINIFY_FETCH_TRADES_SUCCESS = '@CORE.COINIFY_FETCH_TRADES_SUCCESS'
export const COINIFY_FETCH_TRADES_FAILURE = '@CORE.COINIFY_FETCH_TRADES_FAILURE'

export const COINIFY_FETCH_SUBSCRIPTIONS = '@CORE.COINIFY_FETCH_SUBSCRIPTIONS'
export const COINIFY_FETCH_SUBSCRIPTIONS_LOADING = '@CORE.COINIFY_FETCH_SUBSCRIPTIONS_LOADING'
export const COINIFY_FETCH_SUBSCRIPTIONS_SUCCESS = '@CORE.COINIFY_FETCH_SUBSCRIPTIONS_SUCCESS'
export const COINIFY_FETCH_SUBSCRIPTIONS_FAILURE = '@CORE.COINIFY_FETCH_SUBSCRIPTIONS_FAILURE'

export const COINIFY_FETCH_PROFILE = '@CORE.COINIFY_FETCH_PROFILE'
export const COINIFY_FETCH_PROFILE_LOADING = '@CORE.COINIFY_FETCH_PROFILE_LOADING'
export const COINIFY_FETCH_PROFILE_SUCCESS = '@CORE.COINIFY_FETCH_PROFILE_SUCCESS'
Expand Down
Expand Up @@ -18,6 +18,11 @@ export const fetchTradesLoading = () => ({ type: AT.COINIFY_FETCH_TRADES_LOADING
export const fetchTradesSuccess = (data) => ({ type: AT.COINIFY_FETCH_TRADES_SUCCESS, payload: data })
export const fetchTradesFailure = (error) => ({ type: AT.COINIFY_FETCH_TRADES_FAILURE, payload: error })

export const fetchSubscriptions = (data) => ({ type: AT.COINIFY_FETCH_SUBSCRIPTIONS, payload: data })
export const fetchSubscriptionsLoading = () => ({ type: AT.COINIFY_FETCH_SUBSCRIPTIONS_LOADING })
export const fetchSubscriptionsSuccess = (data) => ({ type: AT.COINIFY_FETCH_SUBSCRIPTIONS_SUCCESS, payload: data })
export const fetchSubscriptionsFailure = (error) => ({ type: AT.COINIFY_FETCH_SUBSCRIPTIONS_FAILURE, payload: error })

export const coinifyFetchProfile = () => ({ type: AT.COINIFY_FETCH_PROFILE })
export const coinifyFetchProfileLoading = () => ({ type: AT.COINIFY_FETCH_PROFILE_LOADING })
export const coinifyFetchProfileSuccess = (data) => ({ type: AT.COINIFY_FETCH_PROFILE_SUCCESS, payload: data })
Expand Down
10 changes: 10 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/data/coinify/reducers.js
Expand Up @@ -10,6 +10,7 @@ const INITIAL_STATE = {
mediums: Remote.NotAsked,
rateQuote: Remote.NotAsked,
kycs: Remote.NotAsked,
subscriptions: Remote.NotAsked,
nextAddress: null
}

Expand Down Expand Up @@ -53,6 +54,15 @@ const coinifyReducer = (state = INITIAL_STATE, action) => {
case AT.COINIFY_FETCH_TRADES_FAILURE: {
return assoc('trades', Remote.Failure(payload), state)
}
case AT.COINIFY_FETCH_SUBSCRIPTIONS_LOADING: {
return assoc('subscriptions', Remote.Loading, state)
}
case AT.COINIFY_FETCH_SUBSCRIPTIONS_SUCCESS: {
return assoc('subscriptions', Remote.Success(payload), state)
}
case AT.COINIFY_FETCH_SUBSCRIPTIONS_FAILURE: {
return assoc('subscriptions', Remote.Failure(payload), state)
}
case AT.HANDLE_TRADE_LOADING: {
return assoc('trade', Remote.Loading, state)
}
Expand Down
Expand Up @@ -10,6 +10,7 @@ export default ({ api, options }) => {
yield takeLatest(actionTypes.kvStore.buySell.FETCH_METADATA_BUYSELL_SUCCESS, coinifySagas.init)
yield takeLatest(AT.COINIFY_FETCH_PROFILE, coinifySagas.coinifyFetchProfile)
yield takeLatest(AT.COINIFY_FETCH_TRADES, coinifySagas.fetchTrades)
yield takeLatest(AT.COINIFY_FETCH_SUBSCRIPTIONS, coinifySagas.fetchSubscriptions)
yield takeLatest(AT.COINIFY_FETCH_QUOTE, coinifySagas.fetchQuote)
yield takeLatest(AT.COINIFY_FETCH_RATE_QUOTE, coinifySagas.fetchRateQuote)
yield takeLatest(AT.RESET_PROFILE, coinifySagas.resetProfile)
Expand Down
11 changes: 11 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/data/coinify/sagas.js
Expand Up @@ -290,13 +290,24 @@ export default ({ api, options }) => {
}
}

const fetchSubscriptions = function * () {
try {
yield put(A.fetchSubscriptionsLoading())
const subs = yield apply(coinify, coinify.getSubscriptions)
yield put(A.fetchSubscriptionsSuccess(subs))
} catch (e) {
yield put(A.fetchSubscriptionsFailure(e))
}
}

return {
signup,
buy,
sell,
init,
coinifyFetchProfile,
fetchTrades,
fetchSubscriptions,
fetchQuote,
fetchRateQuote,
resetProfile,
Expand Down
Expand Up @@ -9,6 +9,8 @@ export const getRateQuote = path([dataPath, 'coinify', 'rateQuote'])

export const getTrades = path([dataPath, 'coinify', 'trades'])

export const getSubscriptions = path([dataPath, 'coinify', 'subscriptions'])

export const getProfile = path([dataPath, 'coinify', 'profile'])

export const getMediums = path([dataPath, 'coinify', 'mediums'])
Expand Down

0 comments on commit cef87f7

Please sign in to comment.