2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2020-06-08 20:42:29 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
2020-06-10 00:09:24 +02:00
|
|
|
import * as PAGES from 'constants/pages';
|
2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Button from 'component/button';
|
2019-02-13 17:27:20 +01:00
|
|
|
import { FormField, Form } from 'component/common/form';
|
2021-02-09 17:05:56 +01:00
|
|
|
import { MINIMUM_PUBLISH_BID } from 'constants/claim';
|
2020-03-13 20:53:53 +01:00
|
|
|
import CreditAmount from 'component/common/credit-amount';
|
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2020-04-25 01:53:57 +02:00
|
|
|
import { Lbryio } from 'lbryinc';
|
2020-06-08 20:42:29 +02:00
|
|
|
import Card from 'component/common/card';
|
|
|
|
import classnames from 'classnames';
|
2021-02-09 17:05:56 +01:00
|
|
|
import ChannelSelector from 'component/channelSelector';
|
2020-09-02 22:08:37 +02:00
|
|
|
import LbcSymbol from 'component/common/lbc-symbol';
|
2020-06-10 00:09:24 +02:00
|
|
|
import { parseURI } from 'lbry-redux';
|
|
|
|
import usePersistedState from 'effects/use-persisted-state';
|
2021-02-02 21:00:24 +01:00
|
|
|
import WalletSpendableBalanceHelp from 'component/walletSpendableBalanceHelp';
|
2021-07-03 19:19:23 +02:00
|
|
|
import { STRIPE_PUBLIC_KEY } from 'config';
|
|
|
|
|
|
|
|
let stripeEnvironment = 'test';
|
|
|
|
// if the key contains pk_live it's a live key
|
|
|
|
// update the environment for the calls to the backend to indicate which environment to hit
|
|
|
|
if (STRIPE_PUBLIC_KEY.indexOf('pk_live') > -1) {
|
|
|
|
stripeEnvironment = 'live';
|
|
|
|
}
|
2020-06-08 20:42:29 +02:00
|
|
|
|
2021-02-02 21:00:24 +01:00
|
|
|
const DEFAULT_TIP_AMOUNTS = [1, 5, 25, 100];
|
2017-09-17 22:33:52 +02:00
|
|
|
|
2021-07-03 19:19:23 +02:00
|
|
|
const TAB_BOOST = 'TabBoost';
|
|
|
|
const TAB_FIAT = 'TabFiat';
|
|
|
|
const TAB_LBC = 'TabLBC';
|
2020-06-15 16:04:44 +02:00
|
|
|
type SupportParams = { amount: number, claim_id: string, channel_id?: string };
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
|
|
|
uri: string,
|
2020-06-10 00:09:24 +02:00
|
|
|
claimIsMine: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
title: string,
|
2019-04-24 16:02:08 +02:00
|
|
|
claim: StreamClaim,
|
2018-03-26 23:32:43 +02:00
|
|
|
isPending: boolean,
|
2021-07-03 19:19:23 +02:00
|
|
|
isSupport: boolean,
|
|
|
|
sendSupport: (SupportParams, boolean) => void, // function that comes from lbry-redux
|
2020-04-30 00:02:53 +02:00
|
|
|
closeModal: () => void,
|
2018-05-14 18:19:07 +02:00
|
|
|
balance: number,
|
2020-06-15 16:04:44 +02:00
|
|
|
fetchingChannels: boolean,
|
2020-04-25 01:53:57 +02:00
|
|
|
instantTipEnabled: boolean,
|
|
|
|
instantTipMax: { amount: number, currency: string },
|
2021-02-09 17:05:56 +01:00
|
|
|
activeChannelClaim: ?ChannelClaim,
|
|
|
|
incognito: boolean,
|
2021-07-03 19:19:23 +02:00
|
|
|
doToast: ({ message: string }) => void,
|
|
|
|
isAuthenticated: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2020-03-13 20:53:53 +01:00
|
|
|
function WalletSendTip(props: Props) {
|
2020-04-25 01:53:57 +02:00
|
|
|
const {
|
2020-05-11 21:20:37 +02:00
|
|
|
uri,
|
2020-04-25 01:53:57 +02:00
|
|
|
title,
|
|
|
|
isPending,
|
2020-06-10 00:09:24 +02:00
|
|
|
claimIsMine,
|
2020-04-25 01:53:57 +02:00
|
|
|
balance,
|
2020-06-08 20:42:29 +02:00
|
|
|
claim = {},
|
2020-04-25 01:53:57 +02:00
|
|
|
instantTipEnabled,
|
|
|
|
instantTipMax,
|
|
|
|
sendSupport,
|
2020-04-30 00:02:53 +02:00
|
|
|
closeModal,
|
2020-06-15 16:04:44 +02:00
|
|
|
fetchingChannels,
|
2021-02-09 17:05:56 +01:00
|
|
|
incognito,
|
|
|
|
activeChannelClaim,
|
2021-07-03 19:19:23 +02:00
|
|
|
doToast,
|
|
|
|
isAuthenticated,
|
2020-04-25 01:53:57 +02:00
|
|
|
} = props;
|
2020-06-17 09:11:57 +02:00
|
|
|
const [presetTipAmount, setPresetTipAmount] = usePersistedState('comment-support:presetTip', DEFAULT_TIP_AMOUNTS[0]);
|
|
|
|
const [customTipAmount, setCustomTipAmount] = usePersistedState('comment-support:customTip', 1.0);
|
|
|
|
const [useCustomTip, setUseCustomTip] = usePersistedState('comment-support:useCustomTip', false);
|
2020-03-13 20:53:53 +01:00
|
|
|
const [tipError, setTipError] = React.useState();
|
2020-06-15 16:04:44 +02:00
|
|
|
const [isConfirming, setIsConfirming] = React.useState(false);
|
2020-06-10 00:09:24 +02:00
|
|
|
const { claim_id: claimId } = claim;
|
2020-06-15 16:04:44 +02:00
|
|
|
const { channelName } = parseURI(uri);
|
2021-07-05 13:35:17 +02:00
|
|
|
const activeChannelName = activeChannelClaim && activeChannelClaim.name;
|
|
|
|
const activeChannelId = activeChannelClaim && activeChannelClaim.claim_id;
|
2021-07-03 19:19:23 +02:00
|
|
|
|
|
|
|
const [canReceiveFiatTip, setCanReceiveFiatTip] = React.useState(); // dont persist because it needs to be calc'd per creator
|
|
|
|
const [hasCardSaved, setHasSavedCard] = usePersistedState('comment-support:hasCardSaved', false);
|
|
|
|
|
|
|
|
// setup variables for tip API
|
|
|
|
let channelClaimId, tipChannelName;
|
|
|
|
// if there is a signing channel it's on a file
|
|
|
|
if (claim.signing_channel) {
|
|
|
|
channelClaimId = claim.signing_channel.claim_id;
|
|
|
|
tipChannelName = claim.signing_channel.name;
|
|
|
|
|
|
|
|
// otherwise it's on the channel page
|
|
|
|
} else {
|
|
|
|
channelClaimId = claim.claim_id;
|
|
|
|
tipChannelName = claim.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sourceClaimId = claim.claim_id;
|
|
|
|
|
2021-07-06 22:28:29 +02:00
|
|
|
// check if creator has a payment method saved
|
2021-07-03 19:19:23 +02:00
|
|
|
React.useEffect(() => {
|
2021-07-05 13:35:17 +02:00
|
|
|
if (channelClaimId && isAuthenticated) {
|
|
|
|
Lbryio.call(
|
|
|
|
'customer',
|
|
|
|
'status',
|
|
|
|
{
|
|
|
|
environment: stripeEnvironment,
|
|
|
|
},
|
|
|
|
'post'
|
|
|
|
).then((customerStatusResponse) => {
|
|
|
|
const defaultPaymentMethodId =
|
|
|
|
customerStatusResponse.Customer &&
|
|
|
|
customerStatusResponse.Customer.invoice_settings &&
|
|
|
|
customerStatusResponse.Customer.invoice_settings.default_payment_method &&
|
|
|
|
customerStatusResponse.Customer.invoice_settings.default_payment_method.id;
|
|
|
|
|
|
|
|
setHasSavedCard(Boolean(defaultPaymentMethodId));
|
|
|
|
});
|
2021-07-03 19:19:23 +02:00
|
|
|
}
|
|
|
|
}, [channelClaimId, isAuthenticated]);
|
|
|
|
|
2021-07-06 22:28:29 +02:00
|
|
|
// check if creator has an account saved
|
|
|
|
React.useEffect(() => {
|
|
|
|
var tipInputElement = document.getElementById('tip-input');
|
|
|
|
if (tipInputElement) { tipInputElement.focus() }
|
|
|
|
}, []);
|
|
|
|
|
2021-07-03 19:19:23 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (channelClaimId) {
|
2021-07-05 13:35:17 +02:00
|
|
|
Lbryio.call(
|
|
|
|
'account',
|
|
|
|
'check',
|
|
|
|
{
|
|
|
|
channel_claim_id: channelClaimId,
|
|
|
|
channel_name: tipChannelName,
|
|
|
|
environment: stripeEnvironment,
|
|
|
|
},
|
|
|
|
'post'
|
|
|
|
)
|
|
|
|
.then((accountCheckResponse) => {
|
|
|
|
if (accountCheckResponse === true && canReceiveFiatTip !== true) {
|
|
|
|
setCanReceiveFiatTip(true);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function (error) {
|
2021-07-06 22:28:29 +02:00
|
|
|
// console.log(error);
|
2021-07-05 13:35:17 +02:00
|
|
|
});
|
2021-07-03 19:19:23 +02:00
|
|
|
}
|
|
|
|
}, [channelClaimId]);
|
|
|
|
|
2020-08-26 22:28:33 +02:00
|
|
|
const noBalance = balance === 0;
|
2020-06-17 09:11:57 +02:00
|
|
|
const tipAmount = useCustomTip ? customTipAmount : presetTipAmount;
|
2021-07-03 19:19:23 +02:00
|
|
|
|
2021-07-12 20:42:20 +02:00
|
|
|
const [activeTab, setActiveTab] = React.useState(claimIsMine ? TAB_BOOST : TAB_LBC);
|
2021-07-03 19:19:23 +02:00
|
|
|
|
2021-07-15 14:55:09 +02:00
|
|
|
function setClaimTypeText() {
|
|
|
|
if (claim.value_type === 'stream') {
|
2021-07-16 22:33:59 +02:00
|
|
|
return __('Content');
|
2021-07-15 14:55:09 +02:00
|
|
|
} else if (claim.value_type === 'channel') {
|
|
|
|
return __('Channel');
|
|
|
|
} else if (claim.value_type === 'repost') {
|
|
|
|
return __('Repost');
|
|
|
|
} else if (claim.value_type === 'collection') {
|
|
|
|
return __('List');
|
2021-07-16 22:33:59 +02:00
|
|
|
} else {
|
2021-07-15 14:55:09 +02:00
|
|
|
return __('Claim');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const claimTypeText = setClaimTypeText();
|
|
|
|
|
2021-07-03 19:19:23 +02:00
|
|
|
let iconToUse, explainerText;
|
|
|
|
if (activeTab === TAB_BOOST) {
|
|
|
|
iconToUse = ICONS.LBC;
|
2021-07-15 14:55:09 +02:00
|
|
|
explainerText = __('This refundable boost will improve the discoverability of this %claimTypeText% while active.', {claimTypeText});
|
2021-07-03 19:19:23 +02:00
|
|
|
} else if (activeTab === TAB_FIAT) {
|
|
|
|
iconToUse = ICONS.FINANCE;
|
2021-07-06 22:28:29 +02:00
|
|
|
explainerText = __('Show this channel your appreciation by sending a donation in USD. ');
|
2021-07-03 19:19:23 +02:00
|
|
|
// if (!hasCardSaved) {
|
2021-07-05 16:53:38 +02:00
|
|
|
// explainerText += __('You must add a card to use this functionality.');
|
2021-07-03 19:19:23 +02:00
|
|
|
// }
|
|
|
|
} else if (activeTab === TAB_LBC) {
|
|
|
|
iconToUse = ICONS.LBC;
|
2021-07-06 22:28:29 +02:00
|
|
|
explainerText = __('Show this channel your appreciation by sending a donation of Credits. ');
|
2021-07-03 19:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const isSupport = claimIsMine || activeTab === TAB_BOOST;
|
2020-06-17 09:11:57 +02:00
|
|
|
|
2020-06-10 00:09:24 +02:00
|
|
|
React.useEffect(() => {
|
2021-07-03 19:19:23 +02:00
|
|
|
// Regex for number up to 8 decimal places
|
2020-06-10 00:09:24 +02:00
|
|
|
const regexp = RegExp(/^(\d*([.]\d{0,8})?)$/);
|
|
|
|
const validTipInput = regexp.test(String(tipAmount));
|
|
|
|
let tipError;
|
|
|
|
|
2021-07-06 22:28:29 +02:00
|
|
|
if (tipAmount === 0) {
|
2020-06-10 00:09:24 +02:00
|
|
|
tipError = __('Amount must be a positive number');
|
2021-07-06 22:28:29 +02:00
|
|
|
} else if (!tipAmount || typeof tipAmount !== 'number') {
|
|
|
|
tipError = __('Amount must be a number');
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it's not fiat, aka it's boost or lbc tip
|
|
|
|
else if (activeTab !== TAB_FIAT) {
|
|
|
|
if (!validTipInput) {
|
|
|
|
tipError = __('Amount must have no more than 8 decimal places');
|
|
|
|
} else if (tipAmount === balance) {
|
|
|
|
tipError = __('Please decrease the amount to account for transaction fees');
|
|
|
|
} else if (tipAmount > balance) {
|
|
|
|
tipError = __('Not enough Credits');
|
|
|
|
} else if (tipAmount < MINIMUM_PUBLISH_BID) {
|
|
|
|
tipError = __('Amount must be higher');
|
|
|
|
}
|
|
|
|
// if tip fiat tab
|
|
|
|
} else {
|
|
|
|
if (tipAmount < 1) {
|
|
|
|
tipError = __('Amount must be at least one dollar');
|
|
|
|
} else if (tipAmount > 1000) {
|
|
|
|
tipError = __('Amount cannot be over 1000 dollars');
|
|
|
|
}
|
2020-06-10 00:09:24 +02:00
|
|
|
}
|
2021-07-03 19:19:23 +02:00
|
|
|
|
2020-06-10 00:09:24 +02:00
|
|
|
setTipError(tipError);
|
2021-07-06 22:28:29 +02:00
|
|
|
}, [tipAmount, balance, setTipError, activeTab]);
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2021-07-03 19:19:23 +02:00
|
|
|
//
|
2020-04-25 01:53:57 +02:00
|
|
|
function sendSupportOrConfirm(instantTipMaxAmount = null) {
|
2021-07-03 19:19:23 +02:00
|
|
|
// send a tip
|
|
|
|
if (!isConfirming && (!instantTipMaxAmount || !instantTipEnabled || tipAmount > instantTipMaxAmount)) {
|
2020-06-15 16:04:44 +02:00
|
|
|
setIsConfirming(true);
|
2020-04-25 01:53:57 +02:00
|
|
|
} else {
|
2021-07-03 19:19:23 +02:00
|
|
|
// send a boost
|
2020-06-15 16:04:44 +02:00
|
|
|
const supportParams: SupportParams = { amount: tipAmount, claim_id: claimId };
|
2021-07-03 19:19:23 +02:00
|
|
|
|
|
|
|
// include channel name if donation not anonymous
|
|
|
|
if (activeChannelClaim && !incognito) {
|
|
|
|
supportParams.channel_id = activeChannelClaim.claim_id;
|
2020-06-15 16:04:44 +02:00
|
|
|
}
|
2021-07-03 19:19:23 +02:00
|
|
|
|
|
|
|
// send tip/boost
|
2020-06-15 16:04:44 +02:00
|
|
|
sendSupport(supportParams, isSupport);
|
2020-04-30 00:02:53 +02:00
|
|
|
closeModal();
|
2020-04-25 01:53:57 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-23 18:44:18 +02:00
|
|
|
|
2021-07-03 19:19:23 +02:00
|
|
|
// when the form button is clicked
|
2020-04-25 01:53:57 +02:00
|
|
|
function handleSubmit() {
|
2020-04-23 10:18:17 +02:00
|
|
|
if (tipAmount && claimId) {
|
2021-07-03 19:19:23 +02:00
|
|
|
// send an instant tip (no need to go to an exchange first)
|
|
|
|
if (instantTipEnabled && activeTab !== TAB_FIAT) {
|
2020-04-25 01:53:57 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
2021-07-03 19:19:23 +02:00
|
|
|
// sending fiat tip
|
|
|
|
} else if (activeTab === TAB_FIAT) {
|
|
|
|
if (!isConfirming) {
|
|
|
|
setIsConfirming(true);
|
|
|
|
} else if (isConfirming) {
|
|
|
|
let sendAnonymously = !activeChannelClaim || incognito;
|
|
|
|
|
|
|
|
Lbryio.call(
|
|
|
|
'customer',
|
|
|
|
'tip',
|
|
|
|
{
|
|
|
|
amount: 100 * tipAmount, // convert from dollars to cents
|
2021-07-03 19:36:25 +02:00
|
|
|
creator_channel_name: tipChannelName, // creator_channel_name
|
|
|
|
creator_channel_claim_id: channelClaimId,
|
2021-07-05 13:35:17 +02:00
|
|
|
tipper_channel_name: sendAnonymously ? '' : activeChannelName,
|
|
|
|
tipper_channel_claim_id: sendAnonymously ? '' : activeChannelId,
|
2021-07-03 19:19:23 +02:00
|
|
|
currency: 'USD',
|
|
|
|
anonymous: sendAnonymously,
|
|
|
|
source_claim_id: sourceClaimId,
|
|
|
|
environment: stripeEnvironment,
|
|
|
|
},
|
|
|
|
'post'
|
|
|
|
)
|
|
|
|
.then((customerTipResponse) => {
|
|
|
|
doToast({
|
|
|
|
message: __("You sent $%amount% as a tip to %tipChannelName%, I'm sure they appreciate it!", {
|
|
|
|
amount: tipAmount,
|
|
|
|
tipChannelName,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
})
|
2021-07-06 22:28:29 +02:00
|
|
|
.catch(function(error) {
|
|
|
|
var displayError = 'Sorry, there was an error in processing your payment!';
|
|
|
|
|
|
|
|
if (error.message !== 'payment intent failed to confirm') {
|
|
|
|
displayError = error.message;
|
|
|
|
}
|
|
|
|
|
|
|
|
doToast({ message: displayError, isError: true });
|
2021-07-03 19:19:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
closeModal();
|
|
|
|
}
|
|
|
|
// if it's a boost (?)
|
2020-04-23 18:44:18 +02:00
|
|
|
} else {
|
2020-04-25 01:53:57 +02:00
|
|
|
sendSupportOrConfirm();
|
2020-04-23 18:44:18 +02:00
|
|
|
}
|
2018-03-26 23:32:43 +02:00
|
|
|
}
|
2017-09-17 22:33:52 +02:00
|
|
|
}
|
|
|
|
|
2020-06-17 09:11:57 +02:00
|
|
|
function handleCustomPriceChange(event: SyntheticInputEvent<*>) {
|
2018-06-18 08:34:59 +02:00
|
|
|
const tipAmount = parseFloat(event.target.value);
|
2021-07-06 22:28:29 +02:00
|
|
|
|
2020-06-17 09:11:57 +02:00
|
|
|
setCustomTipAmount(tipAmount);
|
2017-09-17 22:33:52 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 19:19:23 +02:00
|
|
|
function buildButtonText() {
|
|
|
|
// test if frontend will show up as isNan
|
|
|
|
function isNan(tipAmount) {
|
|
|
|
// testing for NaN ES5 style https://stackoverflow.com/a/35912757/3973137
|
|
|
|
// also sometimes it's returned as a string
|
2021-07-05 13:35:17 +02:00
|
|
|
// eslint-disable-next-line
|
|
|
|
if (tipAmount !== tipAmount || tipAmount === 'NaN') {
|
2021-07-03 19:19:23 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it's a valid number display it, otherwise do an empty string
|
|
|
|
const displayAmount = !isNan(tipAmount) ? tipAmount : '';
|
|
|
|
|
|
|
|
if (activeTab === TAB_BOOST) {
|
2021-07-15 14:55:09 +02:00
|
|
|
return (claimIsMine ? __('Boost Your %claimTypeText%', {claimTypeText}) : __('Boost This %claimTypeText%', {claimTypeText}));
|
2021-07-03 19:19:23 +02:00
|
|
|
} else if (activeTab === TAB_FIAT) {
|
2021-07-05 16:53:38 +02:00
|
|
|
return __('Send a $%displayAmount% Tip', { displayAmount });
|
2021-07-03 19:19:23 +02:00
|
|
|
} else if (activeTab === TAB_LBC) {
|
2021-07-05 18:10:16 +02:00
|
|
|
return __('Send a %displayAmount% Credit Tip', { displayAmount });
|
2021-07-03 19:19:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function shouldDisableAmountSelector(amount) {
|
|
|
|
return (
|
2021-07-05 13:35:17 +02:00
|
|
|
(amount > balance && activeTab !== TAB_FIAT) || (activeTab === TAB_FIAT && (!hasCardSaved || !canReceiveFiatTip))
|
2021-07-03 19:19:23 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setConfirmLabel() {
|
|
|
|
if (activeTab === TAB_LBC) {
|
2021-07-05 18:10:16 +02:00
|
|
|
return __('Tipping Credit');
|
2021-07-03 19:19:23 +02:00
|
|
|
} else if (activeTab === TAB_FIAT) {
|
2021-07-05 16:53:38 +02:00
|
|
|
return __('Tipping Fiat (USD)');
|
2021-07-03 19:19:23 +02:00
|
|
|
} else if (activeTab === TAB_BOOST) {
|
2021-07-05 16:53:38 +02:00
|
|
|
return __('Boosting');
|
2021-07-03 19:19:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-13 20:53:53 +01:00
|
|
|
return (
|
2020-06-08 20:42:29 +02:00
|
|
|
<Form onSubmit={handleSubmit}>
|
2021-07-03 19:19:23 +02:00
|
|
|
{/* if there is no LBC balance, show user frontend to get credits */}
|
2020-08-26 22:28:33 +02:00
|
|
|
{noBalance ? (
|
2020-06-10 00:09:24 +02:00
|
|
|
<Card
|
2020-09-02 22:08:37 +02:00
|
|
|
title={<I18nMessage tokens={{ lbc: <LbcSymbol size={22} /> }}>Supporting content requires %lbc%</I18nMessage>}
|
|
|
|
subtitle={
|
|
|
|
<I18nMessage tokens={{ lbc: <LbcSymbol /> }}>
|
|
|
|
With %lbc%, you can send tips to your favorite creators, or help boost their content for more people to
|
|
|
|
see.
|
|
|
|
</I18nMessage>
|
|
|
|
}
|
2020-06-10 00:09:24 +02:00
|
|
|
actions={
|
|
|
|
<div className="section__actions">
|
2020-08-26 22:28:33 +02:00
|
|
|
<Button
|
|
|
|
icon={ICONS.REWARDS}
|
|
|
|
button="primary"
|
|
|
|
label={__('Earn Rewards')}
|
|
|
|
navigate={`/$/${PAGES.REWARDS}`}
|
|
|
|
/>
|
2021-05-31 05:19:13 +02:00
|
|
|
<Button icon={ICONS.BUY} button="secondary" label={__('Buy/Swap Credits')} navigate={`/$/${PAGES.BUY}`} />
|
2020-06-10 00:09:24 +02:00
|
|
|
<Button button="link" label={__('Nevermind')} onClick={closeModal} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
) : (
|
2021-07-03 19:19:23 +02:00
|
|
|
// if there is lbc, the main tip/boost gui with the 3 tabs at the top
|
2020-06-10 00:09:24 +02:00
|
|
|
<Card
|
2021-07-15 14:55:09 +02:00
|
|
|
title={<LbcSymbol postfix={claimIsMine ? __('Boost Your %claimTypeText%', {claimTypeText}) : __('Support This %claimTypeText%', {claimTypeText})} size={22} />}
|
2020-06-10 00:09:24 +02:00
|
|
|
subtitle={
|
|
|
|
<React.Fragment>
|
2021-03-19 07:47:29 +01:00
|
|
|
{!claimIsMine && (
|
|
|
|
<div className="section">
|
2021-07-03 19:19:23 +02:00
|
|
|
{/* tip LBC tab button */}
|
2021-03-19 07:47:29 +01:00
|
|
|
<Button
|
|
|
|
key="tip"
|
2021-07-03 19:19:23 +02:00
|
|
|
icon={ICONS.LBC}
|
2021-03-19 07:47:29 +01:00
|
|
|
label={__('Tip')}
|
|
|
|
button="alt"
|
2021-07-03 19:19:23 +02:00
|
|
|
onClick={() => {
|
2021-07-06 22:28:29 +02:00
|
|
|
var tipInputElement = document.getElementById('tip-input');
|
|
|
|
if (tipInputElement) { tipInputElement.focus() }
|
2021-07-03 19:19:23 +02:00
|
|
|
if (!isConfirming) {
|
|
|
|
setActiveTab(TAB_LBC);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
className={classnames('button-toggle', { 'button-toggle--active': activeTab === TAB_LBC })}
|
2021-03-19 07:47:29 +01:00
|
|
|
/>
|
2021-07-03 19:19:23 +02:00
|
|
|
{/* tip fiat tab button */}
|
2021-07-05 13:35:17 +02:00
|
|
|
{/* @if TARGET='web' */}
|
2021-07-03 19:19:23 +02:00
|
|
|
<Button
|
|
|
|
key="tip-fiat"
|
|
|
|
icon={ICONS.FINANCE}
|
|
|
|
label={__('Tip')}
|
|
|
|
button="alt"
|
|
|
|
onClick={() => {
|
2021-07-06 22:28:29 +02:00
|
|
|
var tipInputElement = document.getElementById('tip-input');
|
|
|
|
if (tipInputElement) { tipInputElement.focus() }
|
2021-07-03 19:19:23 +02:00
|
|
|
if (!isConfirming) {
|
|
|
|
setActiveTab(TAB_FIAT);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
className={classnames('button-toggle', { 'button-toggle--active': activeTab === TAB_FIAT })}
|
|
|
|
/>
|
2021-07-05 13:35:17 +02:00
|
|
|
{/* @endif */}
|
2021-07-03 19:19:23 +02:00
|
|
|
{/* tip LBC tab button */}
|
2021-03-19 07:47:29 +01:00
|
|
|
<Button
|
|
|
|
key="boost"
|
|
|
|
icon={ICONS.TRENDING}
|
|
|
|
label={__('Boost')}
|
|
|
|
button="alt"
|
2021-07-03 19:19:23 +02:00
|
|
|
onClick={() => {
|
2021-07-06 22:28:29 +02:00
|
|
|
var tipInputElement = document.getElementById('tip-input');
|
|
|
|
if (tipInputElement) { tipInputElement.focus() }
|
2021-07-03 19:19:23 +02:00
|
|
|
if (!isConfirming) {
|
|
|
|
setActiveTab(TAB_BOOST);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
className={classnames('button-toggle', { 'button-toggle--active': activeTab === TAB_BOOST })}
|
2021-03-19 07:47:29 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2021-07-03 19:19:23 +02:00
|
|
|
|
|
|
|
{/* short explainer under the button */}
|
2021-03-19 07:47:29 +01:00
|
|
|
<div className="section__subtitle">
|
2021-07-03 19:19:23 +02:00
|
|
|
{explainerText}
|
|
|
|
{/* {activeTab === TAB_FIAT && !hasCardSaved && <Button navigate={`/$/${PAGES.SETTINGS_STRIPE_CARD}`} label={__('Add A Card')} button="link" />} */}
|
|
|
|
{<Button label={__('Learn more')} button="link" href="https://lbry.com/faq/tipping" />}
|
2021-03-19 07:47:29 +01:00
|
|
|
</div>
|
2020-06-10 00:09:24 +02:00
|
|
|
</React.Fragment>
|
|
|
|
}
|
|
|
|
actions={
|
2021-07-03 19:19:23 +02:00
|
|
|
// confirmation modal, allow user to confirm or cancel transaction
|
2020-06-15 16:04:44 +02:00
|
|
|
isConfirming ? (
|
|
|
|
<>
|
|
|
|
<div className="section section--padded card--inline confirm__wrapper">
|
|
|
|
<div className="section">
|
2020-10-11 14:50:41 +02:00
|
|
|
<div className="confirm__label">{__('To --[the tip recipient]--')}</div>
|
2020-06-15 16:04:44 +02:00
|
|
|
<div className="confirm__value">{channelName || title}</div>
|
2020-10-11 14:50:41 +02:00
|
|
|
<div className="confirm__label">{__('From --[the tip sender]--')}</div>
|
2021-02-09 17:05:56 +01:00
|
|
|
<div className="confirm__value">
|
|
|
|
{activeChannelClaim && !incognito ? activeChannelClaim.name : __('Anonymous')}
|
|
|
|
</div>
|
2021-07-03 19:19:23 +02:00
|
|
|
<div className="confirm__label">{setConfirmLabel()}</div>
|
2020-09-02 22:08:37 +02:00
|
|
|
<div className="confirm__value">
|
2021-07-03 19:19:23 +02:00
|
|
|
{activeTab === TAB_FIAT ? <p>$ {tipAmount}</p> : <LbcSymbol postfix={tipAmount} size={22} />}
|
2020-09-02 22:08:37 +02:00
|
|
|
</div>
|
2020-06-15 16:04:44 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="section__actions">
|
2020-06-15 16:11:29 +02:00
|
|
|
<Button
|
|
|
|
autoFocus
|
|
|
|
onClick={handleSubmit}
|
|
|
|
button="primary"
|
|
|
|
disabled={isPending}
|
|
|
|
label={__('Confirm')}
|
|
|
|
/>
|
2020-06-15 16:04:44 +02:00
|
|
|
<Button button="link" label={__('Cancel')} onClick={() => setIsConfirming(false)} />
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<div className="section">
|
2021-02-09 17:05:56 +01:00
|
|
|
<ChannelSelector />
|
2020-06-15 16:04:44 +02:00
|
|
|
</div>
|
|
|
|
|
2021-07-03 19:19:23 +02:00
|
|
|
{activeTab === TAB_FIAT && !hasCardSaved && (
|
|
|
|
<h3 className="add-card-prompt">
|
|
|
|
<Button navigate={`/$/${PAGES.SETTINGS_STRIPE_CARD}`} label={__('Add a Card')} button="link" /> To
|
2021-07-05 16:53:38 +02:00
|
|
|
{__('Tip Creators')}
|
2021-07-03 19:19:23 +02:00
|
|
|
</h3>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{/* section to pick tip/boost amount */}
|
2020-06-15 16:04:44 +02:00
|
|
|
<div className="section">
|
2021-03-19 04:41:14 +01:00
|
|
|
{DEFAULT_TIP_AMOUNTS.map((amount) => (
|
2020-06-15 16:04:44 +02:00
|
|
|
<Button
|
|
|
|
key={amount}
|
2021-07-03 19:19:23 +02:00
|
|
|
disabled={shouldDisableAmountSelector(amount)}
|
2020-06-15 16:04:44 +02:00
|
|
|
button="alt"
|
2020-06-15 16:41:59 +02:00
|
|
|
className={classnames('button-toggle button-toggle--expandformobile', {
|
2021-07-03 19:19:23 +02:00
|
|
|
'button-toggle--active': tipAmount === amount && !useCustomTip,
|
2020-06-15 16:04:44 +02:00
|
|
|
'button-toggle--disabled': amount > balance,
|
|
|
|
})}
|
2020-09-02 22:08:37 +02:00
|
|
|
label={amount}
|
2021-07-03 19:19:23 +02:00
|
|
|
icon={iconToUse}
|
2020-06-17 09:11:57 +02:00
|
|
|
onClick={() => {
|
|
|
|
setPresetTipAmount(amount);
|
|
|
|
setUseCustomTip(false);
|
|
|
|
}}
|
2020-06-15 16:04:44 +02:00
|
|
|
/>
|
|
|
|
))}
|
2021-07-03 19:19:23 +02:00
|
|
|
|
2020-06-10 00:09:24 +02:00
|
|
|
<Button
|
|
|
|
button="alt"
|
2020-06-15 16:41:59 +02:00
|
|
|
className={classnames('button-toggle button-toggle--expandformobile', {
|
2021-07-03 19:19:23 +02:00
|
|
|
'button-toggle--active': useCustomTip, // set as active
|
2020-06-10 00:09:24 +02:00
|
|
|
})}
|
2021-07-03 19:19:23 +02:00
|
|
|
icon={iconToUse}
|
2020-06-15 16:04:44 +02:00
|
|
|
label={__('Custom')}
|
2020-06-17 09:11:57 +02:00
|
|
|
onClick={() => setUseCustomTip(true)}
|
2021-07-06 22:28:29 +02:00
|
|
|
// disabled if it's receive fiat and there is no card or creator can't receive tips
|
2021-07-03 19:19:23 +02:00
|
|
|
disabled={activeTab === TAB_FIAT && (!hasCardSaved || !canReceiveFiatTip)}
|
2020-06-10 00:09:24 +02:00
|
|
|
/>
|
2021-07-03 19:19:23 +02:00
|
|
|
|
|
|
|
{DEFAULT_TIP_AMOUNTS.some((val) => val > balance) && activeTab !== TAB_FIAT && (
|
2020-07-08 09:38:16 +02:00
|
|
|
<Button
|
|
|
|
button="secondary"
|
|
|
|
className="button-toggle-group-action"
|
|
|
|
icon={ICONS.BUY}
|
2021-05-31 05:19:13 +02:00
|
|
|
title={__('Buy or swap more LBRY Credits')}
|
2020-07-08 09:38:16 +02:00
|
|
|
navigate={`/$/${PAGES.BUY}`}
|
|
|
|
/>
|
|
|
|
)}
|
2020-06-15 16:04:44 +02:00
|
|
|
</div>
|
|
|
|
|
2020-06-17 09:11:57 +02:00
|
|
|
{useCustomTip && (
|
2020-06-15 16:04:44 +02:00
|
|
|
<div className="section">
|
|
|
|
<FormField
|
|
|
|
autoFocus
|
|
|
|
name="tip-input"
|
|
|
|
label={
|
|
|
|
<React.Fragment>
|
2020-06-17 09:11:57 +02:00
|
|
|
{__('Custom support amount')}{' '}
|
2021-07-03 19:19:23 +02:00
|
|
|
{activeTab !== TAB_FIAT ? (
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{ lbc_balance: <CreditAmount precision={4} amount={balance} showLBC={false} /> }}
|
|
|
|
>
|
|
|
|
(%lbc_balance% Credits available)
|
|
|
|
</I18nMessage>
|
|
|
|
) : (
|
|
|
|
'in USD'
|
|
|
|
)}
|
2020-06-15 16:04:44 +02:00
|
|
|
</React.Fragment>
|
|
|
|
}
|
|
|
|
className="form-field--price-amount"
|
2021-07-03 19:19:23 +02:00
|
|
|
error={tipError && activeTab !== TAB_FIAT}
|
2020-06-15 16:04:44 +02:00
|
|
|
min="0"
|
|
|
|
step="any"
|
|
|
|
type="number"
|
|
|
|
placeholder="1.23"
|
2020-06-17 09:11:57 +02:00
|
|
|
value={customTipAmount}
|
2021-03-19 04:41:14 +01:00
|
|
|
onChange={(event) => handleCustomPriceChange(event)}
|
2020-06-15 16:04:44 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2021-07-03 19:19:23 +02:00
|
|
|
{/* send tip/boost button */}
|
2020-06-15 16:04:44 +02:00
|
|
|
<div className="section__actions">
|
|
|
|
<Button
|
2020-06-10 00:09:24 +02:00
|
|
|
autoFocus
|
2021-03-19 07:47:29 +01:00
|
|
|
icon={isSupport ? ICONS.TRENDING : ICONS.SUPPORT}
|
2020-06-15 16:04:44 +02:00
|
|
|
button="primary"
|
|
|
|
type="submit"
|
2021-07-03 19:19:23 +02:00
|
|
|
disabled={
|
|
|
|
fetchingChannels ||
|
|
|
|
isPending ||
|
|
|
|
(tipError && activeTab !== TAB_FIAT) ||
|
|
|
|
!tipAmount ||
|
|
|
|
(activeTab === TAB_FIAT && (!hasCardSaved || !canReceiveFiatTip))
|
2020-06-10 00:09:24 +02:00
|
|
|
}
|
2021-07-03 19:19:23 +02:00
|
|
|
label={buildButtonText()}
|
2020-06-10 00:09:24 +02:00
|
|
|
/>
|
2020-06-15 16:04:44 +02:00
|
|
|
{fetchingChannels && <span className="help">{__('Loading your channels...')}</span>}
|
2020-06-10 00:09:24 +02:00
|
|
|
</div>
|
2021-07-03 19:19:23 +02:00
|
|
|
{activeTab !== TAB_FIAT ? (
|
|
|
|
<WalletSpendableBalanceHelp />
|
|
|
|
) : !canReceiveFiatTip ? (
|
2021-07-05 16:53:38 +02:00
|
|
|
<div className="help">{__('Only select creators can receive tips at this time')}</div>
|
2021-07-03 19:19:23 +02:00
|
|
|
) : (
|
2021-07-05 16:53:38 +02:00
|
|
|
<div className="help">{__('The payment will be made from your saved card')}</div>
|
2021-07-03 19:19:23 +02:00
|
|
|
)}
|
2020-06-15 16:04:44 +02:00
|
|
|
</>
|
|
|
|
)
|
2020-06-10 00:09:24 +02:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
2020-06-08 20:42:29 +02:00
|
|
|
</Form>
|
2020-03-13 20:53:53 +01:00
|
|
|
);
|
2017-09-17 22:33:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default WalletSendTip;
|