From bdd1b58140f2412aece8abc3f4073f69129a4e02 Mon Sep 17 00:00:00 2001 From: shreerang6921 <68148922+shreerang6921@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:17:24 +0530 Subject: [PATCH] Fix sending transactions on default networks (#78) * Add default values to networksData state * Handle review changes * Get default chains data from constants file --- src/components/NetworkDropdown.tsx | 13 +++---------- src/context/AccountsContext.tsx | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/components/NetworkDropdown.tsx b/src/components/NetworkDropdown.tsx index c6a76b8..0abfee3 100644 --- a/src/components/NetworkDropdown.tsx +++ b/src/components/NetworkDropdown.tsx @@ -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) => { diff --git a/src/context/AccountsContext.tsx b/src/context/AccountsContext.tsx index 1acb946..9e06d63 100644 --- a/src/context/AccountsContext.tsx +++ b/src/context/AccountsContext.tsx @@ -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([]); + const [networksData, setNetworksData] = useState([ + { + 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(0); const [networkType, setNetworkType] = useState('eth'); return (