@formo/analytics 1.35.2 → 1.37.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.
Files changed (51) hide show
  1. package/dist/cjs/src/FormoAnalytics.d.ts +79 -363
  2. package/dist/cjs/src/FormoAnalytics.js +368 -2234
  3. package/dist/cjs/src/event/EventManager.d.ts +3 -1
  4. package/dist/cjs/src/event/EventManager.js +5 -1
  5. package/dist/cjs/src/event/type.d.ts +1 -0
  6. package/dist/cjs/src/evm/EvmEventTracker.d.ts +175 -0
  7. package/dist/cjs/src/evm/EvmEventTracker.js +1030 -0
  8. package/dist/cjs/src/evm/EvmProviderRegistry.d.ts +132 -0
  9. package/dist/cjs/src/evm/EvmProviderRegistry.js +348 -0
  10. package/dist/cjs/src/evm/EvmRequestTracker.d.ts +98 -0
  11. package/dist/cjs/src/evm/EvmRequestTracker.js +713 -0
  12. package/dist/cjs/src/evm/batch.d.ts +94 -0
  13. package/dist/cjs/src/evm/batch.js +130 -0
  14. package/dist/cjs/src/queue/EventQueue.d.ts +28 -0
  15. package/dist/cjs/src/queue/EventQueue.js +97 -19
  16. package/dist/cjs/src/queue/type.d.ts +1 -0
  17. package/dist/cjs/src/tracking/TrackingPolicy.d.ts +146 -0
  18. package/dist/cjs/src/tracking/TrackingPolicy.js +200 -0
  19. package/dist/cjs/src/validators/address.d.ts +1 -1
  20. package/dist/cjs/src/version.d.ts +1 -1
  21. package/dist/cjs/src/version.js +1 -1
  22. package/dist/cjs/src/wagmi/WagmiEventHandler.d.ts +43 -0
  23. package/dist/cjs/src/wagmi/WagmiEventHandler.js +253 -2
  24. package/dist/cjs/src/wallet/WalletStateStore.d.ts +223 -0
  25. package/dist/cjs/src/wallet/WalletStateStore.js +515 -0
  26. package/dist/esm/src/FormoAnalytics.d.ts +79 -363
  27. package/dist/esm/src/FormoAnalytics.js +369 -2235
  28. package/dist/esm/src/event/EventManager.d.ts +3 -1
  29. package/dist/esm/src/event/EventManager.js +5 -1
  30. package/dist/esm/src/event/type.d.ts +1 -0
  31. package/dist/esm/src/evm/EvmEventTracker.d.ts +175 -0
  32. package/dist/esm/src/evm/EvmEventTracker.js +1027 -0
  33. package/dist/esm/src/evm/EvmProviderRegistry.d.ts +132 -0
  34. package/dist/esm/src/evm/EvmProviderRegistry.js +345 -0
  35. package/dist/esm/src/evm/EvmRequestTracker.d.ts +98 -0
  36. package/dist/esm/src/evm/EvmRequestTracker.js +710 -0
  37. package/dist/esm/src/evm/batch.d.ts +94 -0
  38. package/dist/esm/src/evm/batch.js +123 -0
  39. package/dist/esm/src/queue/EventQueue.d.ts +28 -0
  40. package/dist/esm/src/queue/EventQueue.js +97 -19
  41. package/dist/esm/src/queue/type.d.ts +1 -0
  42. package/dist/esm/src/tracking/TrackingPolicy.d.ts +146 -0
  43. package/dist/esm/src/tracking/TrackingPolicy.js +197 -0
  44. package/dist/esm/src/version.d.ts +1 -1
  45. package/dist/esm/src/version.js +1 -1
  46. package/dist/esm/src/wagmi/WagmiEventHandler.d.ts +43 -0
  47. package/dist/esm/src/wagmi/WagmiEventHandler.js +253 -2
  48. package/dist/esm/src/wallet/WalletStateStore.d.ts +223 -0
  49. package/dist/esm/src/wallet/WalletStateStore.js +512 -0
  50. package/dist/index.umd.min.js +1 -1
  51. package/package.json +6 -4
