feat: supports vs tips

Adds additional boolean to tell if something is a support or not. Also, fixes snackbar. Removes uri which is not used.
This commit is contained in:
Thomas Zarebczan 2019-07-19 15:20:24 -04:00
parent 755424a2a8
commit ee93a47f89
3 changed files with 37 additions and 14 deletions

24
dist/bundle.es.js vendored
View file

@ -1901,10 +1901,13 @@ function doSetDraftTransactionAddress(address) {
}; };
} }
function doSendTip(amount, claimId, uri, successCallback, errorCallback) { function doSendTip(amount, claimId, 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 isSupport = myClaims.find(claim => claim.claim_id === claimId);
if (balance - amount <= 0) { if (balance - amount <= 0) {
dispatch(doToast({ dispatch(doToast({
@ -1916,7 +1919,7 @@ function doSendTip(amount, claimId, uri, successCallback, errorCallback) {
const success = () => { const success = () => {
dispatch(doToast({ dispatch(doToast({
message: __(`You sent ${amount} LBC as a tip, Mahalo!`), message: isSupport ? __(`You sent ${amount} LBC as a support!`) : __(`You sent ${amount} LBC as a tip, Mahalo!`),
linkText: __('History'), linkText: __('History'),
linkTarget: __('/wallet') linkTarget: __('/wallet')
})); }));
@ -1955,7 +1958,7 @@ function doSendTip(amount, claimId, uri, successCallback, errorCallback) {
lbryProxy.support_create({ lbryProxy.support_create({
claim_id: claimId, claim_id: claimId,
amount: creditsToString(amount), amount: creditsToString(amount),
tip: true tip: isSupport ? false : true
}).then(success, error); }).then(success, error);
}; };
} }
@ -2188,7 +2191,7 @@ function doAbandonClaim(txid, nout) {
const errorCallback = () => { const errorCallback = () => {
dispatch(doToast({ dispatch(doToast({
message: isClaim ? 'Error abandoning your claim' : 'Error unlocking your tip', message: isClaim ? 'Error abandoning your claim/support' : 'Error unlocking your tip',
isError: true isError: true
})); }));
}; };
@ -2199,13 +2202,22 @@ function doAbandonClaim(txid, nout) {
data data
}); });
let abandonMessage;
if (isClaim) {
abandonMessage = 'Successfully abandoned your claim.';
} else if (supportToAbandon) {
abandonMessage = 'Successfully abandoned your support.';
} else {
abandonMessage = 'Successfully unlocked your tip!';
}
dispatch(doToast({ dispatch(doToast({
message: isClaim ? 'Successfully abandoned your claim' : 'Successfully unlocked your tip!' message: abandonMessage
})); }));
// After abandoning, call claim_list to show the claim as abandoned // After abandoning, call claim_list to show the claim as abandoned
// Also fetch transactions to show the new abandon transaction // Also fetch transactions to show the new abandon transaction
dispatch(doFetchClaimListMine()); if (isClaim) dispatch(doFetchClaimListMine());
dispatch(doFetchTransactions()); dispatch(doFetchTransactions());
}; };

View file

@ -142,7 +142,7 @@ export function doAbandonClaim(txid: string, nout: number) {
const errorCallback = () => { const errorCallback = () => {
dispatch( dispatch(
doToast({ doToast({
message: isClaim ? 'Error abandoning your claim' : 'Error unlocking your tip', message: isClaim ? 'Error abandoning your claim/support' : 'Error unlocking your tip',
isError: true, isError: true,
}) })
); );
@ -154,17 +154,24 @@ export function doAbandonClaim(txid: string, nout: number) {
data, data,
}); });
let abandonMessage;
if (isClaim) {
abandonMessage = 'Successfully abandoned your claim.';
} else if (supportToAbandon) {
abandonMessage = 'Successfully abandoned your support.';
} else {
abandonMessage = 'Successfully unlocked your tip!';
}
dispatch( dispatch(
doToast({ doToast({
message: isClaim message: abandonMessage,
? 'Successfully abandoned your claim'
: 'Successfully unlocked your tip!',
}) })
); );
// After abandoning, call claim_list to show the claim as abandoned // After abandoning, call claim_list to show the claim as abandoned
// Also fetch transactions to show the new abandon transaction // Also fetch transactions to show the new abandon transaction
dispatch(doFetchClaimListMine()); if (isClaim) dispatch(doFetchClaimListMine());
dispatch(doFetchTransactions()); dispatch(doFetchTransactions());
}; };

View file

@ -3,6 +3,7 @@ import Lbry from 'lbry';
import { doToast } from 'redux/actions/notifications'; import { doToast } from 'redux/actions/notifications';
import { selectBalance } from 'redux/selectors/wallet'; import { selectBalance } from 'redux/selectors/wallet';
import { creditsToString } from 'util/formatCredits'; import { creditsToString } from 'util/formatCredits';
import { selectMyClaimsRaw } from 'redux/selectors/claims';
export function doUpdateBalance() { export function doUpdateBalance() {
return (dispatch, getState) => { return (dispatch, getState) => {
@ -208,10 +209,13 @@ export function doSetDraftTransactionAddress(address) {
}; };
} }
export function doSendTip(amount, claimId, uri, successCallback, errorCallback) { export function doSendTip(amount, claimId, successCallback, errorCallback) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const balance = selectBalance(state); const balance = selectBalance(state);
const myClaims: Array<Claim> = selectMyClaimsRaw(state);
const isSupport = myClaims.find(claim => claim.claim_id === claimId);
if (balance - amount <= 0) { if (balance - amount <= 0) {
dispatch( dispatch(
@ -226,7 +230,7 @@ export function doSendTip(amount, claimId, uri, successCallback, errorCallback)
const success = () => { const success = () => {
dispatch( dispatch(
doToast({ doToast({
message: __(`You sent ${amount} LBC as a tip, Mahalo!`), message: isSupport ? __(`You sent ${amount} LBC as a support!`) : __(`You sent ${amount} LBC as a tip, Mahalo!`),
linkText: __('History'), linkText: __('History'),
linkTarget: __('/wallet'), linkTarget: __('/wallet'),
}) })
@ -268,7 +272,7 @@ export function doSendTip(amount, claimId, uri, successCallback, errorCallback)
Lbry.support_create({ Lbry.support_create({
claim_id: claimId, claim_id: claimId,
amount: creditsToString(amount), amount: creditsToString(amount),
tip: true, tip: isSupport ? false : true,
}).then(success, error); }).then(success, error);
}; };
} }