Skip to content

Commit

Permalink
Merge pull request #182 from enkryptcom/devop/switch-chainid-hex
Browse files Browse the repository at this point in the history
devop: switch chainId to hex string
  • Loading branch information
kvhnuke authored Nov 1, 2022
2 parents c340e2c + 724ddb2 commit e382fc3
Show file tree
Hide file tree
Showing 23 changed files with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface SupportedNetwork {
cgPlatform: string;
}
export interface CGToken {
chainId: number;
chainId: `0x${string}`;
address: string;
name: string;
symbol: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { getCustomError } from "@/libs/error";
import { MiddlewareFunction } from "@enkryptcom/types";
import EthNetworks from "../networks";
import EthereumProvider from "..";
import { numberToHex } from "web3-utils";
import { sendToBackgroundFromBackground } from "@/libs/messenger/extension";
import { InternalMethods } from "@/types/messenger";
import { ProviderRPCRequest } from "@/types/provider";
Expand All @@ -26,7 +25,7 @@ const method: MiddlewareFunction = function (
}
const allNetworks = Object.values(EthNetworks);
const validNetwork = allNetworks.find(
(net) => numberToHex(net.chainID) === payload.params![0].chainId
(net) => net.chainID === payload.params![0].chainId
);
if (validNetwork) {
sendToBackgroundFromBackground({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ProviderRPCRequest } from "@/types/provider";
import { MiddlewareFunction } from "@enkryptcom/types";
import EthNetworks from "../networks";
import EthereumProvider from "..";
import { numberToHex } from "web3-utils";
import { MessageMethod } from "../types";
import DomainState from "@/libs/domain-state";
const method: MiddlewareFunction = function (
Expand All @@ -25,7 +24,7 @@ const method: MiddlewareFunction = function (
}
const allNetworks = Object.values(EthNetworks);
const validNetwork = allNetworks.find(
(net) => numberToHex(net.chainID) === payload.params![0].chainId
(net) => net.chainID === payload.params![0].chainId
);
if (validNetwork) {
sendToBackgroundFromBackground({
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/networks/astr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const astrOptions: EvmNetworkOptions = {
homePage: "https://astar.network/",
blockExplorerTX: "https://blockscout.com/astar/tx/[[txHash]]",
blockExplorerAddr: "https://blockscout.com/astar/address/[[address]]",
chainID: 592,
chainID: "0x250",
isTestNetwork: false,
currencyName: "ASTR",
node: "wss://astar.public.blastapi.io/",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/networks/bsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const bscOptions: EvmNetworkOptions = {
homePage: "https://www.binance.org/en/smartChain",
blockExplorerTX: "https://bscscan.com/tx/[[txHash]]",
blockExplorerAddr: "https://bscscan.com/address/[[address]]",
chainID: 56,
chainID: "0x38",
isTestNetwork: false,
currencyName: "BNB",
node: "wss://nodes.mewapi.io/ws/bsc",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/networks/etc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const etcOptions: EvmNetworkOptions = {
homePage: "https://ethereumclassic.org/",
blockExplorerTX: "https://blockscout.com/etc/mainnet/tx/[[txHash]]",
blockExplorerAddr: "https://blockscout.com/etc/mainnet/address/[[address]]",
chainID: 61,
chainID: "0x3d",
isTestNetwork: false,
currencyName: "ETC",
node: "wss://nodes.mewapi.io/ws/etc",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/networks/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ethOptions: EvmNetworkOptions = {
homePage: "https://ethereum.org",
blockExplorerTX: "https://www.ethvm.com/tx/[[txHash]]",
blockExplorerAddr: "https://www.ethvm.com/address/[[address]]",
chainID: 1,
chainID: "0x1",
isTestNetwork: false,
currencyName: "ETH",
node: "wss://nodes.mewapi.io/ws/eth",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const goerliOptions: EvmNetworkOptions = {
homePage: "https://github.com/goerli/testnet",
blockExplorerTX: "https://goerli.etherscan.io/tx/[[txHash]]",
blockExplorerAddr: "https://goerli.etherscan.io/address/[[address]]",
chainID: 5,
chainID: "0x5",
isTestNetwork: true,
currencyName: "GöETH",
node: "wss://nodes.mewapi.io/ws/goerli",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const karuraOptions: EvmNetworkOptions = {
homePage: "https://karura.network",
blockExplorerTX: "https://blockscout.karura.network/tx/[[txHash]]",
blockExplorerAddr: "https://blockscout.karura.network/address/[[address]]",
chainID: 686,
chainID: "0x2ae",
isTestNetwork: false,
currencyName: "KAR",
node: "wss://eth-rpc-karura.aca-api.network/ws",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/networks/kov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const kovOptions: EvmNetworkOptions = {
homePage: "https://github.com/kovan-testnet",
blockExplorerTX: "https://kovan.etherscan.io/tx/[[txHash]]",
blockExplorerAddr: "https://kovan.etherscan.io/address/[[address]]",
chainID: 42,
chainID: "0x2a",
isTestNetwork: true,
currencyName: "KOV",
node: "wss://nodes.mewapi.io/ws/kovan",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const maticOptions: EvmNetworkOptions = {
homePage: "https://polygonscan.com/",
blockExplorerTX: "https://polygonscan.com/tx/[[txHash]]",
blockExplorerAddr: "https://polygonscan.com/address/[[address]]",
chainID: 137,
chainID: "0x89",
isTestNetwork: false,
currencyName: "MATIC",
node: "wss://nodes.mewapi.io/ws/matic",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const moonbeamOptions: EvmNetworkOptions = {
homePage: "https://moonbeam.network",
blockExplorerTX: "https://moonscan.io/tx/[[txHash]]",
blockExplorerAddr: "https://moonscan.io/address/[[address]]",
chainID: 1284,
chainID: "0x504",
isTestNetwork: false,
currencyName: "GLMR",
node: "wss://wss.api.moonbeam.network/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const moonriverOptions: EvmNetworkOptions = {
homePage: "https://moonbeam.network/networks/moonriver/",
blockExplorerTX: "https://moonriver.moonscan.io//tx/[[txHash]]",
blockExplorerAddr: "https://moonriver.moonscan.io/address/[[address]]",
chainID: 1285,
chainID: "0x505",
isTestNetwork: false,
currencyName: "MOVR",
node: "wss://wss.api.moonriver.moonbeam.network",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/networks/okc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const okcOptions: EvmNetworkOptions = {
homePage: "https://www.oklink.com/en/okc",
blockExplorerTX: "https://www.oklink.com/en/okc/tx/[[txHash]]",
blockExplorerAddr: "https://www.oklink.com/en/okc/address/[[address]]",
chainID: 66,
chainID: "0x42",
isTestNetwork: false,
currencyName: "OKT",
node: "https://exchainrpc.okex.org",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/networks/rin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const rinOptions: EvmNetworkOptions = {
homePage: "https://www.rinkeby.io/",
blockExplorerTX: "https://rinkeby.etherscan.io/tx/[[txHash]]",
blockExplorerAddr: "https://rinkeby.etherscan.io/address/[[address]]",
chainID: 4,
chainID: "0x4",
isTestNetwork: true,
currencyName: "RIN",
node: "wss://nodes.mewapi.io/ws/rinkeby",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/networks/rop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ropOptions: EvmNetworkOptions = {
homePage: "https://github.com/ethereum/ropsten",
blockExplorerTX: "https://ropsten.etherscan.io/tx/[[txHash]]",
blockExplorerAddr: "https://ropsten.etherscan.io/address/[[address]]",
chainID: 3,
chainID: "0x3",
isTestNetwork: true,
currencyName: "ROP",
node: "wss://nodes.mewapi.io/ws/rop",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/networks/sdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const sdnOptions: EvmNetworkOptions = {
homePage: "https://shiden.astar.network/",
blockExplorerTX: "https://blockscout.com/shiden/tx/[[txHash]]",
blockExplorerAddr: "https://blockscout.com/shiden/address/[[address]]",
chainID: 336,
chainID: "0x150",
isTestNetwork: false,
currencyName: "SDN",
node: "wss://shiden.public.blastapi.io",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface EvmNetworkOptions {
homePage: string;
blockExplorerTX: string;
blockExplorerAddr: string;
chainID: number;
chainID: `0x${string}`;
isTestNetwork: boolean;
currencyName: string;
currencyNameLong?: string;
Expand All @@ -52,7 +52,7 @@ export interface EvmNetworkOptions {
}

export class EvmNetwork extends BaseNetwork {
public chainID: number;
public chainID: `0x${string}`;

private assetsInfoHandler?: (
network: BaseNetwork,
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface EthereumRequest {

export interface EthereumNodeType extends NodeType {
signer: [SignerType.secp256k1];
chainID: number;
chainID: `0x${string}`;
}

export interface ERC20TokenInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ const TxInfo = computed<SendTransactionDataType>(() => {
)
.encodeABI();
return {
chainId: numberToHex(props.network.chainID) as `0x{string}`,
chainId: props.network.chainID,
from: addressFrom.value as `0x{string}`,
value: value as `0x${string}`,
to: toAddress as `0x${string}`,
Expand Down Expand Up @@ -349,7 +349,7 @@ const setBaseCosts = () => {
const web3 = new Web3Eth(props.network.node);
const tx = new Transaction(
{
chainId: numberToHex(props.network.chainID) as `0x{string}`,
chainId: props.network.chainID,
from: props.accountInfo.selectedAccount!.address as `0x{string}`,
value: "0x0",
to: NATIVE_TOKEN_ADDRESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TransactionInfo,
} from "./SwapProvider";
import { toBase } from "@/libs/utils/units";
import { numberToHex, toBN } from "web3-utils";
import { toBN } from "web3-utils";
import { BaseNetwork } from "@/types/base-network";
import { EnkryptAccount, NetworkNames } from "@enkryptcom/types";
import { EvmNetwork } from "@/providers/ethereum/types/evm-network";
Expand Down Expand Up @@ -701,7 +701,7 @@ export class ChangellySwapProvider extends SwapProvider {
to: to as `0x${string}`,
data,
value,
chainId: numberToHex((network as EvmNetwork).chainID) as `0x{string}`,
chainId: (network as EvmNetwork).chainID,
},
web3
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { BaseToken } from "@/types/base-token";
import { EnkryptAccount, NetworkNames } from "@enkryptcom/types";
import BigNumber from "bignumber.js";
import Web3Eth from "web3-eth";
import { isAddress, numberToHex, toBN } from "web3-utils";
import { isAddress, toBN } from "web3-utils";
import {
Quote,
QuoteInfo,
Expand Down Expand Up @@ -389,7 +389,7 @@ export class EvmSwapProvider extends SwapProvider {
data,
value,
gas,
chainId: numberToHex(network.chainID) as `0x{string}`,
chainId: network.chainID,
nonce: `0x${toBN(nonce)
.addn(index)
.toString("hex")}` as `0x${string}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import { BaseToken } from "@/types/base-token";
import { Swap } from "@/providers/swap";
import { BaseNetwork } from "@/types/base-network";
import { AccountsHeaderData } from "../../types/account";
import { numberToHex, toBN } from "web3-utils";
import { toBN } from "web3-utils";
import BN from "bn.js";
import Web3Eth from "web3-eth";
import Transaction from "@/providers/ethereum/libs/transaction";
Expand Down Expand Up @@ -252,9 +252,7 @@ const Tx = computed(() => {
to: txData.to as `0x${string}`,
from: txData.from as `0x${string}`,
data: txData.data,
chainId: numberToHex(
(props.network as EvmNetwork).chainID
) as `0x${string}`,
chainId: (props.network as EvmNetwork).chainID,
value: txData.value,
gas: txData.gas,
},
Expand Down

0 comments on commit e382fc3

Please sign in to comment.