@hook-sdk/template 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -215,6 +215,33 @@ function usePaywallState() {
215
215
  }
216
216
  }, [subscription]);
217
217
  const dismissPix = (0, import_react3.useCallback)(() => setPixPending(null), []);
218
+ const subRef = (0, import_react3.useRef)(subscription);
219
+ subRef.current = subscription;
220
+ (0, import_react3.useEffect)(() => {
221
+ if (!pixPending) return;
222
+ let attempts = 0;
223
+ const MAX_ATTEMPTS = 60;
224
+ let cancelled = false;
225
+ const tick = async () => {
226
+ if (cancelled || attempts >= MAX_ATTEMPTS) return;
227
+ attempts++;
228
+ try {
229
+ await subRef.current.refresh();
230
+ if (cancelled) return;
231
+ const s = subRef.current.status();
232
+ if (s === "active" || s === "trialing") {
233
+ setPixPending(null);
234
+ return;
235
+ }
236
+ } catch {
237
+ }
238
+ if (!cancelled) setTimeout(tick, 3e3);
239
+ };
240
+ setTimeout(tick, 3e3);
241
+ return () => {
242
+ cancelled = true;
243
+ };
244
+ }, [pixPending]);
218
245
  return {
219
246
  status,
220
247
  daysLeftInTrial,