From 0e0e2359f25e7ffc38f0d9604a309934491a819d Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Wed, 4 Aug 2021 16:54:20 +0800 Subject: [PATCH] CommentCreate: handle minimum tips To avoid calling `setting.Get` excessively, we'll do the following: (a) Call `setting.Get` once per encountered channel, and stash it. (b) Before sending **each** comment **with a tip**, call `setting.Get` again to get the latest `min_tip`. Report any over- or under-paid values in the confirmation widget before user hits Send. (c) For regular comments (no tips), just send as normal based on stashed data from `a`. - If `min_tip` was `0` but creator later changed to non-zero, Commentron would trigger an error anyway, and the app can get the latest `min_tip` amount to inform the user. - If `min_tip` was not `0` but creator later changed to `0`, the app would be incorrectly forcing the user to pay based on the old amount from `a`. But when he hits `b`, he now knows he has overpaid, and can still cancel. --- ui/component/commentCreate/view.jsx | 67 ++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/ui/component/commentCreate/view.jsx b/ui/component/commentCreate/view.jsx index adf1210d0..ad1b3d638 100644 --- a/ui/component/commentCreate/view.jsx +++ b/ui/component/commentCreate/view.jsx @@ -15,6 +15,7 @@ import WalletTipAmountSelector from 'component/walletTipAmountSelector'; import CreditAmount from 'component/common/credit-amount'; import ChannelThumbnail from 'component/channelThumbnail'; import UriIndicator from 'component/uriIndicator'; +import I18nMessage from 'component/i18nMessage'; import Empty from 'component/common/empty'; import { Lbryio } from 'lbryinc'; import { getChannelIdFromClaim } from 'util/claim'; @@ -97,6 +98,17 @@ export function CommentCreate(props: Props) { const [shouldDisableReviewButton, setShouldDisableReviewButton] = React.useState(); const channelId = getChannelIdFromClaim(claim); const channelSettings = channelId ? settingsByChannelId[channelId] : undefined; + const minTip = (channelSettings && channelSettings.min_tip_amount_comment) || 0; + const minTipMet = minTip === 0 || tipAmount >= minTip; + + const MinTipNotice = + minTip !== 0 ? ( +
+ }}> + This channel requires a minimum tip of %lbc% to post a comment. + +
+ ) : null; function handleCommentChange(event) { let commentValue; @@ -125,6 +137,14 @@ export function CommentCreate(props: Props) { window.removeEventListener('keydown', altEnterListener); } + function handleReview() { + if (channelId) { + // Get the latest minTip value for final review. + doFetchCreatorSettings(channelId); + } + setIsReviewingSupportComment(true); + } + function handleSubmit() { if (activeChannelClaim && commentValue.length) { handleCreateComment(); @@ -238,7 +258,7 @@ export function CommentCreate(props: Props) { } /** - * + * handleCreateComment * @param {string} [txid] Optional transaction id generated by * @param {string} [payment_intent_id] Optional payment_intent_id from Stripe payment * @param {string} [environment] Optional environment for Stripe (test|live) @@ -271,6 +291,7 @@ export function CommentCreate(props: Props) { setAdvancedEditor(!advancedEditor); } + // Fetch channel constraints if not already. React.useEffect(() => { if (!channelSettings && channelId) { doFetchCreatorSettings(channelId); @@ -333,7 +354,7 @@ export function CommentCreate(props: Props) {