Passing params directly w/o using redux store
This commit is contained in:
parent
03ee864af0
commit
de40578608
6 changed files with 9 additions and 80 deletions
|
@ -1,21 +1,15 @@
|
|||
import lbry from "lbry";
|
||||
import { selectBalance } from "selectors/wallet";
|
||||
import {
|
||||
selectSupportTransaction,
|
||||
selectSupportTransactionAmount,
|
||||
} from "selectors/claims";
|
||||
import { doOpenModal, doShowSnackBar } from "actions/app";
|
||||
import * as types from "constants/action_types";
|
||||
import * as modals from "constants/modal_types";
|
||||
|
||||
export function doSendSupport() {
|
||||
export function doSendSupport(amount, claim_id) {
|
||||
return function(dispatch, getState) {
|
||||
const state = getState();
|
||||
const supportTx = selectSupportTransaction(state);
|
||||
const balance = selectBalance(state);
|
||||
const amount = selectSupportTransactionAmount(state);
|
||||
|
||||
if (balance - amount < 1) {
|
||||
if (balance - amount <= 0) {
|
||||
return dispatch(doOpenModal(modals.INSUFFICIENT_BALANCE));
|
||||
}
|
||||
|
||||
|
@ -54,23 +48,9 @@ export function doSendSupport() {
|
|||
|
||||
lbry
|
||||
.claim_send_tip({
|
||||
claim_id: supportTx.claim_id,
|
||||
amount: supportTx.amount,
|
||||
claim_id: claim_id,
|
||||
amount: amount,
|
||||
})
|
||||
.then(successCallback, errorCallback);
|
||||
};
|
||||
}
|
||||
|
||||
export function doSetSupportAmount(amount) {
|
||||
return {
|
||||
type: types.SET_SUPPORT_AMOUNT,
|
||||
data: { amount },
|
||||
};
|
||||
}
|
||||
|
||||
export function doSetSupportClaimID(claim_id) {
|
||||
return {
|
||||
type: types.SET_SUPPORT_CLAIMID,
|
||||
data: { claim_id },
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import {
|
||||
doSendSupport,
|
||||
doSetSupportAmount,
|
||||
doSetSupportClaimID,
|
||||
} from "actions/claims";
|
||||
import { doSendSupport } from "actions/claims";
|
||||
import TipLink from "./view";
|
||||
|
||||
const select = state => ({});
|
||||
|
||||
const perform = dispatch => ({
|
||||
sendSupport: () => dispatch(doSendSupport()),
|
||||
setAmount: amount => dispatch(doSetSupportAmount(amount)),
|
||||
setClaimID: claim_id => dispatch(doSetSupportClaimID(claim_id)),
|
||||
sendSupport: (amount, claim_id) => dispatch(doSendSupport(amount, claim_id)),
|
||||
});
|
||||
|
||||
export default connect(select, perform)(TipLink);
|
||||
|
|
|
@ -21,9 +21,7 @@ class TipLink extends React.PureComponent {
|
|||
let claim_id = this.props.claim_id;
|
||||
let amount = this.state.feeAmount;
|
||||
|
||||
this.props.setClaimID(claim_id);
|
||||
this.props.setAmount(amount);
|
||||
this.props.sendSupport();
|
||||
this.props.sendSupport(amount, claim_id);
|
||||
|
||||
this.props.onTipHide();
|
||||
}
|
||||
|
|
|
@ -115,8 +115,6 @@ export const CLAIM_REWARD_CLEAR_ERROR = "CLAIM_REWARD_CLEAR_ERROR";
|
|||
export const FETCH_REWARD_CONTENT_COMPLETED = "FETCH_REWARD_CONTENT_COMPLETED";
|
||||
|
||||
// Supports
|
||||
export const SET_SUPPORT_CLAIMID = "SET_SUPPORT_CLAIMID";
|
||||
export const SET_SUPPORT_AMOUNT = "SET_SUPPORT_AMOUNT";
|
||||
export const SUPPORT_TRANSACTION_STARTED = "SUPPORT_TRANSACTION_STARTED";
|
||||
export const SUPPORT_TRANSACTION_COMPLETED = "SUPPORT_TRANSACTION_COMPLETED";
|
||||
export const SUPPORT_TRANSACTION_FAILED = "SUPPORT_TRANSACTION_FAILED";
|
||||
|
|
|
@ -2,14 +2,7 @@ import * as types from "constants/action_types";
|
|||
import lbryuri from "lbryuri";
|
||||
|
||||
const reducers = {};
|
||||
const buildSupportTransaction = () => ({
|
||||
claim_id: undefined,
|
||||
amount: undefined,
|
||||
});
|
||||
|
||||
const defaultState = {
|
||||
supportTransaction: buildSupportTransaction(),
|
||||
};
|
||||
const defaultState = {};
|
||||
|
||||
reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) {
|
||||
const { uri, certificate, claim } = action.data;
|
||||
|
@ -197,28 +190,6 @@ reducers[types.CREATE_CHANNEL_COMPLETED] = function(state, action) {
|
|||
});
|
||||
};
|
||||
|
||||
reducers[types.SET_SUPPORT_AMOUNT] = function(state, action) {
|
||||
const oldDraft = state.supportTransaction;
|
||||
const newDraft = Object.assign({}, oldDraft, {
|
||||
amount: parseFloat(action.data.amount),
|
||||
});
|
||||
|
||||
return Object.assign({}, state, {
|
||||
supportTransaction: newDraft,
|
||||
});
|
||||
};
|
||||
|
||||
reducers[types.SET_SUPPORT_CLAIMID] = function(state, action) {
|
||||
const oldDraft = state.supportTransaction;
|
||||
const newDraft = Object.assign({}, oldDraft, {
|
||||
claim_id: action.data.claim_id,
|
||||
});
|
||||
|
||||
return Object.assign({}, state, {
|
||||
supportTransaction: newDraft,
|
||||
});
|
||||
};
|
||||
|
||||
reducers[types.SUPPORT_TRANSACTION_STARTED] = function(state, action) {
|
||||
const newSupportTransaction = Object.assign({}, state.supportTransaction, {
|
||||
sendingSupport: true,
|
||||
|
@ -230,9 +201,7 @@ reducers[types.SUPPORT_TRANSACTION_STARTED] = function(state, action) {
|
|||
};
|
||||
|
||||
reducers[types.SUPPORT_TRANSACTION_COMPLETED] = function(state, action) {
|
||||
return Object.assign({}, state, {
|
||||
supportTransaction: buildSupportTransaction(),
|
||||
});
|
||||
return Object.assign({}, state);
|
||||
};
|
||||
|
||||
reducers[types.SUPPORT_TRANSACTION_FAILED] = function(state, action) {
|
||||
|
|
|
@ -215,13 +215,3 @@ export const selectMyChannelClaims = createSelector(
|
|||
return claims;
|
||||
}
|
||||
);
|
||||
|
||||
export const selectSupportTransaction = createSelector(
|
||||
_selectState,
|
||||
state => state.supportTransaction || {}
|
||||
);
|
||||
|
||||
export const selectSupportTransactionAmount = createSelector(
|
||||
selectSupportTransaction,
|
||||
supportTxAmount => supportTxAmount.amount
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue