Skip to content

Commit

Permalink
feat(SFOX): start to decouple payment initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Welber committed Jul 6, 2018
1 parent 33d4a2e commit 665bf45
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ export const ENABLE_SIFT_SCIENCE = '@COMPONENT.ENABLE_SIFT_SCIENCE'
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'
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ export const enableSiftScience = () => ({ type: AT.ENABLE_SIFT_SCIENCE })
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 })
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export default ({ coreSagas }) => {
yield takeLatest(AT.SUBMIT_QUOTE, sfoxSagas.submitQuote)
yield takeLatest(AT.SUBMIT_SELL_QUOTE, sfoxSagas.submitSellQuote)
yield takeLatest(AT.HANDLE_MODAL_CLOSE, sfoxSagas.checkForProfileFailure)
yield takeLatest(AT.SFOX_INITIALIZE_PAYMENT, sfoxSagas.initializePayment)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,37 @@ export default ({ coreSagas }) => {
}
}

const initializePayment = function * (action) {
try {
const { feeType } = action.payload
yield put(A.sendBtcPaymentUpdatedLoading())
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())
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()))
} catch (e) {
yield put(A.sendBtcPaymentUpdatedFailure(e))
yield put(actions.logs.logErrorMessage(logLocation, 'initializePayment', e))
}
}

return {
checkForProfileFailure,
initializePayment,
prepareAddress,
setBankManually,
setBank,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ 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.sendBtcActions.initialized({ feeType: 'priority' })
this.props.sfoxActions.initializePayment({ feeType: 'priority' })
}

componentWillUnmount () {
Expand Down

0 comments on commit 665bf45

Please sign in to comment.