@hook-sdk/template 0.7.1 → 0.7.3

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
@@ -183,7 +183,8 @@ function usePaywallState() {
183
183
  method: "pix-auto",
184
184
  qrCodePayload: result.qrCodePayload,
185
185
  qrCodeBase64: result.qrCodeBase64,
186
- expiresAt: null
186
+ expiresAt: null,
187
+ paid: false
187
188
  });
188
189
  setOpening(false);
189
190
  return;
@@ -194,7 +195,8 @@ function usePaywallState() {
194
195
  method: "pix-once",
195
196
  qrCodePayload: result.qrCodePayload,
196
197
  qrCodeBase64: result.qrCodeBase64,
197
- expiresAt: result.expiresAt
198
+ expiresAt: result.expiresAt,
199
+ paid: false
198
200
  });
199
201
  setOpening(false);
200
202
  return;
@@ -215,6 +217,33 @@ function usePaywallState() {
215
217
  }
216
218
  }, [subscription]);
217
219
  const dismissPix = (0, import_react3.useCallback)(() => setPixPending(null), []);
220
+ const subRef = (0, import_react3.useRef)(subscription);
221
+ subRef.current = subscription;
222
+ (0, import_react3.useEffect)(() => {
223
+ if (!pixPending || pixPending.paid) return;
224
+ let attempts = 0;
225
+ const MAX_ATTEMPTS = 60;
226
+ let cancelled = false;
227
+ const tick = async () => {
228
+ if (cancelled || attempts >= MAX_ATTEMPTS) return;
229
+ attempts++;
230
+ try {
231
+ await subRef.current.refresh();
232
+ if (cancelled) return;
233
+ const s = subRef.current.status();
234
+ if (s === "active" || s === "trialing") {
235
+ setPixPending((prev) => prev ? { ...prev, paid: true } : prev);
236
+ return;
237
+ }
238
+ } catch {
239
+ }
240
+ if (!cancelled) setTimeout(tick, 3e3);
241
+ };
242
+ setTimeout(tick, 3e3);
243
+ return () => {
244
+ cancelled = true;
245
+ };
246
+ }, [pixPending]);
218
247
  return {
219
248
  status,
220
249
  daysLeftInTrial,