Use "Purchase and Tip Confirmations" setting to determine if a confirmation dialog is needed for tipping.

This commit is contained in:
Jeffrey Fisher 2020-04-24 16:53:57 -07:00 committed by Sean Yesmunt
parent cb470ad970
commit 122781036d
4 changed files with 50 additions and 16 deletions

View file

@ -179,10 +179,10 @@
"No Limit": "No Limit", "No Limit": "No Limit",
"Choose limit": "Choose limit", "Choose limit": "Choose limit",
"This will prevent you from purchasing any content over a certain cost, as a safety measure.": "This will prevent you from purchasing any content over a certain cost, as a safety measure.", "This will prevent you from purchasing any content over a certain cost, as a safety measure.": "This will prevent you from purchasing any content over a certain cost, as a safety measure.",
"Purchase Confirmations": "Purchase Confirmations", "Purchase and Tip Confirmations": "Purchase and Tip Confirmations",
"Always confirm before purchasing content": "Always confirm before purchasing content", "Always confirm before purchasing content or tipping": "Always confirm before purchasing content or tipping",
"Only confirm purchases over a certain price": "Only confirm purchases over a certain price", "Only confirm purchases or tips over a certain amount": "Only confirm purchases or tips over a certain amount",
"When this option is chosen, LBRY won't ask you to confirm downloads below your chosen price.": "When this option is chosen, LBRY won't ask you to confirm downloads below your chosen price.", "When this option is chosen, LBRY won't ask you to confirm downloads or tips below your chosen amount.": "When this option is chosen, LBRY won't ask you to confirm downloads or tips below your chosen amount.",
"Content Settings": "Content Settings", "Content Settings": "Content Settings",
"Show NSFW content": "Show NSFW content", "Show NSFW content": "Show NSFW content",
"NSFW content may include nudity, intense sexuality, profanity, or other adult content. By displaying NSFW content, you are affirming you are of legal age to view mature content in your country or jurisdiction. ": "NSFW content may include nudity, intense sexuality, profanity, or other adult content. By displaying NSFW content, you are affirming you are of legal age to view mature content in your country or jurisdiction. ", "NSFW content may include nudity, intense sexuality, profanity, or other adult content. By displaying NSFW content, you are affirming you are of legal age to view mature content in your country or jurisdiction. ": "NSFW content may include nudity, intense sexuality, profanity, or other adult content. By displaying NSFW content, you are affirming you are of legal age to view mature content in your country or jurisdiction. ",

View file

