fix(core): fix too many subscription request (#6809)

This commit is contained in:
EYHN
2024-05-07 07:07:27 +00:00
parent eac55fe1c1
commit 61d0e14c8b
2 changed files with 22 additions and 10 deletions

View File

@@ -25,11 +25,17 @@ export const AISubscribe = ({ ...btnProps }: AISubscribeProps) => {
useEffect(() => { useEffect(() => {
if (isOpenedExternalWindow) { if (isOpenedExternalWindow) {
// when the external window is opened, revalidate the subscription status every 3 seconds // when the external window is opened, revalidate the subscription when window get focus
const timer = setInterval(() => { window.addEventListener(
subscriptionService.subscription.revalidate(); 'focus',
}, 3000); subscriptionService.subscription.revalidate
return () => clearInterval(timer); );
return () => {
window.removeEventListener(
'focus',
subscriptionService.subscription.revalidate
);
};
} }
return; return;
}, [isOpenedExternalWindow, subscriptionService]); }, [isOpenedExternalWindow, subscriptionService]);

View File

@@ -235,11 +235,17 @@ const Upgrade = ({ recurring }: { recurring: SubscriptionRecurring }) => {
useEffect(() => { useEffect(() => {
if (isOpenedExternalWindow) { if (isOpenedExternalWindow) {
// when the external window is opened, revalidate the subscription status every 3 seconds // when the external window is opened, revalidate the subscription when window get focus
const timer = setInterval(() => { window.addEventListener(
subscriptionService.subscription.revalidate(); 'focus',
}, 1000); subscriptionService.subscription.revalidate
return () => clearInterval(timer); );
return () => {
window.removeEventListener(
'focus',
subscriptionService.subscription.revalidate
);
};
} }
return; return;
}, [isOpenedExternalWindow, subscriptionService]); }, [isOpenedExternalWindow, subscriptionService]);