Skip to content

Commit

Permalink
Merge pull request #22 from TONSolutions/fix-wallet-event-every-init
Browse files Browse the repository at this point in the history
fix: tonconnect wallet connect event
  • Loading branch information
sss1337xyz authored Jan 13, 2025
2 parents 7428f35 + 0872707 commit 3d9ef52
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
35 changes: 21 additions & 14 deletions src/observers/ton-connect.observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,28 @@ export class TonConnectObserver {
eventDetails: any,
): Promise<void> {
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;
}

Expand Down Expand Up @@ -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}`,
{
Expand Down

0 comments on commit 3d9ef52

Please sign in to comment.