This commit is contained in:
zeppi 2021-07-05 07:35:17 -04:00 committed by jessopb
parent d34ef851d0
commit 4f6740d1f8

View file

@ -75,6 +75,8 @@ function WalletSendTip(props: Props) {
const [isConfirming, setIsConfirming] = React.useState(false); const [isConfirming, setIsConfirming] = React.useState(false);
const { claim_id: claimId } = claim; const { claim_id: claimId } = claim;
const { channelName } = parseURI(uri); const { channelName } = parseURI(uri);
const activeChannelName = activeChannelClaim && activeChannelClaim.name;
const activeChannelId = activeChannelClaim && activeChannelClaim.claim_id;
const [canReceiveFiatTip, setCanReceiveFiatTip] = React.useState(); // dont persist because it needs to be calc'd per creator const [canReceiveFiatTip, setCanReceiveFiatTip] = React.useState(); // dont persist because it needs to be calc'd per creator
const [hasCardSaved, setHasSavedCard] = usePersistedState('comment-support:hasCardSaved', false); const [hasCardSaved, setHasSavedCard] = usePersistedState('comment-support:hasCardSaved', false);
@ -99,46 +101,46 @@ function WalletSendTip(props: Props) {
// check if creator has an account saved // check if creator has an account saved
React.useEffect(() => { React.useEffect(() => {
if (channelClaimId && isAuthenticated) { if (channelClaimId && isAuthenticated) {
Lbryio.call( Lbryio.call(
'customer', 'customer',
'status', 'status',
{ {
environment: stripeEnvironment, environment: stripeEnvironment,
}, },
'post' 'post'
).then((customerStatusResponse) => { ).then((customerStatusResponse) => {
const defaultPaymentMethodId = const defaultPaymentMethodId =
customerStatusResponse.Customer && customerStatusResponse.Customer &&
customerStatusResponse.Customer.invoice_settings && customerStatusResponse.Customer.invoice_settings &&
customerStatusResponse.Customer.invoice_settings.default_payment_method && customerStatusResponse.Customer.invoice_settings.default_payment_method &&
customerStatusResponse.Customer.invoice_settings.default_payment_method.id; customerStatusResponse.Customer.invoice_settings.default_payment_method.id;
setHasSavedCard(Boolean(defaultPaymentMethodId)); setHasSavedCard(Boolean(defaultPaymentMethodId));
}); });
} }
}, [channelClaimId, isAuthenticated]); }, [channelClaimId, isAuthenticated]);
React.useEffect(() => { React.useEffect(() => {
if (channelClaimId) { if (channelClaimId) {
Lbryio.call( Lbryio.call(
'account', 'account',
'check', 'check',
{ {
channel_claim_id: channelClaimId, channel_claim_id: channelClaimId,
channel_name: tipChannelName, channel_name: tipChannelName,
environment: stripeEnvironment, environment: stripeEnvironment,
}, },
'post' 'post'
) )
.then((accountCheckResponse) => { .then((accountCheckResponse) => {
if (accountCheckResponse === true && canReceiveFiatTip !== true) { if (accountCheckResponse === true && canReceiveFiatTip !== true) {
setCanReceiveFiatTip(true); setCanReceiveFiatTip(true);
} }
}) })
.catch(function(error) { .catch(function (error) {
console.log(error); console.log(error);
}); });
} }
}, [channelClaimId]); }, [channelClaimId]);
@ -234,8 +236,8 @@ function WalletSendTip(props: Props) {
amount: 100 * tipAmount, // convert from dollars to cents amount: 100 * tipAmount, // convert from dollars to cents
creator_channel_name: tipChannelName, // creator_channel_name creator_channel_name: tipChannelName, // creator_channel_name
creator_channel_claim_id: channelClaimId, creator_channel_claim_id: channelClaimId,
tipper_channel_name: sendAnonymously ? '' : activeChannelClaim.name, tipper_channel_name: sendAnonymously ? '' : activeChannelName,
tipper_channel_claim_id: sendAnonymously ? '' : activeChannelClaim.claim_id, tipper_channel_claim_id: sendAnonymously ? '' : activeChannelId,
currency: 'USD', currency: 'USD',
anonymous: sendAnonymously, anonymous: sendAnonymously,
source_claim_id: sourceClaimId, source_claim_id: sourceClaimId,
@ -276,7 +278,8 @@ function WalletSendTip(props: Props) {
function isNan(tipAmount) { function isNan(tipAmount) {
// testing for NaN ES5 style https://stackoverflow.com/a/35912757/3973137 // testing for NaN ES5 style https://stackoverflow.com/a/35912757/3973137
// also sometimes it's returned as a string // also sometimes it's returned as a string
if (tipAmount !== tipAmount || tipAmount === 'NaN') { //eslint-disable-line // eslint-disable-next-line
if (tipAmount !== tipAmount || tipAmount === 'NaN') {
return true; return true;
} }
return false; return false;
@ -296,8 +299,7 @@ function WalletSendTip(props: Props) {
function shouldDisableAmountSelector(amount) { function shouldDisableAmountSelector(amount) {
return ( return (
(amount > balance && activeTab !== TAB_FIAT) || (amount > balance && activeTab !== TAB_FIAT) || (activeTab === TAB_FIAT && (!hasCardSaved || !canReceiveFiatTip))
(activeTab === TAB_FIAT && (!hasCardSaved || !canReceiveFiatTip))
); );
} }
@ -358,7 +360,7 @@ function WalletSendTip(props: Props) {
className={classnames('button-toggle', { 'button-toggle--active': activeTab === TAB_LBC })} className={classnames('button-toggle', { 'button-toggle--active': activeTab === TAB_LBC })}
/> />
{/* tip fiat tab button */} {/* tip fiat tab button */}
{ /* @if TARGET='web' */ } {/* @if TARGET='web' */}
<Button <Button
key="tip-fiat" key="tip-fiat"
icon={ICONS.FINANCE} icon={ICONS.FINANCE}
@ -371,7 +373,7 @@ function WalletSendTip(props: Props) {
}} }}
className={classnames('button-toggle', { 'button-toggle--active': activeTab === TAB_FIAT })} className={classnames('button-toggle', { 'button-toggle--active': activeTab === TAB_FIAT })}
/> />
{ /* @endif */ } {/* @endif */}
{/* tip LBC tab button */} {/* tip LBC tab button */}
<Button <Button
key="boost" key="boost"