Skip to content

Commit

Permalink
chore: disambiguate keplr / fetch API proxy message namespace (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite authored Jul 5, 2022
1 parent f1983a2 commit 584c7ad
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/provider/src/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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),
Expand All @@ -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(),
Expand All @@ -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),
Expand All @@ -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;
}

Expand Down

0 comments on commit 584c7ad

Please sign in to comment.