2021-03-25 12:24:49 +01:00
|
|
|
// @flow
|
|
|
|
import * as ACTIONS from 'constants/action_types';
|
|
|
|
import { selectPrefsReady } from 'redux/selectors/sync';
|
|
|
|
import { doAlertWaitingForSync } from 'redux/actions/app';
|
2021-04-08 11:02:37 +02:00
|
|
|
import { Lbryio } from 'lbryinc';
|
2021-03-25 12:24:49 +01:00
|
|
|
|
2021-04-08 11:02:37 +02:00
|
|
|
export const doAddCoinSwap = (coinSwapInfo: CoinSwapInfo) => (dispatch: Dispatch, getState: GetState) => {
|
2021-03-25 12:24:49 +01:00
|
|
|
const state = getState();
|
|
|
|
const ready = selectPrefsReady(state);
|
|
|
|
|
|
|
|
if (!ready) {
|
|
|
|
return dispatch(doAlertWaitingForSync());
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
2021-04-04 09:10:55 +02:00
|
|
|
type: ACTIONS.ADD_COIN_SWAP,
|
2021-04-08 11:02:37 +02:00
|
|
|
data: coinSwapInfo,
|
2021-03-25 12:24:49 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-04-08 11:02:37 +02:00
|
|
|
export const doRemoveCoinSwap = (chargeCode: string) => (dispatch: Dispatch, getState: GetState) => {
|
2021-03-25 12:24:49 +01:00
|
|
|
const state = getState();
|
|
|
|
const ready = selectPrefsReady(state);
|
|
|
|
|
|
|
|
if (!ready) {
|
|
|
|
return dispatch(doAlertWaitingForSync());
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
2021-04-04 09:10:55 +02:00
|
|
|
type: ACTIONS.REMOVE_COIN_SWAP,
|
2021-03-25 12:24:49 +01:00
|
|
|
data: {
|
2021-04-08 11:02:37 +02:00
|
|
|
chargeCode,
|
2021-03-25 12:24:49 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2021-04-08 11:02:37 +02:00
|
|
|
|
|
|
|
export const doQueryCoinSwapStatus = (chargeCode: string) => (dispatch: Dispatch, getState: GetState) => {
|
|
|
|
Lbryio.call('btc', 'status', { charge_code: chargeCode }).then((response) => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.COIN_SWAP_STATUS_RECEIVED,
|
|
|
|
data: response,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|