@ -5,16 +5,20 @@ import {
makeSelectClaimForUri, makeSelectClaimForUri,
selectIsSendingSupport, selectIsSendingSupport,
selectBalance, selectBalance,
SETTINGS,
} from 'lbry-redux'; } from 'lbry-redux';
import WalletSendTip from './view'; import WalletSendTip from './view';
import { doOpenModal } from 'redux/actions/app'; import { doOpenModal } from 'redux/actions/app';
import { withRouter } from 'react-router'; import { withRouter } from 'react-router';
import { makeSelectClientSetting } from 'redux/selectors/settings';
const select = (state, props) => ({ const select = (state, props) => ({
isPending: selectIsSendingSupport(state), isPending: selectIsSendingSupport(state),
title: makeSelectTitleForUri(props.uri)(state), title: makeSelectTitleForUri(props.uri)(state),
claim: makeSelectClaimForUri(props.uri, false)(state), claim: makeSelectClaimForUri(props.uri, false)(state),
balance: selectBalance(state), balance: selectBalance(state),
instantTipEnabled: makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state),
instantTipMax: makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({

View file

@ -7,6 +7,7 @@ import useIsMobile from 'effects/use-is-mobile';
import CreditAmount from 'component/common/credit-amount'; import CreditAmount from 'component/common/credit-amount';
import I18nMessage from 'component/i18nMessage'; import I18nMessage from 'component/i18nMessage';
import * as MODALS from 'constants/modal_types'; import * as MODALS from 'constants/modal_types';
import { Lbryio } from 'lbryinc';
type Props = { type Props = {
uri: string, uri: string,
@ -20,24 +21,51 @@ type Props = {
balance: number, balance: number,
isSupport: boolean, isSupport: boolean,
openModal: (id: string, { tipAmount: number, claimId: string, isSupport: boolean }) => void, openModal: (id: string, { tipAmount: number, claimId: string, isSupport: boolean }) => void,
instantTipEnabled: boolean,
instantTipMax: { amount: number, currency: string },
}; };
function WalletSendTip(props: Props) { function WalletSendTip(props: Props) {
const { title, isPending, onCancel, claimIsMine, isSupport, balance, claim } = props; const {
title,
isPending,
onCancel,
claimIsMine,
isSupport,
balance,
claim,
instantTipEnabled,
instantTipMax,
openModal,
sendSupport,
} = props;
const [tipAmount, setTipAmount] = React.useState(0); const [tipAmount, setTipAmount] = React.useState(0);
const [tipError, setTipError] = React.useState(); const [tipError, setTipError] = React.useState();
const { claim_id: claimId } = claim; const { claim_id: claimId } = claim;
const isMobile = useIsMobile(); const isMobile = useIsMobile();
function handleSubmit() { function sendSupportOrConfirm(instantTipMaxAmount = null) {
const { openModal, sendSupport } = props; if (!isSupport && (!instantTipMaxAmount || !instantTipEnabled || tipAmount > instantTipMaxAmount)) {
const modalProps = { tipAmount, claimId, title, isSupport };
openModal(MODALS.CONFIRM_SEND_TIP, modalProps);
} else {
sendSupport(tipAmount, claimId, isSupport);
}
}
function handleSubmit() {
if (tipAmount && claimId) { if (tipAmount && claimId) {
if (isSupport) { if (instantTipEnabled) {
sendSupport(tipAmount, claimId, isSupport); if (instantTipMax.currency === 'LBC') {
sendSupportOrConfirm(instantTipMax.amount);
} else {
// Need to convert currency of instant purchase maximum before trying to send support
Lbryio.getExchangeRates().then(({ LBC_USD }) => {
sendSupportOrConfirm(instantTipMax.amount / LBC_USD);
});
}
} else { } else {
const modalProps = { tipAmount, claimId, title, isSupport }; sendSupportOrConfirm();
openModal(MODALS.CONFIRM_SEND_TIP, modalProps);
} }
} }
} }

View file

@ -367,15 +367,16 @@ class SettingsPage extends React.PureComponent<Props, State> {
} }
/> />
{/* @endif */}
<Card <Card
title={__('Purchase Confirmations')} title={__('Purchase and Tip Confirmations')}
actions={ actions={
<React.Fragment> <React.Fragment>
<FormField <FormField
type="radio" type="radio"
name="confirm_all_purchases" name="confirm_all_purchases"
checked={!instantPurchaseEnabled} checked={!instantPurchaseEnabled}
label={__('Always confirm before purchasing content')} label={__('Always confirm before purchasing content or tipping')}
onChange={() => { onChange={() => {
this.onInstantPurchaseEnabledChange(false); this.onInstantPurchaseEnabledChange(false);
}} }}
@ -384,7 +385,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
type="radio" type="radio"
name="instant_purchases" name="instant_purchases"
checked={instantPurchaseEnabled} checked={instantPurchaseEnabled}
label={__('Only confirm purchases over a certain price')} label={__('Only confirm purchases or tips over a certain amount')}
onChange={() => { onChange={() => {
this.onInstantPurchaseEnabledChange(true); this.onInstantPurchaseEnabledChange(true);
}} }}
@ -400,13 +401,14 @@ class SettingsPage extends React.PureComponent<Props, State> {
)} )}
<p className="help"> <p className="help">
{__("When this option is chosen, LBRY won't ask you to confirm downloads below your chosen price.")} {__(
"When this option is chosen, LBRY won't ask you to confirm downloads or tips below your chosen amount."
)}
</p> </p>
</React.Fragment> </React.Fragment>
} }
/> />
{/* @endif */}
<Card <Card
title={__('Content Settings')} title={__('Content Settings')}
actions={ actions={