From 10be04eab083ba5783610782b9f445f1b1075740 Mon Sep 17 00:00:00 2001 From: abretonc7s <107169956+abretonc7s@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:59:31 +0800 Subject: [PATCH] refactor(sdk): always send RPC requests via network and deeplink (#1181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: set rpc id even without network * refactor: streamline RPC method tracking in write function - Moved RPC method tracking logic to ensure it is executed before sending analytics. - Enhanced logging for the RPC method tracker to include detailed information about the tracked methods and data. - Removed redundant console warnings to clean up the code and improve readability. * refactor(write): simplify message sending logic • Remove conditional analytics sending • Always send RPC requests via network • Add debug logging for triggeredInstaller state • Remove redundant RPC method tracking * feat: cleanup --- .../write.ts | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/packages/sdk/src/services/RemoteCommunicationPostMessageStream/write.ts b/packages/sdk/src/services/RemoteCommunicationPostMessageStream/write.ts index 3ca937f87..ffc92a600 100644 --- a/packages/sdk/src/services/RemoteCommunicationPostMessageStream/write.ts +++ b/packages/sdk/src/services/RemoteCommunicationPostMessageStream/write.ts @@ -1,8 +1,3 @@ -import { - TrackingEvents, - SendAnalytics, - DEFAULT_SERVER_URL, -} from '@metamask/sdk-communication-layer'; import { RemoteCommunicationPostMessageStream } from '../../PostMessageStream/RemoteCommunicationPostMessageStream'; import { METHODS_TO_REDIRECT, RPC_METHODS } from '../../config'; import { @@ -62,7 +57,11 @@ export async function write( deeplinkProtocolAvailable && mobileWeb && authorized; try { - if (!activeDeeplinkProtocol || triggeredInstaller) { + console.warn( + `[RCPMS: _write()] triggeredInstaller=${triggeredInstaller} activeDeeplinkProtocol=${activeDeeplinkProtocol}`, + ); + + if (!triggeredInstaller) { // The only reason not to send via network is because the rpc call will be sent in the deeplink instance.state.remote ?.sendMessage(data?.data) @@ -72,24 +71,6 @@ export async function write( .catch((err: unknown) => { logger(`[RCPMS: _write()] error sending message`, err); }); - } else { - try { - // Only send analytics if we are not sending via network. - await SendAnalytics( - { - id: channelId, - event: TrackingEvents.SDK_RPC_REQUEST, - params: { - method: targetMethod, - from: 'mobile', - }, - }, - instance.state.remote?.state.communicationServerUrl ?? - DEFAULT_SERVER_URL, - ); - } catch (error) { - logger(`[RCPMS: _write()] error sending analytics`, error); - } } if (!isSecure) {