2018-02-08 23:17:03 +01:00
|
|
|
import { call, put, takeLatest } from 'redux-saga/effects';
|
|
|
|
import * as actions from 'constants/show_action_types';
|
2018-02-13 03:18:56 +01:00
|
|
|
import { updateRequestError, addNewChannelToChannelList, updateChannelClaims } from 'actions/show';
|
2018-02-08 23:17:03 +01:00
|
|
|
import { getChannelClaims } from 'api/channelApi';
|
|
|
|
|
2018-02-09 19:02:13 +01:00
|
|
|
function* getChannelClaimsAndShowChannel (action) {
|
2018-02-13 03:18:56 +01:00
|
|
|
const { id, name, shortId, longId } = action.data;
|
2018-02-08 23:17:03 +01:00
|
|
|
let success, message, claimsData;
|
|
|
|
try {
|
|
|
|
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, 1));
|
|
|
|
} catch (error) {
|
2018-02-13 03:18:56 +01:00
|
|
|
return yield put(updateRequestError(error.message));
|
2018-02-08 23:17:03 +01:00
|
|
|
}
|
|
|
|
if (!success) {
|
2018-02-13 03:18:56 +01:00
|
|
|
return yield put(updateRequestError(message));
|
2018-02-08 23:17:03 +01:00
|
|
|
}
|
2018-02-13 03:18:56 +01:00
|
|
|
yield put(addNewChannelToChannelList(id, name, shortId, longId, claimsData));
|
|
|
|
yield put(updateRequestError(null));
|
2018-02-08 23:17:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function* watchShowNewChannel () {
|
2018-02-09 19:02:13 +01:00
|
|
|
yield takeLatest(actions.SHOW_CHANNEL_NEW, getChannelClaimsAndShowChannel);
|
2018-02-08 23:17:03 +01:00
|
|
|
};
|
2018-02-09 19:02:13 +01:00
|
|
|
|
|
|
|
function* getNewClaimsAndUpdateClaimsList (action) {
|
2018-02-13 03:18:56 +01:00
|
|
|
const { channelKey, name, longId, page } = action.data;
|
2018-02-09 19:02:13 +01:00
|
|
|
let success, message, claimsData;
|
|
|
|
try {
|
|
|
|
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, page));
|
|
|
|
} catch (error) {
|
2018-02-13 03:18:56 +01:00
|
|
|
return yield put(updateRequestError(error.message));
|
2018-02-09 19:02:13 +01:00
|
|
|
}
|
|
|
|
if (!success) {
|
2018-02-13 03:18:56 +01:00
|
|
|
return yield put(updateRequestError(message));
|
2018-02-09 19:02:13 +01:00
|
|
|
}
|
2018-02-13 03:18:56 +01:00
|
|
|
yield put(updateChannelClaims(channelKey, claimsData));
|
2018-02-09 19:02:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function* watchShowNewChannelClaimsRequest () {
|
|
|
|
yield takeLatest(actions.CHANNEL_LIST_CLAIMS_UPDATE_ASYNC, getNewClaimsAndUpdateClaimsList);
|
|
|
|
}
|