From 7707586c575ac567b9d5c982cc5f9038b8b9154a Mon Sep 17 00:00:00 2001 From: Linkie Link Date: Thu, 4 Jan 2024 17:02:59 +0100 Subject: [PATCH] Cleanup env variables (#713) * fix: cleaned up env variables and disabled chain selector if there is only one chain * env: update .env.example --- .env.example | 22 +++++++------ src/components/Header/ChainSelect.tsx | 20 +++++++++--- src/components/Trade/TradeChart/DataFeed.ts | 1 - .../Wallet/WalletConnectProvider.tsx | 5 +++ src/components/Wallet/WalletConnecting.tsx | 18 ++--------- src/configs/chains/neutron/pion-1.ts | 8 ++--- src/configs/chains/osmosis/devnet.ts | 3 +- src/configs/chains/osmosis/osmosis-1.ts | 8 ++--- src/constants/env.ts | 28 ---------------- src/types/enums/network.ts | 1 - src/types/interfaces/chain.d.ts | 2 +- src/utils/getCurrentChainId.ts | 32 +++++++++++++++---- 12 files changed, 70 insertions(+), 78 deletions(-) delete mode 100644 src/constants/env.ts diff --git a/.env.example b/.env.example index b58110df..4c14646e 100644 --- a/.env.example +++ b/.env.example @@ -1,11 +1,15 @@ -NEXT_PUBLIC_OSMOSIS1_RPC='https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-rpc-front/' -NEXT_PUBLIC_OSMOSIS1_REST='https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/' -NEXT_PUBLIC_OSMOSIS_DEVNET_RPC='https://rpc.devnet.osmosis.zone/' -NEXT_PUBLIC_OSMOSIS_DEVNET_REST='https://lcd.devnet.osmosis.zone/' -NEXT_PUBLIC_PION1_RPC='https://rpc-palvus.pion-1.ntrn.tech/' -NEXT_PUBLIC_PION1_REST='https://rest-palvus.pion-1.ntrn.tech/' +NEXT_PUBLIC_NETWORK=mainnet + +NEXT_PUBLIC_OSMOSIS_RPC=https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-rpc-front/ +NEXT_PUBLIC_OSMOSIS_REST=https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/ +NEXT_PUBLIC_OSMOSIS_TEST_RPC=https://rpc.devnet.osmosis.zone/ +NEXT_PUBLIC_OSMOSIS_TEST_REST=https://lcd.devnet.osmosis.zone/ +NEXT_PUBLIC_NEUTRON_TEST_RPC=https://rpc-palvus.pion-1.ntrn.tech/ +NEXT_PUBLIC_NEUTRON_TEST_REST=https://rest-palvus.pion-1.ntrn.tech/ NEXT_PUBLIC_WALLET_CONNECT_ID=d93fdffb159bae5ec87d8fee4cdbb045 -CHARTING_LIBRARY_USERNAME="git_username" -CHARTING_LIBRARY_ACCESS_TOKEN="access_token" -CHARTING_LIBRARY_REPOSITORY="github.com/tradingview/charting_library/" +CHARTING_LIBRARY_USERNAME=git_username +CHARTING_LIBRARY_ACCESS_TOKEN=access_token +CHARTING_LIBRARY_REPOSITORY=github.com/tradingview/charting_library/ + + diff --git a/src/components/Header/ChainSelect.tsx b/src/components/Header/ChainSelect.tsx index f5882f97..957e9752 100644 --- a/src/components/Header/ChainSelect.tsx +++ b/src/components/Header/ChainSelect.tsx @@ -1,7 +1,7 @@ import classNames from 'classnames' -import { useCallback } from 'react' -import { useSWRConfig } from 'swr' +import { useCallback, useMemo } from 'react' import { useLocation, useNavigate, useSearchParams } from 'react-router-dom' +import { useSWRConfig } from 'swr' import Button from 'components/Button' import ChainLogo from 'components/Chain/ChainLogo' @@ -12,6 +12,7 @@ import useCurrentChainId from 'hooks/localStorage/useCurrentChainId' import useChainConfig from 'hooks/useChainConfig' import useToggle from 'hooks/useToggle' import useStore from 'store' +import { NETWORK } from 'types/enums/network' import { getPage, getRoute } from 'utils/route' export default function ChainSelect() { @@ -42,14 +43,23 @@ export default function ChainSelect() { [setCurrentChainId, setShowMenu, mutate, navigate, pathname, searchParams], ) + const currentChains = useMemo(() => { + const currentNetworkType = process.env.NEXT_PUBLIC_NETWORK ?? NETWORK.TESTNET + + return Object.entries(chains).filter(([_, chain]) => chain.network === currentNetworkType) + }, []) + return (
    - {Object.entries(chains).map(([name, chain]) => ( + {currentChains.map(([name, chain]) => (
  • { - let chainId = chains[ChainInfoID.Osmosis1].id + const currentNetwork = process.env.NEXT_PUBLIC_NETWORK ?? NETWORK.TESTNET + const defaultChainId = + currentNetwork === NETWORK.MAINNET + ? chains[ChainInfoID.Osmosis1].id + : chains[ChainInfoID.OsmosisDevnet].id + let chainId = defaultChainId if (window) { const subdomain = window.location.hostname.split('.')[0] switch (subdomain) { case 'osmosis': - chainId = ChainInfoID.Osmosis1 + if (currentNetwork === NETWORK.MAINNET) chainId = ChainInfoID.Osmosis1 break case 'testnet-osmosis': - chainId = ChainInfoID.OsmosisDevnet + if (currentNetwork === NETWORK.TESTNET) chainId = ChainInfoID.OsmosisDevnet break case 'testnet-neutron': - chainId = ChainInfoID.Pion1 + if (currentNetwork === NETWORK.TESTNET) chainId = ChainInfoID.Pion1 break } - if (chainId != chains[ChainInfoID.Osmosis1].id) return chainId + if (chainId !== defaultChainId) return chainId } - const localStorageChainId = localStorage.getItem(LocalStorageKeys.CURRENT_CHAIN_ID) + const localStorageChainId = localStorage.getItem(LocalStorageKeys.CURRENT_CHAIN_ID) as ChainInfoID if (localStorageChainId !== null) { - if (chains[chainId]) chainId = localStorageChainId as ChainInfoID + switch (localStorageChainId) { + case ChainInfoID.Osmosis1: + if (currentNetwork === NETWORK.MAINNET) chainId = ChainInfoID.Osmosis1 + break + + case ChainInfoID.OsmosisDevnet: + if (currentNetwork === NETWORK.TESTNET) chainId = ChainInfoID.OsmosisDevnet + break + + case ChainInfoID.Pion1: + if (currentNetwork === NETWORK.TESTNET) chainId = ChainInfoID.Pion1 + break + } } return chainId