Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyth-common-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyth-common-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/pyth-common-js",
"version": "0.3.0",
"version": "0.4.0",
"description": "Pyth Network Common Utils in JS",
"author": {
"name": "Pyth Data Association"
Expand Down
6 changes: 5 additions & 1 deletion pyth-common-js/src/PriceServiceConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import axiosRetry from "axios-retry";
import * as WebSocket from "isomorphic-ws";
import { Logger } from "ts-log";
import { ResilientWebSocket } from "./ResillientWebSocket";
import { makeWebsocketUrl } from "./utils";
import { makeWebsocketUrl, removeLeading0xIfExists } from "./utils";

export type DurationInMs = number;

Expand Down Expand Up @@ -147,6 +147,8 @@ export class PriceServiceConnection {
await this.startWebSocket();
}

priceIds = priceIds.map((priceId) => removeLeading0xIfExists(priceId));

const newPriceIds: HexString[] = [];

for (const id of priceIds) {
Expand Down Expand Up @@ -185,6 +187,8 @@ export class PriceServiceConnection {
await this.startWebSocket();
}

priceIds = priceIds.map((priceId) => removeLeading0xIfExists(priceId));

const removedPriceIds: HexString[] = [];

for (const id of priceIds) {
Expand Down
10 changes: 10 additions & 0 deletions pyth-common-js/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HexString } from "@pythnetwork/pyth-sdk-js";

/**
* Convert http(s) endpoint to ws(s) endpoint.
*
Expand All @@ -12,3 +14,11 @@ export function makeWebsocketUrl(endpoint: string) {

return url.toString();
}

export function removeLeading0xIfExists(id: HexString): HexString {
if (id.startsWith("0x")) {
return id.substring(2);
} else {
return id;
}
}