import Web3 from "web3";
import Common from "ethereumjs-common";
import {
  //BSC_RPC_URL,
  //ETHER_RPC_URL,
  BSC_NETWORK,
  ETHER_NETWORK,
} from "../constants/allConstants.js";

function getWeb3(NETWORK, RPCurl) {
  if (NETWORK == "bsc") {
    return new Web3(new Web3.providers.HttpProvider(RPCurl));
  } else {
    return new Web3(new Web3.providers.HttpProvider(RPCurl));
  }
}

function commonNetwork(NETWORK) {
  if (NETWORK == "bsc") {
    return Common.default.forCustomChain(
      "mainnet",
      {
        name: "BNB",
        networkId: BSC_NETWORK.MAINNET_CHAIN,
        chainId: BSC_NETWORK.MAINNET_CHAIN,
      },
      "petersburg"
    );
  } else {
    return Common.default.forCustomChain(
      "mainnet",
      {
        name: "ETH",
        networkId: ETHER_NETWORK.MAINNET_CHAIN,
        chainId: ETHER_NETWORK.MAINNET_CHAIN,
      },
      "petersburg"
    );
  }
}

function getChainId(NETWORK) {
  if (NETWORK == "bsc") {
    return BSC_NETWORK.MAINNET_CHAIN;
  } else {
    return ETHER_NETWORK.MAINNET_CHAIN;
  }
}

export { getWeb3, commonNetwork, getChainId };
