Skip to content

Commit

Permalink
fix(core): fix too many subscription request
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed May 7, 2024
1 parent ee9e8bf commit ba0e8da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit ba0e8da

Please sign in to comment.