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
Showing only changes of commit 7216d2befd - Show all commits

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);
}; };
} }
@ -380,7 +384,7 @@ export function doWalletLock() {
}; };
} }
export function doSupportAbandonForClaim(claimId, claimType, keep, preview) { export function doSupportAbandonForClaim(claimId, claimType, keep, preview) {
return dispatch => { return dispatch => {
if (preview) { if (preview) {
dispatch({ dispatch({
@ -392,27 +396,26 @@ 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({
type: ACTIONS.ABANDON_CLAIM_SUPPORT_COMPLETED,
data: { claimId, txid: res.txid, effective: res.outputs[0].amount, type: claimType}, // add to pendingSupportTransactions,
});
dispatch(doCheckPendingTxs());
}
return res;
})
.catch(e => {
dispatch({ dispatch({
type: ACTIONS.ABANDON_CLAIM_SUPPORT_FAILED, type: ACTIONS.ABANDON_CLAIM_SUPPORT_COMPLETED,
data: e.message, data: { claimId, txid: res.txid, effective: res.outputs[0].amount, type: claimType }, // add to pendingSupportTransactions,
}); });
})); dispatch(doCheckPendingTxs());
}
return res;
})
.catch(e => {
dispatch({
type: ACTIONS.ABANDON_CLAIM_SUPPORT_FAILED,
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,35 +507,37 @@ 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)
txShows.forEach(result => { .then(txShows => {
if (result.height <= 0) { txShows.forEach(result => {
const entries = Object.entries(pendingTxs); if (result.height <= 0) {
const match = entries.find((entry) => entry[1].txid === result.txid); const entries = Object.entries(pendingTxs);
newPendingTxes[match[0]] = match[1]; const match = entries.find(entry => entry[1].txid === result.txid);
} else { newPendingTxes[match[0]] = match[1];
changed = true; } else {
} changed = true;
}); }
}).then(() => {
if (changed) {
dispatch({
type: ACTIONS.PENDING_SUPPORTS_UPDATED,
data: newPendingTxes,
}); });
if (types.has('channel')) { })
dispatch(doFetchChannelListMine()); .then(() => {
if (changed) {
dispatch({
type: ACTIONS.PENDING_SUPPORTS_UPDATED,
data: newPendingTxes,
});
if (types.has('channel')) {
dispatch(doFetchChannelListMine());
}
if (types.has('stream')) {
dispatch(doFetchClaimListMine());
}
} }
if (types.has('stream')) { if (Object.keys(newPendingTxes).length === 0) clearInterval(txCheckInterval);
dispatch(doFetchClaimListMine()); });
}
}
if (Object.keys(newPendingTxes).length === 0) clearInterval(txCheckInterval);
});
if (!Object.keys(pendingTxsById).length) { if (!Object.keys(pendingTxsById).length) {
clearInterval(txCheckInterval); clearInterval(txCheckInterval);