diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/platform/dev.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/dev.ts | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/packages/taler-wallet-webextension/src/platform/dev.ts b/packages/taler-wallet-webextension/src/platform/dev.ts index 8a410b062..df40b29e7 100644 --- a/packages/taler-wallet-webextension/src/platform/dev.ts +++ b/packages/taler-wallet-webextension/src/platform/dev.ts @@ -15,7 +15,14 @@ */ import { CoreApiResponse } from "@gnu-taler/taler-util"; -import { MessageFromBackend, PlatformAPI } from "./api.js"; +import { WalletOperations } from "@gnu-taler/taler-wallet-core"; +import { BackgroundOperations } from "../wxApi.js"; +import { + MessageFromBackend, + MessageFromFrontend, + MessageResponse, + PlatformAPI, +} from "./api.js"; const frames = ["popup", "wallet"]; @@ -121,12 +128,17 @@ const api: PlatformAPI = { window.parent.removeEventListener("message", listener); }; }, - sendMessageToWalletBackground: async (operation: string, payload: any) => { + + sendMessageToBackground: async < + Op extends WalletOperations | BackgroundOperations, + >( + payload: MessageFromFrontend<Op>, + ): Promise<MessageResponse> => { const replyMe = `reply-${Math.floor(Math.random() * 100000)}`; const message: IframeMessageCommand = { type: "command", header: { replyMe }, - body: { operation, payload, id: "(none)" }, + body: payload, }; window.parent.postMessage(message); @@ -150,6 +162,7 @@ type IframeMessageType = | IframeMessageNotification | IframeMessageResponse | IframeMessageCommand; + interface IframeMessageNotification { type: "notification"; header: Record<string, never>; @@ -160,7 +173,7 @@ interface IframeMessageResponse { header: { responseId: string; }; - body: CoreApiResponse; + body: MessageResponse; } interface IframeMessageCommand { @@ -168,11 +181,7 @@ interface IframeMessageCommand { header: { replyMe: string; }; - body: { - operation: any; - id: string; - payload: any; - }; + body: MessageFromFrontend<any>; } export default api; |