mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
fix: prevent polling race condition and add missing zh/fa translations
This commit is contained in:
@@ -36,6 +36,7 @@ export default function TelegramLoginButton({ referralCode }: TelegramLoginButto
|
|||||||
const pollTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
|
const pollTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
|
||||||
const expireTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
|
const expireTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
|
||||||
const copiedTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
|
const copiedTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
|
||||||
|
const pollInFlightRef = useRef(false);
|
||||||
|
|
||||||
const loginWithDeepLink = useAuthStore((s) => s.loginWithDeepLink);
|
const loginWithDeepLink = useAuthStore((s) => s.loginWithDeepLink);
|
||||||
|
|
||||||
@@ -264,7 +265,8 @@ export default function TelegramLoginButton({ referralCode }: TelegramLoginButto
|
|||||||
|
|
||||||
// Recursive setTimeout prevents overlapping async calls
|
// Recursive setTimeout prevents overlapping async calls
|
||||||
const poll = async () => {
|
const poll = async () => {
|
||||||
if (!mountedRef.current) return;
|
if (!mountedRef.current || pollInFlightRef.current) return;
|
||||||
|
pollInFlightRef.current = true;
|
||||||
try {
|
try {
|
||||||
// Deep link auth is for existing bot users — only campaign_slug applies
|
// Deep link auth is for existing bot users — only campaign_slug applies
|
||||||
await loginWithDeepLink(token, capturedCampaign);
|
await loginWithDeepLink(token, capturedCampaign);
|
||||||
@@ -296,6 +298,8 @@ export default function TelegramLoginButton({ referralCode }: TelegramLoginButto
|
|||||||
// Other error — stop polling
|
// Other error — stop polling
|
||||||
setDeepLinkPolling(false);
|
setDeepLinkPolling(false);
|
||||||
setDeepLinkError(t('common.error'));
|
setDeepLinkError(t('common.error'));
|
||||||
|
} finally {
|
||||||
|
pollInFlightRef.current = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -348,9 +352,12 @@ export default function TelegramLoginButton({ referralCode }: TelegramLoginButto
|
|||||||
clearTimeout(pollTimeoutRef.current);
|
clearTimeout(pollTimeoutRef.current);
|
||||||
pollTimeoutRef.current = null;
|
pollTimeoutRef.current = null;
|
||||||
}
|
}
|
||||||
|
// Skip if another poll is already in-flight to prevent race conditions
|
||||||
|
if (pollInFlightRef.current) return;
|
||||||
const capturedCampaign = capturedCampaignRef.current;
|
const capturedCampaign = capturedCampaignRef.current;
|
||||||
const immediatePoll = async () => {
|
const immediatePoll = async () => {
|
||||||
if (!mountedRef.current) return;
|
if (!mountedRef.current || pollInFlightRef.current) return;
|
||||||
|
pollInFlightRef.current = true;
|
||||||
try {
|
try {
|
||||||
await loginWithDeepLink(deepLinkToken, capturedCampaign);
|
await loginWithDeepLink(deepLinkToken, capturedCampaign);
|
||||||
if (expireTimeoutRef.current) {
|
if (expireTimeoutRef.current) {
|
||||||
@@ -377,6 +384,8 @@ export default function TelegramLoginButton({ referralCode }: TelegramLoginButto
|
|||||||
}
|
}
|
||||||
setDeepLinkPolling(false);
|
setDeepLinkPolling(false);
|
||||||
setDeepLinkError(t('common.error'));
|
setDeepLinkError(t('common.error'));
|
||||||
|
} finally {
|
||||||
|
pollInFlightRef.current = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
immediatePoll();
|
immediatePoll();
|
||||||
|
|||||||
@@ -172,6 +172,9 @@
|
|||||||
"waitingForConfirmation": "در انتظار تایید...",
|
"waitingForConfirmation": "در انتظار تایید...",
|
||||||
"deepLinkExpired": "لینک منقضی شده است. لطفا دوباره تلاش کنید.",
|
"deepLinkExpired": "لینک منقضی شده است. لطفا دوباره تلاش کنید.",
|
||||||
"tryAgain": "تلاش مجدد",
|
"tryAgain": "تلاش مجدد",
|
||||||
|
"scanQrToLogin": "کد QR را با دوربین گوشی اسکن کنید",
|
||||||
|
"orSendCommand": "یا این دستور را به ربات ارسال کنید:",
|
||||||
|
"commandCopied": "دستور کپی شد",
|
||||||
"welcomeBack": "خوش آمدید!",
|
"welcomeBack": "خوش آمدید!",
|
||||||
"loginTitle": "ورود به کابین",
|
"loginTitle": "ورود به کابین",
|
||||||
"loginSubtitle": "با تلگرام یا ایمیل وارد شوید",
|
"loginSubtitle": "با تلگرام یا ایمیل وارد شوید",
|
||||||
|
|||||||
@@ -172,6 +172,9 @@
|
|||||||
"waitingForConfirmation": "等待确认...",
|
"waitingForConfirmation": "等待确认...",
|
||||||
"deepLinkExpired": "链接已过期,请重试。",
|
"deepLinkExpired": "链接已过期,请重试。",
|
||||||
"tryAgain": "重试",
|
"tryAgain": "重试",
|
||||||
|
"scanQrToLogin": "用手机相机扫描二维码",
|
||||||
|
"orSendCommand": "或向机器人发送命令:",
|
||||||
|
"commandCopied": "命令已复制",
|
||||||
"welcomeBack": "欢迎回来!",
|
"welcomeBack": "欢迎回来!",
|
||||||
"loginTitle": "登录个人中心",
|
"loginTitle": "登录个人中心",
|
||||||
"loginSubtitle": "通过Telegram或邮箱登录",
|
"loginSubtitle": "通过Telegram或邮箱登录",
|
||||||
|
|||||||
Reference in New Issue
Block a user