spee.ch/react/sagas/show_asset.js

31 lines
1 KiB
JavaScript
Raw Normal View History

2018-02-08 23:17:03 +01:00
import { call, put, takeLatest } from 'redux-saga/effects';
import * as actions from 'constants/show_action_types';
import { updateRequestError, addAssetToAssetList } from 'actions/show';
2018-02-08 23:17:03 +01:00
import { getShortId, getClaimData } from 'api/assetApi';
function* getAssetDataAndShowAsset (action) {
const {id, name, claimId} = action.data;
// get short Id
2018-02-13 03:50:19 +01:00
console.log('getting short id');
let shortId;
2018-02-08 23:17:03 +01:00
try {
({data: shortId} = yield call(getShortId, name, claimId));
2018-02-08 23:17:03 +01:00
} catch (error) {
return yield put(updateRequestError(error.message));
2018-02-08 23:17:03 +01:00
}
// if no error, get claim data
2018-02-13 03:50:19 +01:00
console.log('getting claim data');
2018-02-08 23:17:03 +01:00
let claimData;
try {
({data: claimData} = yield call(getClaimData, name, claimId));
2018-02-08 23:17:03 +01:00
} catch (error) {
return yield put(updateRequestError(error.message));
2018-02-08 23:17:03 +01:00
}
yield put(addAssetToAssetList(id, null, name, claimId, shortId, claimData));
yield put(updateRequestError(null));
2018-02-08 23:17:03 +01:00
}
export function* watchShowNewAsset () {
2018-02-13 05:01:02 +01:00
yield takeLatest(actions.ASSET_NEW_ASYNC, getAssetDataAndShowAsset);
2018-02-08 23:17:03 +01:00
};