From 08727078dee229116a35a6964f1aa07737f8b09b Mon Sep 17 00:00:00 2001 From: nullptr Date: Mon, 13 Jan 2025 15:24:31 +0300 Subject: [PATCH] fix: tonconnect wallet connect event --- package.json | 2 +- src/observers/ton-connect.observer.ts | 35 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 044d827..0aa070c 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tonsolutions/telemetree-react", - "version": "1.2.6", + "version": "1.2.7", "main": "./lib/index.сjs", "module": "./lib/index.mjs", "types": "./lib/index.d.ts", diff --git a/src/observers/ton-connect.observer.ts b/src/observers/ton-connect.observer.ts index b14671c..10438d4 100644 --- a/src/observers/ton-connect.observer.ts +++ b/src/observers/ton-connect.observer.ts @@ -143,24 +143,28 @@ export class TonConnectObserver { eventDetails: any, ): Promise { const config = getConfig(); + const isTonConnected = localStorage.getItem('telemetree-ton-is-connected') === 'true'; Logger.debug('Raw event details:', { eventName, eventDetails }); // Add this debug log try { switch (eventName) { case TonConnectEvent.WalletConnectSuccess: { - const details = eventDetails as WalletConnectionEvent; - await this.eventBuilder.track( - `${EventType.Wallet}`, - { - wallet: details?.account?.address || details?.wallet_address, - provider: details?.wallet?.name || 'unknown', - chain: details?.account?.chain, - wallet_type: eventDetails.wallet_type, - wallet_version: eventDetails.wallet_version, - sdk_version: eventDetails.custom_data?.ton_connect_sdk_lib, - ui_version: eventDetails.custom_data?.ton_connect_ui_lib, - timestamp: Date.now(), - }, - ); + if (!isTonConnected) { + localStorage.setItem('telemetree-ton-is-connected', "true"); + const details = eventDetails as WalletConnectionEvent; + await this.eventBuilder.track( + `${EventType.Wallet}`, + { + wallet: details?.account?.address || details?.wallet_address, + provider: details?.wallet?.name || 'unknown', + chain: details?.account?.chain, + wallet_type: eventDetails.wallet_type, + wallet_version: eventDetails.wallet_version, + sdk_version: eventDetails.custom_data?.ton_connect_sdk_lib, + ui_version: eventDetails.custom_data?.ton_connect_ui_lib, + timestamp: Date.now(), + }, + ); + } break; } @@ -236,6 +240,9 @@ export class TonConnectObserver { } case TonConnectEvent.WalletDisconnect: { + if (isTonConnected) { + localStorage.setItem('telemetree-ton-is-connected', "false"); + } await this.eventBuilder.track( `${config.defaultSystemEventPrefix} ${EventType.WalletDisconnected}`, {