@formo/analytics 1.36.0 → 1.38.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/cjs/src/FormoAnalytics.d.ts +64 -0
- package/dist/cjs/src/FormoAnalytics.js +155 -5
- package/dist/cjs/src/FormoAnalyticsProvider.js +1 -0
- package/dist/cjs/src/evm/EvmEventTracker.d.ts +38 -10
- package/dist/cjs/src/evm/EvmEventTracker.js +182 -0
- package/dist/cjs/src/evm/EvmProviderRegistry.js +26 -4
- package/dist/cjs/src/evm/EvmRequestTracker.d.ts +36 -40
- package/dist/cjs/src/evm/EvmRequestTracker.js +216 -115
- package/dist/cjs/src/evm/batch.d.ts +94 -0
- package/dist/cjs/src/evm/batch.js +130 -0
- package/dist/cjs/src/provider/detection.d.ts +30 -0
- package/dist/cjs/src/provider/detection.js +62 -0
- package/dist/cjs/src/provider/index.d.ts +1 -1
- package/dist/cjs/src/provider/index.js +3 -1
- package/dist/cjs/src/types/base.d.ts +23 -0
- package/dist/cjs/src/types/provider.d.ts +16 -0
- package/dist/cjs/src/types/provider.js +17 -1
- package/dist/cjs/src/version.d.ts +1 -1
- package/dist/cjs/src/version.js +1 -1
- package/dist/cjs/src/wagmi/WagmiEventHandler.d.ts +87 -0
- package/dist/cjs/src/wagmi/WagmiEventHandler.js +536 -13
- package/dist/esm/src/FormoAnalytics.d.ts +64 -0
- package/dist/esm/src/FormoAnalytics.js +155 -5
- package/dist/esm/src/FormoAnalyticsProvider.js +1 -0
- package/dist/esm/src/evm/EvmEventTracker.d.ts +38 -10
- package/dist/esm/src/evm/EvmEventTracker.js +183 -1
- package/dist/esm/src/evm/EvmProviderRegistry.js +27 -5
- package/dist/esm/src/evm/EvmRequestTracker.d.ts +36 -40
- package/dist/esm/src/evm/EvmRequestTracker.js +215 -114
- package/dist/esm/src/evm/batch.d.ts +94 -0
- package/dist/esm/src/evm/batch.js +123 -0
- package/dist/esm/src/provider/detection.d.ts +30 -0
- package/dist/esm/src/provider/detection.js +60 -0
- package/dist/esm/src/provider/index.d.ts +1 -1
- package/dist/esm/src/provider/index.js +1 -1
- package/dist/esm/src/types/base.d.ts +23 -0
- package/dist/esm/src/types/provider.d.ts +16 -0
- package/dist/esm/src/types/provider.js +16 -0
- package/dist/esm/src/version.d.ts +1 -1
- package/dist/esm/src/version.js +1 -1
- package/dist/esm/src/wagmi/WagmiEventHandler.d.ts +87 -0
- package/dist/esm/src/wagmi/WagmiEventHandler.js +536 -13
- package/dist/index.umd.min.js +1 -1
- package/package.json +4 -3
|
@@ -58,6 +58,8 @@ exports.WagmiEventHandler = exports.MARKER_GRACE_MS = void 0;
|
|
|
58
58
|
exports.__resetSeededWallet = __resetSeededWallet;
|
|
59
59
|
var events_1 = require("../types/events");
|
|
60
60
|
var logger_1 = require("../logger");
|
|
61
|
+
var provider_1 = require("../provider");
|
|
62
|
+
var batch_1 = require("../evm/batch");
|
|
61
63
|
var utils_1 = require("./utils");
|
|
62
64
|
/**
|
|
63
65
|
* Built-in transaction fields that could collide with function args.
|
|
@@ -200,6 +202,48 @@ var ownerKey = function (writeKey, config) {
|
|
|
200
202
|
}
|
|
201
203
|
return "".concat(writeKey, ":").concat(id);
|
|
202
204
|
};
|
|
205
|
+
// User-rejection detection is shared with the EIP-1193 path (4001, the
|
|
206
|
+
// WalletConnect 5000-family, and viem's typed error): see
|
|
207
|
+
// provider/detection.ts for the dialects and why 4001 alone missed every
|
|
208
|
+
// WalletConnect rejection.
|
|
209
|
+
var isUserRejection = provider_1.isUserRejectionError;
|
|
210
|
+
/**
|
|
211
|
+
* Real wallet names behind WalletConnect connectors, resolved lazily.
|
|
212
|
+
*
|
|
213
|
+
* WalletConnect is a transport: the signing wallet (Ledger Live, MetaMask
|
|
214
|
+
* Mobile, Safe, ...) names itself in the session's peer metadata, reachable
|
|
215
|
+
* only through the connector's async `getProvider()`. Connect emission is
|
|
216
|
+
* deliberately synchronous (see the marker comments below), so the lookup
|
|
217
|
+
* can never be awaited in line - it is kicked fire-and-forget the first
|
|
218
|
+
* time a WalletConnect connector is seen, and every event after resolution
|
|
219
|
+
* carries the real wallet's name. The first connect may still say
|
|
220
|
+
* "WalletConnect"; that is the honest state at that instant.
|
|
221
|
+
*
|
|
222
|
+
* HONEST STATUS: with the new-connection invalidation below, no event the
|
|
223
|
+
* wagmi path emits TODAY observably carries the resolved name - connects
|
|
224
|
+
* fire before resolution and rebuilds suppress re-emission. The cache
|
|
225
|
+
* exists for the attribution work (wallet names on signature and
|
|
226
|
+
* transaction events), which fires mid-session, after resolution.
|
|
227
|
+
*
|
|
228
|
+
* Names are keyed by the CONNECTOR (stable across a page's sessions) so
|
|
229
|
+
* they actually serve reads; lookups are guarded per CONNECTION (wagmi
|
|
230
|
+
* replaces the connection object per session), so every new session
|
|
231
|
+
* re-resolves and OVERWRITES the name. A reconnect through the same
|
|
232
|
+
* connector to a different wallet can therefore mislabel at most the one
|
|
233
|
+
* event that fires between the new session's start and its resolution -
|
|
234
|
+
* one microtask for an initialised connector - and self-corrects. The
|
|
235
|
+
* alternative, keying names by connection, was tried and kept the name
|
|
236
|
+
* from ever surfacing: the only reader that fires per session runs before
|
|
237
|
+
* any lookup can resolve. WeakMaps, so nothing outlives its object.
|
|
238
|
+
*/
|
|
239
|
+
var walletConnectPeerNames = new WeakMap();
|
|
240
|
+
var walletConnectPeerLookups = new WeakSet();
|
|
241
|
+
/** The connection whose lookup may write the connector's name: always the
|
|
242
|
+
* newest kicked one, so a slow resolution from a PREVIOUS session cannot
|
|
243
|
+
* land after the current session's and overwrite it. */
|
|
244
|
+
var walletConnectPeerLatest = new WeakMap();
|
|
245
|
+
/** Connections whose provider already has the hybrid-capture wrapper. */
|
|
246
|
+
var wagmiWrappedConnections = new WeakSet();
|
|
203
247
|
/**
|
|
204
248
|
* Pending transactions, shared per destination rather than per handler.
|
|
205
249
|
*
|
|
@@ -209,6 +253,7 @@ var ownerKey = function (writeKey, config) {
|
|
|
209
253
|
* broadcast to match the receipt against.
|
|
210
254
|
*/
|
|
211
255
|
var pendingTransactionsByDestination = new Map();
|
|
256
|
+
var pendingBatchesByDestination = new Map();
|
|
212
257
|
/**
|
|
213
258
|
* Pending records outlive a rebuild by the same grace period as the markers.
|
|
214
259
|
* The ordinary rebuild is cleanup THEN remount, so dropping them the instant
|
|
@@ -223,6 +268,7 @@ function schedulePendingTransactionExpiry(key) {
|
|
|
223
268
|
var timer = setTimeout(function () {
|
|
224
269
|
pendingTransactionExpiry.delete(key);
|
|
225
270
|
pendingTransactionsByDestination.delete(key);
|
|
271
|
+
pendingBatchesByDestination.delete(key);
|
|
226
272
|
}, exports.MARKER_GRACE_MS);
|
|
227
273
|
(_b = (_a = timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
228
274
|
pendingTransactionExpiry.set(key, timer);
|
|
@@ -289,6 +335,7 @@ function __resetSeededWallet() {
|
|
|
289
335
|
pendingTransactionExpiry.forEach(function (t) { return clearTimeout(t); });
|
|
290
336
|
pendingTransactionExpiry.clear();
|
|
291
337
|
pendingTransactionsByDestination.clear();
|
|
338
|
+
pendingBatchesByDestination.clear();
|
|
292
339
|
announcedConnections.clear();
|
|
293
340
|
liveHandlers.clear();
|
|
294
341
|
markerExpiry.forEach(function (timer) { return clearTimeout(timer); });
|
|
@@ -501,6 +548,21 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
501
548
|
enumerable: false,
|
|
502
549
|
configurable: true
|
|
503
550
|
});
|
|
551
|
+
Object.defineProperty(WagmiEventHandler.prototype, "pendingBatches", {
|
|
552
|
+
/** Broadcast batches awaiting `callsStatus`, shared like the map above. */
|
|
553
|
+
get: function () {
|
|
554
|
+
var _a;
|
|
555
|
+
var key = (_a = this.ownerKey) !== null && _a !== void 0 ? _a : "";
|
|
556
|
+
var map = pendingBatchesByDestination.get(key);
|
|
557
|
+
if (!map) {
|
|
558
|
+
map = new Map();
|
|
559
|
+
pendingBatchesByDestination.set(key, map);
|
|
560
|
+
}
|
|
561
|
+
return map;
|
|
562
|
+
},
|
|
563
|
+
enumerable: false,
|
|
564
|
+
configurable: true
|
|
565
|
+
});
|
|
504
566
|
/**
|
|
505
567
|
* Set up listeners for wallet connection, disconnection, and chain changes
|
|
506
568
|
*/
|
|
@@ -577,6 +639,17 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
577
639
|
*/
|
|
578
640
|
WagmiEventHandler.prototype.seedFromCurrentState = function () {
|
|
579
641
|
var _a, _b;
|
|
642
|
+
// Fire-and-forget here: the seed is synchronous by design, so its own
|
|
643
|
+
// connect may carry the generic name; the status flow awaits instead.
|
|
644
|
+
// A throwing store must not break construction.
|
|
645
|
+
try {
|
|
646
|
+
var snapshot = this.getState();
|
|
647
|
+
this.kickWalletConnectPeerLookup(snapshot);
|
|
648
|
+
this.wrapActiveConnectorProvider(snapshot);
|
|
649
|
+
}
|
|
650
|
+
catch (_c) {
|
|
651
|
+
/* the seed continues; names fall back to the connector's own */
|
|
652
|
+
}
|
|
580
653
|
try {
|
|
581
654
|
var state = this.getState();
|
|
582
655
|
if (state.status !== "connected") {
|
|
@@ -829,7 +902,7 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
829
902
|
*/
|
|
830
903
|
WagmiEventHandler.prototype.handleStatusChange = function (status, prevStatus) {
|
|
831
904
|
return __awaiter(this, void 0, void 0, function () {
|
|
832
|
-
var state, address, chainId, disconnectedAddress, disconnectedChainId, walletKey, connection, connectorName, error_1, error_2;
|
|
905
|
+
var snapshot, state, address, chainId, disconnectedAddress, disconnectedChainId, walletKey, connection, connectorName, error_1, error_2;
|
|
833
906
|
var _a, _b, _c, _d;
|
|
834
907
|
return __generator(this, function (_e) {
|
|
835
908
|
switch (_e.label) {
|
|
@@ -850,6 +923,18 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
850
923
|
return [2 /*return*/];
|
|
851
924
|
}
|
|
852
925
|
this.trackingState.isProcessing = true;
|
|
926
|
+
// Start resolving the wallet behind a WalletConnect session. NEVER
|
|
927
|
+
// awaited: every path from a store signal to its emission is
|
|
928
|
+
// synchronous by design, and an await here reorders transitions (it
|
|
929
|
+
// demonstrably drops connects under rapid connect/disconnect cycles).
|
|
930
|
+
try {
|
|
931
|
+
snapshot = this.getState();
|
|
932
|
+
this.kickWalletConnectPeerLookup(snapshot);
|
|
933
|
+
this.wrapActiveConnectorProvider(snapshot);
|
|
934
|
+
}
|
|
935
|
+
catch (_f) {
|
|
936
|
+
// A throwing store must not break the status flow.
|
|
937
|
+
}
|
|
853
938
|
// A status change outranks any connection transition still in flight. A
|
|
854
939
|
// full disconnect advances no ticket of its own, so without this an older
|
|
855
940
|
// fallback continuation could resume and announce a wallet wagmi no longer
|
|
@@ -1117,6 +1202,16 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1117
1202
|
* already recorded the new address synchronously by the time this runs. The
|
|
1118
1203
|
* `lastAddress` check below is what makes the two paths mutually exclusive.
|
|
1119
1204
|
*/
|
|
1205
|
+
WagmiEventHandler.prototype.handleActiveAddressChangeEntryKick = function () {
|
|
1206
|
+
// An account switch replaces the connection object; kick a lookup for
|
|
1207
|
+
// the new one so events that follow can name the wallet.
|
|
1208
|
+
try {
|
|
1209
|
+
this.kickWalletConnectPeerLookup(this.getState());
|
|
1210
|
+
}
|
|
1211
|
+
catch (_a) {
|
|
1212
|
+
/* a throwing store must not break the flow */
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1120
1215
|
WagmiEventHandler.prototype.handleActiveAddressChange = function (address, prevAddress) {
|
|
1121
1216
|
return __awaiter(this, void 0, void 0, function () {
|
|
1122
1217
|
var state, trackedConnectionId, trackedConnectionGone, connectionChanged, liveChain, generation, chainId, stillConnected, goneChainId, error_3, liveNow, stillCurrent, walletKey, connection, alreadyAnnounced, connectorName, error_4;
|
|
@@ -1124,6 +1219,7 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1124
1219
|
return __generator(this, function (_g) {
|
|
1125
1220
|
switch (_g.label) {
|
|
1126
1221
|
case 0:
|
|
1222
|
+
this.handleActiveAddressChangeEntryKick();
|
|
1127
1223
|
state = this.getState();
|
|
1128
1224
|
if (state.status !== "connected")
|
|
1129
1225
|
return [2 /*return*/];
|
|
@@ -1453,8 +1549,23 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1453
1549
|
return;
|
|
1454
1550
|
}
|
|
1455
1551
|
var queryType = queryKey[0];
|
|
1456
|
-
// Only
|
|
1457
|
-
|
|
1552
|
+
// Only the two query families that settle something we broadcast:
|
|
1553
|
+
// waitForTransactionReceipt for single transactions, callsStatus for
|
|
1554
|
+
// EIP-5792 batches (both useCallsStatus and useWaitForCallsStatus share
|
|
1555
|
+
// the 'callsStatus' key, in wagmi 2 and 3 alike).
|
|
1556
|
+
if (queryType !== "waitForTransactionReceipt" && queryType !== "callsStatus") {
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
// Batch settlement dedupes on the pending-batch registry, NOT on
|
|
1560
|
+
// processedQueries: settling deletes the registration, so a duplicate
|
|
1561
|
+
// delivery finds nothing to do. A processed-key here would be worse
|
|
1562
|
+
// than redundant - the status query can complete BEFORE the sendCalls
|
|
1563
|
+
// mutation registers the batch (TanStack dispatches a mutation's
|
|
1564
|
+
// success state after its onSuccess callbacks, and apps await the
|
|
1565
|
+
// status inside onSuccess), and a key recorded on that early skip
|
|
1566
|
+
// would block every refetch from ever settling the batch.
|
|
1567
|
+
if (queryType === "callsStatus") {
|
|
1568
|
+
this.handleCallsStatusQuery(query);
|
|
1458
1569
|
return;
|
|
1459
1570
|
}
|
|
1460
1571
|
var state = query.state;
|
|
@@ -1487,6 +1598,109 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1487
1598
|
// Clean up old processed queries to prevent memory leaks
|
|
1488
1599
|
cleanupOldEntries(this.processedQueries);
|
|
1489
1600
|
};
|
|
1601
|
+
/**
|
|
1602
|
+
* Settle a just-registered batch from a status query that already ran.
|
|
1603
|
+
*
|
|
1604
|
+
* Best-effort by design: the minimal QueryClient interface the SDK
|
|
1605
|
+
* accepts is not guaranteed to expose cache lookup, and a missing
|
|
1606
|
+
* `getAll` just means settlement waits for the next query event, which
|
|
1607
|
+
* is where it normally comes from anyway.
|
|
1608
|
+
*/
|
|
1609
|
+
WagmiEventHandler.prototype.settleFromCachedCallsStatus = function (batchId) {
|
|
1610
|
+
var _a, _b, _c;
|
|
1611
|
+
try {
|
|
1612
|
+
var cache = (_a = this.queryClient) === null || _a === void 0 ? void 0 : _a.getQueryCache();
|
|
1613
|
+
var queries = (_b = cache === null || cache === void 0 ? void 0 : cache.getAll) === null || _b === void 0 ? void 0 : _b.call(cache);
|
|
1614
|
+
if (!Array.isArray(queries))
|
|
1615
|
+
return;
|
|
1616
|
+
for (var _i = 0, queries_1 = queries; _i < queries_1.length; _i++) {
|
|
1617
|
+
var query = queries_1[_i];
|
|
1618
|
+
var key = query === null || query === void 0 ? void 0 : query.queryKey;
|
|
1619
|
+
if (Array.isArray(key) &&
|
|
1620
|
+
key[0] === "callsStatus" &&
|
|
1621
|
+
((_c = key[1]) === null || _c === void 0 ? void 0 : _c.id) === batchId) {
|
|
1622
|
+
this.handleCallsStatusQuery(query);
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
catch (error) {
|
|
1627
|
+
logger_1.logger.debug("WagmiEventHandler: cached callsStatus scan failed", error);
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
/**
|
|
1631
|
+
* Settle an EIP-5792 batch from a `callsStatus` query.
|
|
1632
|
+
*
|
|
1633
|
+
* Only batches whose broadcast this SDK observed are settled: the batch id
|
|
1634
|
+
* must be in `pendingBatches`, for the same reason receipt queries are
|
|
1635
|
+
* gated on an observed hash - queries are visible to any code sharing the
|
|
1636
|
+
* QueryClient, and emitting for an id we never saw broadcast would let a
|
|
1637
|
+
* forged query invent transactions.
|
|
1638
|
+
*
|
|
1639
|
+
* Outcome semantics are shared with the EIP-1193 path (`src/evm/batch.ts`):
|
|
1640
|
+
* per-call receipts outrank the batch verdict, an atomic batch's single
|
|
1641
|
+
* receipt reaches every call, and a 600 leaves receipt-less calls
|
|
1642
|
+
* unsettled rather than guessed.
|
|
1643
|
+
*/
|
|
1644
|
+
WagmiEventHandler.prototype.handleCallsStatusQuery = function (query) {
|
|
1645
|
+
var _this = this;
|
|
1646
|
+
var _a;
|
|
1647
|
+
if (!this.formo.isAutocaptureEnabled("transaction")) {
|
|
1648
|
+
return;
|
|
1649
|
+
}
|
|
1650
|
+
var queryKey = query.queryKey;
|
|
1651
|
+
// Query key format: ['callsStatus', { id, ... }]
|
|
1652
|
+
var params = queryKey[1];
|
|
1653
|
+
var batchId = params === null || params === void 0 ? void 0 : params.id;
|
|
1654
|
+
if (!batchId) {
|
|
1655
|
+
return;
|
|
1656
|
+
}
|
|
1657
|
+
var pending = this.pendingBatches.get(batchId);
|
|
1658
|
+
if (!pending) {
|
|
1659
|
+
logger_1.logger.debug("WagmiEventHandler: unobserved batch", { batchId: batchId });
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
var state = query.state;
|
|
1663
|
+
if (state.status !== "success" || !state.data) {
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
try {
|
|
1667
|
+
var res_1 = state.data;
|
|
1668
|
+
var code_1 = (0, batch_1.readBatchStatusCode)(res_1);
|
|
1669
|
+
// Below 200 the batch is still pending; the query will update again.
|
|
1670
|
+
if (code_1 === undefined || code_1 < 200) {
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
logger_1.logger.debug("WagmiEventHandler: batch settled", { batchId: batchId, code: code_1 });
|
|
1674
|
+
// An explicit mutation chain is authoritative. Otherwise prefer the
|
|
1675
|
+
// chain the settlement result names - EIP-5792 v2 reports where the
|
|
1676
|
+
// batch actually landed - over one inferred from the connection at
|
|
1677
|
+
// broadcast, which goes stale if the wallet moves chains while the
|
|
1678
|
+
// prompt is up. Same precedence as the single-transaction receipt
|
|
1679
|
+
// path.
|
|
1680
|
+
var settledChainId_1 = pending.chainIdWasExplicit
|
|
1681
|
+
? pending.chainId
|
|
1682
|
+
: (_a = (0, batch_1.readBatchChainId)(res_1)) !== null && _a !== void 0 ? _a : pending.chainId;
|
|
1683
|
+
pending.calls.forEach(function (call, index) {
|
|
1684
|
+
var receipt = (0, batch_1.batchReceiptForCall)(res_1, index, pending.calls.length);
|
|
1685
|
+
var outcome = (0, batch_1.batchCallOutcome)(code_1, receipt);
|
|
1686
|
+
// 600 means SOME calls reverted, so a call with no receipt of its
|
|
1687
|
+
// own has not been decided. Reporting it either way would invent a
|
|
1688
|
+
// result; leaving it unsettled is the honest answer.
|
|
1689
|
+
if (outcome === undefined)
|
|
1690
|
+
return;
|
|
1691
|
+
_this.formo.transaction(__assign(__assign(__assign(__assign({ status: outcome, chainId: settledChainId_1 || 0, address: pending.address }, (call.data && { data: call.data })), (call.to && { to: call.to })), (call.value && { value: call.value })), ((receipt === null || receipt === void 0 ? void 0 : receipt.transactionHash)
|
|
1692
|
+
? { transactionHash: receipt.transactionHash }
|
|
1693
|
+
: {})), __assign({ batch_size: pending.calls.length, batch_index: index, batch_id: batchId }, (pending.providerName
|
|
1694
|
+
? { providerName: pending.providerName }
|
|
1695
|
+
: {})));
|
|
1696
|
+
});
|
|
1697
|
+
// Settled; a later refetch of the same query must not re-emit.
|
|
1698
|
+
this.pendingBatches.delete(batchId);
|
|
1699
|
+
}
|
|
1700
|
+
catch (error) {
|
|
1701
|
+
logger_1.logger.error("WagmiEventHandler: callsStatus error:", error);
|
|
1702
|
+
}
|
|
1703
|
+
};
|
|
1490
1704
|
/**
|
|
1491
1705
|
* Handle waitForTransactionReceipt query completion
|
|
1492
1706
|
* Emits CONFIRMED or REVERTED transaction status
|
|
@@ -1561,9 +1775,9 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1561
1775
|
chainId: chainId,
|
|
1562
1776
|
blockNumber: (_b = receipt === null || receipt === void 0 ? void 0 : receipt.blockNumber) === null || _b === void 0 ? void 0 : _b.toString(),
|
|
1563
1777
|
});
|
|
1564
|
-
this.formo.transaction(__assign(__assign(__assign(__assign(__assign({ status: txStatus, chainId: chainId || 0, address: address, transactionHash: transactionHash }, ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.data) && { data: pendingTx.data })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.to) && { to: pendingTx.to })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.value) && { value: pendingTx.value })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.function_name) && { function_name: pendingTx.function_name })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.function_args) && { function_args: pendingTx.function_args })),
|
|
1565
|
-
|
|
1566
|
-
|
|
1778
|
+
this.formo.transaction(__assign(__assign(__assign(__assign(__assign({ status: txStatus, chainId: chainId || 0, address: address, transactionHash: transactionHash }, ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.data) && { data: pendingTx.data })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.to) && { to: pendingTx.to })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.value) && { value: pendingTx.value })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.function_name) && { function_name: pendingTx.function_name })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.function_args) && { function_args: pendingTx.function_args })), __assign(__assign({}, ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.providerName)
|
|
1779
|
+
? { providerName: pendingTx.providerName }
|
|
1780
|
+
: this.mutationAttribution())), pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.safeFunctionArgs));
|
|
1567
1781
|
// Clean up the pending transaction after confirmation
|
|
1568
1782
|
this.pendingTransactions.delete(normalizedHash);
|
|
1569
1783
|
}
|
|
@@ -1616,12 +1830,89 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1616
1830
|
if (mutationType === "sendTransaction" || mutationType === "writeContract") {
|
|
1617
1831
|
this.handleTransactionMutation(mutationType, mutation);
|
|
1618
1832
|
}
|
|
1833
|
+
// Handle EIP-5792 batch mutations (useSendCalls). Absent this branch,
|
|
1834
|
+
// wagmi-mode apps captured nothing for a batch: the EIP-1193 request
|
|
1835
|
+
// wrapper that handles `wallet_sendCalls` is never installed in wagmi
|
|
1836
|
+
// mode, so the mutation was the only place the batch was visible at all.
|
|
1837
|
+
if (mutationType === "sendCalls") {
|
|
1838
|
+
this.handleSendCallsMutation(mutation);
|
|
1839
|
+
}
|
|
1619
1840
|
// Clean up old processed mutations to prevent memory leaks
|
|
1620
1841
|
cleanupOldEntries(this.processedMutations);
|
|
1621
1842
|
};
|
|
1622
1843
|
/**
|
|
1623
1844
|
* Handle signature mutations (signMessage, signTypedData)
|
|
1624
1845
|
*/
|
|
1846
|
+
/**
|
|
1847
|
+
* Is a PENDING wagmi mutation already covering this wallet request?
|
|
1848
|
+
*
|
|
1849
|
+
* The hybrid-capture dedup. TanStack dispatches `pending` BEFORE the
|
|
1850
|
+
* mutationFn issues the wallet call (verified against query-core), so a
|
|
1851
|
+
* hook-driven request always finds its mutation here and the request
|
|
1852
|
+
* wrapper stands down; an imperative viem call never does, and the
|
|
1853
|
+
* wrapper captures it. Matching is by mutation type, refined with cheap
|
|
1854
|
+
* parameter checks where the shapes allow, and errs toward NOT skipping:
|
|
1855
|
+
* a duplicate is visible and diagnosable, a silent loss is neither.
|
|
1856
|
+
*/
|
|
1857
|
+
WagmiEventHandler.prototype.hasMatchingPendingMutation = function (method, params) {
|
|
1858
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1859
|
+
try {
|
|
1860
|
+
var cache = (_a = this.queryClient) === null || _a === void 0 ? void 0 : _a.getMutationCache();
|
|
1861
|
+
var mutations = (_b = cache === null || cache === void 0 ? void 0 : cache.getAll) === null || _b === void 0 ? void 0 : _b.call(cache);
|
|
1862
|
+
if (!Array.isArray(mutations))
|
|
1863
|
+
return false;
|
|
1864
|
+
var wanted = {
|
|
1865
|
+
personal_sign: ["signMessage"],
|
|
1866
|
+
eth_signTypedData_v4: ["signTypedData"],
|
|
1867
|
+
eth_sendTransaction: ["sendTransaction", "writeContract"],
|
|
1868
|
+
wallet_sendCalls: ["sendCalls"],
|
|
1869
|
+
};
|
|
1870
|
+
var types = wanted[method];
|
|
1871
|
+
if (!types)
|
|
1872
|
+
return false;
|
|
1873
|
+
for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
|
|
1874
|
+
var mutation = mutations_1[_i];
|
|
1875
|
+
if (((_c = mutation === null || mutation === void 0 ? void 0 : mutation.state) === null || _c === void 0 ? void 0 : _c.status) !== "pending")
|
|
1876
|
+
continue;
|
|
1877
|
+
var key = (_e = (_d = mutation === null || mutation === void 0 ? void 0 : mutation.options) === null || _d === void 0 ? void 0 : _d.mutationKey) === null || _e === void 0 ? void 0 : _e[0];
|
|
1878
|
+
if (typeof key !== "string" || !types.includes(key))
|
|
1879
|
+
continue;
|
|
1880
|
+
// Cheap refinements. On mismatch keep scanning; on no basis to
|
|
1881
|
+
// compare, treat the type-level match as decisive.
|
|
1882
|
+
var variables = (_f = mutation.state) === null || _f === void 0 ? void 0 : _f.variables;
|
|
1883
|
+
if (key === "sendTransaction" && variables) {
|
|
1884
|
+
var req = (Array.isArray(params) ? params[0] : undefined);
|
|
1885
|
+
var mutTo = variables.to;
|
|
1886
|
+
if (typeof (req === null || req === void 0 ? void 0 : req.to) === "string" &&
|
|
1887
|
+
typeof mutTo === "string" &&
|
|
1888
|
+
req.to.toLowerCase() !== mutTo.toLowerCase()) {
|
|
1889
|
+
continue;
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
return true;
|
|
1893
|
+
}
|
|
1894
|
+
return false;
|
|
1895
|
+
}
|
|
1896
|
+
catch (_g) {
|
|
1897
|
+
return false;
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
/**
|
|
1901
|
+
* Wallet attribution for mutation- and query-derived events.
|
|
1902
|
+
*
|
|
1903
|
+
* Mid-session events (signatures, transactions) fire after the peer
|
|
1904
|
+
* lookup has resolved, so a WalletConnect connector names its actual
|
|
1905
|
+
* signer here - the first observable consumer of the peer cache.
|
|
1906
|
+
*/
|
|
1907
|
+
WagmiEventHandler.prototype.mutationAttribution = function () {
|
|
1908
|
+
try {
|
|
1909
|
+
var name_1 = this.getConnectorName(this.getState());
|
|
1910
|
+
return name_1 ? { providerName: name_1 } : undefined;
|
|
1911
|
+
}
|
|
1912
|
+
catch (_a) {
|
|
1913
|
+
return undefined;
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1625
1916
|
WagmiEventHandler.prototype.handleSignatureMutation = function (mutationType, mutation) {
|
|
1626
1917
|
var _a, _b, _c, _d;
|
|
1627
1918
|
if (!this.formo.isAutocaptureEnabled("signature")) {
|
|
@@ -1682,7 +1973,7 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1682
1973
|
chainId: chainId,
|
|
1683
1974
|
address: address,
|
|
1684
1975
|
message: message,
|
|
1685
|
-
});
|
|
1976
|
+
}, this.mutationAttribution());
|
|
1686
1977
|
}
|
|
1687
1978
|
catch (error) {
|
|
1688
1979
|
logger_1.logger.error("WagmiEventHandler: Error handling signature mutation:", error);
|
|
@@ -1692,7 +1983,7 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1692
1983
|
* Handle transaction mutations (sendTransaction, writeContract)
|
|
1693
1984
|
*/
|
|
1694
1985
|
WagmiEventHandler.prototype.handleTransactionMutation = function (mutationType, mutation) {
|
|
1695
|
-
var _a;
|
|
1986
|
+
var _a, _b;
|
|
1696
1987
|
if (!this.formo.isAutocaptureEnabled("transaction")) {
|
|
1697
1988
|
return;
|
|
1698
1989
|
}
|
|
@@ -1783,7 +2074,7 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1783
2074
|
// Include the sender address to handle wallet switches between broadcast and confirmation
|
|
1784
2075
|
if (status_2 === events_1.TransactionStatus.BROADCASTED && transactionHash) {
|
|
1785
2076
|
var normalizedHash = transactionHash.toLowerCase();
|
|
1786
|
-
var txDetails = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ address: userAddress }, (chainId !== undefined && { chainId: chainId })), { chainIdWasExplicit: explicitChainId !== undefined }), (data && { data: data })), (to && { to: to })), (value && { value: value })), (function_name && { function_name: function_name })), (function_args && { function_args: function_args })), (safeFunctionArgs && { safeFunctionArgs: safeFunctionArgs }));
|
|
2077
|
+
var txDetails = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ address: userAddress }, ((_b = this.mutationAttribution()) !== null && _b !== void 0 ? _b : {})), (chainId !== undefined && { chainId: chainId })), { chainIdWasExplicit: explicitChainId !== undefined }), (data && { data: data })), (to && { to: to })), (value && { value: value })), (function_name && { function_name: function_name })), (function_args && { function_args: function_args })), (safeFunctionArgs && { safeFunctionArgs: safeFunctionArgs }));
|
|
1787
2078
|
this.pendingTransactions.set(normalizedHash, txDetails);
|
|
1788
2079
|
logger_1.logger.debug("WagmiEventHandler: Stored pending transaction for confirmation", {
|
|
1789
2080
|
transactionHash: normalizedHash,
|
|
@@ -1797,14 +2088,99 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1797
2088
|
}
|
|
1798
2089
|
}
|
|
1799
2090
|
}
|
|
1800
|
-
this.formo.transaction(__assign(__assign(__assign(__assign(__assign(__assign({ status: status_2, chainId: chainId || 0, address: userAddress }, (data && { data: data })), (to && { to: to })), (value && { value: value })), (transactionHash && { transactionHash: transactionHash })), (function_name && { function_name: function_name })), (function_args && { function_args: function_args })),
|
|
1801
|
-
// Spread function args as additional properties (only colliding keys are prefixed)
|
|
1802
|
-
safeFunctionArgs);
|
|
2091
|
+
this.formo.transaction(__assign(__assign(__assign(__assign(__assign(__assign({ status: status_2, chainId: chainId || 0, address: userAddress }, (data && { data: data })), (to && { to: to })), (value && { value: value })), (transactionHash && { transactionHash: transactionHash })), (function_name && { function_name: function_name })), (function_args && { function_args: function_args })), __assign(__assign({}, this.mutationAttribution()), safeFunctionArgs));
|
|
1803
2092
|
}
|
|
1804
2093
|
catch (error) {
|
|
1805
2094
|
logger_1.logger.error("WagmiEventHandler: Error handling transaction mutation:", error);
|
|
1806
2095
|
}
|
|
1807
2096
|
};
|
|
2097
|
+
/**
|
|
2098
|
+
* One `transaction` event per call in an EIP-5792 batch, wagmi path.
|
|
2099
|
+
*
|
|
2100
|
+
* Mirrors `EvmRequestTracker.trackBatchedCalls` exactly: the CALL is the
|
|
2101
|
+
* unit of attribution, so each call gets its own STARTED at pending and
|
|
2102
|
+
* BROADCASTED (with `batch_id`) when the wallet returns an id. The batch's
|
|
2103
|
+
* on-chain outcome arrives through the `callsStatus` query, handled in
|
|
2104
|
+
* `handleCallsStatusQuery`.
|
|
2105
|
+
*
|
|
2106
|
+
* Rejection matches the 1193 path's rule: only a user rejection (4001
|
|
2107
|
+
* anywhere in the error chain) marks the calls rejected - one dismissal
|
|
2108
|
+
* dismisses the whole prompt, so every call in it is rejected, and
|
|
2109
|
+
* reporting only the first would undercount. Any other error (a wallet
|
|
2110
|
+
* without EIP-5792 support, a transport failure) emits nothing further:
|
|
2111
|
+
* inventing a rejection the user never made would be worse.
|
|
2112
|
+
*/
|
|
2113
|
+
WagmiEventHandler.prototype.handleSendCallsMutation = function (mutation) {
|
|
2114
|
+
var _this = this;
|
|
2115
|
+
if (!this.formo.isAutocaptureEnabled("transaction")) {
|
|
2116
|
+
return;
|
|
2117
|
+
}
|
|
2118
|
+
var state = mutation.state;
|
|
2119
|
+
var variables = state.variables || {};
|
|
2120
|
+
var rawCalls = Array.isArray(variables.calls) ? variables.calls : [];
|
|
2121
|
+
if (rawCalls.length === 0) {
|
|
2122
|
+
return;
|
|
2123
|
+
}
|
|
2124
|
+
// Same resolution order as single transactions: an explicit per-call
|
|
2125
|
+
// value beats the tracked connection.
|
|
2126
|
+
var explicitChainId = normalizeChainId(variables.chainId);
|
|
2127
|
+
var chainId = explicitChainId !== null && explicitChainId !== void 0 ? explicitChainId : this.trackingState.lastChainId;
|
|
2128
|
+
var accountAddress = resolveAccountAddress(variables.account);
|
|
2129
|
+
var userAddress = accountAddress || this.trackingState.lastAddress;
|
|
2130
|
+
if (!userAddress) {
|
|
2131
|
+
logger_1.logger.warn("WagmiEventHandler: sendCalls without address");
|
|
2132
|
+
return;
|
|
2133
|
+
}
|
|
2134
|
+
try {
|
|
2135
|
+
var calls_1 = rawCalls.map(function (call) { return ({
|
|
2136
|
+
to: call === null || call === void 0 ? void 0 : call.to,
|
|
2137
|
+
value: (call === null || call === void 0 ? void 0 : call.value) !== undefined ? String(call.value) : undefined,
|
|
2138
|
+
data: call === null || call === void 0 ? void 0 : call.data,
|
|
2139
|
+
}); });
|
|
2140
|
+
var attribution_1 = this.mutationAttribution();
|
|
2141
|
+
var emitAll = function (status, extra) {
|
|
2142
|
+
calls_1.forEach(function (call, index) {
|
|
2143
|
+
_this.formo.transaction(__assign(__assign(__assign({ status: status, chainId: chainId || 0, address: userAddress }, (call.data && { data: call.data })), (call.to && { to: call.to })), (call.value && { value: call.value })), __assign(__assign({ batch_size: calls_1.length, batch_index: index }, attribution_1), extra));
|
|
2144
|
+
});
|
|
2145
|
+
};
|
|
2146
|
+
if (state.status === "pending") {
|
|
2147
|
+
// STARTED carries no batch id, exactly as a single transaction has
|
|
2148
|
+
// no hash yet: the wallet has not issued one.
|
|
2149
|
+
logger_1.logger.debug("WagmiEventHandler: sendCalls start", { calls: calls_1.length });
|
|
2150
|
+
emitAll(events_1.TransactionStatus.STARTED);
|
|
2151
|
+
}
|
|
2152
|
+
else if (state.status === "success") {
|
|
2153
|
+
var batchId = (0, batch_1.readBatchId)(state.data);
|
|
2154
|
+
logger_1.logger.debug("WagmiEventHandler: sendCalls broadcast", { batchId: batchId });
|
|
2155
|
+
emitAll(events_1.TransactionStatus.BROADCASTED, batchId ? { batch_id: batchId } : undefined);
|
|
2156
|
+
if (batchId) {
|
|
2157
|
+
this.pendingBatches.set(batchId, __assign(__assign(__assign({ address: userAddress }, (attribution_1 !== null && attribution_1 !== void 0 ? attribution_1 : {})), (chainId !== undefined && { chainId: chainId })), { chainIdWasExplicit: explicitChainId !== undefined, calls: calls_1 }));
|
|
2158
|
+
// Same bound as pendingTransactions, same reason.
|
|
2159
|
+
if (this.pendingBatches.size > 100) {
|
|
2160
|
+
var keys = Array.from(this.pendingBatches.keys());
|
|
2161
|
+
for (var i = 0; i < 50 && i < keys.length; i++) {
|
|
2162
|
+
this.pendingBatches.delete(keys[i]);
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
// The status query can have completed BEFORE this registration:
|
|
2166
|
+
// TanStack dispatches a mutation's success state after its
|
|
2167
|
+
// onSuccess callbacks, and apps await waitForCallsStatus inside
|
|
2168
|
+
// onSuccess. That early query event found no registration and did
|
|
2169
|
+
// nothing, so look for its settled result in the cache now.
|
|
2170
|
+
this.settleFromCachedCallsStatus(batchId);
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
else if (state.status === "error") {
|
|
2174
|
+
if (isUserRejection(state.error)) {
|
|
2175
|
+
logger_1.logger.debug("WagmiEventHandler: sendCalls rejected");
|
|
2176
|
+
emitAll(events_1.TransactionStatus.REJECTED);
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
catch (error) {
|
|
2181
|
+
logger_1.logger.error("WagmiEventHandler: sendCalls error:", error);
|
|
2182
|
+
}
|
|
2183
|
+
};
|
|
1808
2184
|
/**
|
|
1809
2185
|
* Get the current Wagmi state
|
|
1810
2186
|
* Supports both getState() method and direct state property access
|
|
@@ -1882,7 +2258,154 @@ var WagmiEventHandler = /** @class */ (function () {
|
|
|
1882
2258
|
return undefined;
|
|
1883
2259
|
}
|
|
1884
2260
|
var connection = state.connections.get(state.current);
|
|
1885
|
-
|
|
2261
|
+
var connector = connection === null || connection === void 0 ? void 0 : connection.connector;
|
|
2262
|
+
if (!connection || !connector) {
|
|
2263
|
+
return undefined;
|
|
2264
|
+
}
|
|
2265
|
+
var cached = walletConnectPeerNames.get(connector);
|
|
2266
|
+
if (cached) {
|
|
2267
|
+
return cached;
|
|
2268
|
+
}
|
|
2269
|
+
// Backstop kick; the flow entry points kick earlier so the lookup has
|
|
2270
|
+
// usually resolved by the time an emission reads the name.
|
|
2271
|
+
this.kickWalletConnectPeerLookup(state);
|
|
2272
|
+
return connector.name;
|
|
2273
|
+
};
|
|
2274
|
+
/**
|
|
2275
|
+
* Start resolving the wallet behind a WalletConnect connection.
|
|
2276
|
+
*
|
|
2277
|
+
* Fire-and-forget on purpose: emission paths are synchronous by design
|
|
2278
|
+
* and must never wait (see the connect marker comment). Called at the
|
|
2279
|
+
* START of the status/address flows rather than only at read time - the
|
|
2280
|
+
* lookup is one microtask for an initialised connector, and the emission
|
|
2281
|
+
* sits behind several awaits, so kicking early usually means even the
|
|
2282
|
+
* FIRST connect names the real wallet. When the race is lost the event
|
|
2283
|
+
* honestly says "WalletConnect" and every later event names the peer.
|
|
2284
|
+
*/
|
|
2285
|
+
/**
|
|
2286
|
+
* Install the request wrapper on the active connector's provider.
|
|
2287
|
+
*
|
|
2288
|
+
* This is what lets wagmi mode capture IMPERATIVE viem calls
|
|
2289
|
+
* (walletClient.sendTransaction / .signMessage / .writeContract / raw
|
|
2290
|
+
* request), which create no mutation and were silently lost. Hook-driven
|
|
2291
|
+
* calls stay owned by the mutation handlers via the pending-mutation
|
|
2292
|
+
* dedup. Fire-and-forget per connection; a provider that cannot be
|
|
2293
|
+
* produced simply keeps mutation-only capture.
|
|
2294
|
+
*/
|
|
2295
|
+
WagmiEventHandler.prototype.wrapActiveConnectorProvider = function (state) {
|
|
2296
|
+
var _this = this;
|
|
2297
|
+
var _a, _b;
|
|
2298
|
+
// OPT-IN only. Wagmi mode's baseline never touches the signing
|
|
2299
|
+
// transport; instrumenting the provider is an explicit integrator
|
|
2300
|
+
// decision (options.wagmi.eip1193Fallback), made auditable in
|
|
2301
|
+
// configuration rather than implied by a version bump.
|
|
2302
|
+
var optedIn = ((_b = (_a = this.formo.options) === null || _a === void 0 ? void 0 : _a.wagmi) === null || _b === void 0 ? void 0 : _b.eip1193Fallback) === true;
|
|
2303
|
+
if (!optedIn) {
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
var connection = state.current
|
|
2307
|
+
? state.connections.get(state.current)
|
|
2308
|
+
: undefined;
|
|
2309
|
+
var connector = connection === null || connection === void 0 ? void 0 : connection.connector;
|
|
2310
|
+
if (!connection ||
|
|
2311
|
+
typeof (connector === null || connector === void 0 ? void 0 : connector.getProvider) !== "function" ||
|
|
2312
|
+
wagmiWrappedConnections.has(connection)) {
|
|
2313
|
+
return;
|
|
2314
|
+
}
|
|
2315
|
+
wagmiWrappedConnections.add(connection);
|
|
2316
|
+
connector
|
|
2317
|
+
.getProvider()
|
|
2318
|
+
.then(function (provider) {
|
|
2319
|
+
var _a, _b;
|
|
2320
|
+
(_b = (_a = _this.formo)._wrapWagmiProvider) === null || _b === void 0 ? void 0 : _b.call(_a, provider);
|
|
2321
|
+
})
|
|
2322
|
+
.catch(function () {
|
|
2323
|
+
// Mutation-only capture remains; retry on the next connection.
|
|
2324
|
+
wagmiWrappedConnections.delete(connection);
|
|
2325
|
+
});
|
|
2326
|
+
};
|
|
2327
|
+
WagmiEventHandler.prototype.kickWalletConnectPeerLookup = function (state) {
|
|
2328
|
+
var _a, _b;
|
|
2329
|
+
var connection = state.current
|
|
2330
|
+
? state.connections.get(state.current)
|
|
2331
|
+
: undefined;
|
|
2332
|
+
var connector = connection === null || connection === void 0 ? void 0 : connection.connector;
|
|
2333
|
+
if (!connection ||
|
|
2334
|
+
!connector ||
|
|
2335
|
+
typeof connector.name !== "string" ||
|
|
2336
|
+
!/walletconnect/i.test(connector.name) ||
|
|
2337
|
+
typeof connector.getProvider !== "function" ||
|
|
2338
|
+
walletConnectPeerLookups.has(connection)) {
|
|
2339
|
+
return;
|
|
2340
|
+
}
|
|
2341
|
+
walletConnectPeerLookups.add(connection);
|
|
2342
|
+
// A NEW connection invalidates the cached name SYNCHRONOUSLY. The
|
|
2343
|
+
// connect flow reads the cache in the same tick it kicks the lookup,
|
|
2344
|
+
// so retaining the previous session's name here deterministically
|
|
2345
|
+
// attributed a reconnect-to-a-different-wallet to the OLD wallet.
|
|
2346
|
+
// Wrong is worse than generic: the new session's connect now says
|
|
2347
|
+
// "WalletConnect" and the resolved peer serves the session's LATER
|
|
2348
|
+
// events (signatures, transactions - the attribution work) instead.
|
|
2349
|
+
// A rebuild over the SAME connection does not re-kick (guard above),
|
|
2350
|
+
// so it keeps its already-proven name.
|
|
2351
|
+
if (walletConnectPeerLatest.get(connector) !== connection) {
|
|
2352
|
+
walletConnectPeerNames.delete(connector);
|
|
2353
|
+
}
|
|
2354
|
+
walletConnectPeerLatest.set(connector, connection);
|
|
2355
|
+
var settled = false;
|
|
2356
|
+
// A cached name from a PREVIOUS session is unproven for this one. It
|
|
2357
|
+
// keeps serving only until this session's lookup settles or the grace
|
|
2358
|
+
// timer fires - whichever ends the uncertainty first - so a hung
|
|
2359
|
+
// lookup cannot leave the old wallet's name attached indefinitely.
|
|
2360
|
+
var staleTimer = setTimeout(function () {
|
|
2361
|
+
if (!settled &&
|
|
2362
|
+
walletConnectPeerLatest.get(connector) === connection) {
|
|
2363
|
+
walletConnectPeerNames.delete(connector);
|
|
2364
|
+
}
|
|
2365
|
+
}, 3000);
|
|
2366
|
+
(_b = (_a = staleTimer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
2367
|
+
connector
|
|
2368
|
+
.getProvider()
|
|
2369
|
+
.then(function (provider) {
|
|
2370
|
+
settled = true;
|
|
2371
|
+
clearTimeout(staleTimer);
|
|
2372
|
+
// Only the NEWEST session's lookup may write. A previous session's
|
|
2373
|
+
// slow resolution landing late would otherwise overwrite the
|
|
2374
|
+
// current wallet's name with the old one.
|
|
2375
|
+
if (walletConnectPeerLatest.get(connector) !== connection) {
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
var peer = (0, provider_1.readWalletConnectPeer)(provider);
|
|
2379
|
+
if (peer === null || peer === void 0 ? void 0 : peer.name) {
|
|
2380
|
+
walletConnectPeerNames.set(connector, peer.name);
|
|
2381
|
+
logger_1.logger.debug("WagmiEventHandler: WalletConnect peer resolved", {
|
|
2382
|
+
peer: peer.name,
|
|
2383
|
+
});
|
|
2384
|
+
}
|
|
2385
|
+
else {
|
|
2386
|
+
// Resolved WITHOUT peer metadata: the previous wallet's name is
|
|
2387
|
+
// disproven for this session, not merely unproven. Drop it, and
|
|
2388
|
+
// let a later event retry the lookup - the session may simply
|
|
2389
|
+
// not have populated its peer yet.
|
|
2390
|
+
walletConnectPeerNames.delete(connector);
|
|
2391
|
+
walletConnectPeerLookups.delete(connection);
|
|
2392
|
+
}
|
|
2393
|
+
})
|
|
2394
|
+
.catch(function () {
|
|
2395
|
+
settled = true;
|
|
2396
|
+
clearTimeout(staleTimer);
|
|
2397
|
+
// The new session could not be inspected, so the PREVIOUS wallet's
|
|
2398
|
+
// name must not keep serving: drop it and fall back to the
|
|
2399
|
+
// connector's own name until a later session resolves. Guarded so
|
|
2400
|
+
// an old session's late failure cannot clear a newer resolution.
|
|
2401
|
+
if (walletConnectPeerLatest.get(connector) === connection) {
|
|
2402
|
+
walletConnectPeerNames.delete(connector);
|
|
2403
|
+
}
|
|
2404
|
+
// A failed lookup must not permanently disqualify the connection:
|
|
2405
|
+
// the connector may just have been initialising. A later event
|
|
2406
|
+
// retries.
|
|
2407
|
+
walletConnectPeerLookups.delete(connection);
|
|
2408
|
+
});
|
|
1886
2409
|
};
|
|
1887
2410
|
/**
|
|
1888
2411
|
* Clean up all subscriptions
|