Skip to content

Commit

Permalink
fix(KYC): fixed user creation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-blockchain committed Dec 16, 2018
1 parent df9ac92 commit dcfe62c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ TierCard.defaultProps = {
outsideOfProfile: false
}

const mapDispatchToProps = dispatch => ({
const mapDispatchToProps = (dispatch, { tier }) => ({
verifyIdentity: () =>
dispatch(actions.components.identityVerification.verifyIdentity())
dispatch(actions.components.identityVerification.verifyIdentity(tier))
})

export default connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default ({ api, coreSagas }) => {
const { USER_ACTIVATION_STATES, TIERS } = model.profile
const {
getCampaignData,
fetchUser,
createUser,
updateUser,
generateRetailToken,
Expand All @@ -62,7 +63,8 @@ export default ({ api, coreSagas }) => {
const campaignData = yield call(getCampaignData, campaign)
const token = (yield select(
selectors.modules.profile.getApiToken
)).getOrFail()
)).getOrElse(null)
if (!token) return
try {
yield call(
api.registerUserCampaign,
Expand All @@ -83,9 +85,7 @@ export default ({ api, coreSagas }) => {

const createRegisterUserCampaign = function*() {
try {
const userWithEmailExists = yield call(verifyIdentity)
if (userWithEmailExists) return
yield call(createUser)
yield call(verifyIdentity)
yield call(registerUserCampaign, { newUser: true })
} catch (e) {
yield put(
Expand All @@ -103,32 +103,34 @@ export default ({ api, coreSagas }) => {
if (selected === tier)
return yield put(actions.analytics.logKycEvent(REENTERED))
yield call(api.selectTier, tier)
yield call(fetchUser)
yield put(actions.analytics.logKycEvent(STARTED))
}

const checkUserExistance = function*() {
const checkUserUniqueness = function*() {
const userId = (yield select(
selectors.core.kvStore.userCredentials.getUserId
)).getOrElse('')

if (userId) return false
if (userId) return true
try {
const retailToken = yield call(generateRetailToken)
yield call(api.checkUserExistence, retailToken)
return true
} catch (e) {
return false
} catch (e) {
return true
}
}

const verifyIdentity = function*({ payload }) {
const { tier } = payload
const userExists = yield call(checkUserExistance)
if (userExists) {
const unique = yield call(checkUserUniqueness)
if (!unique) {
yield put(actions.modals.showModal(USER_EXISTS_MODAL))
return yield put(actions.analytics.logKycEvent(EMAIL_EXISTS))
}
try {
yield call(createUser)
yield call(selectTier, tier)
yield put(actions.modals.showModal(KYC_MODAL, { desiredTier: tier }))
} catch (e) {
Expand Down Expand Up @@ -251,7 +253,6 @@ export default ({ api, coreSagas }) => {
const savePersonalData = function*() {
try {
yield put(actions.form.startSubmit(PERSONAL_FORM))
yield call(createUser)
const {
firstName,
lastName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const api = {
const coreSagas = {}

const {
createUser,
checkKycFlow,
createRegisterUserCampaign,
goToNextStep,
Expand Down Expand Up @@ -203,28 +202,14 @@ describe('checkKycFlow saga', () => {
})

describe('createRegisterUserCampaign', () => {
it('should return if user exists', () => {
it('should call verify identity and register user campaign', () => {
const saga = testSaga(createRegisterUserCampaign)
saga
.next()
.call(verifyIdentity)
.next(true)
.next()
.call(registerUserCampaign, { newUser: true })
.next()
.isDone()
})
describe('should get user id if user needs verification', () => {
const saga = testSaga(createRegisterUserCampaign)
it('should attempt to verify id', () => {
saga.next().call(verifyIdentity)
})
it('should createUser', () => {
saga.next(false).call(createUser)
})
it('should register user campaign', () => {
saga
.next()
.call(registerUserCampaign, { newUser: true })
.next()
.isDone()
})
})
})

0 comments on commit dcfe62c

Please sign in to comment.