2017-08-08 00:13:58 +02:00
|
|
|
import lbry from "lbry";
|
|
|
|
import { selectBalance } from "selectors/wallet";
|
|
|
|
import { doOpenModal, doShowSnackBar } from "actions/app";
|
|
|
|
import * as types from "constants/action_types";
|
|
|
|
import * as modals from "constants/modal_types";
|
|
|
|
|
2017-08-14 11:43:40 +02:00
|
|
|
export function doSendSupport(amount, claim_id) {
|
2017-08-08 00:13:58 +02:00
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState();
|
|
|
|
const balance = selectBalance(state);
|
|
|
|
|
2017-08-14 11:43:40 +02:00
|
|
|
if (balance - amount <= 0) {
|
2017-08-08 00:13:58 +02:00
|
|
|
return dispatch(doOpenModal(modals.INSUFFICIENT_BALANCE));
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.SUPPORT_TRANSACTION_STARTED,
|
|
|
|
});
|
|
|
|
|
|
|
|
const successCallback = results => {
|
|
|
|
if (results.txid) {
|
|
|
|
dispatch({
|
|
|
|
type: types.SUPPORT_TRANSACTION_COMPLETED,
|
|
|
|
});
|
|
|
|
dispatch(
|
|
|
|
doShowSnackBar({
|
|
|
|
message: __(`You sent ${amount} LBC as support, Mahalo!`),
|
|
|
|
linkText: __("History"),
|
|
|
|
linkTarget: __("/wallet"),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
dispatch({
|
|
|
|
type: types.SUPPORT_TRANSACTION_FAILED,
|
|
|
|
data: { error: results },
|
|
|
|
});
|
|
|
|
dispatch(doOpenModal(modals.TRANSACTION_FAILED));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const errorCallback = error => {
|
|
|
|
dispatch({
|
|
|
|
type: types.SUPPORT_TRANSACTION_FAILED,
|
|
|
|
data: { error: error.message },
|
|
|
|
});
|
|
|
|
dispatch(doOpenModal(modals.TRANSACTION_FAILED));
|
|
|
|
};
|
|
|
|
|
|
|
|
lbry
|
2017-08-20 11:51:57 +02:00
|
|
|
.wallet_send({
|
2017-08-14 11:43:40 +02:00
|
|
|
claim_id: claim_id,
|
|
|
|
amount: amount,
|
2017-08-08 00:13:58 +02:00
|
|
|
})
|
|
|
|
.then(successCallback, errorCallback);
|
|
|
|
};
|
|
|
|
}
|