From cc02edeabb61abd192f8c86012b5993eebfb8e7b Mon Sep 17 00:00:00 2001 From: Spencer Stock Date: Sun, 17 Dec 2023 23:16:23 -0700 Subject: [PATCH] expose getSessionConfig to walletlinkRelay --- .../wallet-sdk/src/provider/DiagnosticLogger.ts | 1 + .../src/relay/walletlink/WalletLinkRelay.ts | 16 ++++++++++++++++ .../connection/WalletLinkConnection.ts | 4 ++-- .../src/relay/walletlink/type/Web3Method.ts | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/wallet-sdk/src/provider/DiagnosticLogger.ts b/packages/wallet-sdk/src/provider/DiagnosticLogger.ts index 88c5bae6eb..f11f2fba4c 100644 --- a/packages/wallet-sdk/src/provider/DiagnosticLogger.ts +++ b/packages/wallet-sdk/src/provider/DiagnosticLogger.ts @@ -43,6 +43,7 @@ export const EVENTS = { SKIPPED_CLEARING_SESSION: 'walletlink_sdk.skipped_clearing_session', GENERAL_ERROR: 'walletlink_sdk.general_error', WEB3_REQUEST: 'walletlink_sdk.web3.request', + GET_SESSION_CONFIG_REQUEST: 'walletlink_sdk.session_config.request', WEB3_REQUEST_PUBLISHED: 'walletlink_sdk.web3.request_published', WEB3_RESPONSE: 'walletlink_sdk.web3.response', METHOD_NOT_IMPLEMENTED: 'walletlink_sdk.method_not_implemented', diff --git a/packages/wallet-sdk/src/relay/walletlink/WalletLinkRelay.ts b/packages/wallet-sdk/src/relay/walletlink/WalletLinkRelay.ts index b3f1e54eda..bae3eaf3f0 100644 --- a/packages/wallet-sdk/src/relay/walletlink/WalletLinkRelay.ts +++ b/packages/wallet-sdk/src/relay/walletlink/WalletLinkRelay.ts @@ -189,6 +189,22 @@ export class WalletLinkRelay extends RelayAbstract implements WalletLinkConnecti public attachUI() { this.ui.attach(); } + public getSessionConfig(): void { + this.connection + .sendGetSessionConfig() + .then(() => { + this.diagnostic?.log(EVENTS.GET_SESSION_CONFIG_REQUEST, { + sessionIdHash: this.getSessionIdHash(), + }); + }) + .catch((err: string) => { + this.diagnostic?.log(EVENTS.FAILURE, { + method: 'relay::getSessionConfig', + message: `failed to get session config with ${err}`, + sessionIdHash: this.getSessionIdHash(), + }); + }); + } public resetAndReload(): void { Promise.race([ diff --git a/packages/wallet-sdk/src/relay/walletlink/connection/WalletLinkConnection.ts b/packages/wallet-sdk/src/relay/walletlink/connection/WalletLinkConnection.ts index aa05c1e87e..d45a09ed1e 100644 --- a/packages/wallet-sdk/src/relay/walletlink/connection/WalletLinkConnection.ts +++ b/packages/wallet-sdk/src/relay/walletlink/connection/WalletLinkConnection.ts @@ -448,13 +448,13 @@ export class WalletLinkConnection { this.sendData(m); } - private sendGetSessionConfig(): void { + public sendGetSessionConfig(): Promise { const m: ClientMessage = { type: 'GetSessionConfig', id: IntNumber(this.nextReqId++), sessionId: this.session.id, }; - this.sendData(m); + return this.makeRequest(m); } private handleSessionMetadataUpdated = (metadata: SessionConfig['metadata']) => { diff --git a/packages/wallet-sdk/src/relay/walletlink/type/Web3Method.ts b/packages/wallet-sdk/src/relay/walletlink/type/Web3Method.ts index 08d1500e13..40658bb30b 100644 --- a/packages/wallet-sdk/src/relay/walletlink/type/Web3Method.ts +++ b/packages/wallet-sdk/src/relay/walletlink/type/Web3Method.ts @@ -10,6 +10,7 @@ export const web3Methods = [ 'scanQRCode', 'generic', 'childRequestEthereumAccounts', + 'getSessionConfig', 'addEthereumChain', 'switchEthereumChain', 'makeEthereumJSONRPCRequest',