-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implements
registerDeviceToken
in Echo
- Loading branch information
Gancho Radkov
committed
Nov 28, 2023
1 parent
5ebc668
commit 19598a8
Showing
8 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters