@ozura/elements 1.3.1-next.70 → 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.
- package/dist/react/index.cjs.js +38 -13
- package/dist/react/index.cjs.js.map +1 -1
- package/dist/react/index.esm.js +38 -13
- package/dist/react/index.esm.js.map +1 -1
- package/dist/react/react/index.d.ts +20 -0
- package/dist/react/vue/index.d.ts +20 -0
- package/dist/server/vue/index.d.ts +20 -0
- package/dist/types/vue/index.d.ts +20 -0
- package/dist/vue/index.cjs.js +36 -10
- package/dist/vue/index.cjs.js.map +1 -1
- package/dist/vue/index.esm.js +36 -10
- package/dist/vue/index.esm.js.map +1 -1
- package/dist/vue/vue/index.d.ts +20 -0
- package/package.json +1 -1
package/dist/react/index.esm.js
CHANGED
|
@@ -2273,9 +2273,11 @@ const OzContext = createContext({
|
|
|
2273
2273
|
notifyUnmount: () => { },
|
|
2274
2274
|
notifyMount: () => { },
|
|
2275
2275
|
notifyTokenize: () => { },
|
|
2276
|
+
notifyChange: () => { },
|
|
2276
2277
|
mountedCount: 0,
|
|
2277
2278
|
readyCount: 0,
|
|
2278
2279
|
tokenizeCount: 0,
|
|
2280
|
+
changeTick: 0,
|
|
2279
2281
|
});
|
|
2280
2282
|
/**
|
|
2281
2283
|
* Creates and owns an OzVault instance for the lifetime of this component.
|
|
@@ -2288,6 +2290,7 @@ function OzElements({ sessionUrl, getSessionKey, fetchWaxKey, pubKey, frameBaseU
|
|
|
2288
2290
|
const [mountedCount, setMountedCount] = useState(0);
|
|
2289
2291
|
const [readyCount, setReadyCount] = useState(0);
|
|
2290
2292
|
const [tokenizeCount, setTokenizeCount] = useState(0);
|
|
2293
|
+
const [changeTick, setChangeTick] = useState(0);
|
|
2291
2294
|
const onLoadErrorRef = useRef(onLoadError);
|
|
2292
2295
|
onLoadErrorRef.current = onLoadError;
|
|
2293
2296
|
const onWaxRefreshRef = useRef(onSessionRefresh !== null && onSessionRefresh !== void 0 ? onSessionRefresh : onWaxRefresh);
|
|
@@ -2410,7 +2413,8 @@ function OzElements({ sessionUrl, getSessionKey, fetchWaxKey, pubKey, frameBaseU
|
|
|
2410
2413
|
setReadyCount(n => Math.max(0, n - 1));
|
|
2411
2414
|
}, []);
|
|
2412
2415
|
const notifyTokenize = useCallback(() => setTokenizeCount(n => n + 1), []);
|
|
2413
|
-
const
|
|
2416
|
+
const notifyChange = useCallback(() => setChangeTick(n => n + 1), []);
|
|
2417
|
+
const value = useMemo(() => ({ vault, initError, notifyMount, notifyReady, notifyUnmount, notifyTokenize, notifyChange, mountedCount, readyCount, tokenizeCount, changeTick }), [vault, initError, notifyMount, notifyReady, notifyUnmount, notifyTokenize, notifyChange, mountedCount, readyCount, tokenizeCount, changeTick]);
|
|
2414
2418
|
return jsx(OzContext.Provider, { value: value, children: children });
|
|
2415
2419
|
}
|
|
2416
2420
|
/**
|
|
@@ -2418,28 +2422,49 @@ function OzElements({ sessionUrl, getSessionKey, fetchWaxKey, pubKey, frameBaseU
|
|
|
2418
2422
|
* an `<OzElements>` provider tree.
|
|
2419
2423
|
*/
|
|
2420
2424
|
function useOzElements() {
|
|
2421
|
-
|
|
2425
|
+
var _a, _b;
|
|
2426
|
+
const { vault, initError, mountedCount, readyCount, notifyTokenize, notifyChange, tokenizeCount } = useContext(OzContext);
|
|
2422
2427
|
const createToken = useCallback(async (options) => {
|
|
2423
2428
|
if (!vault) {
|
|
2424
2429
|
return Promise.reject(new OzError('useOzElements must be called inside an <OzElements> provider.'));
|
|
2425
2430
|
}
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2431
|
+
// Start the call so vault._tokenizing flips synchronously, then notify so
|
|
2432
|
+
// `isTokenizing` re-renders as `true`. Notify again on settle so it returns
|
|
2433
|
+
// to `false`. (vault.isTokenizing is a plain getter — nothing else would
|
|
2434
|
+
// trigger a render while the call is in flight.)
|
|
2435
|
+
const promise = vault.createToken(options);
|
|
2436
|
+
notifyChange();
|
|
2437
|
+
try {
|
|
2438
|
+
const result = await promise;
|
|
2439
|
+
notifyTokenize();
|
|
2440
|
+
return result;
|
|
2441
|
+
}
|
|
2442
|
+
finally {
|
|
2443
|
+
notifyChange();
|
|
2444
|
+
}
|
|
2445
|
+
}, [vault, notifyTokenize, notifyChange]);
|
|
2430
2446
|
const createBankToken = useCallback(async (options) => {
|
|
2431
2447
|
if (!vault) {
|
|
2432
2448
|
return Promise.reject(new OzError('useOzElements must be called inside an <OzElements> provider.'));
|
|
2433
2449
|
}
|
|
2434
|
-
const
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2450
|
+
const promise = vault.createBankToken(options);
|
|
2451
|
+
notifyChange();
|
|
2452
|
+
try {
|
|
2453
|
+
const result = await promise;
|
|
2454
|
+
notifyTokenize();
|
|
2455
|
+
return result;
|
|
2456
|
+
}
|
|
2457
|
+
finally {
|
|
2458
|
+
notifyChange();
|
|
2459
|
+
}
|
|
2460
|
+
}, [vault, notifyTokenize, notifyChange]);
|
|
2438
2461
|
const reset = useCallback(() => {
|
|
2439
2462
|
vault === null || vault === void 0 ? void 0 : vault.reset();
|
|
2440
2463
|
}, [vault]);
|
|
2441
2464
|
const ready = vault !== null && vault.isReady && mountedCount > 0 && readyCount >= mountedCount;
|
|
2442
|
-
|
|
2465
|
+
const isComplete = (_a = vault === null || vault === void 0 ? void 0 : vault.isComplete) !== null && _a !== void 0 ? _a : false;
|
|
2466
|
+
const isTokenizing = (_b = vault === null || vault === void 0 ? void 0 : vault.isTokenizing) !== null && _b !== void 0 ? _b : false;
|
|
2467
|
+
return { createToken, createBankToken, reset, ready, initError, tokenizeCount, isComplete, isTokenizing };
|
|
2443
2468
|
}
|
|
2444
2469
|
const SKELETON_STYLE = {
|
|
2445
2470
|
height: 46,
|
|
@@ -2474,7 +2499,7 @@ function OzFieldBase({ type, variant, style, placeholder, disabled, loadTimeoutM
|
|
|
2474
2499
|
const elementRef = useRef(null);
|
|
2475
2500
|
const [loaded, setLoaded] = useState(false);
|
|
2476
2501
|
const [loadError, setLoadError] = useState(null);
|
|
2477
|
-
const { vault, notifyMount, notifyReady, notifyUnmount } = useContext(OzContext);
|
|
2502
|
+
const { vault, notifyMount, notifyReady, notifyUnmount, notifyChange } = useContext(OzContext);
|
|
2478
2503
|
const onChangeRef = useRef(onChange);
|
|
2479
2504
|
const onFocusRef = useRef(onFocus);
|
|
2480
2505
|
const onBlurRef = useRef(onBlur);
|
|
@@ -2506,7 +2531,7 @@ function OzFieldBase({ type, variant, style, placeholder, disabled, loadTimeoutM
|
|
|
2506
2531
|
notifyReady();
|
|
2507
2532
|
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2508
2533
|
});
|
|
2509
|
-
element.on('change', (e) => { var _a;
|
|
2534
|
+
element.on('change', (e) => { var _a; (_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, e); notifyChange(); });
|
|
2510
2535
|
element.on('focus', () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef); });
|
|
2511
2536
|
element.on('blur', () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef); });
|
|
2512
2537
|
element.on('loaderror', (e) => {
|