Skip to content

Commit

Permalink
feat(Jumio): move completeJumio to saga
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Jul 22, 2018
1 parent e4eec0f commit 867020a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const SFOX_SELL_BTC_PAYMENT_UPDATED_FAILURE =
'@COMPONENT.SFOX_SELL_BTC_PAYMENT_UPDATED_FAILURE'

export const INITIALIZE_JUMIO = '@COMPONENT.INITIALIZE_JUMIO'
export const COMPLETE_JUMIO = '@COMPONENT.COMPLETE_JUMIO'
export const FETCH_JUMIO_STATUS_SUCCESS =
'@COMPONENT.FETCH_JUMIO_STATUS_SUCCESS'
export const FETCH_JUMIO_STATUS_FAILURE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const sfoxSellBtcPaymentUpdatedFailure = err => ({
})

export const initializeJumio = () => ({ type: AT.INITIALIZE_JUMIO })
export const completeJumio = () => ({ type: AT.COMPLETE_JUMIO })
export const fetchJumioStatusLoading = () => ({
type: AT.FETCH_JUMIO_STATUS_LOADING
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export default ({ coreSagas }) => {
yield takeLatest(AT.SFOX_INITIALIZE_PAYMENT, sfoxSagas.initializePayment)
yield takeLatest(AT.INITIALIZE_JUMIO, sfoxSagas.initializeJumio)
yield takeLatest(AT.FETCH_JUMIO_TOKEN, sfoxSagas.fetchJumioToken)
yield takeLatest(AT.COMPLETE_JUMIO, sfoxSagas.completeJumio)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,28 @@ export default ({ coreSagas }) => {
}
}

const completeJumio = function*() {
try {
// Jumio status of 'PENDING' can mean the user finished verification
// flow and the results are 'PENDING' jumio. Or the user has not finished
// and the flow requires user action.
// When a Jumio callback has been retreived, set jumio token to 'complete'
// so the UI can determine which type of 'PENDING' status the user is.
const tokenR = yield select(selectors.core.kvStore.buySell.getSfoxJumio)
const accountsR = yield select(selectors.core.data.sfox.getAccounts)
const accounts = accountsR.getOrElse([])
let token = tokenR.getOrElse({})
token.completed = true
accounts.length
? yield put(modalActions.closeAllModals())
: yield put(A.nextStep('funding'))
yield call(fetchJumioStatus)
yield put(actions.core.kvStore.buySell.sfoxSetJumioToken(token))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'completeJumio', e))
}
}

const fetchJumioStatus = function*() {
try {
yield put(A.fetchJumioStatusLoading())
Expand All @@ -301,10 +323,12 @@ export default ({ coreSagas }) => {
yield put(A.fetchJumioTokenLoading())
const profileR = yield select(selectors.core.data.sfox.getProfile)
const profile = profileR.getOrElse({})
const token = yield apply(profile, profile.fetchJumioToken)
let token = yield apply(profile, profile.fetchJumioToken)
// If a new token must be fetched set 'completed' to false
token.completed = false
yield put(actions.core.kvStore.buySell.sfoxSetJumioToken(token))
yield call(fetchJumioStatus)
yield put(A.fetchJumioTokenSuccess(token))
yield call(fetchJumioStatus)
} catch (e) {
yield put(A.fetchJumioTokenFailure(e))
yield put(actions.logs.logErrorMessage(logLocation, 'fetchJumioToken', e))
Expand All @@ -324,6 +348,7 @@ export default ({ coreSagas }) => {
submitSellQuote,
initializeJumio,
fetchJumioToken,
completeJumio,
upload
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ class JumioContainer extends React.PureComponent {
}

onFinish () {
const { data } = this.props
const { accounts } = data.getOrElse({ accounts: [] })
accounts.length
? this.props.sfoxActions.handleModalClose()
: this.props.sfoxActions.nextStep('funding')
this.props.sfoxActions.completeJumio()
}

render () {
Expand Down

0 comments on commit 867020a

Please sign in to comment.