Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tonconnect wallet connect event #22

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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