mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-18 14:07:31 +00:00
Merge pull request #37 from MyEtherWallet/bity_stop_refresh
Sagas: Adjust bity saga to allow for cancelled polling, and stop poll…
This commit is contained in:
commit
8092a5dec3
@ -24,6 +24,7 @@
|
|||||||
"no-underscore-dangle": 0,
|
"no-underscore-dangle": 0,
|
||||||
"no-console": 0,
|
"no-console": 0,
|
||||||
"no-unused-vars": 0,
|
"no-unused-vars": 0,
|
||||||
|
"no-constant-condition": 0,
|
||||||
"no-trailing-spaces": [1, { "skipBlankLines": true }],
|
"no-trailing-spaces": [1, { "skipBlankLines": true }],
|
||||||
"no-unreachable": 1,
|
"no-unreachable": 1,
|
||||||
"no-alert": 0,
|
"no-alert": 0,
|
||||||
|
@ -8,7 +8,8 @@ import {
|
|||||||
SWAP_PART_TWO_COMPLETE,
|
SWAP_PART_TWO_COMPLETE,
|
||||||
SWAP_DESTINATION_ADDRESS,
|
SWAP_DESTINATION_ADDRESS,
|
||||||
SWAP_RESTART,
|
SWAP_RESTART,
|
||||||
SWAP_LOAD_BITY_RATES
|
SWAP_LOAD_BITY_RATES,
|
||||||
|
SWAP_STOP_LOAD_BITY_RATES
|
||||||
} from './swapConstants';
|
} from './swapConstants';
|
||||||
|
|
||||||
export const originKindSwap = value => {
|
export const originKindSwap = value => {
|
||||||
@ -78,3 +79,9 @@ export const loadBityRates = () => {
|
|||||||
type: SWAP_LOAD_BITY_RATES
|
type: SWAP_LOAD_BITY_RATES
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const stopLoadBityRates = () => {
|
||||||
|
return {
|
||||||
|
type: SWAP_STOP_LOAD_BITY_RATES
|
||||||
|
};
|
||||||
|
};
|
||||||
|
@ -8,3 +8,4 @@ export const SWAP_PART_TWO_COMPLETE = 'SWAP_PART_TWO_COMPLETE';
|
|||||||
export const SWAP_DESTINATION_ADDRESS = 'SWAP_DESTINATION_ADDRESS';
|
export const SWAP_DESTINATION_ADDRESS = 'SWAP_DESTINATION_ADDRESS';
|
||||||
export const SWAP_RESTART = 'SWAP_RESTART';
|
export const SWAP_RESTART = 'SWAP_RESTART';
|
||||||
export const SWAP_LOAD_BITY_RATES = 'SWAP_LOAD_BITY_RATES';
|
export const SWAP_LOAD_BITY_RATES = 'SWAP_LOAD_BITY_RATES';
|
||||||
|
export const SWAP_STOP_LOAD_BITY_RATES = 'SWAP_STOP_LOAD_BITY_RATES';
|
||||||
|
@ -10,7 +10,8 @@ export default class ReceivingAddress extends Component {
|
|||||||
destinationKind: PropTypes.string.isRequired,
|
destinationKind: PropTypes.string.isRequired,
|
||||||
destinationAddressSwap: PropTypes.func.isRequired,
|
destinationAddressSwap: PropTypes.func.isRequired,
|
||||||
destinationAddress: PropTypes.string,
|
destinationAddress: PropTypes.string,
|
||||||
partTwoCompleteSwap: PropTypes.func
|
partTwoCompleteSwap: PropTypes.func,
|
||||||
|
stopLoadBityRates: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
onChangeDestinationAddress = (event: SyntheticInputEvent) => {
|
onChangeDestinationAddress = (event: SyntheticInputEvent) => {
|
||||||
@ -19,6 +20,7 @@ export default class ReceivingAddress extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onClickPartTwoComplete = () => {
|
onClickPartTwoComplete = () => {
|
||||||
|
this.props.stopLoadBityRates();
|
||||||
this.props.partTwoCompleteSwap(true);
|
this.props.partTwoCompleteSwap(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@ class Swap extends Component {
|
|||||||
destinationAddressSwap: PropTypes.func,
|
destinationAddressSwap: PropTypes.func,
|
||||||
restartSwap: PropTypes.func,
|
restartSwap: PropTypes.func,
|
||||||
partTwoCompleteSwap: PropTypes.func,
|
partTwoCompleteSwap: PropTypes.func,
|
||||||
partTwoComplete: PropTypes.bool
|
partTwoComplete: PropTypes.bool,
|
||||||
|
stopLoadBityRates: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -59,7 +60,8 @@ class Swap extends Component {
|
|||||||
destinationAddress,
|
destinationAddress,
|
||||||
restartSwap,
|
restartSwap,
|
||||||
partTwoCompleteSwap,
|
partTwoCompleteSwap,
|
||||||
partTwoComplete
|
partTwoComplete,
|
||||||
|
stopLoadBityRates
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
let wantToSwapMyProps = {
|
let wantToSwapMyProps = {
|
||||||
@ -88,7 +90,8 @@ class Swap extends Component {
|
|||||||
destinationKind,
|
destinationKind,
|
||||||
destinationAddressSwap,
|
destinationAddressSwap,
|
||||||
destinationAddress,
|
destinationAddress,
|
||||||
partTwoCompleteSwap
|
partTwoCompleteSwap,
|
||||||
|
stopLoadBityRates
|
||||||
};
|
};
|
||||||
|
|
||||||
const referenceNumber = '2341asdfads';
|
const referenceNumber = '2341asdfads';
|
||||||
|
@ -1,23 +1,45 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import { takeLatest, call, apply, put, select, fork } from 'redux-saga/effects';
|
import { call, put, fork, take, cancel, cancelled } from 'redux-saga/effects';
|
||||||
|
|
||||||
import type { Effect } from 'redux-saga/effects';
|
import type { Effect } from 'redux-saga/effects';
|
||||||
import { delay } from 'redux-saga';
|
import { delay } from 'redux-saga';
|
||||||
import { updateBityRatesSwap } from 'actions/swap';
|
import { updateBityRatesSwap } from 'actions/swap';
|
||||||
import { SWAP_LOAD_BITY_RATES } from 'actions/swapConstants';
|
import {
|
||||||
|
SWAP_LOAD_BITY_RATES,
|
||||||
|
SWAP_STOP_LOAD_BITY_RATES
|
||||||
|
} from 'actions/swapConstants';
|
||||||
import type { UnlockPrivateKeyAction } from 'actions/wallet';
|
import type { UnlockPrivateKeyAction } from 'actions/wallet';
|
||||||
import { getAllRates } from 'api/bity';
|
import { getAllRates } from 'api/bity';
|
||||||
|
|
||||||
export function* loadBityRates(action?: any): Generator<Effect, void, any> {
|
export function* loadBityRates(action?: any): Generator<Effect, void, any> {
|
||||||
if (!action) return;
|
try {
|
||||||
// eslint-disable-next-line
|
while (true) {
|
||||||
while (true) {
|
// TODO - yield put(actions.requestStart()) if we want to display swap refresh status
|
||||||
const data = yield call(getAllRates);
|
// network request
|
||||||
yield put(updateBityRatesSwap(data));
|
const data = yield call(getAllRates);
|
||||||
yield call(delay, 5000);
|
// action
|
||||||
|
yield put(updateBityRatesSwap(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 default function* bitySaga(): Generator<Effect, void, any> {
|
export default function* bitySaga(): Generator<Effect, void, any> {
|
||||||
yield takeLatest(SWAP_LOAD_BITY_RATES, loadBityRates);
|
while (yield take(SWAP_LOAD_BITY_RATES)) {
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user