William O'Beirne f5b6a49463 Translation updates (#120)
* Updated all translations, moved into their own folders.

* Switch translations to use Markdown component.

* Remove markup tests, since were using a module now.

* Fix flow errors, render react elements instead of dangerouslysetinnerhtml.

* Make translate a connected component, so it updates with Redux.

* Fix flow errors

* First pass at returning raw when needed for placeholder.

* Added aria test.

* Fixed flow errors and linter warnings.

* Move settimeout to saga.

* Change reload to 250 ms from 1500 ms
2017-08-28 13:05:38 -05:00

38 lines
1.3 KiB
JavaScript

// @flow
import { delay } from 'redux-saga';
import { getAllRates } from 'api/bity';
import { call, put, fork, take, cancel, cancelled } from 'redux-saga/effects';
import type { Effect } from 'redux-saga/effects';
import { loadBityRatesSucceededSwap } from 'actions/swap';
export function* loadBityRates(_action?: any): Generator<Effect, void, any> {
try {
while (true) {
// TODO - BITY_RATE_REQUESTED
// network request
const data = yield call(getAllRates);
// action
yield put(loadBityRatesSucceededSwap(data));
// wait 5 seconds before refreshing rates
yield call(delay, 5000);
}
} finally {
if (yield cancelled()) {
// TODO - implement request cancel if needed
// yield put(actions.requestFailure('Request cancelled!'))
}
}
}
export function* getBityRatesSaga(): Generator<Effect, void, any> {
while (yield take('SWAP_LOAD_BITY_RATES_REQUESTED')) {
// starts the task in the background
const loadBityRatesTask = yield fork(loadBityRates);
// wait for the user to get to point where refresh is no longer needed
yield take('SWAP_STOP_LOAD_BITY_RATES');
// cancel the background task
// this will cause the forked loadBityRates task to jump into its finally block
yield cancel(loadBityRatesTask);
}
}