From a9738e95a0159886a11d40a9f75b56fa81f8dfdb Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 18 Sep 2024 11:31:28 +0300 Subject: [PATCH 1/2] fix: sets domain if available else sets `sp` --- packages/core/src/controllers/events.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/core/src/controllers/events.ts b/packages/core/src/controllers/events.ts index a16ccb193..da4d249ae 100644 --- a/packages/core/src/controllers/events.ts +++ b/packages/core/src/controllers/events.ts @@ -1,6 +1,6 @@ import { generateChildLogger, Logger } from "@walletconnect/logger"; import { ICore, IEventClient, EventClientTypes } from "@walletconnect/types"; -import { formatUA, isTestRun, uuidv4 } from "@walletconnect/utils"; +import { formatUA, isTestRun, uuidv4, getAppMetadata } from "@walletconnect/utils"; import { CORE_STORAGE_PREFIX, EVENTS_CLIENT_API_URL, @@ -45,6 +45,7 @@ export class EventClient extends IEventClient { const initEvent = { eventId: uuidv4(), timestamp: Date.now(), + domain: this.getAppDomain(), props: { event: "INIT", type: "", @@ -83,12 +84,12 @@ export class EventClient extends IEventClient { }; const eventObj = { eventId, - bundleId, timestamp, props, + bundleId, + domain: this.getAppDomain(), ...this.setMethods(eventId), }; - if (this.telemetryEnabled) { this.events.set(eventId, eventObj); this.shouldPersist = true; @@ -210,8 +211,12 @@ export class EventClient extends IEventClient { }; private sendEvent = async (events: EventClientTypes.Event[]) => { + // if domain isn't available, set `sp` as `desktop` so data would be extracted on api side + const platform = this.getAppDomain() ? "" : "desktop"; const response = await fetch( - `${EVENTS_CLIENT_API_URL}?projectId=${this.core.projectId}&st=events_sdk&sv=js-${RELAYER_SDK_VERSION}`, + `${EVENTS_CLIENT_API_URL}?projectId=${ + this.core.projectId + }&st=events_sdk&sv=js-${RELAYER_SDK_VERSION}${platform ? `&sp=${platform}` : ""}`, { method: "POST", body: JSON.stringify(events), @@ -219,4 +224,8 @@ export class EventClient extends IEventClient { ); return response; }; + + private getAppDomain = () => { + return getAppMetadata().url; + }; } From fe0e55cca27e3dd0a192c84529e9ee4f17c62401 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 18 Sep 2024 11:39:28 +0300 Subject: [PATCH 2/2] refactor: optimize conditions --- packages/core/src/controllers/events.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/core/src/controllers/events.ts b/packages/core/src/controllers/events.ts index da4d249ae..d7af4fce0 100644 --- a/packages/core/src/controllers/events.ts +++ b/packages/core/src/controllers/events.ts @@ -212,11 +212,9 @@ export class EventClient extends IEventClient { private sendEvent = async (events: EventClientTypes.Event[]) => { // if domain isn't available, set `sp` as `desktop` so data would be extracted on api side - const platform = this.getAppDomain() ? "" : "desktop"; + const platform = this.getAppDomain() ? "" : "&sp=desktop"; const response = await fetch( - `${EVENTS_CLIENT_API_URL}?projectId=${ - this.core.projectId - }&st=events_sdk&sv=js-${RELAYER_SDK_VERSION}${platform ? `&sp=${platform}` : ""}`, + `${EVENTS_CLIENT_API_URL}?projectId=${this.core.projectId}&st=events_sdk&sv=js-${RELAYER_SDK_VERSION}${platform}`, { method: "POST", body: JSON.stringify(events),