Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: claimOverlap fix & degen remaining #553

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions apps/u3/src/components/social/farcaster/FCastTips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function FCastTips({
});
const { currFid, encryptedSigner } = useFarcasterCtx();
const [allowance, setAllowance] = useState<string>('0');
const [remainingAllowance, setRemainingAllowance] = useState<string>('0');
const [loading, setLoading] = useState(false);

const loadUserinfo = useCallback(async () => {
Expand All @@ -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);
Expand Down Expand Up @@ -158,6 +162,7 @@ export default function FCastTips({
userinfo={userinfo}
userData={userData}
allowance={allowance}
remainingAllowance={remainingAllowance}
cast={cast}
updateCb={updateCb}
/>
Expand All @@ -174,6 +179,7 @@ function TipsModal({
userData,
cast,
allowance,
remainingAllowance,
updateCb,
}: {
open: boolean;
Expand All @@ -183,6 +189,7 @@ function TipsModal({
userinfo: { address: string; fname: string };
cast: FarCast;
allowance: string;
remainingAllowance: string;
updateCb: () => void;
}) {
return (
Expand Down Expand Up @@ -227,6 +234,7 @@ function TipsModal({
fname={userData.userName}
cast={cast}
allowance={allowance}
remainingAllowance={remainingAllowance}
successCallback={() => {
setOpen(false);
updateCb();
Expand All @@ -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();
Expand Down Expand Up @@ -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 (
<Tabs
Expand Down Expand Up @@ -408,7 +420,7 @@ function TipTransaction({
<div className="flex flex-col gap-5">
<div className="flex gap-1 items-center justify-between">
{tipsCount.map((item) => {
const isAllowance = allowanceNum >= item;
const isAllowance = remainingAllowanceNum >= item;
return (
<div
key={item}
Expand All @@ -433,7 +445,7 @@ function TipTransaction({
<input
type="number"
className="w-full p-1 px-2 text-white bg-[#1B1E23] outline-none"
placeholder={`Max ${allowanceNum}`}
placeholder={`Remaining ${remainingAllowanceNum}, Total ${allowance}`}
value={allowanceValue}
onChange={(e) => {
setAllowanceValue(e.target.value);
Expand All @@ -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);
}}
/>
<p className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -84,6 +86,10 @@ export default function RedEnvelopeFloatingWindow() {
return null;
}

if (claimStatus.statusCode === 101) {
return null;
}

if (claimed) {
return (
<div
Expand Down