Skip to content

Commit

Permalink
Merge pull request #21 from TONSolutions/te-765/fix-wallet
Browse files Browse the repository at this point in the history
feat: fix bugs and new events
  • Loading branch information
sss1337xyz authored Jan 10, 2025
2 parents d96f3aa + 592ae9a commit 7428f35
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 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.5",
"version": "1.2.6",
"main": "./lib/index.сjs",
"module": "./lib/index.mjs",
"types": "./lib/index.d.ts",
Expand Down
18 changes: 11 additions & 7 deletions src/components/TwaAnalyticsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare global {
WebView?: Telegram.WebView;
};
__telemetreeSessionStarted?: boolean;
__telemetreeTonObserverStarted?: boolean;
}
}

Expand Down Expand Up @@ -83,13 +84,16 @@ const TwaAnalyticsProvider: FunctionComponent<TwaAnalyticsProviderProps> = ({
useEffect(() => {
let observer: TonConnectObserver | null = null;

try {
observer = new TonConnectObserver(eventBuilder);
Logger.info('TON Connect observer initialized successfully');
} catch (error) {
Logger.error('Failed to initialize TON Connect observer', {
error: error instanceof Error ? error.message : 'Unknown error',
});
if (!window.__telemetreeTonObserverStarted){
try {
observer = new TonConnectObserver(eventBuilder);
window.__telemetreeTonObserverStarted = true;
Logger.info('TON Connect observer initialized successfully');
} catch (error) {
Logger.error('Failed to initialize TON Connect observer', {
error: error instanceof Error ? error.message : 'Unknown error',
});
}
}

return () => {
Expand Down
3 changes: 1 addition & 2 deletions src/enum/event-type.enum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export enum EventType {
Click = 'Click',
PageView = 'Pageview',
Wallet = 'Wallet',
Closed = 'Closed',
MainButtonPressed = 'MainButtonPressed',
SettingsButtonPressed = 'SettingsButtonPressed',
Expand Down Expand Up @@ -40,8 +39,8 @@ export enum EventType {
SessionEnd = 'Session end',

// Wallet events
Wallet = 'Wallet',
WalletConnectStarted = 'Wallet connect started',
WalletConnected = 'Wallet connected',
WalletConnectError = 'Wallet connect error',
WalletConnectionRestoringStarted = 'Wallet connection restoring started',
WalletConnectionRestored = 'Wallet connection restored',
Expand Down
47 changes: 43 additions & 4 deletions src/observers/ton-connect.observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface CustomData {
}

interface BaseEventDetails {
wallet_address?: string;
wallet_type?: string;
wallet_version?: string;
custom_data?: CustomData;
Expand Down Expand Up @@ -143,15 +144,14 @@ export class TonConnectObserver {
): Promise<void> {
const config = getConfig();
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(
`${config.defaultSystemEventPrefix} ${EventType.WalletConnected}`,
`${EventType.Wallet}`,
{
wallet: details?.account?.address,
wallet: details?.account?.address || details?.wallet_address,
provider: details?.wallet?.name || 'unknown',
chain: details?.account?.chain,
wallet_type: eventDetails.wallet_type,
Expand Down Expand Up @@ -239,7 +239,46 @@ export class TonConnectObserver {
await this.eventBuilder.track(
`${config.defaultSystemEventPrefix} ${EventType.WalletDisconnected}`,
{
lastWallet: eventDetails?.wallet,
lastWallet: eventDetails?.wallet_address,
timestamp: Date.now(),
},
);
break;
}

case TonConnectEvent.ConnectionRestoringError: {
await this.eventBuilder.track(
`${config.defaultSystemEventPrefix} ${EventType.WalletConnectionRestoreError}`,
{
wallet_type: eventDetails.wallet_type,
wallet_version: eventDetails.wallet_version,
wallet: eventDetails?.wallet_address,
timestamp: Date.now(),
},
);
break;
}

case TonConnectEvent.ConnectionRestoringSuccess: {
await this.eventBuilder.track(
`${config.defaultSystemEventPrefix} ${EventType.WalletConnectionRestored}`,
{
wallet_type: eventDetails.wallet_type,
wallet_version: eventDetails.wallet_version,
wallet: eventDetails?.wallet_address,
timestamp: Date.now(),
},
);
break;
}

case TonConnectEvent.ConnectionRestoringStarted: {
await this.eventBuilder.track(
`${config.defaultSystemEventPrefix} ${EventType.WalletConnectionRestoringStarted}`,
{
wallet_type: eventDetails.wallet_type,
wallet_version: eventDetails.wallet_version,
wallet: eventDetails?.wallet_address,
timestamp: Date.now(),
},
);
Expand Down

0 comments on commit 7428f35

Please sign in to comment.