Handle comment + tip failure, don't re-support

This commit is contained in:
saltrafael 2021-06-10 09:19:17 -03:00 committed by Thomas Zarebczan
parent 141ebcf1cd
commit 7483429ee6

View file

@ -62,6 +62,8 @@ export function CommentCreate(props: Props) {
location: { pathname }, location: { pathname },
} = useHistory(); } = useHistory();
const [isSubmitting, setIsSubmitting] = React.useState(false); const [isSubmitting, setIsSubmitting] = React.useState(false);
const [commentFailure, setCommentFailure] = React.useState(false);
const [successTip, setSuccessTip] = React.useState({ txid: undefined, tipAmount: undefined });
const { claim_id: claimId } = claim; const { claim_id: claimId } = claim;
const [isSupportComment, setIsSupportComment] = React.useState(); const [isSupportComment, setIsSupportComment] = React.useState();
const [isReviewingSupportComment, setIsReviewingSupportComment] = React.useState(); const [isReviewingSupportComment, setIsReviewingSupportComment] = React.useState();
@ -120,6 +122,13 @@ export function CommentCreate(props: Props) {
return; return;
} }
if (commentFailure && tipAmount === successTip.tipAmount) {
handleCreateComment(successTip.txid);
return;
} else {
setSuccessTip({ txid: undefined, tipAmount: undefined });
}
const params = { const params = {
amount: tipAmount, amount: tipAmount,
claim_id: claimId, claim_id: claimId,
@ -135,6 +144,7 @@ export function CommentCreate(props: Props) {
setTimeout(() => { setTimeout(() => {
handleCreateComment(txid); handleCreateComment(txid);
}, 1500); }, 1500);
setSuccessTip({ txid, tipAmount });
}, },
() => { () => {
setIsSubmitting(false); setIsSubmitting(false);
@ -153,6 +163,7 @@ export function CommentCreate(props: Props) {
setLastCommentTime(Date.now()); setLastCommentTime(Date.now());
setIsReviewingSupportComment(false); setIsReviewingSupportComment(false);
setIsSupportComment(false); setIsSupportComment(false);
setCommentFailure(false);
justCommented.push(res.comment_id); justCommented.push(res.comment_id);
if (onDoneReplying) { if (onDoneReplying) {
@ -162,6 +173,7 @@ export function CommentCreate(props: Props) {
}) })
.catch(() => { .catch(() => {
setIsSubmitting(false); setIsSubmitting(false);
setCommentFailure(true);
}); });
} }
@ -212,7 +224,7 @@ export function CommentCreate(props: Props) {
autoFocus autoFocus
button="primary" button="primary"
disabled={disabled} disabled={disabled}
label={isSubmitting ? __('Sending...') : __('Send')} label={isSubmitting ? __('Sending...') : (commentFailure && tipAmount === successTip.tipAmount) ? __('Re-submit') : __('Send')}
onClick={handleSupportComment} onClick={handleSupportComment}
/> />
<Button button="link" label={__('Cancel')} onClick={() => setIsReviewingSupportComment(false)} /> <Button button="link" label={__('Cancel')} onClick={() => setIsReviewingSupportComment(false)} />