From df45590899d209dbdc706a394a76ad1ace7c7665 Mon Sep 17 00:00:00 2001 From: Reza Rahemtola Date: Mon, 29 Jul 2024 15:40:05 +0200 Subject: [PATCH] feat: Check connection method --- packages/adena-extension/src/inject.ts | 5 +++++ packages/adena-extension/src/inject/executor/executor.ts | 9 ++++++++- .../src/inject/message/message-handler.ts | 3 +++ packages/adena-extension/src/inject/message/message.ts | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/adena-extension/src/inject.ts b/packages/adena-extension/src/inject.ts index b522e3610..7dd3c87bd 100644 --- a/packages/adena-extension/src/inject.ts +++ b/packages/adena-extension/src/inject.ts @@ -19,6 +19,11 @@ const init = (): void => { const response = await executor.addEstablish(name); return response; }, + async CheckConnection(name: string): Promise { + const executor = new AdenaExecutor(); + const response = await executor.checkConnection(name); + return response; + }, async DoContract(message: RequestDoContractMessage): Promise { const executor = new AdenaExecutor(); const response = await executor.doContract(message); diff --git a/packages/adena-extension/src/inject/executor/executor.ts b/packages/adena-extension/src/inject/executor/executor.ts index f9ae41e19..ecff09228 100644 --- a/packages/adena-extension/src/inject/executor/executor.ts +++ b/packages/adena-extension/src/inject/executor/executor.ts @@ -63,6 +63,13 @@ export class AdenaExecutor { return this.sendEventMessage(eventMessage); }; + public checkConnection = (name?: string): Promise => { + const eventMessage = AdenaExecutor.createEventMessage('CHECK_CONNECTION', { + name: name ?? 'Unknown', + }); + return this.sendEventMessage(eventMessage); + }; + public doContract = (params: RequestDoContractMessage): Promise => { const result = this.validateContractMessage(params); if (result) { @@ -139,7 +146,7 @@ export class AdenaExecutor { } }; - private sendEventMessage = (eventMessage: InjectionMessage): Promise => { + private sendEventMessage = async (eventMessage: InjectionMessage): Promise => { this.listen(); this.eventMessage = { ...eventMessage, diff --git a/packages/adena-extension/src/inject/message/message-handler.ts b/packages/adena-extension/src/inject/message/message-handler.ts index 7f8f6a63b..ffd09d23b 100644 --- a/packages/adena-extension/src/inject/message/message-handler.ts +++ b/packages/adena-extension/src/inject/message/message-handler.ts @@ -82,6 +82,9 @@ export class MessageHandler { case 'ADD_ESTABLISH': HandlerMethod.addEstablish(message, sendResponse); break; + case 'CHECK_CONNECTION': + HandlerMethod.checkEstablished(message, sendResponse); + break; case 'ADD_NETWORK': HandlerMethod.checkEstablished(message, sendResponse).then((isEstablished) => { if (isEstablished) { diff --git a/packages/adena-extension/src/inject/message/message.ts b/packages/adena-extension/src/inject/message/message.ts index 610cb2cd5..4df94bead 100644 --- a/packages/adena-extension/src/inject/message/message.ts +++ b/packages/adena-extension/src/inject/message/message.ts @@ -5,6 +5,10 @@ const MESSAGE_TYPES = { code: 0, description: 'Establish Connection.', }, + CHECK_CONNECTION: { + code: 0, + description: 'Check Connection status', + }, DO_CONTRACT: { code: 0, description: 'Do Contract.', @@ -193,6 +197,7 @@ export class InjectionMessageInstance { public getType = (): | 'ADD_ESTABLISH' + | 'CHECK_CONNECTION' | 'DO_CONTRACT' | 'GET_ACCOUNT' | 'SIGN_AMINO'