@ozura/elements 1.3.1-next.71 → 1.3.1-next.72

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.
@@ -2275,9 +2275,11 @@ const OzContext = react.createContext({
2275
2275
  notifyUnmount: () => { },
2276
2276
  notifyMount: () => { },
2277
2277
  notifyTokenize: () => { },
2278
+ notifyChange: () => { },
2278
2279
  mountedCount: 0,
2279
2280
  readyCount: 0,
2280
2281
  tokenizeCount: 0,
2282
+ changeTick: 0,
2281
2283
  });
2282
2284
  /**
2283
2285
  * Creates and owns an OzVault instance for the lifetime of this component.
@@ -2290,6 +2292,7 @@ function OzElements({ sessionUrl, getSessionKey, fetchWaxKey, pubKey, frameBaseU
2290
2292
  const [mountedCount, setMountedCount] = react.useState(0);
2291
2293
  const [readyCount, setReadyCount] = react.useState(0);
2292
2294
  const [tokenizeCount, setTokenizeCount] = react.useState(0);
2295
+ const [changeTick, setChangeTick] = react.useState(0);
2293
2296
  const onLoadErrorRef = react.useRef(onLoadError);
2294
2297
  onLoadErrorRef.current = onLoadError;
2295
2298
  const onWaxRefreshRef = react.useRef(onSessionRefresh !== null && onSessionRefresh !== void 0 ? onSessionRefresh : onWaxRefresh);
@@ -2412,7 +2415,8 @@ function OzElements({ sessionUrl, getSessionKey, fetchWaxKey, pubKey, frameBaseU
2412
2415
  setReadyCount(n => Math.max(0, n - 1));
2413
2416
  }, []);
2414
2417
  const notifyTokenize = react.useCallback(() => setTokenizeCount(n => n + 1), []);
2415
- const value = react.useMemo(() => ({ vault, initError, notifyMount, notifyReady, notifyUnmount, notifyTokenize, mountedCount, readyCount, tokenizeCount }), [vault, initError, notifyMount, notifyReady, notifyUnmount, notifyTokenize, mountedCount, readyCount, tokenizeCount]);
2418
+ const notifyChange = react.useCallback(() => setChangeTick(n => n + 1), []);
2419
+ const value = react.useMemo(() => ({ vault, initError, notifyMount, notifyReady, notifyUnmount, notifyTokenize, notifyChange, mountedCount, readyCount, tokenizeCount, changeTick }), [vault, initError, notifyMount, notifyReady, notifyUnmount, notifyTokenize, notifyChange, mountedCount, readyCount, tokenizeCount, changeTick]);
2416
2420
  return jsxRuntime.jsx(OzContext.Provider, { value: value, children: children });
2417
2421
  }
2418
2422
  /**
@@ -2421,23 +2425,41 @@ function OzElements({ sessionUrl, getSessionKey, fetchWaxKey, pubKey, frameBaseU
2421
2425
  */
2422
2426
  function useOzElements() {
2423
2427
  var _a, _b;
2424
- const { vault, initError, mountedCount, readyCount, notifyTokenize, tokenizeCount } = react.useContext(OzContext);
2428
+ const { vault, initError, mountedCount, readyCount, notifyTokenize, notifyChange, tokenizeCount } = react.useContext(OzContext);
2425
2429
  const createToken = react.useCallback(async (options) => {
2426
2430
  if (!vault) {
2427
2431
  return Promise.reject(new OzError('useOzElements must be called inside an <OzElements> provider.'));
2428
2432
  }
2429
- const result = await vault.createToken(options);
2430
- notifyTokenize();
2431
- return result;
2432
- }, [vault, notifyTokenize]);
2433
+ // Start the call so vault._tokenizing flips synchronously, then notify so
2434
+ // `isTokenizing` re-renders as `true`. Notify again on settle so it returns
2435
+ // to `false`. (vault.isTokenizing is a plain getter — nothing else would
2436
+ // trigger a render while the call is in flight.)
2437
+ const promise = vault.createToken(options);
2438
+ notifyChange();
2439
+ try {
2440
+ const result = await promise;
2441
+ notifyTokenize();
2442
+ return result;
2443
+ }
2444
+ finally {
2445
+ notifyChange();
2446
+ }
2447
+ }, [vault, notifyTokenize, notifyChange]);
2433
2448
  const createBankToken = react.useCallback(async (options) => {
2434
2449
  if (!vault) {
2435
2450
  return Promise.reject(new OzError('useOzElements must be called inside an <OzElements> provider.'));
2436
2451
  }
2437
- const result = await vault.createBankToken(options);
2438
- notifyTokenize();
2439
- return result;
2440
- }, [vault, notifyTokenize]);
2452
+ const promise = vault.createBankToken(options);
2453
+ notifyChange();
2454
+ try {
2455
+ const result = await promise;
2456
+ notifyTokenize();
2457
+ return result;
2458
+ }
2459
+ finally {
2460
+ notifyChange();
2461
+ }
2462
+ }, [vault, notifyTokenize, notifyChange]);
2441
2463
  const reset = react.useCallback(() => {
2442
2464
  vault === null || vault === void 0 ? void 0 : vault.reset();
2443
2465
  }, [vault]);
@@ -2479,7 +2501,7 @@ function OzFieldBase({ type, variant, style, placeholder, disabled, loadTimeoutM
2479
2501
  const elementRef = react.useRef(null);
2480
2502
  const [loaded, setLoaded] = react.useState(false);
2481
2503
  const [loadError, setLoadError] = react.useState(null);
2482
- const { vault, notifyMount, notifyReady, notifyUnmount } = react.useContext(OzContext);
2504
+ const { vault, notifyMount, notifyReady, notifyUnmount, notifyChange } = react.useContext(OzContext);
2483
2505
  const onChangeRef = react.useRef(onChange);
2484
2506
  const onFocusRef = react.useRef(onFocus);
2485
2507
  const onBlurRef = react.useRef(onBlur);
@@ -2511,7 +2533,7 @@ function OzFieldBase({ type, variant, style, placeholder, disabled, loadTimeoutM
2511
2533
  notifyReady();
2512
2534
  (_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
2513
2535
  });
2514
- element.on('change', (e) => { var _a; return (_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, e); });
2536
+ element.on('change', (e) => { var _a; (_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, e); notifyChange(); });
2515
2537
  element.on('focus', () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef); });
2516
2538
  element.on('blur', () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef); });
2517
2539
  element.on('loaderror', (e) => {