Skip to content

Commit

Permalink
feat(add bank account wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed May 21, 2018
1 parent 507cd9d commit 3f10e2e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const AddBankDetails = (props) => {
</Text>
<Text weight={300} size='12px'>
<FormattedMessage id='coinifyexchangedata.addbankdetails.swift' defaultMessage='Bank Identifier Code (SWIFT/BIC)' />
<Field name='swift' validate={[required]} component={TextBox} />
<Field name='bic' validate={[required]} component={TextBox} />
</Text>
</InputWrapper>
</BorderBox>
Expand All @@ -62,4 +62,4 @@ const AddBankDetails = (props) => {
)
}

export default reduxForm({ form: 'coinifyAddBankDetails' })(AddBankDetails)
export default reduxForm({ form: 'coinifyAddBankDetails', destroyOnUnmount: false })(AddBankDetails)
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import React from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import AddCustomerDetails from './template.js'

import { actions } from 'data'
import { getData } from './selectors.js'
import Success from './template.success.js'
import Loading from '../../../../template.loading'
class AddCustomerDetailsContainer extends React.PureComponent {
constructor (props) {
super(props)
this.onSubmit = this.onSubmit.bind(this)
}

onSubmit (e) {
e.preventDefault()
// TODO: Store form data in the state
onSubmit (mediums, account) {
const { coinifyDataActions } = this.props
console.log('Submitting')
coinifyDataActions.addBankAccount(mediums, account)
}

render () {
return <AddCustomerDetails {...this.props} onSubmit={this.onSubmit} />
return this.props.data.cata({
Success: (value) => <Success onSubmit={this.onSubmit} {...value} />,
Failure: (msg) => <div>Failure: {msg.error}</div>,
Loading: () => <Loading />,
NotAsked: () => <Loading />
})
}
}

const mapStateToProps = (state) => ({
data: getData(state)
})

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

export default connect(mapStateToProps, mapDispatchToProps)(AddCustomerDetailsContainer)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export const COINIFY_GET_MEDIUM_ACCOUNTS_LOADING = '@CORE.COINIFY_GET_MEDIUM_ACC
export const COINIFY_GET_MEDIUM_ACCOUNTS_SUCCESS = '@CORE.COINIFY_GET_MEDIUM_ACCOUNTS_SUCCESS'
export const COINIFY_GET_MEDIUM_ACCOUNTS_FAILURE = '@CORE.COINIFY_GET_MEDIUM_ACCOUNTS_FAILURE'

export const COINIFY_ADD_BANK_ACCOUNT = '@CORE.COINIFY_ADD_BANK_ACCOUNT'
export const COINIFY_ADD_BANK_ACCOUNT_FAILURE = '@CORE.COINIFY_ADD_BANK_ACCOUNT_FAILURE'
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_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 @@ -56,6 +56,11 @@ export const getMediumAccountsLoading = () => ({ type: AT.COINIFY_GET_MEDIUM_ACC
export const getMediumAccountsSuccess = (accounts) => ({ type: AT.COINIFY_GET_MEDIUM_ACCOUNTS_SUCCESS, payload: accounts })
export const getMediumAccountsFailure = (error) => ({ type: AT.COINIFY_GET_MEDIUM_ACCOUNTS_FAILURE, payload: error })

export const addBankAccount = (medium, account) => ({ type: AT.COINIFY_ADD_BANK_ACCOUNT, payload: { medium, account } })
export const addBankAccountFailure = (error) => ({ type: AT.COINIFY_ADD_BANK_ACCOUNT_FAILURE, payload: error })
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 initiateBuy = (data) => ({ type: AT.COINIFY_BUY, payload: data })

export const initiateSell = (data) => ({ type: AT.COINIFY_SELL, payload: data })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default ({ api, options }) => {
yield takeLatest(AT.RESET_PROFILE, coinifySagas.resetProfile)
yield takeLatest(AT.COINIFY_GET_PAYMENT_MEDIUMS, coinifySagas.getPaymentMediums)
yield takeLatest(AT.COINIFY_GET_MEDIUM_ACCOUNTS, coinifySagas.getMediumAccounts)
yield takeLatest(AT.COINIFY_ADD_BANK_ACCOUNT, coinifySagas.addBankAccount)
yield takeLatest(AT.COINIFY_FETCH_QUOTE_AND_MEDIUMS, coinifySagas.fetchQuoteAndMediums)
yield takeLatest(AT.COINIFY_CANCEL_TRADE, coinifySagas.cancelTrade)
yield takeLatest(AT.COINIFY_BUY, coinifySagas.buy)
Expand Down
33 changes: 27 additions & 6 deletions packages/blockchain-wallet-v4/src/redux/data/coinify/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default ({ api, options }) => {
const delegate = new ExchangeDelegate(state, api)
const value = yield select(buySellSelectors.getMetadata)
const walletOptions = state.walletOptionsPath.data
let coinify = yield apply(coinifyService, coinifyService.refresh, [value, delegate, walletOptions])
let coinify = yield apply(coinifyService, coinifyService.refresh,
[value, delegate, walletOptions])
yield apply(coinify, coinify.profile.fetch)
yield put(A.coinifyFetchProfileSuccess(coinify))
return coinify
Expand All @@ -28,7 +29,8 @@ export default ({ api, options }) => {
const value = yield select(buySellSelectors.getMetadata)

const walletOptions = state.walletOptionsPath.data
coinify = yield apply(coinifyService, coinifyService.refresh, [value, delegate, walletOptions])
coinify = yield apply(coinifyService, coinifyService.refresh,
[value, delegate, walletOptions])
yield apply(coinify, coinify.profile.fetch)
yield put(A.coinifyFetchProfileSuccess(coinify))
}
Expand Down Expand Up @@ -57,8 +59,11 @@ export default ({ api, options }) => {
const coinify = yield select(S.getProfile)
yield put(A.fetchQuoteLoading())
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])
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 @@ -69,7 +74,9 @@ export default ({ api, options }) => {
const fetchQuoteAndMediums = function * (data) {
try {
const { amt, baseCurrency, quoteCurrency, medium, type } = data.payload
const getQuote = type === 'sell' ? coinify.data.getSellQuote : coinify.data.getBuyQuote
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)
Expand Down Expand Up @@ -139,12 +146,25 @@ export default ({ api, options }) => {
}
}

const addBankAccount = function * (data) {
try {
const { medium, account } = data.payload
const bankAccount = yield apply(medium, medium.addBankAccount, [account])
console.log(bankAccount)
// yield put(A.addBankAccountSuccess(bankAccount))
} catch (e) {
yield put(A.addBankAccountFailure(e))
}
}

const signup = function * () {
const countryCode = 'FR' // TODO should be passed in
const fiatCurrency = 'EUR' // TODO should be passed in
try {
const coinify = yield call(getCoinify)
const signupResponse = yield apply(coinify, coinify.signup, [countryCode, fiatCurrency]) // TODO countryCode and fiatCurrency passed in as args
const signupResponse = yield apply(coinify, coinify.signup,
[countryCode, fiatCurrency])
// TODO countryCode and fiatCurrency passed in as args

yield put(buySellA.coinifySetProfileBuySell(signupResponse))
yield put(A.coinifySetToken(signupResponse))
Expand Down Expand Up @@ -255,6 +275,7 @@ export default ({ api, options }) => {
resetProfile,
getPaymentMediums,
getMediumAccounts,
addBankAccount,
fetchQuoteAndMediums,
cancelTrade,
triggerKYC,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { path } from 'ramda'
import { path, prop } from 'ramda'
import { dataPath } from '../../paths'

export const getCoinify = path([dataPath, 'coinify'])
Expand All @@ -13,6 +13,8 @@ export const getProfile = path([dataPath, 'coinify', 'profile'])

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

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

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

export const getLevel = state => getProfile(state).map(path(['_level']))
Expand Down
9 changes: 6 additions & 3 deletions packages/blockchain-wallet-v4/src/redux/data/sfox/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export default ({ api, options }) => {
try {
const sfox = yield call(getSfox)
const methods = yield apply(sfox, sfox.getBuyMethods)
const addedBankAccount = yield apply(methods.ach, methods.ach.addAccount, [routing, account, name, type])
const addedBankAccount = yield apply(methods.ach, methods.ach.addAccount,
[routing, account, name, type])
yield put(A.setBankManuallySuccess(addedBankAccount))
} catch (e) {
yield put(A.setBankAccountFailure(e))
Expand Down Expand Up @@ -168,7 +169,8 @@ export default ({ api, options }) => {
try {
const sfox = yield call(getSfox)
const profile = yield select(S.getProfile)
const sfoxUrl = yield apply(profile.data, profile.data.getSignedURL, [idType, file.name])
const sfoxUrl = yield apply(profile.data, profile.data.getSignedURL,
[idType, file.name])

yield call(api.uploadVerificationDocument, sfoxUrl.signed_url, file)

Expand Down Expand Up @@ -197,7 +199,8 @@ export default ({ api, options }) => {
const { amount1, amount2 } = data.payload
try {
const accounts = yield select(S.getAccounts)
const response = yield apply(accounts.data[0], accounts.data[0].verify, [amount1, amount2])
const response = yield apply(accounts.data[0], accounts.data[0].verify,
[amount1, amount2])
console.log('deposits response', response)
/*
valid response: {payment_method_id: "69fa19d0-f045-4097-96ec-4e1c74ccc695", status: "active"}
Expand Down

0 comments on commit 3f10e2e

Please sign in to comment.