fix: prevent polling race condition and add missing zh/fa translations

This commit is contained in:
Fringg
2026-03-22 05:21:01 +03:00
parent 76c9d6448a
commit e57166745c
3 changed files with 17 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ export default function TelegramLoginButton({ referralCode }: TelegramLoginButto
const pollTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
const expireTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
const copiedTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
const pollInFlightRef = useRef(false);
const loginWithDeepLink = useAuthStore((s) => s.loginWithDeepLink);
@@ -264,7 +265,8 @@ export default function TelegramLoginButton({ referralCode }: TelegramLoginButto
// Recursive setTimeout prevents overlapping async calls
const poll = async () => {
if (!mountedRef.current) return;
if (!mountedRef.current || pollInFlightRef.current) return;
pollInFlightRef.current = true;
try {
// Deep link auth is for existing bot users — only campaign_slug applies
await loginWithDeepLink(token, capturedCampaign);
@@ -296,6 +298,8 @@ export default function TelegramLoginButton({ referralCode }: TelegramLoginButto
// Other error — stop polling
setDeepLinkPolling(false);
setDeepLinkError(t('common.error'));
} finally {
pollInFlightRef.current = false;
}
};
@@ -348,9 +352,12 @@ export default function TelegramLoginButton({ referralCode }: TelegramLoginButto
clearTimeout(pollTimeoutRef.current);
pollTimeoutRef.current = null;
}
// Skip if another poll is already in-flight to prevent race conditions
if (pollInFlightRef.current) return;
const capturedCampaign = capturedCampaignRef.current;
const immediatePoll = async () => {
if (!mountedRef.current) return;
if (!mountedRef.current || pollInFlightRef.current) return;
pollInFlightRef.current = true;
try {
await loginWithDeepLink(deepLinkToken, capturedCampaign);
if (expireTimeoutRef.current) {
@@ -377,6 +384,8 @@ export default function TelegramLoginButton({ referralCode }: TelegramLoginButto
}
setDeepLinkPolling(false);
setDeepLinkError(t('common.error'));
} finally {
pollInFlightRef.current = false;
}
};
immediatePoll();

View File

@@ -172,6 +172,9 @@
"waitingForConfirmation": "در انتظار تایید...",
"deepLinkExpired": "لینک منقضی شده است. لطفا دوباره تلاش کنید.",
"tryAgain": "تلاش مجدد",
"scanQrToLogin": "کد QR را با دوربین گوشی اسکن کنید",
"orSendCommand": "یا این دستور را به ربات ارسال کنید:",
"commandCopied": "دستور کپی شد",
"welcomeBack": "خوش آمدید!",
"loginTitle": "ورود به کابین",
"loginSubtitle": "با تلگرام یا ایمیل وارد شوید",

View File

@@ -172,6 +172,9 @@
"waitingForConfirmation": "等待确认...",
"deepLinkExpired": "链接已过期,请重试。",
"tryAgain": "重试",
"scanQrToLogin": "用手机相机扫描二维码",
"orSendCommand": "或向机器人发送命令:",
"commandCopied": "命令已复制",
"welcomeBack": "欢迎回来!",
"loginTitle": "登录个人中心",
"loginSubtitle": "通过Telegram或邮箱登录",