Skip to content

Commit c0a0661

Browse files
Use default value for undefined protocols
1 parent b1afadd commit c0a0661

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

packages/snaps-controllers/coverage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"branches": 95.25,
2+
"branches": 95.21,
33
"functions": 98.71,
44
"lines": 98.87,
55
"statements": 98.7

packages/snaps-controllers/src/websocket/WebSocketService.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type InternalSocket = {
7676
id: string;
7777
snapId: SnapId;
7878
url: string;
79-
protocols?: string[];
79+
protocols: string[];
8080
openPromise: Promise<void>;
8181
// eslint-disable-next-line no-restricted-globals
8282
socket: WebSocket;
@@ -148,13 +148,12 @@ export class WebSocketService {
148148
*
149149
* @param snapId - The Snap ID.
150150
* @param url - The URL.
151-
* @param protocols - An optional protocols parameter.
151+
* @param protocols - A protocols parameter.
152152
* @returns True if a matching connection already exists, otherwise false.
153153
*/
154-
#exists(snapId: SnapId, url: string, protocols?: string[]) {
154+
#exists(snapId: SnapId, url: string, protocols: string[]) {
155155
return this.#getAll(snapId).some(
156-
(socket) =>
157-
socket.url === url && isEqual(socket.protocols ?? [], protocols ?? []),
156+
(socket) => socket.url === url && isEqual(socket.protocols, protocols),
158157
);
159158
}
160159

@@ -189,7 +188,7 @@ export class WebSocketService {
189188
* @returns The identifier for the opened connection.
190189
* @throws If the connection fails.
191190
*/
192-
async #open(snapId: SnapId, url: string, protocols?: string[]) {
191+
async #open(snapId: SnapId, url: string, protocols: string[] = []) {
193192
assert(
194193
!this.#exists(snapId, url, protocols),
195194
`An open WebSocket connection to ${url} already exists.`,
@@ -325,7 +324,7 @@ export class WebSocketService {
325324
.map((socket) => ({
326325
id: socket.id,
327326
url: socket.url,
328-
...(socket.protocols ? { protocols: socket.protocols } : {}),
327+
protocols: socket.protocols,
329328
}));
330329
}
331330
}

packages/snaps-sdk/src/types/methods/get-web-sockets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ export type GetWebSocketsParams = never;
1111
export type GetWebSocketsResult = {
1212
id: string;
1313
url: string;
14-
protocols?: string[];
14+
protocols: string[];
1515
}[];

0 commit comments

Comments
 (0)