Skip to content

Commit

Permalink
refactor(sdk): always send RPC requests via network and deeplink (#1181)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
abretonc7s authored Dec 19, 2024
1 parent f9a9921 commit 10be04e
Showing 1 changed file with 5 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit 10be04e

Please sign in to comment.