Skip to content

Commit

Permalink
expose getSessionConfig to walletlinkRelay
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerstock committed Dec 18, 2023
1 parent ae895de commit 2f56502
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/wallet-sdk/src/provider/DiagnosticLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
17 changes: 17 additions & 0 deletions packages/wallet-sdk/src/relay/walletlink/WalletLinkRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ export class WalletLinkRelay extends RelayAbstract implements WalletLinkConnecti
public attachUI() {
this.ui.attach();
}
public getSessionConfig() {
return this.connection
.sendGetSessionConfig()
.then((config) => {
this.diagnostic?.log(EVENTS.GET_SESSION_CONFIG_REQUEST, {
sessionIdHash: this.getSessionIdHash(),
});
return config;
})
.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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,13 @@ export class WalletLinkConnection {
this.sendData(m);
}

private sendGetSessionConfig(): void {
public sendGetSessionConfig(): Promise<ServerMessage> {
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']) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const web3Methods = [
'scanQRCode',
'generic',
'childRequestEthereumAccounts',
'getSessionConfig',
'addEthereumChain',
'switchEthereumChain',
'makeEthereumJSONRPCRequest',
Expand Down

0 comments on commit 2f56502

Please sign in to comment.