Auto-populate eth chain data from chain id (#96)

* Auto-populate eth data from json file

* Modify variable names

* Clear fields if chainId is not found

* Format code

* Fix indentation

* Use reset to clear values

* Exclude chain id while resetting

* Make review changes

* Fix format
This commit is contained in:
IshaVenikar authored and Nabarun Gogoi committed 2024-04-25 17:08:27 +05:30
1 parent 33147bee0d
commit 888302a0dd
3 files changed
+22 -3

No files matched your search

+1
View File
@@ -0,0 +1 @@
[{"name":"Ethereum Mainnet","chain":"ETH","icon":"ethereum","rpc":["https://mainnet.infura.io/v3/${INFURA_API_KEY}","wss://mainnet.infura.io/ws/v3/${INFURA_API_KEY}","https://api.mycryptoapi.com/eth","https://cloudflare-eth.com","https://ethereum-rpc.publicnode.com","wss://ethereum-rpc.publicnode.com","https://mainnet.gateway.tenderly.co","wss://mainnet.gateway.tenderly.co","https://rpc.blocknative.com/boost","https://rpc.flashbots.net","https://rpc.flashbots.net/fast","https://rpc.mevblocker.io","https://rpc.mevblocker.io/fast","https://rpc.mevblocker.io/noreverts","https://rpc.mevblocker.io/fullprivacy","https://eth.drpc.org","wss://eth.drpc.org"],"features":[{"name":"EIP155"},{"name":"EIP1559"}],"faucets":[],"nativeCurrency":{"name":"Ether","symbol":"ETH","decimals":18},"infoURL":"https://ethereum.org","shortName":"eth","chainId":1,"networkId":1,"slip44":60,"ens":{"registry":"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},"explorers":[{"name":"etherscan","url":"https://etherscan.io","standard":"EIP3091"},{"name":"blockscout","url":"https://eth.blockscout.com","icon":"blockscout","standard":"EIP3091"},{"name":"dexguru","url":"https://ethereum.dex.guru","icon":"dexguru","standard":"EIP3091"}]},{"name":"Expanse Network","chain":"EXP","rpc":["https://node.expanse.tech"],"faucets":[],"nativeCurrency":{"name":"Expanse Network Ether","symbol":"EXP","decimals":18},"infoURL":"https://expanse.tech","shortName":"exp","chainId":2,"networkId":1,"slip44":40},{"name":"Ropsten","title":"Ethereum Testnet Ropsten","chain":"ETH","rpc":["https://ropsten.infura.io/v3/${INFURA_API_KEY}","wss://ropsten.infura.io/ws/v3/${INFURA_API_KEY}"],"faucets":["http://fauceth.komputing.org?chain=3&address=${ADDRESS}","https://faucet.ropsten.be?${ADDRESS}"],"nativeCurrency":{"name":"Ropsten Ether","symbol":"ETH","decimals":18},"infoURL":"https://github.com/ethereum/ropsten","shortName":"rop","chainId":3,"networkId":3,"slip44":1,"ens":{"registry":"0x112234455c3a32fd11230c42e7bccd4a84e02010"},"explorers":[{"name":"etherscan","url":"https://ropsten.etherscan.io","standard":"EIP3091"}]},{"name":"Rinkeby","title":"Ethereum Testnet Rinkeby","chain":"ETH","rpc":["https://rinkeby.infura.io/v3/${INFURA_API_KEY}","wss://rinkeby.infura.io/ws/v3/${INFURA_API_KEY}"],"faucets":["http://fauceth.komputing.org?chain=4&address=${ADDRESS}","https://faucet.rinkeby.io"],"nativeCurrency":{"name":"Rinkeby Ether","symbol":"ETH","decimals":18},"infoURL":"https://www.rinkeby.io","shortName":"rin","chainId":4,"networkId":4,"slip44":1,"ens":{"registry":"0xe7410170f87102df0055eb195163a03b7f2bff4a"},"explorers":[{"name":"etherscan-rinkeby","url":"https://rinkeby.etherscan.io","standard":"EIP3091"}]},{"name":"Goerli","title":"Ethereum Testnet Goerli","chain":"ETH","rpc":["https://goerli.infura.io/v3/${INFURA_API_KEY}","wss://goerli.infura.io/v3/${INFURA_API_KEY}","https://rpc.goerli.mudit.blog/","https://ethereum-goerli-rpc.publicnode.com","wss://ethereum-goerli-rpc.publicnode.com","https://goerli.gateway.tenderly.co","wss://goerli.gateway.tenderly.co"],"faucets":["http://fauceth.komputing.org?chain=5&address=${ADDRESS}","https://goerli-faucet.slock.it?address=${ADDRESS}","https://faucet.goerli.mudit.blog"],"nativeCurrency":{"name":"Goerli Ether","symbol":"ETH","decimals":18},"infoURL":"https://goerli.net/#about","shortName":"gor","chainId":5,"networkId":5,"slip44":1,"ens":{"registry":"0x112234455c3a32fd11230c42e7bccd4a84e02010"},"explorers":[{"name":"etherscan-goerli","url":"https://goerli.etherscan.io","standard":"EIP3091"},{"name":"blockscout-goerli","url":"https://eth-goerli.blockscout.com","icon":"blockscout","standard":"EIP3091"}]},{"name":"Kotti Testnet","title":"Ethereum Classic Kotti Testnet","status":"deprecated","chain":"ETC","icon":"ethereumclassictestnet","rpc":[],"faucets":[],"nativeCurrency":{"name":"Kotti Ether","symbol":"KOT","decimals":18},"infoURL":"https://ethereumclassic.org/development/testnets","shortName":"kot","chainId":6,"networkId":6,"slip44":1},{"name":"ThaiChain","chain":"TCH","rpc":["https://rpc.dome.cloud","https://rpc.thaichain.org"],"faucets":[],"features":[{"name":"EIP155"},{"name":"EIP1559"}],"nativeCurrency":{"name":"ThaiChain Ether","symbol":"TCH","decimals":18},"infoURL":"https://thaichain.io","shortName":"tch","chainId":7,"networkId":7,"explorers":[{"name":"Thaichain Explorer","url":"https://exp.thaichain.org","standard":"EIP3091"}]},{"name":"Ubiq","chain":"UBQ","rpc":["https://rpc.octano.dev","https://pyrus2.ubiqscan.io"],"faucets":[],"nativeCurrency":{"name":"Ubiq Ether","symbol":"UBQ","decimals":18},"infoURL":"https://ubiqsmart.com","shortName":"ubq","chainId":8,"networkId":8,"slip44":108,"explorers":[{"name":"ubiqscan","url":"https://ubiqscan.io","standard":"EIP3091"}]},{"name":"Ubiq Network Testnet","chain":"UBQ","rpc":[],"faucets":[],"nativeCurrency":{"name":"Ubiq Testnet Ether","symbol":"TUBQ","decimals":18},"infoURL":"https://ethersocial.org","shortName":"tubq","chainId":9,"networkId":2,"slip44":1},{"name":"OP Mainnet","chaiLine truncated
+19 -3
View File
@@ -18,8 +18,9 @@ import { NetworksDataState, NetworksFormData, StackParamsList } from '../types';
import { SelectNetworkType } from '../components/SelectNetworkType';
import { storeNetworkData } from '../utils/accounts';
import { useNetworks } from '../context/NetworksContext';
import { COSMOS, EIP155 } from '../utils/constants';
import { COSMOS, EIP155, CHAINID_DEBOUNCE_DELAY } from '../utils/constants';
import { getCosmosAccounts } from '../utils/accounts';
import ETH_CHAINS from '../assets/ethereum-chains.json';
// TODO: Add validation to form inputs
const AddNetwork = () => {
@@ -31,6 +32,7 @@ const AddNetwork = () => {
formState: { errors, isValid },
handleSubmit,
setValue,
reset,
} = useForm<NetworksDataState>({
mode: 'onChange',
});
@@ -49,11 +51,25 @@ const AddNetwork = () => {
};
const fetchChainDetails = useDebouncedCallback((chainId: string) => {
if (namespace === EIP155) {
const ethChainDetails = ETH_CHAINS.find(
chain => chain.chainId === Number(chainId),
);
if (!ethChainDetails) {
reset({ chainId: chainId });
return;
}
setValue('networkName', ethChainDetails.name);
setValue('rpcUrl', ethChainDetails.rpc[0]);
setValue('blockExplorerUrl', ethChainDetails.explorers![0].url);
setValue('coinType', String(ethChainDetails.slip44));
setValue('currencySymbol', ethChainDetails.nativeCurrency.symbol);
}
const cosmosChainDetails = chains.find(
({ chain_id }) => chain_id === chainId,
);
if (!cosmosChainDetails) {
reset({ chainId: chainId });
return;
}
setValue('networkName', cosmosChainDetails.pretty_name);
@@ -62,7 +78,7 @@ const AddNetwork = () => {
setValue('addressPrefix', cosmosChainDetails.bech32_prefix);
setValue('coinType', String(cosmosChainDetails.slip44));
setValue('nativeDenom', cosmosChainDetails.fees?.fee_tokens[0].denom || '');
}, 2000);
}, CHAINID_DEBOUNCE_DELAY);
const submit = useCallback(
async (data: NetworksFormData) => {
+2
View File
@@ -24,3 +24,5 @@ export const DEFAULT_NETWORKS = [
isDefault: true,
},
];
export const CHAINID_DEBOUNCE_DELAY = 250;