lbry-desktop/ui/redux/actions/coinSwap.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

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';
import { Lbryio } from 'lbryinc';
2021-03-25 12:24:49 +01: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({
type: ACTIONS.ADD_COIN_SWAP,
data: coinSwapInfo,
2021-03-25 12:24:49 +01: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({
type: ACTIONS.REMOVE_COIN_SWAP,
2021-03-25 12:24:49 +01:00
data: {
chargeCode,
2021-03-25 12:24:49 +01: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,
});
});
};