@@ -1,79 +1,31 @@
1
1
  import { EIP6963ProviderDetail } from "mipd";
2
2
  import { Address, ChainID, Config, EIP1193Provider, IFormoAnalytics, IFormoEventContext, IFormoEventProperties, Options, SignatureStatus, TransactionStatus } from "./types";
3
+ import { AutocaptureEventType } from "./tracking/TrackingPolicy";
3
4
  import { SolanaManager } from "./solana/SolanaManager";
4
5
  import type { PrivyUser } from "./privy";
6
+ /**
7
+ * Constants for provider switching reasons
8
+ */
5
9
  export declare class FormoAnalytics implements IFormoAnalytics {
6
10
  readonly writeKey: string;
7
11
  options: Options;
8
- private _chainState;
9
- private _activeNamespace?;
12
+ /** Wallet identity, chain state and the active-wallet cookie. */
13
+ private wallet;
10
14
  private get _provider();
11
- /**
12
- * Drop a provider's reported-connect record when it stops being active.
13
- *
14
- * The active provider is displaced from several places, and not all of them
15
- * go through the `_provider` setter: `setChainState()` writes
16
- * `_chainState.evm.provider` directly and `clearChainState()` replaces the
17
- * whole namespace. Guarding only the setter left A's record alive across a
18
- * real A-to-B switch, so returning to A was suppressed.
19
- */
20
- private forgetConnectRecord;
21
15
  private set _provider(value);
22
16
  private get _evmAddress();
23
17
  private get _evmChainId();
24
- /**
25
- * Last known chain per tracked provider, fed by `chainChanged` / `connect`
26
- * and by a one-off probe at tracking time. Read synchronously when labelling
27
- * an autocaptured event, so the wallet's request transport is never used for
28
- * analytics. Weak so an untracked provider can be collected.
29
- */
30
- /**
31
- * The connect this SDK has actually REPORTED for a provider.
32
- *
33
- * Deduplicating on "is an address known" was wrong in both directions.
34
- * `onConnected` and `onAccountsChanged` both observe one connection, so
35
- * something has to stop them double-reporting - but an address can be
36
- * present without a connect ever having been sent: restored from the
37
- * active-wallet cookie, or reported with an unresolved chain and then
38
- * refused by `tracking.excludeChains`. Suppressing on address presence lost
39
- * the connect entirely in those cases.
40
- *
41
- * Records what was reported, so a later event can be recognised as a
42
- * genuine improvement on it rather than a duplicate.
43
- */
44
18
  private _announcedConnect;
45
- private _providerChainIds;
46
- /**
47
- * Bumped on every chain observation, PER PROVIDER. An `eth_chainId` answer
48
- * that resolves after a newer observation for the same provider must not
49
- * overwrite it.
50
- *
51
- * Deliberately per provider, not per SDK instance: a global counter meant
52
- * any activity on wallet B discarded a perfectly valid in-flight answer for
53
- * wallet A, leaving A at chain 0 - and, since an unresolved chain fails
54
- * closed, dropping all of A's events whenever `excludeChains` is set.
55
- */
56
- private _providerChainGenerations;
57
- private _providerListenersMap;
58
19
  private session;
59
20
  private eventManager;
60
- /**
61
- * EIP-6963 provider details discovered through the browser
62
- * This array contains all available providers with their metadata
63
- */
64
- private _providers;
65
- /**
66
- * Set of providers that have been tracked with event listeners
67
- * This is separate from _providers because:
68
- * - _providers contains all discovered providers (EIP-6963)
69
- * - _trackedProviders contains only providers that have been set up with listeners
70
- * - A provider can be discovered but not yet tracked (e.g., during initialization)
71
- * - A provider can be tracked but later removed from discovery
72
- */
73
- private _trackedProviders;
74
- private _injectedProviderDetail?;
75
- private _processingAccountsChanged;
76
- private _seenProviders;
21
+ /** Which EVM wallets exist, and what is known about each. */
22
+ private evm;
23
+ /** Which providers to watch, and what their events mean. */
24
+ private evmEvents;
25
+ /** Autocapture for signatures and transactions. */
26
+ private evmRequests;
27
+ /** Every "may we track this?" rule. See src/tracking/TrackingPolicy.ts. */
28
+ private trackingPolicy;
77
29
  /**
78
30
  * Wagmi event handler for tracking wallet events via Wagmi v2
79
31
  * Only initialized when options.wagmi is provided
@@ -103,15 +55,25 @@ export declare class FormoAnalytics implements IFormoAnalytics {
103
55
  private _onLocationChangeListener?;
104
56
  private _pageHooksDisposed;
105
57
  config: Config;
106
- currentChainId?: ChainID;
107
- currentAddress?: Address;
108
- currentUserId?: string;
109
58
  /**
110
- * Helper method to check if a provider is different from the currently active one
111
- * @param provider The provider to check
112
- * @returns true if there's a provider mismatch, false otherwise
59
+ * The wallet later events are attributed to, derived from whichever
60
+ * namespace last claimed the slot. Read by the wagmi and Privy
61
+ * integrations; the store is the only writer.
113
62
  */
114
- private isProviderMismatch;
63
+ get currentAddress(): Address | undefined;
64
+ get currentChainId(): ChainID | undefined;
65
+ /**
66
+ * These stay writable.
67
+ *
68
+ * Both were public mutable fields, so a consumer assigning one is using a
69
+ * documented public API. Getter-only replacements would break that
70
+ * silently: TypeScript rejects the assignment, and plain JavaScript throws
71
+ * on an accessor with no setter. The writes forward into the store, which
72
+ * keeps a single owner without turning a refactor into a breaking change.
73
+ */
74
+ set currentAddress(value: Address | undefined);
75
+ set currentChainId(value: ChainID | undefined);
76
+ currentUserId?: string;
115
77
  private constructor();
116
78
  static init(writeKey: string, options?: Options): Promise<FormoAnalytics>;
117
79
  /**
@@ -161,6 +123,45 @@ export declare class FormoAnalytics implements IFormoAnalytics {
161
123
  chainId?: ChainID;
162
124
  address?: Address;
163
125
  }, properties?: IFormoEventProperties, context?: IFormoEventContext, callback?: (...args: unknown[]) => void): Promise<void>;
126
+ /** @see WalletStateStore.set */
127
+ private setChainState;
128
+ /** @see WalletStateStore.clear */
129
+ private clearChainState;
130
+ /**
131
+ * Record validated wallet/chain state WITHOUT emitting an event.
132
+ *
133
+ * Integrations must call this on every connect / chain change / disconnect,
134
+ * even when the matching autocapture event is disabled, or the exclusion
135
+ * gate (which keys off the central chain, not the event payload) can be
136
+ * bypassed. Stays on the class because integrations bind to it.
137
+ * @see WalletStateStore.syncWalletState
138
+ */
139
+ syncWalletState(params: {
140
+ chainId?: ChainID;
141
+ address?: Address;
142
+ }): void;
143
+ /** @see WalletStateStore.clearProvider */
144
+ private clearActiveProvider;
145
+ /** @see WalletStateStore.backfill */
146
+ private backfillActiveWallet;
147
+ /** @see WalletStateStore.clearStaleEvmWalletOnSwitchWhileSuppressed */
148
+ private clearStaleEvmWalletOnSwitchWhileSuppressed;
149
+ /** @see EvmProviderRegistry.addListener */
150
+ private addProviderListener;
151
+ /** @see EvmProviderRegistry.removeListeners */
152
+ private removeProviderListeners;
153
+ /** @see EvmProviderRegistry.infoFor */
154
+ private getProviderInfo;
155
+ /** @see EvmProviderRegistry.isWrapped */
156
+ private isProviderAlreadyWrapped;
157
+ /** @see EvmProviderRegistry.resolveChainId */
158
+ private resolveChainIdForProvider;
159
+ /** @see EvmProviderRegistry.rememberChain */
160
+ private rememberProviderChain;
161
+ /** @see EvmProviderRegistry.addressOf */
162
+ private getAddress;
163
+ /** @see EvmProviderRegistry.accountsOf */
164
+ private getAccounts;
164
165
  /**
165
166
  * Emits a chain network change event.
166
167
  * @param {ChainID} params.chainId
@@ -325,65 +326,6 @@ export declare class FormoAnalytics implements IFormoAnalytics {
325
326
  * @returns {boolean} True if the user has opted out
326
327
  */
327
328
  hasOptedOutTracking(): boolean;
328
- /**
329
- * Track an EIP-1193 provider by wrapping its request method and adding event listeners
330
- * Note: This is only used in non-Wagmi mode. When Wagmi is enabled, all tracking
331
- * happens through Wagmi's connector system instead of EIP-1193/EIP-6963.
332
- * @param provider The EIP-1193 provider to track
333
- */
334
- private trackEIP1193Provider;
335
- private trackProviders;
336
- private addProviderListener;
337
- private registerAccountsChangedListener;
338
- private onAccountsChanged;
339
- /**
340
- * Handles changes to the accounts of a given EIP-1193 provider.
341
- *
342
- * @param provider - The EIP-1193 provider whose accounts have changed.
343
- * @param accounts - The new array of account addresses. An empty array indicates a disconnect.
344
- * @returns A promise that resolves when the account change has been processed.
345
- *
346
- * If the accounts array is empty and the provider is the active provider, this method triggers
347
- * a disconnect flow. Otherwise, it updates the state to reflect the new accounts as needed.
348
- */
349
- private _handleAccountsChanged;
350
- private registerChainChangedListener;
351
- private onChainChanged;
352
- /**
353
- * Record a provider's chain from its `connect` event, and nothing else.
354
- *
355
- * Used when connect autocapture is off. `connect` carries `chainId` in its
356
- * payload, so this needs no RPC - unlike the full handler, which resolves
357
- * the account.
358
- */
359
- private registerConnectChainObserver;
360
- /**
361
- * Whether a connect for this wallet still needs reporting.
362
- *
363
- * True when nothing has been reported for this provider, or when the account
364
- * changed. A wallet already reported is not reported again.
365
- *
366
- * Deliberately does NOT re-report to correct a chain. When `accountsChanged`
367
- * wins the race on a provider that exposes no synchronous `chainId`, the
368
- * connect carries 0 - honestly, since the chain is unknown at that instant -
369
- * and the `connect` payload that follows knows the real one. Emitting again
370
- * to relabel would mean two connects for one connection, which is the bug
371
- * this whole path exists to prevent. That payload still corrects
372
- * `currentChainId`, so everything after it is attributed properly.
373
- */
374
- private shouldReportConnect;
375
- /**
376
- * Record a connect as reported - but only if it will actually be sent.
377
- *
378
- * `connect()` passes through `shouldTrack()`, which refuses an unresolvable
379
- * chain when `tracking.excludeChains` is configured. Marking a refused event
380
- * as reported would suppress the authoritative one that follows.
381
- */
382
- private markConnectReported;
383
- private registerConnectListener;
384
- private registerDisconnectListener;
385
- private onConnected;
386
- private registerRequestListeners;
387
329
  private onLocationChange;
388
330
  private trackPageHits;
389
331
  /**
@@ -397,94 +339,26 @@ export declare class FormoAnalytics implements IFormoAnalytics {
397
339
  /**
398
340
  * Visitor-level tracking suppression.
399
341
  *
400
- * Returns true when the SDK must not persist any identity/session/chain
401
- * state or send any events for this visitor - i.e. an explicit opt-out or a
402
- * jurisdiction/timezone exclusion. Public entry points that write state
403
- * before reaching the `shouldTrack()` event gate (identify/connect/detect)
404
- * check this first so suppressed visitors leave no cookies or session state.
405
- * @returns {boolean} True if all tracking and persistence must be suppressed
342
+ * True when the SDK must not persist identity/session/chain state or send
343
+ * events for this visitor. Public entry points that write state before
344
+ * reaching the `shouldTrack()` gate (identify / connect / detect) check this
345
+ * first, so a suppressed visitor leaves no cookies or session state.
346
+ *
347
+ * The rule lives in `TrackingPolicy`; this stays on the class because it is
348
+ * part of the surface integrations bind to.
406
349
  * @internal Also read by `identifyPrivyUser` (via a structural cast) so the
407
350
  * Privy sync skips chain reconciliation and emission for suppressed visitors.
408
351
  */
409
352
  isTrackingSuppressed(): boolean;
410
- /**
411
- * Whether the current chain id is in `tracking.excludeChains`.
412
- *
413
- * Split out from `shouldTrack()` so `identify()` can check it *before*
414
- * mutating identity state. `trackEvent()` drops an excluded event silently
415
- * and returns void, but `identify()` marks the wallet as identified first, so
416
- * without this guard an identify on an excluded chain is dedup-marked and
417
- * then discarded, and the wallet never re-emits for the rest of the session
418
- * even after switching to an allowed chain. On the Privy path that loses the
419
- * user's whole cluster at once rather than a single wallet.
420
- *
421
- * Mirrors the chain rule in `shouldTrack()`: only applies when `tracking` is
422
- * an options object with `excludeChains` set, and only once a chain id is
423
- * known.
424
- */
425
- private isCurrentChainExcluded;
426
- /**
427
- * Whether the current environment is excluded from tracking - the visitor's
428
- * timezone, the current hostname, or the current pathname matches a
429
- * configured exclusion.
430
- *
431
- * Timezone is visitor/session-level (stable for the session); host/path are
432
- * current-page-level and transient - if a SPA navigates to an allowed path,
433
- * tracking resumes for future actions. Used as the "do not write identity or
434
- * send events" gate at every entry point that would persist state before the
435
- * `shouldTrack()` event gate.
436
- * @returns {boolean} True if the current environment is excluded
437
- */
438
- private isCurrentEnvironmentExcluded;
439
- /**
440
- * Whether the current hostname matches a configured `tracking.excludeHosts`
441
- * entry (exact match). Current-page-level - see isCurrentEnvironmentExcluded.
442
- * @returns {boolean} True if the current hostname is excluded
443
- */
444
- private isHostExcluded;
445
- /**
446
- * Whether the current pathname matches a configured `tracking.excludePaths`
447
- * entry (exact match). Current-page-level - see isCurrentEnvironmentExcluded.
448
- * @returns {boolean} True if the current pathname is excluded
449
- */
450
- private isPathExcluded;
451
- /**
452
- * Whether the current call is in a visitor-level suppression state - opt-out
453
- * or excluded timezone - for which any persisted identity cookie should be
454
- * actively purged (not merely skipped). Host/path exclusions are
455
- * deliberately excluded here: they are transient current-page states, so a
456
- * cookie legitimately written on an allowed page must survive a visit to an
457
- * excluded route.
458
- * @returns {boolean} True if persisted identity must be purged
459
- */
460
- private isPersistedIdentityPurgeRequired;
461
- /**
462
- * Whether the visitor's browser-resolved timezone matches a configured
463
- * `tracking.excludeTimezones` entry (case-insensitive). Client-side and
464
- * best-effort - see TrackingOptions.excludeTimezones.
465
- * @returns {boolean} True if the current timezone is excluded
466
- */
467
- private isTimezoneExcluded;
468
- /**
469
- * Determines if tracking should be enabled based on configuration and consent
470
- * @returns {boolean} True if tracking should be enabled
471
- */
353
+ /** @see TrackingPolicy.shouldTrack */
472
354
  private shouldTrack;
473
355
  /**
474
356
  * Check if a specific wallet event type is enabled for autocapture
475
357
  * @param eventType The wallet event type to check
476
358
  * @returns {boolean} True if the event type should be autocaptured
477
359
  */
478
- isAutocaptureEnabled(eventType: "connect" | "disconnect" | "signature" | "transaction" | "chain"): boolean;
479
- /**
480
- * Get provider information for a given provider
481
- * @param provider The provider to get info for
482
- * @returns Provider information
483
- */
484
- private getProviderInfo;
485
- private getProviders;
360
+ isAutocaptureEnabled(eventType: AutocaptureEventType): boolean;
486
361
  get providers(): readonly EIP6963ProviderDetail[];
487
- private detectWallets;
488
362
  get provider(): EIP1193Provider | undefined;
489
363
  /**
490
364
  * Access the Solana integration manager.
@@ -498,84 +372,7 @@ export declare class FormoAnalytics implements IFormoAnalytics {
498
372
  * ```
499
373
  */
500
374
  get solana(): SolanaManager;
501
- private getAddress;
502
- private getAccounts;
503
- /**
504
- * Resolve the chain an autocaptured request actually ran on.
505
- *
506
- * `_evmChainId` is maintained by `chainChanged` from whichever provider is
507
- * currently active. When a request arrives from a *different* tracked
508
- * provider - which happens whenever a visitor has two wallets installed -
509
- * that cached value describes the wrong wallet, and tagging the event with
510
- * it silently mis-attributes the chain.
511
- *
512
- * Answered entirely from a per-provider snapshot. This is deliberately
513
- * SYNCHRONOUS and never issues an RPC.
514
- *
515
- * An earlier version called `eth_chainId` on the signing provider and
516
- * time-boxed it with `Promise.race`. That is not safe: the race abandons the
517
- * SDK's promise but cannot cancel the provider's request. On a transport
518
- * that serializes - WalletConnect's relay socket, the very case this path
519
- * exists to serve - an abandoned lookup stays at the head of the wallet's
520
- * queue, and every later RPC the dapp makes queues behind it until reload.
521
- * Mislabelling a chain is a reporting defect; wedging the user's wallet is
522
- * not acceptable to avoid one.
523
- *
524
- * When nothing is known, this reports 0 ("unknown") rather than guessing
525
- * with the active provider's chain, which is known-wrong for another wallet.
526
- */
527
- private resolveChainIdForProvider;
528
- /**
529
- * Record a provider's chain. Fed by `chainChanged` and `connect`, and by the
530
- * one-off probe at tracking time - never from inside a user request.
531
- */
532
- private rememberProviderChain;
533
- /** Advance and return this provider's chain-observation generation. */
534
- private bumpProviderChainGeneration;
535
- /**
536
- * Seed a provider's chain from whatever it already exposes synchronously.
537
- *
538
- * Most EIP-1193 implementations carry a `chainId` property (MetaMask,
539
- * WalletConnect, Coinbase). Reading it costs nothing and cannot block.
540
- *
541
- * There is deliberately no RPC fallback. An earlier version probed with
542
- * `eth_chainId` when a provider was first tracked, on the theory that
543
- * tracking time is off the user's critical path. It is not: a serialized
544
- * transport has ONE queue, so a stalled probe sits in front of every later
545
- * signature and transaction the dapp makes. It could also land out of order
546
- * - a slow probe response overwriting a newer `chainChanged` - and relabel
547
- * events onto a chain the wallet had already left.
548
- *
549
- * A provider that exposes nothing stays unknown until it emits
550
- * `chainChanged` or `connect`, and unknown is reported honestly as 0.
551
- */
552
- private seedProviderChainFromState;
553
375
  private getCurrentChainId;
554
- private buildSignatureEventPayload;
555
- private buildTransactionEventPayload;
556
- /**
557
- * Persist an EVM address discovered through autocapture (signature / transaction)
558
- * as the current EVM address when none is currently set. This lets subsequent
559
- * track()/page() calls carry the address even when the underlying wallet never
560
- * fires an EIP-1193 `accountsChanged` event (embedded wallets, smart accounts,
561
- * social-login wrappers). If `accountsChanged` later fires it overwrites this
562
- * value in the normal way; existing connections are never clobbered.
563
- */
564
- private backfillActiveWallet;
565
- /**
566
- * Apply an EVM autocapture connect/switch while tracking is suppressed
567
- * (opt-out / timezone / excluded host or path): never LEARN the wallet, but
568
- * if it is a switch away from an already-learned EVM wallet, drop the stale
569
- * one (which also clears the active-wallet cookie) so it can't attach to a
570
- * later allowed-page event.
571
- */
572
- private clearStaleEvmWalletOnSwitchWhileSuppressed;
573
- /**
574
- * Polls for transaction receipt and emits tx.status = CONFIRMED or REVERTED.
575
- */
576
- private pollTransactionReceipt;
577
- private removeProviderListeners;
578
- private untrackProvider;
579
376
  getTrackedProvidersCount(): number;
580
377
  /**
581
378
  * Get current provider state for debugging
@@ -587,86 +384,5 @@ export declare class FormoAnalytics implements IFormoAnalytics {
587
384
  seenProviders: number;
588
385
  activeProvider: boolean;
589
386
  };
590
- /**
591
- * Clean up providers that are no longer available
592
- * This helps maintain consistent state and prevents memory leaks
593
- */
594
- private cleanupUnavailableProviders;
595
- /**
596
- * Helper method to check if a provider is already wrapped
597
- * @param provider The provider to check
598
- * @param currentRequest The current request function
599
- * @returns true if the provider is already wrapped
600
- */
601
- private isProviderAlreadyWrapped;
602
- /**
603
- * Handle provider mismatch by switching to the new provider and invalidating old tokens
604
- * @param provider The new provider to switch to
605
- */
606
- private handleProviderMismatch;
607
- /**
608
- * Determine which namespace a chainId belongs to.
609
- */
610
- private getNamespace;
611
- /**
612
- * Update per-chain state and sync the derived currentAddress/currentChainId.
613
- * Accepts either a namespace string ('evm'/'solana') or a chainId number
614
- * to resolve the namespace automatically. When a chainId number is passed,
615
- * it is also stored as the namespace's chainId (unless explicitly overridden
616
- * in the update object).
617
- */
618
- private setChainState;
619
- /**
620
- * Clear per-chain state for a given namespace (or chainId) and sync derived state.
621
- */
622
- private clearChainState;
623
- /**
624
- * Sync validated wallet/chain state into the SDK's central state
625
- * WITHOUT emitting an event.
626
- *
627
- * Integrations (e.g. the wagmi handler) must call this on every
628
- * connect / chain-change / disconnect - even when the corresponding
629
- * autocapture event is disabled. Otherwise `currentChainId` stays
630
- * stale/undefined and `shouldTrack()`'s `tracking.excludeChains`
631
- * check (which keys off `currentChainId`, not the event payload) can
632
- * be bypassed, letting wallet activity on an excluded chain still be
633
- * collected.
634
- *
635
- * - valid `address` present → record per-chain + derived state
636
- * - `address` absent → clear chain state (disconnect)
637
- */
638
- syncWalletState(params: {
639
- chainId?: ChainID;
640
- address?: Address;
641
- }): void;
642
- /**
643
- * Synchronize currentAddress/currentChainId from the active namespace.
644
- * Last-connected-chain-wins: _activeNamespace takes precedence.
645
- */
646
- private syncDerivedState;
647
- /**
648
- * Persist (or clear) the current wallet snapshot in a cookie so that the
649
- * SDK can repopulate `currentAddress`/`currentChainId` at init on the next
650
- * page load - closing the gap between page-show and wagmi/EIP-1193
651
- * reconnection during which track()/page() events would otherwise ship
652
- * with an empty address.
653
- */
654
- private persistActiveWallet;
655
- /**
656
- * Seed `currentAddress`/`currentChainId` from the persisted snapshot, if
657
- * any. Called once during construction before the first page hit fires.
658
- */
659
- private loadActiveWallet;
660
- /**
661
- * Helper method to clear the active provider state
662
- * Centralizes provider clearing logic for consistency
663
- */
664
- private clearActiveProvider;
665
- /**
666
- * Helper method to safely add a provider detail to _providers array, ensuring no duplicates
667
- * @param detail The provider detail to add
668
- * @returns true if the provider was added, false if it was already present
669
- */
670
- private safeAddProviderDetail;
671
387
  }
672
388
  //# sourceMappingURL=FormoAnalytics.d.ts.map