Skip to content

Commit

Permalink
refactor(coinify kyc sagas)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed Jun 19, 2018
1 parent c8cb7df commit 7392080
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/blockchain-wallet-v4/src/redux/data/coinify/sagas.js
Expand Up @@ -288,16 +288,19 @@ export default ({ api, options }) => {
}
}

const sortKycs = function * () {
const coinify = yield call(getCoinify)
const kycs = yield apply(coinify, coinify.getKYCs)
const byTime = (a, b) => prop('createdAt', b) - prop('createdAt', a)
return sort(byTime, kycs)
}

const getKYCs = function * () {
try {
yield put(A.getKYCsLoading())
const coinify = yield call(getCoinify)
const kycs = yield apply(coinify, coinify.getKYCs)
const byTime = (a, b) => b.createdAt - a.createdAt
const sortedKYCs = sort(byTime, kycs)

const sortedKYCs = yield call(sortKycs)
yield put(A.getKYCsSuccess(sortedKYCs))
return kycs
return sortedKYCs
} catch (e) {
console.log('getKYCs failure', e)
yield put(A.getKYCsFailure(e))
Expand All @@ -307,15 +310,11 @@ export default ({ api, options }) => {
const pollKYCsPending = function * () {
try {
const kycs = yield select(S.getKycs)
console.log(kycs)
const statusPath = x => path(['0', 'state'], x)
let status = kycs.map(kycs => statusPath(kycs)).getOrElse('pending')
const statusPath = path(['0', 'state'])
let status = kycs.map(statusPath).getOrElse(undefined)
while (equals(status, 'pending')) {
yield call(delay, 1000)
const coinify = yield call(getCoinify)
const kycs = yield apply(coinify, coinify.getKYCs)
const byTime = (a, b) => b.createdAt - a.createdAt
const sortedKYCs = sort(byTime, kycs)
const sortedKYCs = yield call(sortKycs)
status = statusPath(sortedKYCs)
yield put(A.getKYCsSuccess(sortedKYCs))
}
Expand Down

0 comments on commit 7392080

Please sign in to comment.