From 584c7ad652c54ee99df948f1f61d8ed318b74327 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 5 Jul 2022 11:31:16 +0200 Subject: [PATCH] chore: disambiguate keplr / fetch API proxy message namespace (#54) --- packages/provider/src/inject.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/provider/src/inject.ts b/packages/provider/src/inject.ts index 7a7fd2283a..6ead5c5515 100644 --- a/packages/provider/src/inject.ts +++ b/packages/provider/src/inject.ts @@ -26,14 +26,14 @@ import deepmerge from "deepmerge"; import Long from "long"; export interface ProxyRequest { - type: "proxy-request"; + type: "fetchai:proxy-request-v1"; id: string; method: keyof Keplr; args: any[]; } export interface ProxyRequestResponse { - type: "proxy-request-response"; + type: "fetchai:proxy-request-response-v1"; id: string; result: Result | undefined; } @@ -62,7 +62,7 @@ export class InjectedKeplr implements IKeplr { const message: ProxyRequest = parseMessage ? parseMessage(e.data) : e.data; - if (!message || message.type !== "proxy-request") { + if (!message || message.type !== "fetchai:proxy-request-v1") { return; } @@ -149,7 +149,7 @@ export class InjectedKeplr implements IKeplr { ); const proxyResponse: ProxyRequestResponse = { - type: "proxy-request-response", + type: "fetchai:proxy-request-response-v1", id: message.id, result: { return: JSONUint8Array.wrap(result), @@ -159,7 +159,7 @@ export class InjectedKeplr implements IKeplr { eventListener.postMessage(proxyResponse); } catch (e) { const proxyResponse: ProxyRequestResponse = { - type: "proxy-request-response", + type: "fetchai:proxy-request-response-v1", id: message.id, result: { error: e.message || e.toString(), @@ -180,7 +180,7 @@ export class InjectedKeplr implements IKeplr { .join(""); const proxyMessage: ProxyRequest = { - type: "proxy-request", + type: "fetchai:proxy-request-v1", id, method, args: JSONUint8Array.wrap(args), @@ -192,7 +192,10 @@ export class InjectedKeplr implements IKeplr { ? this.parseMessage(e.data) : e.data; - if (!proxyResponse || proxyResponse.type !== "proxy-request-response") { + if ( + !proxyResponse || + proxyResponse.type !== "fetchai:proxy-request-response-v1" + ) { return; }