Skip to content

Commit

Permalink
handle net_version where network may give it as hex
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Jul 11, 2024
1 parent f6a5c16 commit b1a3287
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isHexString } from "@ethereumjs/util";
import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
import { JRPCEngine, JRPCMiddleware, providerFromEngine } from "@toruslabs/openlogin-jrpc";
import { CHAIN_NAMESPACES, CustomChainConfig, WalletInitializationError } from "@web3auth/base";
Expand Down Expand Up @@ -135,7 +136,9 @@ export class EthereumSigningProvider extends BaseProvider<
params: [],
});

if (parseInt(chainId, 16) !== parseInt(network, 10)) throw providerErrors.chainDisconnected(`Invalid network, net_version is: ${network}`);
const finalNetwork = isHexString(network) ? parseInt(network, 16) : parseInt(network, 10);

if (parseInt(chainId, 16) !== finalNetwork) throw providerErrors.chainDisconnected(`Invalid network, net_version is: ${network}`);
if (this.state.chainId !== chainId) {
this.emit("chainChanged", chainId);
this.emit("connect", { chainId });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isHexString } from "@ethereumjs/util";
import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
import { JRPCEngine, JRPCMiddleware, providerFromEngine } from "@toruslabs/openlogin-jrpc";
import { CHAIN_NAMESPACES, CustomChainConfig, WalletInitializationError } from "@web3auth/base";
Expand Down Expand Up @@ -94,7 +95,9 @@ export class EthereumPrivateKeyProvider extends BaseProvider<BaseProviderConfig,
params: [],
});

if (parseInt(chainId, 16) !== parseInt(network, 10)) throw providerErrors.chainDisconnected(`Invalid network, net_version is: ${network}`);
const finalNetwork = isHexString(network) ? parseInt(network, 16) : parseInt(network, 10);

if (parseInt(chainId, 16) !== finalNetwork) throw providerErrors.chainDisconnected(`Invalid network, net_version is: ${network}`);
if (this.state.chainId !== chainId) {
this.emit("chainChanged", chainId);
this.emit("connect", { chainId });
Expand Down

0 comments on commit b1a3287

Please sign in to comment.