From c216b110c50711f2bd1daec929a7f694c2efd42d Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Mon, 25 Jul 2022 12:14:39 +0000 Subject: [PATCH 1/2] Handle leading 0x when sub/unsub --- pyth-common-js/src/PriceServiceConnection.ts | 6 +++++- pyth-common-js/src/utils.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pyth-common-js/src/PriceServiceConnection.ts b/pyth-common-js/src/PriceServiceConnection.ts index 2e4922f..ee55dee 100644 --- a/pyth-common-js/src/PriceServiceConnection.ts +++ b/pyth-common-js/src/PriceServiceConnection.ts @@ -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; @@ -147,6 +147,8 @@ export class PriceServiceConnection { await this.startWebSocket(); } + priceIds = priceIds.map((priceId) => removeLeading0xIfExists(priceId)); + const newPriceIds: HexString[] = []; for (const id of priceIds) { @@ -185,6 +187,8 @@ export class PriceServiceConnection { await this.startWebSocket(); } + priceIds = priceIds.map((priceId) => removeLeading0xIfExists(priceId)); + const removedPriceIds: HexString[] = []; for (const id of priceIds) { diff --git a/pyth-common-js/src/utils.ts b/pyth-common-js/src/utils.ts index 0bba9ca..fbd7084 100644 --- a/pyth-common-js/src/utils.ts +++ b/pyth-common-js/src/utils.ts @@ -1,3 +1,5 @@ +import { HexString } from "@pythnetwork/pyth-sdk-js"; + /** * Convert http(s) endpoint to ws(s) endpoint. * @@ -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; + } +} From 2d3c620a2ab38c67a15286358f94429e8ed1f3da Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Mon, 25 Jul 2022 12:15:04 +0000 Subject: [PATCH 2/2] Bump pyth-common-js version to 0.4.0 --- pyth-common-js/package-lock.json | 4 ++-- pyth-common-js/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyth-common-js/package-lock.json b/pyth-common-js/package-lock.json index ae201cd..c7599e2 100644 --- a/pyth-common-js/package-lock.json +++ b/pyth-common-js/package-lock.json @@ -1,12 +1,12 @@ { "name": "@pythnetwork/pyth-common-js", - "version": "0.3.0", + "version": "0.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@pythnetwork/pyth-common-js", - "version": "0.3.0", + "version": "0.4.0", "license": "Apache-2.0", "dependencies": { "@pythnetwork/pyth-sdk-js": "^0.1.0", diff --git a/pyth-common-js/package.json b/pyth-common-js/package.json index 03f8e60..c8b9dc7 100644 --- a/pyth-common-js/package.json +++ b/pyth-common-js/package.json @@ -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"