@formo/analytics 1.14.2 → 1.14.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formo/analytics",
3
- "version": "1.14.2",
3
+ "version": "1.14.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/getformo/sdk.git"
@@ -319,29 +319,38 @@ export class FormoAnalytics implements IFormoAnalytics {
319
319
  */
320
320
 
321
321
  private trackProvider(provider: EIP1193Provider): void {
322
- if (provider === this._provider) {
323
- console.warn("FormoAnalytics::trackProvider: Provider already tracked.");
324
- return;
325
- }
326
-
327
- this.currentChainId = undefined;
328
- this.currentConnectedAddress = undefined;
322
+ try {
323
+ if (provider === this._provider) {
324
+ console.warn(
325
+ "FormoAnalytics::trackProvider: Provider already tracked."
326
+ );
327
+ return;
328
+ }
329
329
 
330
- if (this._provider) {
331
- const actions = Object.keys(this._providerListeners);
332
- for (const action of actions) {
333
- this._provider.removeListener(action, this._providerListeners[action]);
334
- delete this._providerListeners[action];
330
+ this.currentChainId = undefined;
331
+ this.currentConnectedAddress = undefined;
332
+
333
+ if (this._provider) {
334
+ const actions = Object.keys(this._providerListeners);
335
+ for (const action of actions) {
336
+ this._provider.removeListener(
337
+ action,
338
+ this._providerListeners[action]
339
+ );
340
+ delete this._providerListeners[action];
341
+ }
335
342
  }
336
- }
337
343
 
338
- this._provider = provider;
344
+ this._provider = provider;
339
345
 
340
- // Register listeners for web3 provider events
341
- this.registerAddressChangedListener();
342
- this.registerChainChangedListener();
343
- this.registerSignatureListener();
344
- this.registerTransactionListener();
346
+ // Register listeners for web3 provider events
347
+ this.registerAddressChangedListener();
348
+ this.registerChainChangedListener();
349
+ this.registerSignatureListener();
350
+ this.registerTransactionListener();
351
+ } catch (error) {
352
+ console.error("FormoAnalytics::trackProvider: error:", error);
353
+ }
345
354
  }
346
355
 
347
356
  private registerAddressChangedListener(): void {
@@ -607,59 +616,68 @@ export class FormoAnalytics implements IFormoAnalytics {
607
616
  }
608
617
 
609
618
  private async trackEvent(action: string, payload: any): Promise<void> {
610
- const address = await this.getAddress();
619
+ try {
620
+ const address = await this.getAddress();
611
621
 
612
- const requestData: RequestEvent = {
613
- address,
614
- timestamp: new Date().toISOString(),
615
- action,
616
- version: "1",
617
- payload: await this.buildEventPayload(toSnakeCase(payload)),
618
- };
622
+ const requestData: RequestEvent = {
623
+ address,
624
+ timestamp: new Date().toISOString(),
625
+ action,
626
+ version: "1",
627
+ payload: await this.buildEventPayload(toSnakeCase(payload)),
628
+ };
619
629
 
620
- await this.eventQueue.enqueue(requestData, (err, _, data) => {
621
- if (err) {
622
- console.error(err);
623
- } else console.log(`Events sent successfully: ${data.length} events`);
624
- });
630
+ await this.eventQueue.enqueue(requestData, (err, _, data) => {
631
+ if (err) {
632
+ console.error(err);
633
+ } else console.log(`Events sent successfully: ${data.length} events`);
634
+ });
635
+ } catch (error) {
636
+ console.error("FormoAnalytics::trackEvent: error:", error);
637
+ }
625
638
  }
626
639
 
627
640
  /*
628
641
  Utility functions
629
642
  */
630
643
 
631
- private async getProviders(): Promise<EIP6963ProviderDetail[]> {
644
+ private async getProviders(): Promise<readonly EIP6963ProviderDetail[]> {
632
645
  const store = createStore();
633
- const providers = [...store.getProviders()];
646
+ let providers = store.getProviders();
634
647
  // TODO: consider using store.subscribe to detect changes to providers list
635
- // store.subscribe(providers => (state.providers = providers))
648
+ store.subscribe((providerDetails) => (providers = providerDetails));
636
649
 
637
650
  // Fallback to injected provider if no providers are found
638
651
  if (providers.length === 0) {
639
- return [window?.ethereum];
652
+ return window?.ethereum ? [window.ethereum] : [];
640
653
  }
641
654
  return providers;
642
655
  }
643
656
 
644
- private async identifyAll(providers: EIP6963ProviderDetail[]): Promise<void> {
657
+ private async identifyAll(
658
+ providers: readonly EIP6963ProviderDetail[]
659
+ ): Promise<void> {
645
660
  try {
646
- for (const { provider, info } of providers) {
647
- const accounts = await this.getAccounts(provider);
661
+ for (const eip6963ProviderDetail of providers) {
662
+ if (!eip6963ProviderDetail) continue;
663
+ const accounts = await this.getAccounts(
664
+ eip6963ProviderDetail?.provider
665
+ );
648
666
  // Identify with accounts
649
667
  if (accounts && accounts.length > 0) {
650
668
  for (const address of accounts) {
651
669
  await this.identify({
652
670
  address,
653
- providerName: info.name,
654
- rdns: info.rdns,
671
+ providerName: eip6963ProviderDetail?.info.name,
672
+ rdns: eip6963ProviderDetail?.info.rdns,
655
673
  });
656
674
  }
657
675
  } else {
658
676
  // Identify without accounts
659
677
  await this.identify({
660
678
  address: null,
661
- providerName: info.name,
662
- rdns: info.rdns,
679
+ providerName: eip6963ProviderDetail?.info.name,
680
+ rdns: eip6963ProviderDetail?.info.rdns,
663
681
  });
664
682
  }
665
683
  }