Skip to content

Commit

Permalink
Merge pull request #210 from pollum-io/feat/add-istestnet-prop
Browse files Browse the repository at this point in the history
feat: add isTestnet property in network object
  • Loading branch information
lucasgabrielgsp authored Dec 8, 2023
2 parents d989e6c + 069f2f1 commit 7608515
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/sysweb3-keyring/src/initial-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const initialNetworksState = {
apiUrl: '',
explorer: 'https://blockbook.elint.services/',
slip44: 57,
isTestnet: false,
},
5700: {
chainId: 5700,
Expand All @@ -57,6 +58,7 @@ export const initialNetworksState = {
apiUrl: '',
explorer: '',
slip44: 5700,
isTestnet: true,
},
},
ethereum: {
Expand All @@ -68,6 +70,7 @@ export const initialNetworksState = {
currency: 'eth',
explorer: 'https://etherscan.io/',
apiUrl: 'https://api.etherscan.io/api',
isTestnet: false,
},
137: {
chainId: 137,
Expand All @@ -77,6 +80,7 @@ export const initialNetworksState = {
url: 'https://polygon-rpc.com',
apiUrl: 'https://api.polygonscan.com/api',
explorer: 'https://polygonscan.com/',
isTestnet: false,
},
80001: {
chainId: 80001,
Expand All @@ -86,6 +90,7 @@ export const initialNetworksState = {
url: 'https://endpoints.omniatech.io/v1/matic/mumbai/public',
apiUrl: 'https://api-testnet.polygonscan.com/api',
explorer: 'https://mumbai.polygonscan.com/',
isTestnet: true,
},
57: {
chainId: 57,
Expand All @@ -95,6 +100,7 @@ export const initialNetworksState = {
url: 'https://rpc.syscoin.org',
apiUrl: 'https://explorer.syscoin.org/api',
explorer: 'https://explorer.syscoin.org/',
isTestnet: false,
},
570: {
chainId: 570,
Expand All @@ -104,6 +110,7 @@ export const initialNetworksState = {
url: 'https://rpc.rollux.com',
apiUrl: 'https://explorer.rollux.com/api',
explorer: 'https://explorer.rollux.com/',
isTestnet: false,
},
5700: {
chainId: 5700,
Expand All @@ -113,6 +120,7 @@ export const initialNetworksState = {
url: 'https://rpc.tanenbaum.io',
apiUrl: 'https://tanenbaum.io/api',
explorer: 'https://tanenbaum.io/',
isTestnet: true,
},
},
};
Expand Down Expand Up @@ -141,5 +149,6 @@ export const initialWalletState: IWalletState = {
url: 'https://blockbook.elint.services/',
default: true,
currency: 'sys',
isTestnet: false,
},
};
1 change: 1 addition & 0 deletions packages/sysweb3-network/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export type INetwork = {
currency?: string;
explorer?: string;
slip44?: number;
isTestnet: boolean;
};

export enum INetworkType {
Expand Down
12 changes: 11 additions & 1 deletion packages/sysweb3-network/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const validateEthRpc = async (
valid: boolean;
hexChainId: string;
details: Chain | undefined;
isTestnet: boolean;
chain: string;
}> => {
try {
Expand All @@ -104,11 +105,18 @@ export const validateEthRpc = async (
throw new Error('RPC has an invalid chain ID');
}

const ethTestnetsChainsIds = [5700, 80001, 11155111, 421611, 5, 69]; // Some ChainIds from Ethereum Testnets as Polygon Testnet, Goerli, Sepolia, etc.

const isTestnet = details
? details.name.toLowerCase().includes('test')
: ethTestnetsChainsIds.includes(chainId); // Fallback for RPCs that don't have details

return {
chainId,
details,
chain: details && details.chain ? details.chain : 'unknown',
hexChainId,
isTestnet,
valid,
};
} catch (error) {
Expand All @@ -123,7 +131,7 @@ export const getEthRpc = async (
formattedNetwork: INetwork;
}> => {
const endsWithSlash = /\/$/;
const { valid, hexChainId, details } = await validateEthRpc(
const { valid, hexChainId, details, isTestnet } = await validateEthRpc(
data.url,
isInCooldown
);
Expand All @@ -149,6 +157,7 @@ export const getEthRpc = async (
explorer: String(explorer),
currency: details ? details.nativeCurrency.symbol : data.symbol,
chainId: chainIdNumber,
isTestnet,
};

return {
Expand Down Expand Up @@ -264,6 +273,7 @@ export const getSysRpc = async (data: any) => {
slip44: networkConfig
? networkConfig.networks[networkType].slip44
: syscoinSLIP,
isTestnet: chain === 'test',
};
const rpc = {
formattedNetwork,
Expand Down

0 comments on commit 7608515

Please sign in to comment.