mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-25 09:15:16 +00:00
### Re-implements: * min/max validators on initial currency swap selection * polling of order status * timer that persists across refreshes via localStorage (computed based on `createdTime` and `validFor` amount) * swap persists across refreshes once order is created. * various type refactors ### New additions: * *SimpleButton* (can be PRd separately on request) * clear loading state after order create (via SimpleButton and font-awesome) * buffers for non-BTC swaps (bity does not actually accept 0.01 BTC worth of ETH as they claim they do in their JSON response, so a magic number of 10% is added to the minimum).
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
// @flow
|
|
import { delay } from 'redux-saga';
|
|
import { getAllRates } from 'api/bity';
|
|
import {
|
|
call,
|
|
put,
|
|
fork,
|
|
take,
|
|
cancel,
|
|
cancelled,
|
|
takeLatest
|
|
} 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);
|
|
}
|
|
}
|