Skip to content

Commit

Permalink
fix(SFOX): decouple sfox sell from sendBtc payment
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Welber committed Jul 6, 2018
1 parent 665bf45 commit aaa6fb9
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 34 deletions.
8 changes: 4 additions & 4 deletions config/wallet-options-v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@
"countries": ["US"],
"states": ["AR", "AZ", "CA", "CO", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "MI", "MN", "MO", "MT", "NE", "NV", "OK", "PA", "SC", "SD", "TN", "TX", "VA", "WI", "WV"],
"config": {
"production": true,
"production": false,
"availability": true,
"apiKey": "f31614a7-5074-49f2-8c2a-bfb8e55de2bd",
"apiKey": "6CD61A0E965D48A7B1883A860490DC9E",
"plaid": "0b041cd9e9fbf1e7d93a0d5a39f5b9",
"plaidEnv": "production",
"siftScience": "a19cc360a1",
"plaidEnv": "tartan",
"siftScience": "3884e5fae5",
"surveyLinks": [
"https://blockchain.co1.qualtrics.com/SE/?SID=SV_bPCcv7eZgqlQSrP",
"https://blockchain.co1.qualtrics.com/SE/?SID=SV_4HIEh5KIodM8UTP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ export const DISABLE_SIFT_SCIENCE = '@COMPONENT.DISABLE_SIFT_SCIENCE'
export const HANDLE_MODAL_CLOSE = '@COMPONENT.HANDLE_MODAL_CLOSE'

export const SFOX_INITIALIZE_PAYMENT = '@COMPONENT.SFOX_INITIALIZE_PAYMENT'

export const SFOX_SELL_BTC_PAYMENT_UPDATED_SUCCESS = '@COMPONENT.SFOX_SELL_BTC_PAYMENT_UPDATED_SUCCESS'
export const SFOX_SELL_BTC_PAYMENT_UPDATED_LOADING = '@COMPONENT.SFOX_SELL_BTC_PAYMENT_UPDATED_LOADING'
export const SFOX_SELL_BTC_PAYMENT_UPDATED_FAILURE = '@COMPONENT.SFOX_SELL_BTC_PAYMENT_UPDATED_FAILURE'
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ export const disableSiftScience = () => ({ type: AT.DISABLE_SIFT_SCIENCE })
export const handleModalClose = () => ({ type: AT.HANDLE_MODAL_CLOSE })

export const initializePayment = payload => ({ type: AT.SFOX_INITIALIZE_PAYMENT, payload })

export const sfoxSellBtcPaymentUpdatedSuccess = payment => ({ type: AT.SFOX_SELL_BTC_PAYMENT_UPDATED_SUCCESS, payload: payment })
export const sfoxSellBtcPaymentUpdatedLoading = () => ({ type: AT.SFOX_SELL_BTC_PAYMENT_UPDATED_LOADING })
export const sfoxSellBtcPaymentUpdatedFailure = (err) => ({ type: AT.SFOX_SELL_BTC_PAYMENT_UPDATED_FAILURE, payload: err })
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Remote } from 'blockchain-wallet-v4/src'
const INITIAL_STATE = {
sfoxBusy: Remote.NotAsked,
qaSellAddress: null,
siftScienceEnabled: false
siftScienceEnabled: false,
payment: Remote.NotAsked
}

const sfoxSignup = (state = INITIAL_STATE, action) => {
Expand Down Expand Up @@ -36,6 +37,15 @@ const sfoxSignup = (state = INITIAL_STATE, action) => {
case AT.DISABLE_SIFT_SCIENCE: {
return assoc('siftScienceEnabled', false, state)
}
case AT.SFOX_SELL_BTC_PAYMENT_UPDATED_SUCCESS: {
return assoc('payment', Remote.Success(payload), state)
}
case AT.SFOX_SELL_BTC_PAYMENT_UPDATED_LOADING: {
return assoc('payment', Remote.Loading, state)
}
case AT.SFOX_SELL_BTC_PAYMENT_UPDATED_FAILURE: {
return assoc('payment', Remote.Failure(payload), state)
}
default:
return state
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import * as actions from '../../actions'
import * as selectors from '../../selectors.js'
import * as modalActions from '../../modals/actions'
import * as modalSelectors from '../../modals/selectors'
import * as sendBtcActions from '../../components/sendBtc/actions'
import * as sendBtcSelectors from '../../components/sendBtc/selectors'
import settings from 'config'
import * as C from 'services/AlertService'
import { promptForSecondPassword } from 'services/SagaService'
Expand Down Expand Up @@ -156,15 +154,15 @@ export default ({ coreSagas }) => {
yield put(A.sfoxLoading())
const trade = yield call(coreSagas.data.sfox.handleSellTrade, q)

let p = yield select(sendBtcSelectors.getPayment)
const state = yield select()

let p = path(['sfoxSignup', 'payment'], state)
let payment = yield coreSagas.payment.btc.create({ payment: p.getOrElse({}), network: settings.NETWORK_BITCOIN })

payment = yield payment.amount(parseInt(trade.sendAmount))

// QA Tool: manually set a "to" address on the payment object for testing sell
const qaState = yield select()
const qaAddress = path(['qa', 'qaSellAddress'], qaState)

const qaAddress = path(['qa', 'qaSellAddress'], state)
if (qaAddress) {
payment = yield payment.to(qaAddress)
} else {
Expand All @@ -182,10 +180,13 @@ export default ({ coreSagas }) => {
payment = yield payment.sign(password)
payment = yield payment.publish()

yield put(sendBtcActions.sendBtcPaymentUpdatedSuccess(payment.value()))
yield put(actions.core.data.bitcoin.fetchData())
yield put(actions.core.wallet.setTransactionNote(payment.value().txId, payment.value().description))

yield put(A.sfoxSuccess())
yield put(actions.form.change('buySellTabStatus', 'status', 'order_history'))
yield put(modalActions.showModal('SfoxTradeDetails', { trade }))
yield call(initializePayment)
} catch (e) {
yield put(A.sfoxFailure(e))
yield put(actions.logs.logErrorMessage(logLocation, 'submitSellQuote', e))
Expand All @@ -200,30 +201,18 @@ export default ({ coreSagas }) => {
}
}

const initializePayment = function * (action) {
const initializePayment = function * () {
try {
const { feeType } = action.payload
yield put(A.sendBtcPaymentUpdatedLoading())
yield put(A.sfoxSellBtcPaymentUpdatedLoading())
let payment = coreSagas.payment.btc.create(({ network: settings.NETWORK_BITCOIN }))
payment = yield payment.init()
// const accountsR = yield select(selectors.core.common.btc.getAccountsBalances)
const defaultIndex = yield select(selectors.core.wallet.getDefaultAccountIndex)
// const defaultAccountR = accountsR.map(nth(defaultIndex))
const defaultFeePerByte = path(['fees', feeType || 'regular'], payment.value())
const defaultFeePerByte = path(['fees', 'priority'], payment.value())
payment = yield payment.from(defaultIndex)
payment = yield payment.fee(defaultFeePerByte)
// const initialValues = {
// to: to,
// coin: 'BTC',
// amount: amount,
// message: message,
// from: defaultAccountR.getOrElse(),
// feePerByte: defaultFeePerByte
// }
// yield put(initialize('sendBtc', initialValues))
yield put(A.sendBtcPaymentUpdatedSuccess(payment.value()))
yield put(A.sfoxSellBtcPaymentUpdatedSuccess(payment.value()))
} catch (e) {
yield put(A.sendBtcPaymentUpdatedFailure(e))
yield put(A.sfoxSellBtcPaymentUpdatedFailure(e))
yield put(actions.logs.logErrorMessage(logLocation, 'initializePayment', e))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class SfoxCheckout extends React.PureComponent {
this.props.sfoxDataActions.sfoxFetchAccounts()
this.props.sfoxDataActions.fetchQuote({quote: { amt: 1e8, baseCurrency: 'BTC', quoteCurrency: 'USD' }})
this.props.sfoxDataActions.fetchSellQuote({quote: { amt: 1e8, baseCurrency: 'BTC', quoteCurrency: 'USD' }})
// this.props.sendBtcActions.initialized({ feeType: 'priority' })
this.props.sfoxActions.initializePayment({ feeType: 'priority' })
this.props.sfoxActions.initializePayment()
}

componentWillUnmount () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ export const getBase = (state) =>
export const getErrors = (state) =>
path(['form', 'exchangeCheckout', 'syncErrors'], state)

export const getPayment = (state) =>
selectors.components.sendBtc.getPayment(state).getOrElse(null)
export const getPayment = path(['sfoxSignup', 'payment'])
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const Success = props => {
const accounts = Remote.of(props.value.accounts).getOrElse([])
const profile = Remote.of(props.value.profile).getOrElse({ account: { verification_status: {} }, limits: { buy: 0, sell: 0 } })
const verificationStatus = Remote.of(props.value.verificationStatus).getOrElse({ level: 'unverified', required_docs: [] })
const payment = Remote.of(props.payment).getOrElse({ effectiveBalance: 0 })
const payment = props.payment.getOrElse({ effectiveBalance: 0 })

const { trades, type, busy } = rest
const step = determineStep(profile, verificationStatus, accounts)
Expand Down

0 comments on commit aaa6fb9

Please sign in to comment.