@aomi-labs/react 0.3.10 → 0.3.11
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 +57 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +57 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1454,41 +1454,84 @@ function useWalletHandler({
|
|
|
1454
1454
|
}) {
|
|
1455
1455
|
const [pendingRequests, setPendingRequests] = (0, import_react8.useState)([]);
|
|
1456
1456
|
const requestsRef = (0, import_react8.useRef)(pendingRequests);
|
|
1457
|
-
const
|
|
1458
|
-
|
|
1459
|
-
|
|
1457
|
+
const inFlightRequestSetRef = (0, import_react8.useRef)(/* @__PURE__ */ new Set());
|
|
1458
|
+
const suppressedRequestSetRef = (0, import_react8.useRef)(/* @__PURE__ */ new Set());
|
|
1459
|
+
const syncVisibleRequests = (0, import_react8.useCallback)(() => {
|
|
1460
|
+
setPendingRequests(
|
|
1461
|
+
requestsRef.current.filter(
|
|
1462
|
+
(request) => !suppressedRequestSetRef.current.has(request.id)
|
|
1463
|
+
)
|
|
1464
|
+
);
|
|
1460
1465
|
}, []);
|
|
1466
|
+
const setRequests = (0, import_react8.useCallback)((requests) => {
|
|
1467
|
+
const incomingIds = new Set(requests.map((request) => request.id));
|
|
1468
|
+
for (const id of suppressedRequestSetRef.current) {
|
|
1469
|
+
if (!incomingIds.has(id) && !inFlightRequestSetRef.current.has(id)) {
|
|
1470
|
+
suppressedRequestSetRef.current.delete(id);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
const preservedInFlight = requestsRef.current.filter(
|
|
1474
|
+
(request) => inFlightRequestSetRef.current.has(request.id) && !incomingIds.has(request.id)
|
|
1475
|
+
);
|
|
1476
|
+
requestsRef.current = [...requests, ...preservedInFlight];
|
|
1477
|
+
syncVisibleRequests();
|
|
1478
|
+
}, [syncVisibleRequests]);
|
|
1479
|
+
const startRequest = (0, import_react8.useCallback)((id) => {
|
|
1480
|
+
if (!requestsRef.current.some((request) => request.id === id)) {
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
inFlightRequestSetRef.current.add(id);
|
|
1484
|
+
suppressedRequestSetRef.current.add(id);
|
|
1485
|
+
syncVisibleRequests();
|
|
1486
|
+
}, [syncVisibleRequests]);
|
|
1461
1487
|
const resolveRequest = (0, import_react8.useCallback)(
|
|
1462
|
-
(id, result) => {
|
|
1488
|
+
async (id, result) => {
|
|
1463
1489
|
const session = getSession();
|
|
1464
1490
|
if (!session) {
|
|
1465
1491
|
console.error("[wallet-handler] No session available to resolve request");
|
|
1466
1492
|
return;
|
|
1467
1493
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1494
|
+
startRequest(id);
|
|
1495
|
+
try {
|
|
1496
|
+
await session.resolve(id, result);
|
|
1497
|
+
} catch (err) {
|
|
1470
1498
|
console.error("[wallet-handler] Failed to resolve request:", err);
|
|
1471
|
-
}
|
|
1499
|
+
} finally {
|
|
1500
|
+
requestsRef.current = requestsRef.current.filter(
|
|
1501
|
+
(request) => request.id !== id
|
|
1502
|
+
);
|
|
1503
|
+
inFlightRequestSetRef.current.delete(id);
|
|
1504
|
+
syncVisibleRequests();
|
|
1505
|
+
}
|
|
1472
1506
|
},
|
|
1473
|
-
[getSession,
|
|
1507
|
+
[getSession, startRequest, syncVisibleRequests]
|
|
1474
1508
|
);
|
|
1475
1509
|
const rejectRequest = (0, import_react8.useCallback)(
|
|
1476
|
-
(id, error) => {
|
|
1510
|
+
async (id, error) => {
|
|
1477
1511
|
const session = getSession();
|
|
1478
1512
|
if (!session) {
|
|
1479
1513
|
console.error("[wallet-handler] No session available to reject request");
|
|
1480
1514
|
return;
|
|
1481
1515
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1516
|
+
startRequest(id);
|
|
1517
|
+
try {
|
|
1518
|
+
await session.reject(id, error);
|
|
1519
|
+
} catch (err) {
|
|
1484
1520
|
console.error("[wallet-handler] Failed to reject request:", err);
|
|
1485
|
-
}
|
|
1521
|
+
} finally {
|
|
1522
|
+
requestsRef.current = requestsRef.current.filter(
|
|
1523
|
+
(request) => request.id !== id
|
|
1524
|
+
);
|
|
1525
|
+
inFlightRequestSetRef.current.delete(id);
|
|
1526
|
+
syncVisibleRequests();
|
|
1527
|
+
}
|
|
1486
1528
|
},
|
|
1487
|
-
[getSession,
|
|
1529
|
+
[getSession, startRequest, syncVisibleRequests]
|
|
1488
1530
|
);
|
|
1489
1531
|
return {
|
|
1490
1532
|
pendingRequests,
|
|
1491
1533
|
setRequests,
|
|
1534
|
+
startRequest,
|
|
1492
1535
|
resolveRequest,
|
|
1493
1536
|
rejectRequest
|
|
1494
1537
|
};
|
|
@@ -1834,9 +1877,7 @@ function AomiRuntimeCore({
|
|
|
1834
1877
|
clearAllNotifications: notificationContext.clearAll,
|
|
1835
1878
|
// Wallet API
|
|
1836
1879
|
pendingWalletRequests: walletHandler.pendingRequests,
|
|
1837
|
-
startWalletRequest:
|
|
1838
|
-
},
|
|
1839
|
-
// No-op: ClientSession manages processing state
|
|
1880
|
+
startWalletRequest: walletHandler.startRequest,
|
|
1840
1881
|
resolveWalletRequest: walletHandler.resolveRequest,
|
|
1841
1882
|
rejectWalletRequest: walletHandler.rejectRequest,
|
|
1842
1883
|
// Event API
|