Fix sending transactions on default networks (#78)

* Add default values to networksData state

* Handle review changes

* Get default chains data from constants file
This commit is contained in:
shreerang6921 2024-04-03 15:17:24 +05:30 committed by Nabarun Gogoi
parent 2e18397a95
commit bdd1b58140
2 changed files with 21 additions and 11 deletions

View File

@ -13,20 +13,13 @@ const NetworkDropdown = ({ updateNetwork }: NetworkDropdownProps) => {
const { networksData } = useAccounts();
const networks = useMemo(() => {
const defaultNetworks = [
{ value: 'eth', chainId: 'eip155:1', displayName: 'Ethereum' },
{ value: 'cosmos', chainId: 'cosmos:cosmoshub-4', displayName: 'Cosmos' },
];
networksData.forEach(network => {
defaultNetworks.push({
return networksData.map(network => {
return {
value: network.networkType,
chainId: network.chainId,
displayName: network.networkName,
});
};
});
return defaultNetworks;
}, [networksData]);
const handleNetworkPress = (network: string, displayName: string) => {

View File

@ -1,6 +1,8 @@
import React, { createContext, useContext, useState } from 'react';
import { AccountsState, NetworksDataState } from '../types';
import { EIP155_CHAINS } from '../utils/wallet-connect/EIP155Data';
import { COSMOS_TESTNET_CHAINS } from '../utils/wallet-connect/COSMOSData';
const AccountsContext = createContext<{
accounts: AccountsState;
@ -32,7 +34,22 @@ const AccountsProvider = ({ children }: { children: any }) => {
ethAccounts: [],
cosmosAccounts: [],
});
const [networksData, setNetworksData] = useState<NetworksDataState[]>([]);
const [networksData, setNetworksData] = useState<NetworksDataState[]>([
{
chainId: 'eip155:11155111',
networkName: EIP155_CHAINS['eip155:11155111'].name,
networkType: 'eth',
rpcUrl: EIP155_CHAINS['eip155:11155111'].rpc,
currencySymbol: 'ETH',
},
{
chainId: 'cosmos:theta-testnet-001',
networkName: COSMOS_TESTNET_CHAINS['cosmos:theta-testnet-001'].name,
networkType: 'cosmos',
rpcUrl: COSMOS_TESTNET_CHAINS['cosmos:theta-testnet-001'].rpc,
currencySymbol: 'ATOM',
},
]);
const [currentIndex, setCurrentIndex] = useState<number>(0);
const [networkType, setNetworkType] = useState<string>('eth');
return (