@openzeppelin/ui-react 3.2.0 → 3.3.0

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
@@ -33,7 +33,7 @@ let _tanstack_react_query = require("@tanstack/react-query");
33
33
  let _openzeppelin_ui_components = require("@openzeppelin/ui-components");
34
34
 
35
35
  //#region src/version.ts
36
- const VERSION = "3.2.0";
36
+ const VERSION = "3.3.0";
37
37
 
38
38
  //#endregion
39
39
  //#region src/hooks/AdapterContext.tsx
@@ -1173,11 +1173,11 @@ const NOOP_RETRY = () => {};
1173
1173
  * {@link EngineResult}. Not exported from the package.
1174
1174
  */
1175
1175
  function useResolutionEngine(params) {
1176
- const { input, namespace, debounceMs, enabled, shouldAttempt, getMethod } = params;
1176
+ const { input, namespace, debounceMs, enabled, shouldAttempt, getMethod, runtimeSource } = params;
1177
1177
  const walletState = (0, react.useContext)(WalletStateContext);
1178
- const activeRuntime = walletState?.activeRuntime ?? null;
1179
- const activeNetworkId = walletState?.activeNetworkId ?? null;
1180
- const isRuntimeLoading = walletState?.isRuntimeLoading ?? false;
1178
+ const activeRuntime = runtimeSource ? runtimeSource.runtime : walletState?.activeRuntime ?? null;
1179
+ const activeNetworkId = runtimeSource ? runtimeSource.networkId : walletState?.activeNetworkId ?? null;
1180
+ const isRuntimeLoading = runtimeSource ? runtimeSource.isRuntimeLoading : walletState?.isRuntimeLoading ?? false;
1181
1181
  const { queryClient, config } = useNameResolutionContext();
1182
1182
  const trimmedLive = (input ?? "").trim();
1183
1183
  const normalizedLive = trimmedLive.toLowerCase();
@@ -1332,40 +1332,13 @@ function toNameResult(engine) {
1332
1332
  }
1333
1333
 
1334
1334
  //#endregion
1335
- //#region src/hooks/nameResolution/useResolveAddress.ts
1336
- /**
1337
- * Reverse-resolve an address to a name. Soft-reads the active runtime from
1338
- * `WalletStateContext` (never throws when no provider is mounted — degrades to
1339
- * idle / UNSUPPORTED_NETWORK) and calls `runtime.nameResolution?.resolveAddress`.
1340
- * Caches per (network, address) via the owned QueryClient. Not debounced by
1341
- * default — addresses are pasted, not typed char-by-char.
1342
- *
1343
- * Applies no client-side address-shape check (INV-32): resolution is attempted on
1344
- * any non-empty input and malformed addresses are rejected via the adapter's typed
1345
- * error union. Address-shape validation is SF-3's concern.
1346
- *
1347
- * @param address - The address to reverse-resolve. `null` / empty yields
1348
- * `status: 'idle'`.
1349
- * @param options - `debounceMs` / `enabled` overrides.
1350
- * @returns The current {@link UseResolveAddressResult}.
1351
- */
1352
- function useResolveAddress(address, options) {
1353
- const { config } = useNameResolutionContext();
1354
- return toAddressResult(useResolutionEngine({
1355
- input: address,
1356
- namespace: "addr",
1357
- debounceMs: options?.debounceMs ?? config.reverseDebounceMs,
1358
- enabled: options?.enabled ?? true,
1359
- shouldAttempt: () => true,
1360
- getMethod: (cap) => cap.resolveAddress
1361
- }));
1362
- }
1335
+ //#region src/hooks/nameResolution/mapAddressEngineResult.ts
1363
1336
  /**
1364
1337
  * Remap the engine's generic `input` to `address` (INV-24). A `debouncing` arm —
1365
1338
  * only reachable when a caller passes a non-zero reverse `debounceMs` — collapses
1366
1339
  * to `loading` so {@link UseResolveAddressResult} keeps no `debouncing` variant.
1367
1340
  */
1368
- function toAddressResult(engine) {
1341
+ function mapAddressEngineResult(engine) {
1369
1342
  switch (engine.status) {
1370
1343
  case "idle": return { status: "idle" };
1371
1344
  case "debouncing":
@@ -1387,6 +1360,71 @@ function toAddressResult(engine) {
1387
1360
  }
1388
1361
  }
1389
1362
 
1363
+ //#endregion
1364
+ //#region src/hooks/nameResolution/useNetworkRuntimeSource.ts
1365
+ /**
1366
+ * Soft-reads {@link RuntimeContext} (never throws) and requests the registry
1367
+ * runtime for `network`. Call during render so loading state updates propagate.
1368
+ *
1369
+ * Does not mutate {@link WalletStateProvider}'s active network — wallet-global
1370
+ * runtime is never consulted when a scoped network is supplied (INV-154).
1371
+ */
1372
+ function useNetworkRuntimeSource(network) {
1373
+ const runtimeContext = (0, react.useContext)(RuntimeContext);
1374
+ if (!network) return {
1375
+ runtime: null,
1376
+ networkId: "",
1377
+ isRuntimeLoading: false
1378
+ };
1379
+ if (!runtimeContext) return {
1380
+ runtime: null,
1381
+ networkId: network.id,
1382
+ isRuntimeLoading: false
1383
+ };
1384
+ const { runtime, isLoading } = runtimeContext.getRuntimeForNetwork(network);
1385
+ return {
1386
+ runtime,
1387
+ networkId: network.id,
1388
+ isRuntimeLoading: isLoading
1389
+ };
1390
+ }
1391
+
1392
+ //#endregion
1393
+ //#region src/hooks/nameResolution/useResolveAddress.ts
1394
+ /**
1395
+ * Reverse-resolve an address to a name. Soft-reads the active runtime from
1396
+ * `WalletStateContext` (never throws when no provider is mounted — degrades to
1397
+ * idle / UNSUPPORTED_NETWORK) and calls `runtime.nameResolution?.resolveAddress`.
1398
+ * Pass `options.network` to scope resolution to a specific network without
1399
+ * changing the wallet's active network. Caches per (network, address) via the
1400
+ * owned QueryClient. Not debounced by default — addresses are pasted, not
1401
+ * typed char-by-char.
1402
+ *
1403
+ * Applies no client-side address-shape check (INV-32): resolution is attempted on
1404
+ * any non-empty input and malformed addresses are rejected via the adapter's typed
1405
+ * error union. Address-shape validation is SF-3's concern.
1406
+ *
1407
+ * @param address - The address to reverse-resolve. `null` / empty yields
1408
+ * `status: 'idle'`.
1409
+ * @param options - `debounceMs` / `enabled` / `network` overrides.
1410
+ * @returns The current {@link UseResolveAddressResult}.
1411
+ */
1412
+ function useResolveAddress(address, options) {
1413
+ const { config } = useNameResolutionContext();
1414
+ const debounceMs = options?.debounceMs ?? config.reverseDebounceMs;
1415
+ const enabled = options?.enabled ?? true;
1416
+ const networkSource = useNetworkRuntimeSource(options?.network ?? null);
1417
+ return mapAddressEngineResult(useResolutionEngine({
1418
+ input: address,
1419
+ namespace: "addr",
1420
+ debounceMs,
1421
+ enabled,
1422
+ shouldAttempt: () => true,
1423
+ getMethod: (cap) => cap.resolveAddress,
1424
+ runtimeSource: options?.network != null ? networkSource : void 0
1425
+ }));
1426
+ }
1427
+
1390
1428
  //#endregion
1391
1429
  //#region src/hooks/nameResolution/NameResolutionProvider.tsx
1392
1430
  /**
@@ -1412,6 +1450,54 @@ function NameResolutionProvider({ children, config, queryClient }) {
1412
1450
  });
1413
1451
  }
1414
1452
 
1453
+ //#endregion
1454
+ //#region src/hooks/nameResolution/createNameResolver.ts
1455
+ const EMPTY_RESOLVER$1 = {};
1456
+ /**
1457
+ * Projects a {@link NameResolutionCapability} into the SF-3 {@link NameResolver}
1458
+ * seam with SF-2 cache-key parity (INV-119).
1459
+ */
1460
+ function createNameResolverFromCapability(capability, networkId, runtimeInstanceId, queryClient, config) {
1461
+ if (!capability) return EMPTY_RESOLVER$1;
1462
+ const resolveNameMethod = capability.resolveName;
1463
+ return {
1464
+ isValidName: (name) => capability.isValidName(name),
1465
+ resolveName: resolveNameMethod ? async (name) => {
1466
+ const normalized = name.trim().toLowerCase();
1467
+ try {
1468
+ return {
1469
+ ok: true,
1470
+ value: await queryClient.fetchQuery({
1471
+ queryKey: buildResolutionKey("name", networkId, normalized, runtimeInstanceId),
1472
+ queryFn: async () => {
1473
+ let result;
1474
+ try {
1475
+ result = await resolveNameMethod(normalized);
1476
+ } catch (cause) {
1477
+ throw new ResolutionQueryError({
1478
+ code: "ADAPTER_ERROR",
1479
+ message: cause instanceof Error ? cause.message : String(cause),
1480
+ cause
1481
+ });
1482
+ }
1483
+ if (!result.ok) throw new ResolutionQueryError(result.error);
1484
+ return result.value;
1485
+ },
1486
+ staleTime: config.staleTimeMs,
1487
+ gcTime: config.gcTimeMs,
1488
+ retry: (failureCount, error) => (error instanceof ResolutionQueryError ? isTransientError(error.resolutionError) : true) && failureCount < config.transientRetryCount
1489
+ })
1490
+ };
1491
+ } catch (error) {
1492
+ return {
1493
+ ok: false,
1494
+ error: toNameResolutionError(error)
1495
+ };
1496
+ }
1497
+ } : void 0
1498
+ };
1499
+ }
1500
+
1415
1501
  //#endregion
1416
1502
  //#region src/hooks/nameResolution/useRuntimeNameResolver.ts
1417
1503
  /**
@@ -1421,7 +1507,7 @@ function NameResolutionProvider({ children, config, queryClient }) {
1421
1507
  */
1422
1508
  const EMPTY_RESOLVER = {};
1423
1509
  /**
1424
- * Project the active runtime's `NameResolutionCapability` into the injected
1510
+ * Project a runtime's `NameResolutionCapability` into the injected
1425
1511
  * {@link NameResolver} seam consumed by `@openzeppelin/ui-components` (SF-3, D3).
1426
1512
  * Mounted ambiently by the renderer:
1427
1513
  *
@@ -1429,6 +1515,10 @@ const EMPTY_RESOLVER = {};
1429
1515
  * <NameResolverProvider {...useRuntimeNameResolver()}>{form}</NameResolverProvider>
1430
1516
  * ```
1431
1517
  *
1518
+ * Pass `scopedNetwork` to resolve against a specific network via
1519
+ * {@link RuntimeProvider}'s registry without changing {@link WalletStateProvider}'s
1520
+ * active network (e.g. address-book Add Alias dropdown).
1521
+ *
1432
1522
  * Each imperative call is backed by SF-2's **owned** resolution `QueryClient`
1433
1523
  * via `fetchQuery`, reusing SF-2's exact query-key convention
1434
1524
  * (`buildResolutionKey('name', networkId, normalizedName)`) — so a name
@@ -1437,9 +1527,10 @@ const EMPTY_RESOLVER = {};
1437
1527
  * out-of-order safety, never a parallel cache (INV-119).
1438
1528
  *
1439
1529
  * Degradation, in order (all method-omission, never a throw):
1440
- * - No `WalletStateProvider` mounted empty resolver. The context is read
1441
- * directly (not via `useWalletState()`, which throws) so the ambient
1442
- * renderer mount stays safe for wallet-less usage.
1530
+ * - No `WalletStateProvider` mounted (wallet path) or no `RuntimeProvider`
1531
+ * (network path) empty resolver. The context is read directly (not via
1532
+ * `useWalletState()`, which throws) so the ambient renderer mount stays safe
1533
+ * for wallet-less usage.
1443
1534
  * - No active runtime, or runtime without the capability → empty resolver.
1444
1535
  * - Capability without `resolveName` → `isValidName` only; forward unsupported.
1445
1536
  *
@@ -1449,61 +1540,49 @@ const EMPTY_RESOLVER = {};
1449
1540
  *
1450
1541
  * @returns A referentially stable {@link NameResolver} for the active runtime.
1451
1542
  */
1452
- function useRuntimeNameResolver() {
1543
+ function useRuntimeNameResolver(scopedNetwork) {
1453
1544
  const walletState = (0, react.useContext)(WalletStateContext);
1454
1545
  const { queryClient, config } = useNameResolutionContext();
1455
- const activeRuntime = walletState?.activeRuntime ?? null;
1546
+ const networkSource = useNetworkRuntimeSource(scopedNetwork ?? null);
1547
+ const useNetworkScoped = scopedNetwork != null;
1548
+ const activeRuntime = useNetworkScoped ? networkSource.runtime : walletState?.activeRuntime ?? null;
1456
1549
  const capability = activeRuntime?.nameResolution;
1457
- const networkId = walletState?.activeNetworkId ?? "";
1550
+ const networkId = useNetworkScoped ? networkSource.networkId : walletState?.activeNetworkId ?? "";
1458
1551
  const runtimeInstanceId = getRuntimeInstanceId(activeRuntime);
1459
1552
  return (0, react.useMemo)(() => {
1460
1553
  if (!capability) return EMPTY_RESOLVER;
1461
- const resolveNameMethod = capability.resolveName;
1462
- return {
1463
- isValidName: (name) => capability.isValidName(name),
1464
- resolveName: resolveNameMethod ? async (name) => {
1465
- const normalized = name.trim().toLowerCase();
1466
- try {
1467
- return {
1468
- ok: true,
1469
- value: await queryClient.fetchQuery({
1470
- queryKey: buildResolutionKey("name", networkId, normalized, runtimeInstanceId),
1471
- queryFn: async () => {
1472
- let result;
1473
- try {
1474
- result = await resolveNameMethod(normalized);
1475
- } catch (cause) {
1476
- throw new ResolutionQueryError({
1477
- code: "ADAPTER_ERROR",
1478
- message: cause instanceof Error ? cause.message : String(cause),
1479
- cause
1480
- });
1481
- }
1482
- if (!result.ok) throw new ResolutionQueryError(result.error);
1483
- return result.value;
1484
- },
1485
- staleTime: config.staleTimeMs,
1486
- gcTime: config.gcTimeMs,
1487
- retry: (failureCount, error) => (error instanceof ResolutionQueryError ? isTransientError(error.resolutionError) : true) && failureCount < config.transientRetryCount
1488
- })
1489
- };
1490
- } catch (error) {
1491
- return {
1492
- ok: false,
1493
- error: toNameResolutionError(error)
1494
- };
1495
- }
1496
- } : void 0
1497
- };
1554
+ return createNameResolverFromCapability(capability, networkId, runtimeInstanceId, queryClient, config);
1498
1555
  }, [
1499
1556
  capability,
1557
+ networkId,
1558
+ runtimeInstanceId,
1500
1559
  queryClient,
1501
1560
  config,
1502
- networkId,
1503
- runtimeInstanceId
1561
+ useNetworkScoped ? networkSource.isRuntimeLoading : walletState?.isRuntimeLoading ?? false
1504
1562
  ]);
1505
1563
  }
1506
1564
 
1565
+ //#endregion
1566
+ //#region src/hooks/nameResolution/useNetworkNameResolver.ts
1567
+ /**
1568
+ * @deprecated Pass the network to {@link useRuntimeNameResolver} instead.
1569
+ */
1570
+ function useNetworkNameResolver(network) {
1571
+ return useRuntimeNameResolver(network ?? void 0);
1572
+ }
1573
+
1574
+ //#endregion
1575
+ //#region src/hooks/nameResolution/useNetworkResolveAddress.ts
1576
+ /**
1577
+ * @deprecated Pass `network` in {@link UseResolveAddressOptions} to {@link useResolveAddress}.
1578
+ */
1579
+ function useNetworkResolveAddress(address, network, options) {
1580
+ return useResolveAddress(address, network != null ? {
1581
+ ...options,
1582
+ network
1583
+ } : options);
1584
+ }
1585
+
1507
1586
  //#endregion
1508
1587
  //#region src/hooks/runtime/runtimeCreationConfig.ts
1509
1588
  /** Safe default: miss-fallback OFF; no uiKit override. INV-204 */
@@ -1799,6 +1878,8 @@ exports.useDerivedConnectStatus = useDerivedConnectStatus;
1799
1878
  exports.useDerivedDisconnect = useDerivedDisconnect;
1800
1879
  exports.useDerivedSwitchChainStatus = useDerivedSwitchChainStatus;
1801
1880
  exports.useNameResolutionContext = useNameResolutionContext;
1881
+ exports.useNetworkNameResolver = useNetworkNameResolver;
1882
+ exports.useNetworkResolveAddress = useNetworkResolveAddress;
1802
1883
  exports.useResolveAddress = useResolveAddress;
1803
1884
  exports.useResolveName = useResolveName;
1804
1885
  exports.useResolveRuntime = useResolveRuntime;