From 79abf70ea0c7ffae3a48f868aabf51f2bdd2fe26 Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Tue, 31 Oct 2023 17:41:12 +0100 Subject: [PATCH 1/3] Fix typo error Fixed error while declaring EthereumWalletRegistry instance. Error caused using Mainnet contracts on Goerli chain resulting with error when SDK is consumed with an entrypoint. --- typescript/src/lib/ethereum/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/src/lib/ethereum/index.ts b/typescript/src/lib/ethereum/index.ts index d61c7eaad..84f9b0f75 100644 --- a/typescript/src/lib/ethereum/index.ts +++ b/typescript/src/lib/ethereum/index.ts @@ -96,7 +96,7 @@ export async function loadEthereumContracts( const tbtcVault = new EthereumTBTCVault({ signerOrProvider: signer }, network) const walletRegistry = new EthereumWalletRegistry( { signerOrProvider: signer }, - "mainnet" + network ) const bridgeWalletRegistry = await bridge.walletRegistry() From a46b0f951d9cacc9d54ce212963f3fab73a52744 Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Wed, 1 Nov 2023 02:11:58 +0100 Subject: [PATCH 2/3] Fix URL API error on the browser The SDK uses a Node implementation of the URL API which is not complementary to the native browser implementation. I have added a conditional that if you have window.URL available then use it, and if you don't have it then fallback to the Node implementation --- typescript/src/lib/electrum/client.ts | 5 ++++- typescript/tsconfig.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/typescript/src/lib/electrum/client.ts b/typescript/src/lib/electrum/client.ts index 881f28564..e0b1a8f79 100644 --- a/typescript/src/lib/electrum/client.ts +++ b/typescript/src/lib/electrum/client.ts @@ -15,12 +15,15 @@ import { } from "../bitcoin" import Electrum from "electrum-client-js" import { BigNumber } from "ethers" -import { URL } from "url" +import { URL as nodeURL } from "url" import { backoffRetrier, Hex, RetrierFn } from "../utils" import MainnetElectrumUrls from "./urls/mainnet.json" import TestnetElectrumUrls from "./urls/testnet.json" +const browserURL = window.URL +const URL = browserURL ?? nodeURL + /** * Represents a set of credentials required to establish an Electrum connection. */ diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index 8584d28ba..8f75788d7 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "ES2017", "module": "commonjs", - "lib": ["es2020"], + "lib": ["es2020", "dom"], "declaration": true, "declarationMap": true, "sourceMap": true, From 4c855eda2cff651b1d08c4b98f5c329d2982e05e Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Wed, 1 Nov 2023 11:15:01 +0100 Subject: [PATCH 3/3] Add environment check It's mandatory to check if `window` element is present in global scope before it's used. --- typescript/src/lib/electrum/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typescript/src/lib/electrum/client.ts b/typescript/src/lib/electrum/client.ts index e0b1a8f79..272c4bbbe 100644 --- a/typescript/src/lib/electrum/client.ts +++ b/typescript/src/lib/electrum/client.ts @@ -21,8 +21,8 @@ import { backoffRetrier, Hex, RetrierFn } from "../utils" import MainnetElectrumUrls from "./urls/mainnet.json" import TestnetElectrumUrls from "./urls/testnet.json" -const browserURL = window.URL -const URL = browserURL ?? nodeURL +const browserURL = typeof window !== "undefined" && window.URL +const URL = nodeURL ?? browserURL /** * Represents a set of credentials required to establish an Electrum connection.