From 7392080b45cf3c97741d9c19a49462be15d96ec6 Mon Sep 17 00:00:00 2001 From: Sixte de Maupeou Date: Tue, 19 Jun 2018 10:46:47 +0100 Subject: [PATCH] refactor(coinify kyc sagas) --- .../src/redux/data/coinify/sagas.js | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/blockchain-wallet-v4/src/redux/data/coinify/sagas.js b/packages/blockchain-wallet-v4/src/redux/data/coinify/sagas.js index a310d58194c..7909b786bda 100644 --- a/packages/blockchain-wallet-v4/src/redux/data/coinify/sagas.js +++ b/packages/blockchain-wallet-v4/src/redux/data/coinify/sagas.js @@ -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)) @@ -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)) }