Skip to content

Commit

Permalink
feat(add type parameter to coinify fetchQuote for sell conversion)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed May 21, 2018
1 parent 1821168 commit fe19da7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ export default ({ coreSagas }) => {
const form = path(['meta', 'form'], action)
const field = path(['meta', 'field'], action)
const payload = prop('payload', action)

if (!any(equals(form))(['coinifyCheckoutBuy', 'coinifyCheckoutSell'])) return
yield put(A.coinifyCheckoutBusyOn())
if (!payload) return null

const limits = yield select(selectors.core.data.coinify.getLimits)

const values = yield select(selectors.form.getFormValues(form))

if (!payload) return null
const type = form === 'coinifyCheckoutBuy' ? 'buy' : 'sell'

switch (field) {
case 'leftVal':
Expand All @@ -117,13 +117,15 @@ export default ({ coreSagas }) => {
yield put(A.setCoinifyCheckoutError(leftLimitsError))
return
}
const leftResult = yield call(coreSagas.data.coinify.fetchQuote, { quote: { amount: payload * 100, baseCurrency: values.currency, quoteCurrency: 'BTC' } })
const leftResult = yield call(coreSagas.data.coinify.fetchQuote,
{ quote: { amount: payload * 100, baseCurrency: values.currency, quoteCurrency: 'BTC', type } })
const amount = leftResult.quoteAmount
yield put(actions.form.initialize(form, merge(values, { 'rightVal': amount / 1e8 })))
yield put(A.coinifyCheckoutBusyOff())
break
case 'rightVal':
const rightResult = yield call(coreSagas.data.coinify.fetchQuote, { quote: { amount: Math.round((payload * 1e8) * -1), baseCurrency: 'BTC', quoteCurrency: values.currency } })
const rightResult = yield call(coreSagas.data.coinify.fetchQuote,
{ quote: { amount: Math.round((payload * 1e8) * -1), baseCurrency: 'BTC', quoteCurrency: values.currency, type } })
const fiatAmount = Math.abs(rightResult.quoteAmount)

const rightLimitsError = service.getLimitsError(fiatAmount, limits.data, values.currency)
Expand Down Expand Up @@ -152,8 +154,10 @@ export default ({ coreSagas }) => {
const { amount, type } = action.payload
const form = type === 'buy' ? 'coinifyCheckoutBuy' : 'coinifyCheckoutSell'
const values = yield select(selectors.form.getFormValues(form))
const leftResult = yield call(coreSagas.data.coinify.fetchQuote, { quote: { amount: amount * 100, baseCurrency: values.currency, quoteCurrency: 'BTC' } })
yield put(actions.form.initialize('coinifyCheckout', merge(values, { 'leftVal': action.payload, 'rightVal': leftResult.quoteAmount / 1e8 })))
const leftResult = yield call(coreSagas.data.coinify.fetchQuote,
{ quote: { amount: amount * 100, baseCurrency: values.currency, quoteCurrency: 'BTC', type } })
yield put(actions.form.initialize('coinifyCheckout',
merge(values, { 'leftVal': action.payload, 'rightVal': leftResult.quoteAmount / 1e8 })))
yield put(A.coinifyCheckoutBusyOff())
yield put(A.clearCoinifyCheckoutError())
} catch (e) {
Expand All @@ -175,7 +179,8 @@ export default ({ coreSagas }) => {
const trade = yield select(selectors.core.data.coinify.getTrade)

yield put(actions.form.change('buySellTabStatus', 'status', 'order_history'))
yield put(actions.modals.showModal('CoinifyTradeDetails', { trade: trade.data, status: status }))
yield put(actions.modals.showModal('CoinifyTradeDetails',
{ trade: trade.data, status: status }))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'fromISX', e))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ConfirmContainer extends Component {
if (this.props.ui.editing) {
const { baseCurrency, quoteCurrency } = this.props.data.data.quote
const amt = +this.props.editingAmount * 100
this.props.coinifyDataActions.fetchQuoteAndMediums({ amt, baseCurrency, quoteCurrency, medium })
this.props.coinifyDataActions.fetchQuoteAndMediums({ amt, baseCurrency, quoteCurrency, medium, type: 'buy' })
} else {
const quote = this.props.data.data.quote
this.props.coinifyActions.initiateBuy({ quote, medium })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ class ExchangeCheckout extends React.PureComponent {
}

setMax () {
let field = this.props.fiatLimits ? 'fiat' : 'crypto'
let baseCurr = this.props.fiatLimits ? this.props.fiat : this.props.crypto
let quoteCurr = this.props.fiatLimits ? this.props.crypto : this.props.fiat
const { crypto, fiat, fiatLimits, type } = this.props
let field = fiatLimits ? 'fiat' : 'crypto'
let baseCurrency = fiatLimits ? fiat : crypto
let quoteCurrency = fiatLimits ? crypto : fiat

this.props.dispatch(focus('exchangeCheckout', field))
this.props.dispatch(change('exchangeCheckout', field, this.props.limits.max))
this.props.fetchQuote({ amt: this.props.limits.max * 100, baseCurr: baseCurr, quoteCurr: quoteCurr })
this.props.fetchQuote({ amt: this.props.limits.max * 100, baseCurrency: baseCurrency, quoteCurrency: quoteCurrency, type })
}

render () {
Expand Down Expand Up @@ -135,7 +136,7 @@ class ExchangeCheckout extends React.PureComponent {
hideErrors
component={NumberBox}
validate={[belowMaxAmount, aboveMinAmount, required]}
onChange={event => fetchQuote({ amt: event.target.value * 100, baseCurr: fiat, quoteCurr: crypto })}
onChange={event => fetchQuote({ amt: event.target.value * 100, baseCurrency: fiat, quoteCurrency: crypto })}
/>
</FormItem>
<FormItem width='50%'>
Expand All @@ -144,7 +145,7 @@ class ExchangeCheckout extends React.PureComponent {
hideErrors
component={NumberBox}
validate={[required]}
onChange={event => fetchQuote({ amt: event.target.value * 1e8, baseCurr: crypto, quoteCurr: fiat })}
onChange={event => fetchQuote({ amt: event.target.value * 1e8, baseCurrency: crypto, quoteCurrency: fiat })}
/>
</FormItem>
</CheckoutInput>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class QuoteInput extends Component {
let { side } = this.state
return {
amt: convert.from[spec[side]](this.state[side]),
baseCurr: toUpper(spec[side]),
quoteCurr: toUpper(spec[otherSide(side)])
baseCurrency: toUpper(spec[side]),
quoteCurrency: toUpper(spec[otherSide(side)])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Checkout extends React.PureComponent {
this.props.sfoxDataActions.fetchTrades()
this.props.sfoxDataActions.fetchProfile()
this.props.sfoxDataActions.sfoxFetchAccounts()
this.props.sfoxDataActions.fetchQuote({quote: { amt: 1e8, baseCurr: 'BTC', quoteCurr: 'USD' }})
this.props.sfoxDataActions.fetchSellQuote({quote: { amt: 1e8, baseCurr: 'BTC', quoteCurr: 'USD' }})
this.props.sfoxDataActions.fetchQuote({quote: { amt: 1e8, baseCurrency: 'BTC', quoteCurrency: 'USD' }})
this.props.sfoxDataActions.fetchSellQuote({quote: { amt: 1e8, baseCurrency: 'BTC', quoteCurrency: 'USD' }})
}

componentDidMount () {
Expand Down
10 changes: 6 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 @@ -56,8 +56,9 @@ export default ({ api, options }) => {
try {
const coinify = yield select(S.getProfile)
yield put(A.fetchQuoteLoading())
const { amount, baseCurrency, quoteCurrency } = data.quote
const quote = yield apply(coinify.data, coinify.data.getBuyQuote, [Math.floor(amount), baseCurrency, quoteCurrency])
const { amount, baseCurrency, quoteCurrency, type } = data.quote
const getQuote = type === 'sell' ? coinify.data.getSellQuote : coinify.data.getBuyQuote
const quote = yield apply(coinify.data, getQuote, [Math.floor(amount), baseCurrency, quoteCurrency])
yield put(A.fetchQuoteSuccess(quote))
return quote
} catch (e) {
Expand All @@ -67,8 +68,9 @@ export default ({ api, options }) => {

const fetchQuoteAndMediums = function * (data) {
try {
const { amt, baseCurrency, quoteCurrency, medium } = data.payload
const quote = yield apply(coinify, coinify.getBuyQuote, [amt, baseCurrency, quoteCurrency])
const { amt, baseCurrency, quoteCurrency, medium, type } = data.payload
const getQuote = type === 'sell' ? coinify.data.getSellQuote : coinify.data.getBuyQuote
const quote = yield apply(coinify, getQuote, [amt, baseCurrency, quoteCurrency])
const mediums = yield apply(quote, quote.getPaymentMediums)
const account = yield apply(mediums[medium], mediums[medium].getAccounts)
yield put(A.fetchQuoteSuccess(quote))
Expand Down
8 changes: 4 additions & 4 deletions packages/blockchain-wallet-v4/src/redux/data/sfox/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export default ({ api, options }) => {
const nextAddress = data.payload.nextAddress
yield put(A.setNextAddress(nextAddress))
yield call(refreshSFOX)
const { amt, baseCurr, quoteCurr } = data.payload.quote
const quote = yield apply(sfox, sfox.getBuyQuote, [amt, baseCurr, quoteCurr])
const { amt, baseCurrency, quoteCurrency } = data.payload.quote
const quote = yield apply(sfox, sfox.getBuyQuote, [amt, baseCurrency, quoteCurrency])
yield put(A.fetchQuoteSuccess(quote))
yield fork(waitForRefreshQuote, data.payload)
} catch (e) {
Expand All @@ -57,8 +57,8 @@ export default ({ api, options }) => {
// const nextAddress = data.payload.nextAddress
// yield put(A.setNextAddress(nextAddress))
yield call(refreshSFOX)
const { amt, baseCurr, quoteCurr } = data.payload.quote
const quote = yield apply(sfox, sfox.getSellQuote, [amt, baseCurr, quoteCurr])
const { amt, baseCurrency, quoteCurrency } = data.payload.quote
const quote = yield apply(sfox, sfox.getSellQuote, [amt, baseCurrency, quoteCurrency])
yield put(A.fetchSellQuoteSuccess(quote))
// yield fork(waitForRefreshQuote, data.payload)
} catch (e) {
Expand Down

0 comments on commit fe19da7

Please sign in to comment.