mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-09 18:45:38 +00:00
6c09e7160a
* add exports to config saga, refactor * add config saga tests * add exports to necessary files * add remaining saga test & snapshots * update orders saga spec to use Infinity constant * update dWallet saga spec snapshot * refactor config saga slightly * update config saga spec * update config saga snapshot * update rates saga spec * remove unused vars from config saga spec
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { showNotification } from 'actions/notifications';
|
|
import { loadBityRatesSucceededSwap } from 'actions/swap';
|
|
import { TypeKeys } from 'actions/swap/constants';
|
|
import { getAllRates } from 'api/bity';
|
|
import { delay, SagaIterator } from 'redux-saga';
|
|
import { call, cancel, fork, put, take, takeLatest } from 'redux-saga/effects';
|
|
|
|
const POLLING_CYCLE = 30000;
|
|
|
|
export function* loadBityRates(): SagaIterator {
|
|
while (true) {
|
|
try {
|
|
const data = yield call(getAllRates);
|
|
yield put(loadBityRatesSucceededSwap(data));
|
|
} catch (error) {
|
|
yield put(showNotification('danger', error.message));
|
|
}
|
|
yield call(delay, POLLING_CYCLE);
|
|
}
|
|
}
|
|
|
|
// Fork our recurring API call, watch for the need to cancel.
|
|
export function* handleBityRates(): SagaIterator {
|
|
const loadBityRatesTask = yield fork(loadBityRates);
|
|
yield take(TypeKeys.SWAP_STOP_LOAD_BITY_RATES);
|
|
yield cancel(loadBityRatesTask);
|
|
}
|
|
|
|
// Watch for latest SWAP_LOAD_BITY_RATES_REQUESTED action.
|
|
export function* getBityRatesSaga(): SagaIterator {
|
|
yield takeLatest(TypeKeys.SWAP_LOAD_BITY_RATES_REQUESTED, handleBityRates);
|
|
}
|