From 87267d4c5e3afe101414772aba1548282080201b Mon Sep 17 00:00:00 2001 From: ttang Date: Mon, 19 Feb 2024 16:05:43 +0800 Subject: [PATCH] fix: claimOverlap fix & degen remaining --- .../components/social/farcaster/FCastTips.tsx | 34 +++++++++++++++---- .../RedEnvelopeFloatingWindow.tsx | 6 ++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/apps/u3/src/components/social/farcaster/FCastTips.tsx b/apps/u3/src/components/social/farcaster/FCastTips.tsx index 943df77c..14bbf958 100644 --- a/apps/u3/src/components/social/farcaster/FCastTips.tsx +++ b/apps/u3/src/components/social/farcaster/FCastTips.tsx @@ -52,6 +52,7 @@ export default function FCastTips({ }); const { currFid, encryptedSigner } = useFarcasterCtx(); const [allowance, setAllowance] = useState('0'); + const [remainingAllowance, setRemainingAllowance] = useState('0'); const [loading, setLoading] = useState(false); const loadUserinfo = useCallback(async () => { @@ -62,6 +63,9 @@ export default function FCastTips({ setUserInfo(data.data); setAllowance(allowanceData.data?.[0]?.tip_allowance || '0'); setReplyTipAllowance(allowanceData.data?.[0]?.tip_allowance || '0'); + setRemainingAllowance( + allowanceData.data?.[0]?.remaining_allowance || '0' + ); setReplyTipAmountTotal('0'); } catch (e) { console.error(e); @@ -158,6 +162,7 @@ export default function FCastTips({ userinfo={userinfo} userData={userData} allowance={allowance} + remainingAllowance={remainingAllowance} cast={cast} updateCb={updateCb} /> @@ -174,6 +179,7 @@ function TipsModal({ userData, cast, allowance, + remainingAllowance, updateCb, }: { open: boolean; @@ -183,6 +189,7 @@ function TipsModal({ userinfo: { address: string; fname: string }; cast: FarCast; allowance: string; + remainingAllowance: string; updateCb: () => void; }) { return ( @@ -227,6 +234,7 @@ function TipsModal({ fname={userData.userName} cast={cast} allowance={allowance} + remainingAllowance={remainingAllowance} successCallback={() => { setOpen(false); updateCb(); @@ -243,12 +251,14 @@ function TipTransaction({ address, cast, allowance, + remainingAllowance, successCallback, }: { fname: string; address: string; cast: FarCast; allowance: string; + remainingAllowance: string; successCallback?: () => void; }) { const { currFid, encryptedSigner } = useFarcasterCtx(); @@ -361,19 +371,21 @@ function TipTransaction({ successCallback?.(); } catch (error) { console.error(error); - toast.success('allowance tip failed'); + toast.error('allowance tip failed'); } }, [allowanceValue, currFid, encryptedSigner, allowance]); useEffect(() => { - if (Number(allowance) > 0) { + if (Number(remainingAllowance) > 0) { setTab('TabReply'); } - }, [allowance]); + }, [remainingAllowance]); const useAllowance = getUseReplyTipDefault(); - const allowanceNum = Number.isNaN(Number(allowance)) ? 0 : Number(allowance); + const remainingAllowanceNum = Number.isNaN(Number(remainingAllowance)) + ? 0 + : Number(remainingAllowance); return (
{tipsCount.map((item) => { - const isAllowance = allowanceNum >= item; + const isAllowance = remainingAllowanceNum >= item; return (
{ setAllowanceValue(e.target.value); @@ -459,12 +471,20 @@ function TipTransaction({ className="border border-white" checked={useAllowance} onCheckedChange={(v) => { + if (allowanceValue === '') { + toast.error('Please select an amount'); + return; + } + if (remainingAllowanceNum < Number(allowanceValue) * 5) { + toast.error('You have used up the default allowance'); + return; + } if (v) { setUseReplyTipDefault(); } else { setUseReplyTipDefault('false'); } - setCount(count + 1); + setCount(Number(count) + 1); }} />

diff --git a/apps/u3/src/components/social/frames/red-envelope/RedEnvelopeFloatingWindow.tsx b/apps/u3/src/components/social/frames/red-envelope/RedEnvelopeFloatingWindow.tsx index 24d6cf8a..4529d173 100644 --- a/apps/u3/src/components/social/frames/red-envelope/RedEnvelopeFloatingWindow.tsx +++ b/apps/u3/src/components/social/frames/red-envelope/RedEnvelopeFloatingWindow.tsx @@ -6,8 +6,10 @@ import { claimRedEnvelope, redEnvelopeClaimCheck, } from '@/services/social/api/farcaster'; +import { useFarcasterCtx } from '@/contexts/social/FarcasterCtx'; export default function RedEnvelopeFloatingWindow() { + const { claimStatus } = useFarcasterCtx(); const { isLogin } = useLogin(); const [open, setOpen] = useState(false); const [mounted, setMounted] = useState(false); @@ -84,6 +86,10 @@ export default function RedEnvelopeFloatingWindow() { return null; } + if (claimStatus.statusCode === 101) { + return null; + } + if (claimed) { return (