Skip to content

Commit

Permalink
feat(coinify create sell trade)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed May 23, 2018
1 parent baec25f commit b277c8d
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const saveMediumSuccess = (medium) => ({ type: AT.COINIFY_SAVE_MEDIUM_SUC

export const initiateBuy = (data) => ({ type: AT.COINIFY_BUY, payload: data })

export const initiateSell = (data) => ({ type: AT.COINIFY_SELL, payload: data })
export const initiateSell = () => ({ type: AT.COINIFY_SELL })

export const initializeCheckoutForm = (type) => ({ type: AT.COINIFY_INITIALIZED, payload: { type } })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export default ({ coreSagas }) => {
}
}

const sell = function * (payload) {
const sell = function * () {
try {
const sellTrade = yield call(coreSagas.data.coinify.sell, payload)
const sellTrade = yield call(coreSagas.data.coinify.sell)

if (!sellTrade) {
const trade = yield select(selectors.core.data.coinify.getTrade)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Remote } from 'blockchain-wallet-v4/src'
import FaqRow from 'components/Faq/FaqRow'
import CountdownTimer from 'components/Form/CountdownTimer'
import { Wrapper as ExchangeCheckoutWrapper } from '../../ExchangeCheckout'
import { flex, spacing } from 'services/StyleService'
import { spacing } from 'services/StyleService'
import { reviewOrder, currencySymbolMap } from 'services/CoinifyService'
import { FormattedMessage } from 'react-intl'
import { OrderDetailsTable, OrderDetailsRow } from 'components/BuySell/OrderDetails'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { prop } from 'ramda'

import { actions } from 'data'
import { getData } from './selectors.js'
Expand All @@ -10,13 +11,12 @@ import Loading from '../../../../template.loading'
class SelectAccountsContainer extends React.PureComponent {
constructor (props) {
super(props)
this.setBankAccount = this.setBankAccount.bind(this)
this.deleteBankAccount = this.deleteBankAccount.bind(this)
this.onSubmit = this.onSubmit.bind(this)
}

onSubmit (e) {
e.preventDefault()
// TODO: Store form data in the state
setBankAccount (bankAccount) {
this.props.coinifyDataActions.setBankAccount(bankAccount)
}

deleteBankAccount (bankAccount) {
Expand All @@ -28,7 +28,7 @@ class SelectAccountsContainer extends React.PureComponent {
return data.cata({
Success: (value) =>
<Success
onSubmit={this.onSubmit}
setBankAccount={() => this.setBankAccount(prop(radioButtonSelected, value.bankAccounts))}
deleteBankAccount={this.deleteBankAccount}
radioButtonSelected={radioButtonSelected}
{...value} />,
Expand All @@ -42,7 +42,8 @@ class SelectAccountsContainer extends React.PureComponent {
const mapStateToProps = (state) => getData(state)

const mapDispatchToProps = (dispatch) => ({
coinifyActions: bindActionCreators(actions.modules.coinify, dispatch)
coinifyActions: bindActionCreators(actions.modules.coinify, dispatch),
coinifyDataActions: bindActionCreators(actions.core.data.coinify, dispatch)
})

export default connect(mapStateToProps, mapDispatchToProps)(SelectAccountsContainer)
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ClickableIcon = styled(Icon)`
`

const SelectAccounts = (props) => {
const { invalid, submitting, bankAccounts, deleteBankAccount, radioButtonSelected } = props
const { invalid, submitting, bankAccounts, setBankAccount, deleteBankAccount, radioButtonSelected } = props
const noRadioButtonSelected = or(isNil(radioButtonSelected), equals(radioButtonSelected, ''))

return (
Expand Down Expand Up @@ -59,7 +59,7 @@ const SelectAccounts = (props) => {
<ColRight>
<ColRightInner>
<StepTransition to={4} Component={Button} style={spacing('mt-45')} nature='primary'
fullwidth disabled={submitting || invalid || noRadioButtonSelected}>
onClick={setBankAccount} fullwidth disabled={submitting || invalid || noRadioButtonSelected}>
<FormattedMessage id='coinifyexchangedata.selectaccounts.continue' defaultMessage='Continue' />
</StepTransition>
<CancelWrapper style={spacing('mt-15')}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ import Loading from '../../../template.loading'
class SellContainer extends React.Component {
constructor (props) {
super(props)

this.submitQuote = this.submitQuote.bind(this)
this.startSell = this.startSell.bind(this)
}

componentDidMount () {
this.props.coinifyActions.initializeCheckoutForm('sell')
}
submitQuote () {
const { sellQuoteR } = this.props
sellQuoteR.map(quote => this.props.coinifyDataActions.getMediumsWithBankAccounts(quote))
this.props.coinifyActions.saveMedium('blockchain')
}

startSell () {
const { sellQuoteR, paymentMedium, coinifyActions } = this.props
coinifyActions.coinifyLoading()
sellQuoteR.map(q => this.props.coinifyActions.initiateSell({ quote: q, medium: paymentMedium }))
this.props.coinifyActions.initiateSell()
}

render () {
Expand Down Expand Up @@ -56,7 +61,7 @@ class SellContainer extends React.Component {
busy={busy}
clearTradeError={() => coinifyNotAsked()}
trade={trade}
onOrderCheckoutSubmit={() => sellQuoteR.map(quote => this.props.coinifyDataActions.getMediumsWithBankAccounts(quote))}
onOrderCheckoutSubmit={this.submitQuote}
/>,
Failure: (msg) => <div>Failure: {msg.error}</div>,
Loading: () => <Loading />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export const COINIFY_ADD_BANK_ACCOUNT_FAILURE = '@CORE.COINIFY_ADD_BANK_ACCOUNT_
export const COINIFY_ADD_BANK_ACCOUNT_LOADING = '@CORE.COINIFY_ADD_BANK_ACCOUNT_LOADING'
export const COINIFY_ADD_BANK_ACCOUNT_SUCCESS = '@CORE.COINIFY_ADD_BANK_ACCOUNT_SUCCESS'

export const COINIFY_SET_BANK_ACCOUNT = '@CORE.COINIFY_SET_BANK_ACCOUNT'

export const COINIFY_BUY = '@CORE.COINIFY_BUY'

export const COINIFY_SELL = '@CORE.COINIFY_SELL'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ export const addBankAccountFailure = (error) => ({ type: AT.COINIFY_ADD_BANK_ACC
export const addBankAccountLoading = () => ({ type: AT.COINIFY_ADD_BANK_ACCOUNT_LOADING })
export const addBankAccountSuccess = (account) => ({ type: AT.COINIFY_ADD_BANK_ACCOUNT_SUCCESS, payload: account })

export const setBankAccount = (account) => ({ type: AT.COINIFY_SET_BANK_ACCOUNT, payload: account })

export const initiateBuy = (data) => ({ type: AT.COINIFY_BUY, payload: data })

export const initiateSell = (data) => ({ type: AT.COINIFY_SELL, payload: data })
export const initiateSell = () => ({ type: AT.COINIFY_SELL })

export const cancelTrade = (trade) => ({ type: AT.COINIFY_CANCEL_TRADE, payload: trade })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ const sfoxReducer = (state = INITIAL_STATE, action) => {
case AT.COINIFY_GET_MEDIUM_ACCOUNTS_FAILURE: {
return assoc('accounts', payload, state)
}
case AT.COINIFY_SET_BANK_ACCOUNT: {
return assoc('account', payload, state)
}
case AT.GET_KYCS_LOADING: {
return assoc('kycs', Remote.Loading, state)
}
Expand Down
14 changes: 6 additions & 8 deletions packages/blockchain-wallet-v4/src/redux/data/coinify/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ export default ({ api, options }) => {
const addBankAccount = function * (data) {
try {
const { medium, account } = data.payload
yield apply(medium, medium.addBankAccount, [account])
// yield put(A.addBankAccountSuccess(bankAccount))
const bankAccount = yield apply(medium, medium.addBankAccount, [account])
yield put(A.setBankAccount(bankAccount))
} catch (e) {
console.log(e)
// yield put(A.addBankAccountFailure(e))
Expand Down Expand Up @@ -217,14 +217,12 @@ export default ({ api, options }) => {
}
}

const sell = function * (data) {
const { quote, medium } = data.payload
const sell = function * () {
try {
yield put(A.handleTradeLoading())
console.log('core saga sell', data.payload)
const mediums = yield apply(quote, quote.getPaymentMediums)
const accounts = yield apply(mediums[medium], mediums[medium].getAccounts)
const sellResult = yield apply(accounts[0], accounts[0].sell)
console.log('core saga sell')
const account = yield select(S.getAccount)
const sellResult = yield apply(account, account.sell)
yield put(A.handleTradeSuccess(sellResult))
console.log('coinify sell result in core', sellResult)
yield put(A.fetchTrades())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const getProfile = path([dataPath, 'coinify', 'profile'])

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

// Bank account selected to receive sale fiat
export const getAccount = path([dataPath, 'coinify', 'account'])

export const getBaseCurrency = state => getQuote(state).map(prop('_baseCurrency'))

export const getLimits = state => getProfile(state).map(path(['_limits']))
Expand Down

0 comments on commit b277c8d

Please sign in to comment.