diff --git a/packages/frontend/core/src/components/affine/setting-modal/general-setting/plans/ai/actions/subscribe.tsx b/packages/frontend/core/src/components/affine/setting-modal/general-setting/plans/ai/actions/subscribe.tsx index c8d7e5a359..da4c68f160 100644 --- a/packages/frontend/core/src/components/affine/setting-modal/general-setting/plans/ai/actions/subscribe.tsx +++ b/packages/frontend/core/src/components/affine/setting-modal/general-setting/plans/ai/actions/subscribe.tsx @@ -25,11 +25,17 @@ export const AISubscribe = ({ ...btnProps }: AISubscribeProps) => { useEffect(() => { if (isOpenedExternalWindow) { - // when the external window is opened, revalidate the subscription status every 3 seconds - const timer = setInterval(() => { - subscriptionService.subscription.revalidate(); - }, 3000); - return () => clearInterval(timer); + // when the external window is opened, revalidate the subscription when window get focus + window.addEventListener( + 'focus', + subscriptionService.subscription.revalidate + ); + return () => { + window.removeEventListener( + 'focus', + subscriptionService.subscription.revalidate + ); + }; } return; }, [isOpenedExternalWindow, subscriptionService]); diff --git a/packages/frontend/core/src/components/affine/setting-modal/general-setting/plans/plan-card.tsx b/packages/frontend/core/src/components/affine/setting-modal/general-setting/plans/plan-card.tsx index 911e637d65..a0d65b2787 100644 --- a/packages/frontend/core/src/components/affine/setting-modal/general-setting/plans/plan-card.tsx +++ b/packages/frontend/core/src/components/affine/setting-modal/general-setting/plans/plan-card.tsx @@ -235,11 +235,17 @@ const Upgrade = ({ recurring }: { recurring: SubscriptionRecurring }) => { useEffect(() => { if (isOpenedExternalWindow) { - // when the external window is opened, revalidate the subscription status every 3 seconds - const timer = setInterval(() => { - subscriptionService.subscription.revalidate(); - }, 1000); - return () => clearInterval(timer); + // when the external window is opened, revalidate the subscription when window get focus + window.addEventListener( + 'focus', + subscriptionService.subscription.revalidate + ); + return () => { + window.removeEventListener( + 'focus', + subscriptionService.subscription.revalidate + ); + }; } return; }, [isOpenedExternalWindow, subscriptionService]);