github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/blockapps-ba-master/ui/src/components/ExplorerUrl/explorer.saga.js (about)

     1  import { takeLatest, put, call } from 'redux-saga/effects';
     2  import {
     3    GET_EXPLORER_URL,
     4    getExplorerUrlSuccess,
     5    getExplorerUrlFailure
     6  } from './explorer.actions';
     7  import { API_URL } from '../../environment';
     8  import { handleApiError } from '../../lib/apiErrorHandler';
     9  
    10  const apiUrl = API_URL + '/system/explorer-url';
    11  
    12  function getExplorerUrlCall() {
    13    return fetch(apiUrl, {
    14      method: 'GET',
    15      headers: {
    16        'Content-Type': 'application/json;charset=utf-8',
    17        'Accept': 'application/json'
    18      }
    19    })
    20    .then(handleApiError)
    21    .then(function(response) {
    22      return response.json();
    23    })
    24    .catch(function(error){
    25      throw error;
    26    });
    27  }
    28  
    29  function* getExplorerUrl(action) {
    30    try {
    31      const response = yield call(getExplorerUrlCall);
    32      if(response.data.explorerUrl) {
    33        yield put(getExplorerUrlSuccess(response.data.explorerUrl));
    34      }
    35    }
    36    catch(err)
    37    {
    38      yield put(getExplorerUrlFailure(err));
    39    }
    40  }
    41  
    42  export default function* watchLoginSubmit() {
    43    yield takeLatest(GET_EXPLORER_URL, getExplorerUrl);
    44  }