Set Bity Rates Polling Cycle to 30 Seconds

This commit is contained in:
Daniel Ternyak 2017-11-16 14:25:30 -06:00 committed by GitHub
parent 2a6d93eaa4
commit 8f69f103e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -1,9 +1,12 @@
import { showNotification } from 'actions/notifications'; import { showNotification } from 'actions/notifications';
import { loadBityRatesSucceededSwap } from 'actions/swap'; import { loadBityRatesSucceededSwap } from 'actions/swap';
import { TypeKeys } from 'actions/swap/constants';
import { getAllRates } from 'api/bity'; import { getAllRates } from 'api/bity';
import { delay, SagaIterator } from 'redux-saga'; import { delay, SagaIterator } from 'redux-saga';
import { call, cancel, fork, put, take, takeLatest } from 'redux-saga/effects'; import { call, cancel, fork, put, take, takeLatest } from 'redux-saga/effects';
const POLLING_CYCLE = 30000;
export function* loadBityRates(): SagaIterator { export function* loadBityRates(): SagaIterator {
while (true) { while (true) {
try { try {
@ -12,18 +15,18 @@ export function* loadBityRates(): SagaIterator {
} catch (error) { } catch (error) {
yield put(showNotification('danger', error.message)); yield put(showNotification('danger', error.message));
} }
yield call(delay, 5000); yield call(delay, POLLING_CYCLE);
} }
} }
// Fork our recurring API call, watch for the need to cancel. // Fork our recurring API call, watch for the need to cancel.
function* handleBityRates(): SagaIterator { function* handleBityRates(): SagaIterator {
const loadBityRatesTask = yield fork(loadBityRates); const loadBityRatesTask = yield fork(loadBityRates);
yield take('SWAP_STOP_LOAD_BITY_RATES'); yield take(TypeKeys.SWAP_STOP_LOAD_BITY_RATES);
yield cancel(loadBityRatesTask); yield cancel(loadBityRatesTask);
} }
// Watch for latest SWAP_LOAD_BITY_RATES_REQUESTED action. // Watch for latest SWAP_LOAD_BITY_RATES_REQUESTED action.
export function* getBityRatesSaga(): SagaIterator { export function* getBityRatesSaga(): SagaIterator {
yield takeLatest('SWAP_LOAD_BITY_RATES_REQUESTED', handleBityRates); yield takeLatest(TypeKeys.SWAP_LOAD_BITY_RATES_REQUESTED, handleBityRates);
} }