Skip to content

Commit

Permalink
fix(use ramda and map to remove token value of undefined errors)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed Jun 5, 2018
1 parent 1ce2c05 commit 2ba6bf4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
28 changes: 16 additions & 12 deletions packages/blockchain-wallet-v4-frontend/src/scenes/BuySell/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import React from 'react'
import styled from 'styled-components'
import { getData } from './selectors'
import { actions } from 'data'
import { connect } from 'react-redux'
import SfoxCheckout from './SfoxCheckout'
import CoinifyCheckout from './CoinifyCheckout'
import { bindActionCreators, compose } from 'redux'
import { Field, reduxForm } from 'redux-form'
import ui from 'redux-ui'
import { path } from 'ramda'

import { Remote } from 'blockchain-wallet-v4/src'
import { actions } from 'data'
import { TabMenuBuySellStatus } from 'components/Form'
import HorizontalMenu from 'components/HorizontalMenu'
import SelectPartner from './template.success'
import Loading from 'components/BuySell/Loading'
import ui from 'redux-ui'
import { hasAccount } from 'services/ExchangeService'
import SfoxCheckout from './SfoxCheckout'
import CoinifyCheckout from './CoinifyCheckout'
import { getData } from './selectors'
import SelectPartner from './template.success'

const Wrapper = styled.div`
width: 100%;
Expand Down Expand Up @@ -44,7 +47,7 @@ class BuySellContainer extends React.PureComponent {

componentDidMount () {
this.props.formActions.initialize('buySellTabStatus', { status: 'buy' })
this.props.formActions.change('selectPartner', 'country', this.props.data.data.countryCode)
this.props.data.map(data => this.props.formActions.change('selectPartner', 'country', data.countryCode))
}

/**
Expand All @@ -54,16 +57,17 @@ class BuySellContainer extends React.PureComponent {
*/

renderPartner (buySell, options, type) {
if (buySell.sfox.account_token) {
if (path(['sfox', 'account_token'], buySell)) {
return <SfoxCheckout type={type} options={options} value={buySell} />
}
if (buySell.unocoin.token) { // TODO replace token
if (path(['unocoin', 'token'], buySell)) { // TODO replace token
return <span>Unocoin</span>
}
if (buySell.coinify.offline_token) {
if (path(['coinify', 'offline_token'], buySell)) {
return <CoinifyCheckout type={type} options={options} value={buySell} />
}
return <SelectPartner type={type} options={options} value={buySell} onSubmit={this.onSubmit} submitEmail={this.submitEmail} {...this.props} />
return <SelectPartner type={type} options={options} value={buySell}
onSubmit={this.onSubmit} submitEmail={this.submitEmail} {...this.props} />
}

submitEmail () {
Expand All @@ -75,7 +79,7 @@ class BuySellContainer extends React.PureComponent {
const { data, type } = this.props

let view = data.cata({
Success: (value) => this.renderPartner(value.buySell.value, value.options, type),
Success: (value) => this.renderPartner(path(['buySell', 'value'], value), value.options, type),
Failure: (message) => <div>failure: {message}</div>,
Loading: () => <Loading />,
NotAsked: () => <Loading />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isNil } from 'ramda'
import { isNil, prop } from 'ramda'

export const hasAccount = (partners) => {
const { coinify, sfox } = partners
if (!isNil(sfox.account_token)) return 'sfox'
if (!isNil(coinify.offline_token)) return 'coinify'
if (!isNil(prop('account_token', sfox))) return 'sfox'
if (!isNil(prop('offline_token', coinify))) return 'coinify'
}

export const findMatch = (settings, options) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default ({ api, options }) => {
const init = function * () {
try {
const val = yield select(buySellSelectors.getMetadata)
if (!val.data.value.coinify.offline_token) return
if (!path(['data', 'value', 'coinify', 'offline_token'], val)) return
yield call(refreshCoinify)
} catch (e) {
console.warn(e)
Expand Down
7 changes: 4 additions & 3 deletions packages/blockchain-wallet-v4/src/redux/data/sfox/sagas.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import ExchangeDelegate from '../../../exchange/delegate'
import { apply, fork, call, put, select, take } from 'redux-saga/effects'
import { path, prepend } from 'ramda'

import ExchangeDelegate from '../../../exchange/delegate'
import * as S from './selectors'
import * as A from './actions'
import * as AT from './actionTypes'
import * as buySellSelectors from '../../kvStore/buySell/selectors'
import * as buySellA from '../../kvStore/buySell/actions'
import { sfoxService } from '../../../exchange/service'
import { prepend } from 'ramda'

let sfox

Expand All @@ -22,7 +23,7 @@ export default ({ api, options }) => {
const init = function * () {
try {
const value = yield select(buySellSelectors.getMetadata)
if (!value.data.value.sfox.account_token) return
if (!path(['data', 'value', 'sfox', 'account_token'], value)) return
yield call(refreshSFOX)
} catch (e) {
throw new Error(e)
Expand Down

0 comments on commit 2ba6bf4

Please sign in to comment.