signed support functionality #322

Merged
neb-b merged 1 commit from signed-supports into master 2020-06-11 00:09:24 +02:00
2 changed files with 211 additions and 209 deletions

307
dist/bundle.es.js vendored

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,11 @@
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
import Lbry from 'lbry'; import Lbry from 'lbry';
import { doToast } from 'redux/actions/notifications'; import { doToast } from 'redux/actions/notifications';
import { selectBalance, selectPendingSupportTransactions, selectTxoPageParams } from 'redux/selectors/wallet'; import {
selectBalance,
selectPendingSupportTransactions,
selectTxoPageParams,
} from 'redux/selectors/wallet';
import { creditsToString } from 'util/format-credits'; import { creditsToString } from 'util/format-credits';
import { selectMyClaimsRaw } from 'redux/selectors/claims'; import { selectMyClaimsRaw } from 'redux/selectors/claims';
import { doFetchChannelListMine, doFetchClaimListMine } from 'redux/actions/claims'; import { doFetchChannelListMine, doFetchClaimListMine } from 'redux/actions/claims';
@ -98,7 +102,7 @@ export function doFetchTxoPage() {
}; };
} }
export function doUpdateTxoPageParams(params: TxoListParams) { export function doUpdateTxoPageParams(params) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: ACTIONS.UPDATE_TXO_FETCH_PARAMS, type: ACTIONS.UPDATE_TXO_FETCH_PARAMS,
@ -236,16 +240,16 @@ export function doSetDraftTransactionAddress(address) {
}; };
} }
export function doSendTip(amount, claimId, isSupport, successCallback, errorCallback) { export function doSendTip(params, isSupport, successCallback, errorCallback) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const balance = selectBalance(state); const balance = selectBalance(state);
const myClaims = selectMyClaimsRaw(state); const myClaims = selectMyClaimsRaw(state);
const shouldSupport = const shouldSupport =
isSupport || (myClaims ? myClaims.find(claim => claim.claim_id === claimId) : false); isSupport || (myClaims ? myClaims.find(claim => claim.claim_id === params.claim_id) : false);
if (balance - amount <= 0) { if (balance - params.amount <= 0) {
dispatch( dispatch(
doToast({ doToast({
message: __('Insufficient credits'), message: __('Insufficient credits'),
@ -259,8 +263,8 @@ export function doSendTip(amount, claimId, isSupport, successCallback, errorCall
dispatch( dispatch(
doToast({ doToast({
message: shouldSupport message: shouldSupport
? __('You deposited %amount% LBC as a support!', { amount }) ? __('You deposited %amount% LBC as a support!', { amount: params.amount })
: __('You sent %amount% LBC as a tip, Mahalo!', { amount }), : __('You sent %amount% LBC as a tip, Mahalo!', { amount: params.amount }),
linkText: __('History'), linkText: __('History'),
linkTarget: __('/wallet'), linkTarget: __('/wallet'),
}) })
@ -300,10 +304,10 @@ export function doSendTip(amount, claimId, isSupport, successCallback, errorCall
}); });
Lbry.support_create({ Lbry.support_create({
claim_id: claimId, ...params,
amount: creditsToString(amount),
tip: !shouldSupport, tip: !shouldSupport,
blocking: true, blocking: true,
amount: creditsToString(params.amount),
}).then(success, error); }).then(success, error);
}; };
} }
@ -392,16 +396,15 @@ export function doSupportAbandonForClaim(claimId, claimType, keep, preview) {
}); });
} }
const params = {claim_id: claimId}; const params = { claim_id: claimId };
if (preview) params['preview'] = true; if (preview) params['preview'] = true;
if (keep) params['keep'] = keep; if (keep) params['keep'] = keep;
return ( return Lbry.support_abandon(params)
Lbry.support_abandon(params) .then(res => {
.then((res) => {
if (!preview) { if (!preview) {
dispatch({ dispatch({
type: ACTIONS.ABANDON_CLAIM_SUPPORT_COMPLETED, type: ACTIONS.ABANDON_CLAIM_SUPPORT_COMPLETED,
data: { claimId, txid: res.txid, effective: res.outputs[0].amount, type: claimType}, // add to pendingSupportTransactions, data: { claimId, txid: res.txid, effective: res.outputs[0].amount, type: claimType }, // add to pendingSupportTransactions,
}); });
dispatch(doCheckPendingTxs()); dispatch(doCheckPendingTxs());
} }
@ -412,7 +415,7 @@ export function doSupportAbandonForClaim(claimId, claimType, keep, preview) {
type: ACTIONS.ABANDON_CLAIM_SUPPORT_FAILED, type: ACTIONS.ABANDON_CLAIM_SUPPORT_FAILED,
data: e.message, data: e.message,
}); });
})); });
}; };
} }
@ -469,7 +472,6 @@ export function doWalletStatus() {
}; };
} }
export function doSetTransactionListFilter(filterOption) { export function doSetTransactionListFilter(filterOption) {
return { return {
type: ACTIONS.SET_TRANSACTION_LIST_FILTER, type: ACTIONS.SET_TRANSACTION_LIST_FILTER,
@ -490,10 +492,7 @@ export function doUpdateBlockHeight() {
} }
// Calls transaction_show on txes until any pending txes are confirmed // Calls transaction_show on txes until any pending txes are confirmed
export const doCheckPendingTxs = () => ( export const doCheckPendingTxs = () => (dispatch, getState) => {
dispatch,
getState
) => {
const state = getState(); const state = getState();
const pendingTxsById = selectPendingSupportTransactions(state); // {} const pendingTxsById = selectPendingSupportTransactions(state); // {}
if (!Object.keys(pendingTxsById).length) { if (!Object.keys(pendingTxsById).length) {
@ -508,21 +507,23 @@ export const doCheckPendingTxs = () => (
const types = new Set([]); const types = new Set([]);
let changed = false; let changed = false;
Object.entries(pendingTxs).forEach(([claim, data]) => { Object.entries(pendingTxs).forEach(([claim, data]) => {
promises.push(Lbry.transaction_show({txid: data.txid})); promises.push(Lbry.transaction_show({ txid: data.txid }));
types.add(data.type); types.add(data.type);
}); });
Promise.all(promises).then(txShows => { Promise.all(promises)
.then(txShows => {
txShows.forEach(result => { txShows.forEach(result => {
if (result.height <= 0) { if (result.height <= 0) {
const entries = Object.entries(pendingTxs); const entries = Object.entries(pendingTxs);
const match = entries.find((entry) => entry[1].txid === result.txid); const match = entries.find(entry => entry[1].txid === result.txid);
newPendingTxes[match[0]] = match[1]; newPendingTxes[match[0]] = match[1];
} else { } else {
changed = true; changed = true;
} }
}); });
}).then(() => { })
.then(() => {
if (changed) { if (changed) {
dispatch({ dispatch({
type: ACTIONS.PENDING_SUPPORTS_UPDATED, type: ACTIONS.PENDING_SUPPORTS_UPDATED,