Skip to content

Commit

Permalink
feat: implements registerDeviceToken in Echo
Browse files Browse the repository at this point in the history
  • Loading branch information
Gancho Radkov committed Nov 28, 2023
1 parent 5ebc668 commit 19598a8
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/core/src/constants/echo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const ECHO_CONTEXT = "echo";

export const ECHO_URL = "https://echo.walletconnect.com";
1 change: 1 addition & 0 deletions packages/core/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from "./pairing";
export * from "./history";
export * from "./expirer";
export * from "./verify";
export * from "./echo";
41 changes: 41 additions & 0 deletions packages/core/src/controllers/echo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable no-console */
import { generateChildLogger, Logger } from "@walletconnect/logger";
import { IEcho } from "@walletconnect/types";
import { ECHO_CONTEXT, ECHO_URL } from "../constants";

export class Echo extends IEcho {
public readonly context = ECHO_CONTEXT;
constructor(public projectId: string, public logger: Logger) {
super(projectId, logger);
this.logger = generateChildLogger(logger, this.context);
console.log("Echo constructor called", projectId);
}

public registerDeviceToken: IEcho["registerDeviceToken"] = async (params) => {
const { clientId, token, notificationType, enableAlwaysDecrypted = false } = params;

const echoUrl = `${ECHO_URL}/${this.projectId}/clients`;

console.log("register called", params, echoUrl);
const echoResponse = await fetch(echoUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
client_id: clientId,
type: notificationType,
token,
always_raw: enableAlwaysDecrypted,
}),
});
console.log("echo body", {
client_id: clientId,
type: notificationType,
token,
always_raw: enableAlwaysDecrypted,
});

console.log("echoResponse", echoResponse);
};
}
1 change: 1 addition & 0 deletions packages/core/src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from "./pairing";
export * from "./history";
export * from "./expirer";
export * from "./verify";
export * from "./echo";
4 changes: 3 additions & 1 deletion packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "@walletconnect/logger";
import { CoreTypes, ICore } from "@walletconnect/types";

import { Crypto, Relayer, Pairing, JsonRpcHistory, Expirer, Verify } from "./controllers";
import { Crypto, Relayer, Pairing, JsonRpcHistory, Expirer, Verify, Echo } from "./controllers";
import {
CORE_CONTEXT,
CORE_DEFAULT,
Expand Down Expand Up @@ -39,6 +39,7 @@ export class Core extends ICore {
public expirer: ICore["expirer"];
public pairing: ICore["pairing"];
public verify: ICore["verify"];
public echo: ICore["echo"];

private initialized = false;

Expand Down Expand Up @@ -77,6 +78,7 @@ export class Core extends ICore {
});
this.pairing = new Pairing(this, this.logger);
this.verify = new Verify(this.projectId || "", this.logger);
this.echo = new Echo(this.projectId || "", this.logger);
}

get context() {
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IExpirer } from "./expirer";
import { IPairing } from "./pairing";
import { Logger } from "@walletconnect/logger";
import { IVerify } from "./verify";
import { IEcho } from "./echo";
export declare namespace CoreTypes {
interface Options {
projectId?: string;
Expand Down Expand Up @@ -54,6 +55,7 @@ export abstract class ICore extends IEvents {
public abstract expirer: IExpirer;
public abstract pairing: IPairing;
public abstract verify: IVerify;
public abstract echo: IEcho;

constructor(public opts?: CoreTypes.Options) {
super();
Expand Down
13 changes: 13 additions & 0 deletions packages/types/src/core/echo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Logger } from "@walletconnect/logger";

export abstract class IEcho {
public abstract readonly context: string;
constructor(public projectId: string, public logger: Logger) {}

public abstract registerDeviceToken(params: {
clientId: string;
token: string;
notificationType: "fcm" | "apns" | "apns-sandbox" | "noop";
enableAlwaysDecrypted?: boolean;
}): Promise<void>;
}
1 change: 1 addition & 0 deletions packages/types/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from "./keychain";
export * from "./expirer";
export * from "./pairing";
export * from "./verify";
export * from "./echo";

0 comments on commit 19598a8

Please sign in to comment.