diff --git a/.env.example b/.env.example index 64e71de..a1eeca2 100644 --- a/.env.example +++ b/.env.example @@ -1,72 +1,16 @@ -# LOCAL -VITE_APP_LOCAL_CAPTCHA_SITE_KEY='' -VITE_APP_LOCAL_FAUCET_URL='' -VITE_APP_LOCAL_FAUCET_ADDRESS='' -VITE_APP_LOCAL_BRIDGE_URL='' -VITE_APP_LOCAL_GRAPHQL_URL='' -VITE_APP_LOCAL_GRAPHQL_WS='' -VITE_APP_LOCAL_RPC='' -VITE_APP_LOCAL_API='' -VITE_APP_LOCAL_EXPLORER_URL='' -VITE_APP_LOCAL_STAKING_URL='' -VITE_APP_LOCAL_CHAIN_NAME='' -VITE_APP_LOCAL_CHAIN_ID='' - -# DEV -VITE_APP_DEV_CAPTCHA_SITE_KEY='' -VITE_APP_DEV_FAUCET_URL='' -VITE_APP_DEV_FAUCET_ADDRESS='' -VITE_APP_DEV_BRIDGE_URL='' -VITE_APP_DEV_GRAPHQL_URL='' -VITE_APP_DEV_GRAPHQL_WS='' -VITE_APP_DEV_RPC='' -VITE_APP_DEV_API='' -VITE_APP_DEV_EXPLORER_URL='' -VITE_APP_DEV_STAKING_URL='' -VITE_APP_DEV_CHAIN_NAME='' -VITE_APP_DEV_CHAIN_ID='' - -# PRIVATE -VITE_APP_PRIVATE_CAPTCHA_SITE_KEY='' -VITE_APP_PRIVATE_FAUCET_URL='' -VITE_APP_PRIVATE_FAUCET_ADDRESS='' -VITE_APP_PRIVATE_BRIDGE_URL='' -VITE_APP_PRIVATE_GRAPHQL_URL='' -VITE_APP_PRIVATE_GRAPHQL_WS='' -VITE_APP_PRIVATE_RPC='' -VITE_APP_PRIVATE_API='' -VITE_APP_PRIVATE_EXPLORER_URL='' -VITE_APP_PRIVATE_STAKING_URL='' -VITE_APP_PRIVATE_CHAIN_NAME='' -VITE_APP_PRIVATE_CHAIN_ID='' - -# PUBLIC -VITE_APP_PUBLIC_CAPTCHA_SITE_KEY='' -VITE_APP_PUBLIC_FAUCET_URL='' -VITE_APP_PUBLIC_FAUCET_ADDRESS='' -VITE_APP_PUBLIC_BRIDGE_URL='' -VITE_APP_PUBLIC_GRAPHQL_UR='' -VITE_APP_PUBLIC_GRAPHQL_WS='' -VITE_APP_PUBLIC_RPC='' -VITE_APP_PUBLIC_API='' -VITE_APP_PUBLIC_EXPLORER_URL='' -VITE_APP_PUBLIC_STAKING_URL='' -VITE_APP_PUBLIC_CHAIN_NAME='' -VITE_APP_PUBLIC_CHAIN_ID='' - -# MAINNET -VITE_APP_MAINNET_BRIDGE_URL='' -VITE_APP_MAINNET_GRAPHQL_URL='' -VITE_APP_MAINNET_GRAPHQL_WS='' -VITE_APP_MAINNET_RPC='' -VITE_APP_MAINNET_API='' -VITE_APP_MAINNET_EXPLORER_URL='' -VITE_APP_MAINNET_STAKING_URL='' -VITE_APP_MAINNET_CHAIN_NAME='' -VITE_APP_MAINNET_CHAIN_ID='' - -# GENERAL SETTINGS +# APP SETTINGS VITE_APP_DEPLOYMENT_VERSION='' #v0.0.1 format -VITE_NODE_ENV='' #Production or empty -VITE_APP_DEFAULT_NETWORK='' # LOCAL | PRIVATE | PUBLIC | MAINNET +VITE_APP_NODE_ENV='' #Production or empty VITE_APP_GAS_PRICE=5000000000000 +VITE_APP_CAPTCHA_SITE_KEY='' +VITE_APP_FAUCET_URL='' +VITE_APP_FAUCET_ADDRESS='' +VITE_APP_BRIDGE_URL='' +VITE_APP_GRAPHQL_URL='' +VITE_APP_GRAPHQL_WS='' +VITE_APP_RPC='' +VITE_APP_API='' +VITE_APP_STAKING_URL='' +VITE_APP_EXPLORER_URL='' +VITE_APP_CHAIN_NAME='' +VITE_APP_CHAIN_ID='' diff --git a/.vscode/launch.json b/.vscode/launch.json index 6384559..45ea252 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,14 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "Launch Edge", + "request": "launch", + "type": "pwa-msedge", + "url": "http://localhost:3000", + "webRoot": "${workspaceFolder}", + "userDataDir": false + }, { "type": "pwa-chrome", "request": "launch", diff --git a/src/App.tsx b/src/App.tsx index f55deeb..06a2181 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,14 +1,13 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { useCallback, useEffect, useState } from 'react' +import { useCallback, useEffect } from 'react' import { ThemeProvider } from '@mui/material/styles' import { useDispatch, useSelector } from 'react-redux' import { Box, CssBaseline } from '@mui/material' -import { ApolloClient, ApolloProvider, NormalizedCacheObject } from '@apollo/client' +import { ApolloProvider } from '@apollo/client' import { Routes, Route, useLocation, Navigate } from 'react-router-dom' import { updateUser } from 'store/profile' import { updateUserTransactions } from 'store/userTransactions' import NotificationPopup from 'components/NotificationPopup' -import CosmosNetworkConfig from 'ledgers/CosmosNetworkConfig' import { switchLedgerType } from 'ledgers/utils' import { connectUser } from './utils/projectUtils' import { useApollo } from './graphql/client' @@ -25,7 +24,7 @@ import theme from './theme' import { RootState } from './store' import '@fontsource/poppins' -import { ApolloLinks, defaultApolloLinks } from 'graphql/helpers' +import { defaultApolloLinks } from 'graphql/helpers' import { CHAIN_DETAILS } from 'utils/constants' import NetworkChangingLoading from 'components/NetworkChangeLoading' import { networkLoadingStyles } from 'components/NetworkChangeLoading/styles' @@ -35,22 +34,20 @@ const App = () => { const location = useLocation() const themeColor = useSelector((state: RootState) => state.settings.theme) const newApolloClient = useApollo(null) - const [currentApolloClient, setCurrentApolloClient] = useState>( - newApolloClient(defaultApolloLinks) - ) + const isMainnet = CHAIN_DETAILS.CHAIN_ID === 'cudos-1' + const { lastLoggedAddress, - chosenNetwork: currentNetwork, connectedLedger, loadingState } = useSelector((state: RootState) => state.profile) const dispatch = useDispatch() - const connectAccount = useCallback(async (chosenNetwork: string, walletName: SUPPORTED_WALLET) => { + const connectAccount = useCallback(async (walletName: SUPPORTED_WALLET) => { try { - const { address } = await switchLedgerType(chosenNetwork!, walletName) + const { address } = await switchLedgerType(walletName) if (address !== lastLoggedAddress || lastLoggedAddress === '') { dispatch( updateUserTransactions({ @@ -62,7 +59,7 @@ const App = () => { ) } - const connectedUser = await connectUser(chosenNetwork, walletName) + const connectedUser = await connectUser(walletName) dispatch(updateUser(connectedUser)) } catch (e) { @@ -82,46 +79,27 @@ const App = () => { }) ) - await connectAccount(currentNetwork, SUPPORTED_WALLET.Keplr) + await connectAccount(SUPPORTED_WALLET.Keplr) }) if (isExtensionEnabled(SUPPORTED_WALLET.Cosmostation)) { window.cosmostation.cosmos.on('accountChanged', async () => { - await connectAccount(currentNetwork, SUPPORTED_WALLET.Cosmostation) + await connectAccount(SUPPORTED_WALLET.Cosmostation) }) } return () => { window.removeEventListener('keplr_keystorechange', async () => { - await connectAccount(currentNetwork, SUPPORTED_WALLET.Keplr) + await connectAccount(SUPPORTED_WALLET.Keplr) }) window.removeEventListener('accountChanged', async () => { - await connectAccount(currentNetwork, SUPPORTED_WALLET.Cosmostation) + await connectAccount(SUPPORTED_WALLET.Cosmostation) }) } }, []) - - useEffect(() => { - dispatch(updateUser({ loadingState: true }) - ) - const newApolloLinks: ApolloLinks = { - uri: CHAIN_DETAILS.GRAPHQL_URL[currentNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], - url: CHAIN_DETAILS.GRAPHQL_WS[currentNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_WS] - } - - setCurrentApolloClient(newApolloClient(newApolloLinks)) - - if (connectedLedger) { - connectAccount(currentNetwork, connectedLedger) - } - - setTimeout(() => { dispatch(updateUser({ loadingState: false })) }, 4000) - - }, [currentNetwork]) - return ( - + {location.pathname !== '/' ? null : ( @@ -150,13 +128,11 @@ const App = () => { } /> - { - CHAIN_DETAILS.CHAIN_ID[currentNetwork! as keyof typeof CHAIN_DETAILS.CHAIN_ID] - === CHAIN_DETAILS.CHAIN_ID.MAINNET ? null : ( - - } /> - - )} + {isMainnet ? null : ( + + } /> + + )} } /> diff --git a/src/api/getAccountDelegations.ts b/src/api/getAccountDelegations.ts index abba20c..2230112 100644 --- a/src/api/getAccountDelegations.ts +++ b/src/api/getAccountDelegations.ts @@ -3,7 +3,6 @@ import { CHAIN_DETAILS } from 'utils/constants' import { AccountDelegationsDocument } from '../graphql/account_actions' export const fetchDelegations = async ( - chosenNetwork: string, address: string, signal?: AbortSignal ) => { @@ -11,7 +10,7 @@ export const fetchDelegations = async ( try { const { data } = await axios.post( - CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL].toString(), + CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, query: AccountDelegationsDocument diff --git a/src/api/getAccountRedelegations.ts b/src/api/getAccountRedelegations.ts index ec0915c..a4ddb36 100644 --- a/src/api/getAccountRedelegations.ts +++ b/src/api/getAccountRedelegations.ts @@ -4,7 +4,6 @@ import { CHAIN_DETAILS } from 'utils/constants' import { AccountRedelegationsDocument } from '../graphql/account_actions' export const fetchRedelegations = async ( - chosenNetwork: string, address: string, signal?: AbortSignal ) => { @@ -16,7 +15,7 @@ export const fetchRedelegations = async ( try { const { data } = await axios.post( - CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL].toString(), + CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, query: AccountRedelegationsDocument diff --git a/src/api/getAccountUndelegations.ts b/src/api/getAccountUndelegations.ts index 55739f2..ddb5941 100644 --- a/src/api/getAccountUndelegations.ts +++ b/src/api/getAccountUndelegations.ts @@ -3,7 +3,6 @@ import { CHAIN_DETAILS } from 'utils/constants' import { AccountUndelegationsDocument } from '../graphql/account_actions' export const fetchUndedelegations = async ( - chosenNetwork: string, address: string, signal?: AbortSignal ) => { @@ -15,7 +14,7 @@ export const fetchUndedelegations = async ( try { const { data } = await axios.post( - CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL].toString(), + CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, query: AccountUndelegationsDocument diff --git a/src/api/getRewards.ts b/src/api/getRewards.ts index 8d92dc8..a0ed657 100644 --- a/src/api/getRewards.ts +++ b/src/api/getRewards.ts @@ -5,13 +5,13 @@ import { formatBigNum } from '../utils/projectUtils' import { AccountDelegationRewardsDocument } from '../graphql/account_actions' import { CHAIN_DETAILS } from 'utils/constants' -export const fetchRewards = async (chosenNetwork: string, address: string, signal?: AbortSignal) => { +export const fetchRewards = async (address: string, signal?: AbortSignal) => { const defaultReturnValue = new BigNumber(0) const rewardArray: Array = [] const validatorArray: { address: string; amount: string }[] = [] try { const { data } = await axios.post( - CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL].toString(), + CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, query: AccountDelegationRewardsDocument diff --git a/src/api/getUnbondingBalance.ts b/src/api/getUnbondingBalance.ts index 64d458f..c7ce64f 100644 --- a/src/api/getUnbondingBalance.ts +++ b/src/api/getUnbondingBalance.ts @@ -5,7 +5,6 @@ import { formatBigNum } from 'utils/projectUtils' import { AccountUnbondingBalanceDocument } from '../graphql/account_actions' export const getUnbondingBalance = async ( - chosenNetwork: string, address: string, signal?: AbortSignal ) => { @@ -14,7 +13,7 @@ export const getUnbondingBalance = async ( try { const { data } = await axios.post( - CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL]?.toString(), + CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, query: AccountUnbondingBalanceDocument diff --git a/src/components/Dialog/components/DelegationModal/Delegation.tsx b/src/components/Dialog/components/DelegationModal/Delegation.tsx index 7094072..d1d5913 100644 --- a/src/components/Dialog/components/DelegationModal/Delegation.tsx +++ b/src/components/Dialog/components/DelegationModal/Delegation.tsx @@ -58,7 +58,7 @@ const Delegation: React.FC = ({ modalProps, handleModal }) => { const [delegationAmount, setDelegationAmount] = useState('') const { validator, amount, fee } = modalProps - const { address, connectedLedger, chosenNetwork } = useSelector( + const { address, connectedLedger } = useSelector( ({ profile }: RootState) => profile ) const dispatch = useDispatch() @@ -66,7 +66,7 @@ const Delegation: React.FC = ({ modalProps, handleModal }) => { useEffect(() => { let isMounted = true const loadBalance = async () => { - const client = await signingClient(chosenNetwork, connectedLedger!) + const client = await signingClient(connectedLedger!) const walletBalance = await client.getBalance( address, @@ -104,7 +104,7 @@ const Delegation: React.FC = ({ modalProps, handleModal }) => { value: msg } - const client = await signingClient(chosenNetwork, connectedLedger!) + const client = await signingClient(connectedLedger!) const gasUsed = await client.simulate(address, [msgAny], 'memo') @@ -162,7 +162,6 @@ const Delegation: React.FC = ({ modalProps, handleModal }) => { try { const delegationResult = await delegate( - chosenNetwork, address, validator?.address || '', amount || '', @@ -176,13 +175,11 @@ const Delegation: React.FC = ({ modalProps, handleModal }) => { txHash: delegationResult.transactionHash }) - const walletBalance = await getWalletBalance(chosenNetwork!, address) + const walletBalance = await getWalletBalance(address) const { delegationsArray } = await fetchDelegations( - chosenNetwork!, address ) const stakedAmountBalance = await getStakedBalance( - chosenNetwork!, address ) @@ -256,11 +253,7 @@ const Delegation: React.FC = ({ modalProps, handleModal }) => { fontWeight={700} color="primary.main" > - { - CHAIN_DETAILS.CHAIN_NAME[ - chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_NAME - ] - } + {CHAIN_DETAILS.CHAIN_NAME} diff --git a/src/components/Dialog/components/DelegationModal/Success.tsx b/src/components/Dialog/components/DelegationModal/Success.tsx index accefe8..69d3dc9 100644 --- a/src/components/Dialog/components/DelegationModal/Success.tsx +++ b/src/components/Dialog/components/DelegationModal/Success.tsx @@ -4,8 +4,6 @@ import { DelegationModalProps, initialDelegationModalState } from 'store/modal' import numeral from 'numeral' import SuccessIcon from 'assets/vectors/success.svg' import { ModalContainer, CancelRoundedIcon } from '../styles' -import { RootState } from 'store' -import { useSelector } from 'react-redux' import { CHAIN_DETAILS } from 'utils/constants' type SuccessProps = { @@ -15,7 +13,6 @@ type SuccessProps = { const Success: React.FC = ({ modalProps, handleModal }) => { const { validator, gasUsed, txHash, fee } = modalProps - const { chosenNetwork } = useSelector((state: RootState) => state.profile) const handleClose = () => { handleModal({ @@ -78,9 +75,7 @@ const Success: React.FC = ({ modalProps, handleModal }) => { onClick={() => window .open( - `${ - CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL] - }/transactions/${txHash}`, + `${CHAIN_DETAILS.EXPLORER_URL}/transactions/${txHash}`, '_blank' ) ?.focus() diff --git a/src/components/Layout/Header.tsx b/src/components/Layout/Header.tsx index e6d9381..6c7e97b 100644 --- a/src/components/Layout/Header.tsx +++ b/src/components/Layout/Header.tsx @@ -19,8 +19,8 @@ const Header = () => { const nagivate = useNavigate() const isMidLowewRes = useMidLowerResCheck() const isMidLowRes = useMidlowResCheck() - const { chosenNetwork, loadingState } = useSelector((state: RootState) => state.profile) - const isMainnet = CHAIN_DETAILS.CHAIN_ID[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_ID] === CHAIN_DETAILS.CHAIN_ID.MAINNET + const { loadingState } = useSelector((state: RootState) => state.profile) + const isMainnet = CHAIN_DETAILS.CHAIN_ID === 'cudos-1' const isWelcomePage = location.pathname === '/' const [logoComponent, setLogoComponent] = useState() @@ -51,7 +51,7 @@ const Header = () => { gap={1} sx={headerStyles.linkHolder} onClick={() => window - .open(CHAIN_DETAILS.BRIDGE_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.BRIDGE_URL], '_blank') + .open(CHAIN_DETAILS.BRIDGE_URL, '_blank') ?.focus()} > diff --git a/src/components/Layout/LeftMenu.tsx b/src/components/Layout/LeftMenu.tsx index d37d7d9..e638651 100644 --- a/src/components/Layout/LeftMenu.tsx +++ b/src/components/Layout/LeftMenu.tsx @@ -11,15 +11,15 @@ import { styles } from './styles' const Menu = () => { const [selected, setSelected] = useState(0) const [menuItems, setMenuItems] = useState([]) - const { chosenNetwork, loadingState } = useSelector((state: RootState) => state.profile) + const { loadingState } = useSelector((state: RootState) => state.profile) const { pathname } = useLocation() const isScreenWidthLessThan1440px = useIsScreenLessThan('1440px', 'width') useEffect(() => { - setMenuItems(getMenuItems(chosenNetwork, loadingState)) + setMenuItems(getMenuItems(loadingState)) - }, [chosenNetwork, loadingState]) + }, [loadingState]) useEffect(() => { diff --git a/src/components/Layout/NetworkInfo.tsx b/src/components/Layout/NetworkInfo.tsx index fc9c0ae..17852e9 100644 --- a/src/components/Layout/NetworkInfo.tsx +++ b/src/components/Layout/NetworkInfo.tsx @@ -1,75 +1,20 @@ -import { useState } from 'react' import { StyledNetwork, styles } from './networkStyles' -import ArrowIcon from 'assets/vectors/arrow-down.svg?component' import { CHAIN_DETAILS } from 'utils/constants' import { COLORS_DARK_THEME } from 'theme/colors' import GlobusIcon from 'assets/vectors/globus-icon.svg?component' -import { Typography, Box, Collapse } from '@mui/material' +import { Typography, Box } from '@mui/material' import { RootState } from 'store' -import { useDispatch, useSelector } from 'react-redux' -import { handleAvailableNetworks } from 'utils/projectUtils' -import { updateUser } from 'store/profile' -import Card from 'components/Card' - -const NetworkLinkComponent = ({ network, setChosenNetwork }: { - network: networkToDisplay, - setChosenNetwork: (selectedNetwork: string) => void -}): JSX.Element => { - - const [hovered, setHovered] = useState(false) - - return ( - setHovered(true)} - onMouseOut={() => setHovered(false)} - onClick={() => setChosenNetwork(network.SHORT_NAMES[0].toUpperCase())} - > - - - {network.ALIAS_NAME} - - - ) -} +import { useSelector } from 'react-redux' +import { getChainPrettyName } from 'utils/projectUtils' const NetworkInfo = () => { - const dispatch = useDispatch() - const [open, setOpen] = useState(false) - const { chosenNetwork, loadingState } = useSelector((state: RootState) => state.profile) - const aliasChainName = CHAIN_DETAILS[chosenNetwork as keyof typeof CHAIN_DETAILS].ALIAS_NAME - const networksToDisplayInMenu = handleAvailableNetworks(CHAIN_DETAILS.DEFAULT_NETWORK) - - const setChosenNetwork = (selectedNetwork: string) => { - dispatch(updateUser({ chosenNetwork: selectedNetwork })) - setOpen(false) - } - - // const collapsable = networksToDisplayInMenu.length > 1 - const collapsable = false + const { loadingState } = useSelector((state: RootState) => state.profile) + const aliasChainName = getChainPrettyName(CHAIN_DETAILS.CHAIN_ID) return ( - - - { } : () => setOpen(true)} - onMouseLeave={() => setOpen(false)} - style={styles.userContainer} - > + + { {aliasChainName} } - {collapsable ? - - - : null} - { } : () => setOpen(true)} - onMouseLeave={() => setOpen(false)} - style={{ marginTop: '-28px', zIndex: '-1' }} - in={open} - > - - {networksToDisplayInMenu.map((NETWORK, idx) => { - return aliasChainName !== NETWORK.ALIAS_NAME ? - : null - })} - - ) } diff --git a/src/components/Layout/UserInfo.tsx b/src/components/Layout/UserInfo.tsx index 68cd016..3a330b1 100644 --- a/src/components/Layout/UserInfo.tsx +++ b/src/components/Layout/UserInfo.tsx @@ -21,7 +21,7 @@ import { styles } from './styles' const UserInfo = () => { const navigate = useNavigate() const dispatch = useDispatch() - const { address, accountName, connectedLedger, chosenNetwork } = useSelector( + const { address, accountName, connectedLedger } = useSelector( (state: RootState) => state.profile ) @@ -38,7 +38,7 @@ const UserInfo = () => { } const handleExplorer = () => { - window.open(`${CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL].toString()}`, '_blank') + window.open(`${CHAIN_DETAILS.EXPLORER_URL}`, '_blank') } const handleDisconnect = () => { @@ -54,8 +54,7 @@ const UserInfo = () => { delegations: [], redelegations: [], undelegations: [], - connectedLedger: '', - chosenNetwork: CHAIN_DETAILS.DEFAULT_NETWORK + connectedLedger: '' }) ) navigate('/') diff --git a/src/components/Layout/menuHelpers.tsx b/src/components/Layout/menuHelpers.tsx index 38417ce..c62e272 100644 --- a/src/components/Layout/menuHelpers.tsx +++ b/src/components/Layout/menuHelpers.tsx @@ -10,7 +10,7 @@ export interface MenuItems { text: string; } -export const getMenuItems = (chosenNetwork: string, loadingState: boolean): MenuItems[] => { +export const getMenuItems = (loadingState: boolean): MenuItems[] => { const MenuItems = [ { icon: , link: '/dashboard', text: 'Dashboard' }, @@ -18,8 +18,8 @@ export const getMenuItems = (chosenNetwork: string, loadingState: boolean): Menu { icon: , link: '/proposals', text: 'Proposals' }, ] - if (CHAIN_DETAILS.CHAIN_ID[chosenNetwork! as keyof typeof CHAIN_DETAILS.CHAIN_ID] - !== CHAIN_DETAILS.CHAIN_ID.MAINNET && !loadingState) { + if (CHAIN_DETAILS.CHAIN_ID + !== 'cudos-1' && !loadingState) { MenuItems.push({ icon: , link: '/faucet', text: 'Faucet' }) } diff --git a/src/components/NetworkChangeLoading/index.tsx b/src/components/NetworkChangeLoading/index.tsx index eaaccfe..ec64e92 100644 --- a/src/components/NetworkChangeLoading/index.tsx +++ b/src/components/NetworkChangeLoading/index.tsx @@ -1,13 +1,11 @@ import { Box, CircularProgress, Typography } from "@mui/material" import { Fragment } from "react" -import { useSelector } from "react-redux" -import { RootState } from "store" import { CHAIN_DETAILS } from "utils/constants" +import { getChainPrettyName } from "utils/projectUtils" const NetworkChangingLoading = () => { - const { chosenNetwork } = useSelector((state: RootState) => state.profile) - const aliasChainName = CHAIN_DETAILS[chosenNetwork as keyof typeof CHAIN_DETAILS].ALIAS_NAME + const aliasChainName = getChainPrettyName(CHAIN_DETAILS.CHAIN_ID) return ( diff --git a/src/containers/ConnectWallet/ConnectWallet.tsx b/src/containers/ConnectWallet/ConnectWallet.tsx index e6e32be..957e98d 100644 --- a/src/containers/ConnectWallet/ConnectWallet.tsx +++ b/src/containers/ConnectWallet/ConnectWallet.tsx @@ -36,7 +36,7 @@ import { styles } from './styles' const ConnectWallet = () => { const dispatch = useDispatch() const navigate = useNavigate() - const { lastLoggedAddress, chosenNetwork: currentNetwork } = useSelector((state: RootState) => state.profile) + const { lastLoggedAddress } = useSelector((state: RootState) => state.profile) const { setWarning } = useNotifications() const [loading, setLoading] = useState(new Map()) const [userBrowser, setUserBrowser] = useState(undefined) @@ -47,18 +47,18 @@ const ConnectWallet = () => { } } - const connect = async (chosenNetwork: string, walletName: SUPPORTED_WALLET) => { + const connect = async (walletName: SUPPORTED_WALLET) => { try { setLoading(new Map(loading.set(walletName, true))) await delay(1000) - const { address } = await switchLedgerType(chosenNetwork, walletName) + const { address } = await switchLedgerType(walletName) if (address !== lastLoggedAddress) { dispatch(updateUserTransactions({ offsetCount: 0, data: [] })) } - const connectedUser = await connectUser(chosenNetwork, walletName) + const connectedUser = await connectUser(walletName) dispatch(updateUser(connectedUser)) navigate('dashboard') @@ -75,7 +75,7 @@ const ConnectWallet = () => { const click = (walletName: SUPPORTED_WALLET) => { if (isExtensionEnabled(walletName)) { - connect(currentNetwork, walletName) + connect(walletName) return } diff --git a/src/containers/Dashboard/LatestActivity/LatestActivity.tsx b/src/containers/Dashboard/LatestActivity/LatestActivity.tsx index 2897b4c..232bf66 100644 --- a/src/containers/Dashboard/LatestActivity/LatestActivity.tsx +++ b/src/containers/Dashboard/LatestActivity/LatestActivity.tsx @@ -25,7 +25,6 @@ import { styles } from '../styles' const LatestActivity = () => { const { state } = useUserTransactions() - const { chosenNetwork } = useSelector((state: RootState) => state.profile) const { data, loading, hasActivity } = state const theme = useTheme() @@ -49,11 +48,7 @@ const LatestActivity = () => { onClick={() => window .open( - `${ - CHAIN_DETAILS.EXPLORER_URL[ - chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL - ] - }/blocks/${tx.height}`, + `${CHAIN_DETAILS.EXPLORER_URL}/blocks/${tx.height}`, '_blank' ) ?.focus() @@ -73,12 +68,7 @@ const LatestActivity = () => { sx={{ cursor: 'pointer' }} onClick={() => window - .open( - `${ - CHAIN_DETAILS.EXPLORER_URL[ - chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL - ] - }/transactions/${tx.hash}`, + .open(`${CHAIN_DETAILS.EXPLORER_URL}/transactions/${tx.hash}`, '_blank' ) ?.focus() diff --git a/src/containers/Dashboard/WalletInformation/components/ClaimRewardsModal/Rewards.tsx b/src/containers/Dashboard/WalletInformation/components/ClaimRewardsModal/Rewards.tsx index 72f8879..b3130bc 100644 --- a/src/containers/Dashboard/WalletInformation/components/ClaimRewardsModal/Rewards.tsx +++ b/src/containers/Dashboard/WalletInformation/components/ClaimRewardsModal/Rewards.tsx @@ -54,7 +54,7 @@ const Rewards: React.FC = ({ modalProps, handleModal }) => { ({ profile }: RootState) => profile ) - const { stakedValidators, chosenNetwork } = useSelector((state: RootState) => state.profile) + const { stakedValidators } = useSelector((state: RootState) => state.profile) const { validator } = useSelector( (state: RootState) => state.validatorDetails @@ -73,7 +73,7 @@ const Rewards: React.FC = ({ modalProps, handleModal }) => { return } - const { validatorArray } = await fetchRewards(chosenNetwork!, address) + const { validatorArray } = await fetchRewards(address) const isValidator = validatorsState.items.findIndex( @@ -82,7 +82,6 @@ const Rewards: React.FC = ({ modalProps, handleModal }) => { ) > -1 const { result, fee, restakeTx } = await claimRewards( - chosenNetwork, isSingleRewardWithdraw ? getSingleReward : validatorArray, address, { @@ -104,7 +103,7 @@ const Rewards: React.FC = ({ modalProps, handleModal }) => { }) const { validatorArray: updatedValidatorArray, totalRewards } = - await fetchRewards(chosenNetwork!, address) + await fetchRewards(address) dispatch( updateUser({ @@ -175,7 +174,7 @@ const Rewards: React.FC = ({ modalProps, handleModal }) => { Network - {CHAIN_DETAILS.CHAIN_NAME[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_NAME]} + {CHAIN_DETAILS.CHAIN_NAME} diff --git a/src/containers/Dashboard/WalletInformation/components/ClaimRewardsModal/Success.tsx b/src/containers/Dashboard/WalletInformation/components/ClaimRewardsModal/Success.tsx index 49cc6ac..8702c0b 100644 --- a/src/containers/Dashboard/WalletInformation/components/ClaimRewardsModal/Success.tsx +++ b/src/containers/Dashboard/WalletInformation/components/ClaimRewardsModal/Success.tsx @@ -19,8 +19,6 @@ type SuccessProps = { const Success: React.FC = ({ modalProps, handleModal }) => { const { gasUsed, txHash, fee, txRestakeHash } = modalProps - const { chosenNetwork } = useSelector((state: RootState) => state.profile) - const handleClose = () => { handleModal({ ...initialRewardsModalProps @@ -80,10 +78,7 @@ const Success: React.FC = ({ modalProps, handleModal }) => { sx={{ textDecoration: 'underline' }} onClick={() => window - .open( - `${ - CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL] - }/transactions/${txHash}`, + .open(`${CHAIN_DETAILS.EXPLORER_URL}/transactions/${txHash}`, '_blank' ) ?.focus() @@ -111,10 +106,7 @@ const Success: React.FC = ({ modalProps, handleModal }) => { sx={{ textDecoration: 'underline' }} onClick={() => window - .open( - `${ - CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL] - }/transactions/${txRestakeHash}`, + .open(`${CHAIN_DETAILS.EXPLORER_URL}/transactions/${txRestakeHash}`, '_blank' ) ?.focus() diff --git a/src/containers/Dashboard/WalletInformation/index.tsx b/src/containers/Dashboard/WalletInformation/index.tsx index 886724b..78d66ff 100644 --- a/src/containers/Dashboard/WalletInformation/index.tsx +++ b/src/containers/Dashboard/WalletInformation/index.tsx @@ -49,8 +49,7 @@ const WalletInformation: React.FC = () => { unbondingBalance, address, stakedValidators, - lastLoggedAddress, - chosenNetwork + lastLoggedAddress } = state const dispatch = useDispatch() const { setError } = useNotifications() @@ -80,13 +79,12 @@ const WalletInformation: React.FC = () => { const fetchData = async () => { try { const { totalRewards, validatorArray } = await fetchRewards( - chosenNetwork!, address, controller.signal ) - const walletBalance = await getWalletBalance(chosenNetwork!, address) - const stakedAmountBalance = await getStakedBalance(chosenNetwork!, address) - const { unbondingBalance } = await getUnbondingBalance(chosenNetwork!, address) + const walletBalance = await getWalletBalance(address) + const stakedAmountBalance = await getStakedBalance(address) + const { unbondingBalance } = await getUnbondingBalance(address) dispatch( updateUser({ @@ -110,7 +108,7 @@ const WalletInformation: React.FC = () => { clearInterval(timer) controller?.abort() } - }, [address, dispatch, lastLoggedAddress, chosenNetwork]) + }, [address, dispatch, lastLoggedAddress]) return ( { title="Go to Explorer" onClick={() => window - .open( - `${CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL] - }/accounts/${address}`, + .open(`${CHAIN_DETAILS.EXPLORER_URL}/accounts/${address}`, '_blank' ) ?.focus() diff --git a/src/containers/Faucet/components/Activity/hooks.ts b/src/containers/Faucet/components/Activity/hooks.ts index 1216059..44ad18e 100644 --- a/src/containers/Faucet/components/Activity/hooks.ts +++ b/src/containers/Faucet/components/Activity/hooks.ts @@ -5,14 +5,11 @@ import { useGetMessagesByAddressQuery } from 'graphql/types' import { ActivityState } from './types' -import { useSelector } from 'react-redux' -import { RootState } from 'store' import { CHAIN_DETAILS } from 'utils/constants' const LIMIT = 50 export const useActivity = () => { - const { chosenNetwork } = useSelector((state: RootState) => state.profile) const [state, setState] = useState({ items: [], loading: false @@ -48,7 +45,7 @@ export const useActivity = () => { } }) .filter( - (item: any) => item.address !== CHAIN_DETAILS.FAUCET_ADDRESS[chosenNetwork as keyof typeof CHAIN_DETAILS.FAUCET_ADDRESS] + (item: any) => item.address !== CHAIN_DETAILS.FAUCET_ADDRESS ) return formattedItems @@ -58,7 +55,7 @@ export const useActivity = () => { variables: { limit: LIMIT, offset: 0, - address: `{${CHAIN_DETAILS.FAUCET_ADDRESS[chosenNetwork as keyof typeof CHAIN_DETAILS.FAUCET_ADDRESS]}}`, + address: `{${CHAIN_DETAILS.FAUCET_ADDRESS}}`, types: `{cosmos.bank.v1beta1.MsgSend}` }, onCompleted: (data: any) => { @@ -77,7 +74,7 @@ export const useActivity = () => { variables: { limit: LIMIT + 1, offset: 0, - address: `{${CHAIN_DETAILS.FAUCET_ADDRESS[chosenNetwork as keyof typeof CHAIN_DETAILS.FAUCET_ADDRESS]}}` + address: `{${CHAIN_DETAILS.FAUCET_ADDRESS}}` }, updateQuery: (prev, { subscriptionData }) => { if (!subscriptionData.data) return prev diff --git a/src/containers/Faucet/components/Form/index.tsx b/src/containers/Faucet/components/Form/index.tsx index ed1f497..2931246 100644 --- a/src/containers/Faucet/components/Form/index.tsx +++ b/src/containers/Faucet/components/Form/index.tsx @@ -12,8 +12,6 @@ import { isValidCudosAddress } from 'utils/projectUtils' import useModal from '../FaucetModal/hooks' import { styles } from './styles' import { CHAIN_DETAILS } from 'utils/constants' -import { useSelector } from 'react-redux' -import { RootState } from 'store' const Form = () => { const captchaRef = useRef(null) @@ -21,7 +19,6 @@ const Form = () => { const [amount, setAmount] = useState('') const [validatedCaptcha, setValidatedCaptcha] = useState(false) const { setWarning } = useNotifications() - const { chosenNetwork } = useSelector((state: RootState) => state.profile) const maxAmountAllowed: number = 100 const { handleModal } = useModal() @@ -85,7 +82,7 @@ const Form = () => { handleModal({ open: true, status: ModalStatus.LOADING }) const response = await getFaucetTokens( - CHAIN_DETAILS.FAUCET_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.FAUCET_URL], + CHAIN_DETAILS.FAUCET_URL, data ) @@ -184,7 +181,7 @@ const Form = () => { theme="dark" ref={captchaRef} onChange={checkCaptcha} - sitekey={CHAIN_DETAILS.CAPTCHA_SITE_KEY[chosenNetwork as keyof typeof CHAIN_DETAILS.CAPTCHA_SITE_KEY]} + sitekey={CHAIN_DETAILS.CAPTCHA_SITE_KEY} /> diff --git a/src/containers/Proposals/Proposal.tsx b/src/containers/Proposals/Proposal.tsx index 3e54986..9ba4583 100644 --- a/src/containers/Proposals/Proposal.tsx +++ b/src/containers/Proposals/Proposal.tsx @@ -27,7 +27,6 @@ import { styles } from './styles' const Proposal = () => { const proposalState = useSelector((state: RootState) => state.proposals) - const { chosenNetwork } = useSelector((state: RootState) => state.profile) const [searchResults, setSearchResults] = useState(proposalState) const { handleModal: handleVotingModal } = useVotingModal() const { handleModal: handleDepositModal } = useDepositModal() @@ -36,7 +35,7 @@ const Proposal = () => { const handleExplorer = (address: string) => { window.open( - `${CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL].toString()}/accounts/${address}`, + `${CHAIN_DETAILS.EXPLORER_URL}/accounts/${address}`, '_blank' ) } diff --git a/src/containers/Proposals/ProposalDetails/components/ProposalInformation/index.tsx b/src/containers/Proposals/ProposalDetails/components/ProposalInformation/index.tsx index 910c7e4..598e47e 100644 --- a/src/containers/Proposals/ProposalDetails/components/ProposalInformation/index.tsx +++ b/src/containers/Proposals/ProposalDetails/components/ProposalInformation/index.tsx @@ -25,13 +25,12 @@ interface Change { const ProposalInformation = () => { const { overview } = useSelector((state: RootState) => state.proposalDetails) - const { chosenNetwork } = useSelector((state: RootState) => state.profile) const { handleModal: handleVotingModal } = useVotingModal() const { handleModal: handleDepositModal } = useDepositModal() const handleExplorer = (address: string) => { window.open( - `${CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL]?.toString()}/accounts/${address}`, + `${CHAIN_DETAILS.EXPLORER_URL}/accounts/${address}`, '_blank' ) } diff --git a/src/containers/Proposals/ProposalDetails/components/VotingStatistics/hooks.ts b/src/containers/Proposals/ProposalDetails/components/VotingStatistics/hooks.ts index 1b52df1..1f306ed 100644 --- a/src/containers/Proposals/ProposalDetails/components/VotingStatistics/hooks.ts +++ b/src/containers/Proposals/ProposalDetails/components/VotingStatistics/hooks.ts @@ -6,11 +6,8 @@ import { ProposalDetailsVotesWeightedDocument } from 'graphql/proposal_details_v import { useParams } from 'react-router-dom' import { VoteState } from './types' import { CHAIN_DETAILS } from 'utils/constants' -import { RootState } from 'store' -import { useSelector } from 'react-redux' export const useVotingStatistics = (resetPagination: any) => { - const { chosenNetwork } = useSelector((state: RootState) => state.profile) const { proposalId } = useParams() const [state, setState] = useState({ data: [], @@ -38,8 +35,8 @@ export const useVotingStatistics = (resetPagination: any) => { }) } - const fetchWeightedVotes = async (chosenNetwork: string) => { - return axios.post(CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], { + const fetchWeightedVotes = async () => { + return axios.post(CHAIN_DETAILS.GRAPHQL_URL, { variables: { proposalId }, @@ -159,7 +156,7 @@ export const useVotingStatistics = (resetPagination: any) => { proposalId: Number(proposalId) }, onSubscriptionData: (data) => { - fetchWeightedVotes(chosenNetwork).then((votesWeightedData) => { + fetchWeightedVotes().then((votesWeightedData) => { const mergedVotesData = mergeRegularVotesWithWeighted( data.subscriptionData.data?.proposalVote, votesWeightedData diff --git a/src/containers/Proposals/components/DepositModal/Deposit.tsx b/src/containers/Proposals/components/DepositModal/Deposit.tsx index 2f105d4..4457427 100644 --- a/src/containers/Proposals/components/DepositModal/Deposit.tsx +++ b/src/containers/Proposals/components/DepositModal/Deposit.tsx @@ -22,7 +22,7 @@ type DepositProps = { const Deposit: React.FC = ({ handleModal, modalProps }) => { const [depositAmount, setDepositAmount] = useState('') - const { address, balance, connectedLedger, chosenNetwork } = useSelector( + const { address, balance, connectedLedger } = useSelector( (state: RootState) => state.profile ) @@ -47,7 +47,6 @@ const Deposit: React.FC = ({ handleModal, modalProps }) => { }) const { gasFee, result } = await depositProposal( - chosenNetwork, depositorAddress, proposalId, amount, @@ -64,7 +63,7 @@ const Deposit: React.FC = ({ handleModal, modalProps }) => { hash: result.transactionHash }) - const walletBalance = await getWalletBalance(chosenNetwork!, address) + const walletBalance = await getWalletBalance(address) dispatch( updateUser({ diff --git a/src/containers/Proposals/components/DepositModal/Success.tsx b/src/containers/Proposals/components/DepositModal/Success.tsx index 9be413b..bd8188e 100644 --- a/src/containers/Proposals/components/DepositModal/Success.tsx +++ b/src/containers/Proposals/components/DepositModal/Success.tsx @@ -17,7 +17,7 @@ type SuccessProps = { } const Success: React.FC = ({ modalProps, handleModal }) => { - const { address, chosenNetwork } = useSelector(({ profile }: RootState) => profile) + const { address } = useSelector(({ profile }: RootState) => profile) const { title, id, fee, hash, amount } = modalProps const handleClose = () => { @@ -91,10 +91,7 @@ const Success: React.FC = ({ modalProps, handleModal }) => { sx={{ textDecoration: 'underline' }} onClick={() => window - .open( - `${ - CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL] - }/transactions/${hash}`, + .open(`${CHAIN_DETAILS.EXPLORER_URL}/transactions/${hash}`, '_blank' ) ?.focus() diff --git a/src/containers/Proposals/components/ProposalModal/Proposals.tsx b/src/containers/Proposals/components/ProposalModal/Proposals.tsx index 69c8835..1363a82 100644 --- a/src/containers/Proposals/components/ProposalModal/Proposals.tsx +++ b/src/containers/Proposals/components/ProposalModal/Proposals.tsx @@ -34,7 +34,7 @@ type ProposalProps = { const Proposals: React.FC = ({ handleModal, modalProps }) => { const { setError } = useNotifications() - const { address, connectedLedger, chosenNetwork } = useSelector( + const { address, connectedLedger } = useSelector( ({ profile }: RootState) => profile ) @@ -96,7 +96,6 @@ const Proposals: React.FC = ({ handleModal, modalProps }) => { } }) const { result, gasFee } = await createProposal( - chosenNetwork, proposalData, proposerAddress, connectedLedger! @@ -108,7 +107,7 @@ const Proposals: React.FC = ({ handleModal, modalProps }) => { hash: result.transactionHash }) - const walletBalance = await getWalletBalance(chosenNetwork!, address) + const walletBalance = await getWalletBalance(address) dispatch( updateUser({ @@ -170,7 +169,7 @@ const Proposals: React.FC = ({ handleModal, modalProps }) => { Network - {CHAIN_DETAILS.CHAIN_NAME[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_NAME]} + {CHAIN_DETAILS.CHAIN_NAME} diff --git a/src/containers/Proposals/components/ProposalModal/Success.tsx b/src/containers/Proposals/components/ProposalModal/Success.tsx index aaaaeaa..dad937b 100644 --- a/src/containers/Proposals/components/ProposalModal/Success.tsx +++ b/src/containers/Proposals/components/ProposalModal/Success.tsx @@ -17,7 +17,7 @@ type SuccessProps = { } const Success: React.FC = ({ modalProps, handleModal }) => { - const { address, chosenNetwork } = useSelector(({ profile }: RootState) => profile) + const { address } = useSelector(({ profile }: RootState) => profile) const { fee, hash, proposalData } = modalProps @@ -117,10 +117,7 @@ const Success: React.FC = ({ modalProps, handleModal }) => { sx={{ textDecoration: 'underline' }} onClick={() => window - .open( - `${ - CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL] - }/transactions/${hash}`, + .open(`${CHAIN_DETAILS.EXPLORER_URL}/transactions/${hash}`, '_blank' ) ?.focus() diff --git a/src/containers/Proposals/components/VotingModal/Success.tsx b/src/containers/Proposals/components/VotingModal/Success.tsx index bba5133..651ee31 100644 --- a/src/containers/Proposals/components/VotingModal/Success.tsx +++ b/src/containers/Proposals/components/VotingModal/Success.tsx @@ -17,7 +17,7 @@ type SuccessProps = { } const Success: React.FC = ({ modalProps, handleModal }) => { - const { address, chosenNetwork } = useSelector(({ profile }: RootState) => profile) + const { address } = useSelector(({ profile }: RootState) => profile) const { type, title, id, fee, hash } = modalProps const handleClose = () => { @@ -106,10 +106,7 @@ const Success: React.FC = ({ modalProps, handleModal }) => { sx={{ textDecoration: 'underline' }} onClick={() => window - .open( - `${ - CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL] - }/transactions/${hash}`, + .open(`${CHAIN_DETAILS.EXPLORER_URL}/transactions/${hash}`, '_blank' ) ?.focus() diff --git a/src/containers/Proposals/components/VotingModal/Vote.tsx b/src/containers/Proposals/components/VotingModal/Vote.tsx index ea84e06..99eadda 100644 --- a/src/containers/Proposals/components/VotingModal/Vote.tsx +++ b/src/containers/Proposals/components/VotingModal/Vote.tsx @@ -23,7 +23,7 @@ const Vote: React.FC = ({ handleModal, modalProps }) => { const { id, title } = modalProps - const { address, connectedLedger, chosenNetwork } = useSelector( + const { address, connectedLedger } = useSelector( (state: RootState) => state.profile ) @@ -38,7 +38,6 @@ const Vote: React.FC = ({ handleModal, modalProps }) => { }) const { gasFee, result } = await voteProposal( - chosenNetwork, voterAddress, proposalId, votingOption, diff --git a/src/containers/ValidatorDetails/components/Activity/components/Table/index.tsx b/src/containers/ValidatorDetails/components/Activity/components/Table/index.tsx index e14f3ef..630f00b 100644 --- a/src/containers/ValidatorDetails/components/Activity/components/Table/index.tsx +++ b/src/containers/ValidatorDetails/components/Activity/components/Table/index.tsx @@ -12,8 +12,6 @@ import getMiddleEllipsis from 'utils/get_middle_ellipsis' import { defaultMessages, unknownMessage } from 'ledgers/utils' import numeral from 'numeral' import { columns } from './utils' -import { RootState } from 'store' -import { useSelector } from 'react-redux' import { CHAIN_DETAILS } from 'utils/constants' type ActivityTableProps = { @@ -31,8 +29,6 @@ const ActivityTable: React.FC = ({ hasNextPage = false, isNextPageLoading = false }) => { - - const { chosenNetwork } = useSelector((state: RootState) => state.profile) const handleScroll = async (e: React.UIEvent) => { const { scrollHeight, scrollTop, clientHeight } = e.currentTarget @@ -64,7 +60,7 @@ const ActivityTable: React.FC = ({ onClick={() => window .open( - `${CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL]}/blocks/${tx.height}`, + `${CHAIN_DETAILS.EXPLORER_URL}/blocks/${tx.height}`, '_blank' ) ?.focus() @@ -85,7 +81,7 @@ const ActivityTable: React.FC = ({ onClick={() => window .open( - `${CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL]}/transactions/${ + `${CHAIN_DETAILS.EXPLORER_URL}/transactions/${ tx.hash }`, '_blank' diff --git a/src/containers/ValidatorDetails/components/Delegators/components/Delegations/index.tsx b/src/containers/ValidatorDetails/components/Delegators/components/Delegations/index.tsx index 34f34c9..bcccccd 100644 --- a/src/containers/ValidatorDetails/components/Delegators/components/Delegations/index.tsx +++ b/src/containers/ValidatorDetails/components/Delegators/components/Delegations/index.tsx @@ -14,8 +14,6 @@ import CudosLogo from 'assets/vectors/cudos-logo.svg' import NoData from 'components/NoData' import { DelegationsType, DelegationType } from '../../types' import { delegationsColumns } from '../../utils' -import { useSelector } from 'react-redux' -import { RootState } from 'store' import { CHAIN_DETAILS } from 'utils/constants' type DelegationsProps = { @@ -26,8 +24,6 @@ type DelegationsProps = { const Delegations: React.FC = (props) => { const { delegations, handlePageCallback } = props - const { chosenNetwork } = useSelector((state: RootState) => state.profile) - const { page, rowsPerPage, handleChangePage } = usePagination({ pageChangeCallback: handlePageCallback }) @@ -53,7 +49,7 @@ const Delegations: React.FC = (props) => { onClick={() => window .open( - `${CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL]}/accounts/${ + `${CHAIN_DETAILS.EXPLORER_URL}/accounts/${ item.address }`, '_blank' diff --git a/src/containers/ValidatorDetails/components/Delegators/components/Redelegations/index.tsx b/src/containers/ValidatorDetails/components/Delegators/components/Redelegations/index.tsx index 20b4042..b4f28c8 100644 --- a/src/containers/ValidatorDetails/components/Delegators/components/Redelegations/index.tsx +++ b/src/containers/ValidatorDetails/components/Delegators/components/Redelegations/index.tsx @@ -18,8 +18,6 @@ import NoData from 'components/NoData' import { RedelegationsType, RedelegationType } from '../../types' import { redelegationsColumns } from '../../utils' import { CHAIN_DETAILS } from 'utils/constants' -import { useSelector } from 'react-redux' -import { RootState } from 'store' type RedelegationsProps = { redelegations: RedelegationsType @@ -29,8 +27,6 @@ type RedelegationsProps = { const Redelegations: React.FC = (props) => { const { redelegations, handlePageCallback } = props - const { chosenNetwork } = useSelector((state: RootState) => state.profile) - const { page, rowsPerPage, handleChangePage } = usePagination({ pageChangeCallback: handlePageCallback }) @@ -56,7 +52,7 @@ const Redelegations: React.FC = (props) => { onClick={() => window .open( - `${CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL]}/accounts/${ + `${CHAIN_DETAILS.EXPLORER_URL}/accounts/${ item.address }`, '_blank' @@ -82,7 +78,7 @@ const Redelegations: React.FC = (props) => { onClick={() => window .open( - `${CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL]}/validators/${item.to}`, + `${CHAIN_DETAILS.EXPLORER_URL}/validators/${item.to}`, '_blank' ) ?.focus() diff --git a/src/containers/ValidatorDetails/components/Delegators/components/Unbondings/index.tsx b/src/containers/ValidatorDetails/components/Delegators/components/Unbondings/index.tsx index a4f90c2..c761a95 100644 --- a/src/containers/ValidatorDetails/components/Delegators/components/Unbondings/index.tsx +++ b/src/containers/ValidatorDetails/components/Delegators/components/Unbondings/index.tsx @@ -17,8 +17,6 @@ import NoData from 'components/NoData' import { UnbondingsType, UnbondingType } from '../../types' import { unbondingsColumns } from '../../utils' import { CHAIN_DETAILS } from 'utils/constants' -import { RootState } from 'store' -import { useSelector } from 'react-redux' type UnbondingsProps = { unbondings: UnbondingsType @@ -28,8 +26,6 @@ type UnbondingsProps = { const Unbondings: React.FC = (props) => { const { unbondings, handlePageCallback } = props - const { chosenNetwork } = useSelector((state: RootState) => state.profile) - const { page, rowsPerPage, handleChangePage } = usePagination({ pageChangeCallback: handlePageCallback }) @@ -55,7 +51,7 @@ const Unbondings: React.FC = (props) => { onClick={() => window .open( - `${CHAIN_DETAILS.EXPLORER_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL]}/accounts/${ + `${CHAIN_DETAILS.EXPLORER_URL}/accounts/${ item.address }`, '_blank' diff --git a/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx b/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx index d33ca3c..25374ab 100644 --- a/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx +++ b/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx @@ -52,7 +52,7 @@ const Redelegation: React.FC = ({ const { validator, amount, fee } = modalProps const dispatch = useDispatch() - const { address, connectedLedger, chosenNetwork } = useSelector( + const { address, connectedLedger } = useSelector( ({ profile }: RootState) => profile ) const validators = useSelector(({ validator }: RootState) => validator.items) @@ -87,7 +87,7 @@ const Redelegation: React.FC = ({ useEffect(() => { const loadBalance = async () => { - const client = await signingClient(chosenNetwork, connectedLedger!) + const client = await signingClient(connectedLedger!) const walletBalance = await client.getDelegation( address, @@ -128,7 +128,7 @@ const Redelegation: React.FC = ({ value: msg } - const client = await signingClient(chosenNetwork, connectedLedger!) + const client = await signingClient(connectedLedger!) const gasUsed = await client.simulate(address, [msgAny], 'memo') @@ -174,7 +174,7 @@ const Redelegation: React.FC = ({ value: msg } - const client = await signingClient(chosenNetwork, connectedLedger!) + const client = await signingClient(connectedLedger!) const gasUsed = await client.simulate(address, [msgAny], 'memo') @@ -221,7 +221,6 @@ const Redelegation: React.FC = ({ try { const redelegationResult = await redelegate( - chosenNetwork, address, validator?.address || '', redelegationAddress, @@ -236,7 +235,7 @@ const Redelegation: React.FC = ({ txHash: redelegationResult.transactionHash }) - const { redelegationsArray } = await fetchRedelegations(chosenNetwork!, address) + const { redelegationsArray } = await fetchRedelegations(address) dispatch( updateUser({ redelegations: redelegationsArray @@ -302,7 +301,7 @@ const Redelegation: React.FC = ({ fontWeight={700} color="primary.main" > - {CHAIN_DETAILS.CHAIN_NAME[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_NAME]} + {CHAIN_DETAILS.CHAIN_NAME} diff --git a/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/UndelegationModal/Undelegation.tsx b/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/UndelegationModal/Undelegation.tsx index ef4af84..46dfa57 100644 --- a/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/UndelegationModal/Undelegation.tsx +++ b/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/UndelegationModal/Undelegation.tsx @@ -50,13 +50,13 @@ const Undelegation: React.FC = ({ const { validator, amount, fee } = modalProps const dispatch = useDispatch() - const { address, connectedLedger, chosenNetwork } = useSelector( + const { address, connectedLedger } = useSelector( ({ profile }: RootState) => profile ) useEffect(() => { const loadBalance = async () => { - const client = await signingClient(chosenNetwork, connectedLedger!) + const client = await signingClient(connectedLedger!) const walletBalance = await client.getDelegation( address, @@ -91,7 +91,7 @@ const Undelegation: React.FC = ({ value: msg } - const client = await signingClient(chosenNetwork, connectedLedger!) + const client = await signingClient(connectedLedger!) const gasUsed = await client.simulate(address, [msgAny], 'memo') @@ -136,7 +136,7 @@ const Undelegation: React.FC = ({ value: msg } - const client = await signingClient(chosenNetwork, connectedLedger!) + const client = await signingClient(connectedLedger!) const gasUsed = await client.simulate(address, [msgAny], 'memo') @@ -172,7 +172,6 @@ const Undelegation: React.FC = ({ try { const undelegationResult = await undelegate( - chosenNetwork, address, validator?.address || '', amount || '', @@ -185,7 +184,7 @@ const Undelegation: React.FC = ({ gasUsed: undelegationResult.gasUsed, txHash: undelegationResult.transactionHash }) - const { undelegationsArray } = await fetchUndedelegations(chosenNetwork!, address) + const { undelegationsArray } = await fetchUndedelegations(address) dispatch( updateUser({ undelegations: undelegationsArray @@ -254,7 +253,7 @@ const Undelegation: React.FC = ({ fontWeight={700} color="primary.main" > - {CHAIN_DETAILS.CHAIN_NAME[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_NAME]} + {CHAIN_DETAILS.CHAIN_NAME} diff --git a/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/index.tsx b/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/index.tsx index 217d0f7..d157e5d 100644 --- a/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/index.tsx +++ b/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/index.tsx @@ -46,7 +46,7 @@ type InfoProps = { const ValidatorInfo: React.FC = ({ overview, status }) => { const [openActionsDropdown, setOpenActionsDropdown] = useState(false) const info = useSelector((state: RootState) => state.notifications.info) - const { stakedValidators, chosenNetwork } = useSelector( + const { stakedValidators } = useSelector( (state: RootState) => state.profile ) const { validator } = useSelector( @@ -110,11 +110,7 @@ const ValidatorInfo: React.FC = ({ overview, status }) => { onClick={() => window .open( - `${ - CHAIN_DETAILS.EXPLORER_URL[ - chosenNetwork as keyof typeof CHAIN_DETAILS.EXPLORER_URL - ] - }/validators/${overview.operatorAddress}`, + `${CHAIN_DETAILS.EXPLORER_URL}/validators/${overview.operatorAddress}`, '_blank' ) ?.focus() @@ -412,7 +408,7 @@ const ValidatorInfo: React.FC = ({ overview, status }) => { borderRadius: '10px', background: theme.custom.statuses[ - statusTheme.status as keyof typeof theme.custom.statuses + statusTheme.status as keyof typeof theme.custom.statuses ], fontWeight: 700, letterSpacing: '2px' diff --git a/src/containers/ValidatorDetails/components/MyDelegations/index.tsx b/src/containers/ValidatorDetails/components/MyDelegations/index.tsx index b758d47..422d50d 100644 --- a/src/containers/ValidatorDetails/components/MyDelegations/index.tsx +++ b/src/containers/ValidatorDetails/components/MyDelegations/index.tsx @@ -20,8 +20,7 @@ const MyDelegations = () => { redelegations, undelegations, stakedValidators, - address, - chosenNetwork + address } = useSelector((state: RootState) => state.profile) const { validator } = useSelector( (state: RootState) => state.validatorDetails @@ -79,23 +78,19 @@ const MyDelegations = () => { const fetchData = async () => { try { const { validatorArray } = await fetchRewards( - chosenNetwork!, address, controller.signal ) const { redelegationsArray } = await fetchRedelegations( - chosenNetwork!, address, controller.signal ) const { undelegationsArray } = await fetchUndedelegations( - chosenNetwork!, address, controller.signal ) const { delegationsArray } = await fetchDelegations( - chosenNetwork!, address, controller.signal ) diff --git a/src/containers/ValidatorDetails/components/Statistics/hooks.ts b/src/containers/ValidatorDetails/components/Statistics/hooks.ts index 6faa81d..513b7c8 100644 --- a/src/containers/ValidatorDetails/components/Statistics/hooks.ts +++ b/src/containers/ValidatorDetails/components/Statistics/hooks.ts @@ -48,7 +48,6 @@ const initialState: AccountDetailState = { } export const useStatistics = () => { - const { chosenNetwork } = useSelector((state: RootState) => state.profile) const { validatorId } = useParams() const [state, setState] = useState(initialState) const selfDelegateAddress = useSelector( @@ -183,12 +182,12 @@ export const useStatistics = () => { const fetchBalance = async () => { const promises = [ - fetchCommission(chosenNetwork, selfDelegateAddress), - fetchAvailableBalances(chosenNetwork, selfDelegateAddress), - fetchDelegationBalance(chosenNetwork, selfDelegateAddress), - fetchUnbondingBalance(chosenNetwork, selfDelegateAddress), - fetchRewards(chosenNetwork, selfDelegateAddress), - fetchVotingPower(chosenNetwork, validatorId!) + fetchCommission(selfDelegateAddress), + fetchAvailableBalances(selfDelegateAddress), + fetchDelegationBalance(selfDelegateAddress), + fetchUnbondingBalance(selfDelegateAddress), + fetchRewards(selfDelegateAddress), + fetchVotingPower(validatorId!) ] const [commission, available, delegation, unbonding, rewards, votingPower] = await Promise.allSettled(promises) diff --git a/src/containers/ValidatorDetails/components/Statistics/utils.ts b/src/containers/ValidatorDetails/components/Statistics/utils.ts index e9c37d9..6cb6a3d 100644 --- a/src/containers/ValidatorDetails/components/Statistics/utils.ts +++ b/src/containers/ValidatorDetails/components/Statistics/utils.ts @@ -13,14 +13,14 @@ import { } from 'graphql/account_actions' import { CHAIN_DETAILS } from 'utils/constants' -export const fetchCommission = async (chosenNetwork: string, address: string) => { +export const fetchCommission = async (address: string) => { const defaultReturnValue = { commission: { coins: null } } try { - const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], { + const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL, { variables: { validatorAddress: toValidatorAddress(address) }, @@ -32,14 +32,14 @@ export const fetchCommission = async (chosenNetwork: string, address: string) => } } -export const fetchAccountWithdrawalAddress = async (chosenNetwork: string, address: string) => { +export const fetchAccountWithdrawalAddress = async (address: string) => { const defaultReturnValue = { withdrawalAddress: { address } } try { - const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], { + const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, @@ -51,14 +51,14 @@ export const fetchAccountWithdrawalAddress = async (chosenNetwork: string, addre } } -export const fetchAvailableBalances = async (chosenNetwork: string, address: string) => { +export const fetchAvailableBalances = async (address: string) => { const defaultReturnValue = { accountBalances: { coins: [] } } try { - const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], { + const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, @@ -70,14 +70,14 @@ export const fetchAvailableBalances = async (chosenNetwork: string, address: str } } -export const fetchDelegationBalance = async (chosenNetwork: string, address: string) => { +export const fetchDelegationBalance = async (address: string) => { const defaultReturnValue = { delegationBalance: { coins: [] } } try { - const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], { + const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, @@ -89,14 +89,14 @@ export const fetchDelegationBalance = async (chosenNetwork: string, address: str } } -export const fetchUnbondingBalance = async (chosenNetwork: string, address: string) => { +export const fetchUnbondingBalance = async (address: string) => { const defaultReturnValue = { unbondingBalance: { coins: [] } } try { - const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], { + const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, @@ -108,12 +108,12 @@ export const fetchUnbondingBalance = async (chosenNetwork: string, address: stri } } -export const fetchRewards = async (chosenNetwork: string, address: string) => { +export const fetchRewards = async (address: string) => { const defaultReturnValue = { delegationRewards: [] } try { - const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], { + const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, @@ -125,12 +125,12 @@ export const fetchRewards = async (chosenNetwork: string, address: string) => { } } -export const fetchVotingPower = async (chosenNetwork: string, address: string) => { +export const fetchVotingPower = async (address: string) => { const defaultVotingPower = { votingPower: [] } try { - const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], { + const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, @@ -142,12 +142,12 @@ export const fetchVotingPower = async (chosenNetwork: string, address: string) = } } -export const fetchAccountDelegations = async (chosenNetwork: string, address: string) => { +export const fetchAccountDelegations = async (address: string) => { const defaultAccountDelegations = { accountDelegations: [] } try { - const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], { + const { data } = await axios.post(CHAIN_DETAILS.GRAPHQL_URL, { variables: { address }, diff --git a/src/graphql/helpers.ts b/src/graphql/helpers.ts index 05ab2f5..3eab727 100644 --- a/src/graphql/helpers.ts +++ b/src/graphql/helpers.ts @@ -6,6 +6,6 @@ export interface ApolloLinks { } export const defaultApolloLinks: ApolloLinks = { - uri: CHAIN_DETAILS.GRAPHQL_URL[CHAIN_DETAILS.DEFAULT_NETWORK! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL], - url: CHAIN_DETAILS.GRAPHQL_WS[CHAIN_DETAILS.DEFAULT_NETWORK! as keyof typeof CHAIN_DETAILS.GRAPHQL_WS] + uri: CHAIN_DETAILS.GRAPHQL_URL, + url: CHAIN_DETAILS.GRAPHQL_WS } diff --git a/src/ledgers/CosmoStationLedger.ts b/src/ledgers/CosmoStationLedger.ts index 7887317..053fa25 100644 --- a/src/ledgers/CosmoStationLedger.ts +++ b/src/ledgers/CosmoStationLedger.ts @@ -2,7 +2,7 @@ import { cosmos, InstallError } from '@cosmostation/extension-client' import { CHAIN_DETAILS } from 'utils/constants' import CosmosNetworkConfig from './CosmosNetworkConfig' -export const connectCosmostationLedger = async (chosenNetwork: string): Promise<{ +export const connectCosmostationLedger = async (): Promise<{ address: string accountName: string }> => { @@ -17,13 +17,13 @@ export const connectCosmostationLedger = async (chosenNetwork: string): Promise< if ( !activatedChains.includes( - CHAIN_DETAILS.CHAIN_ID[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_ID].toLowerCase() + CHAIN_DETAILS.CHAIN_ID.toLowerCase() ) ) { await provider.addChain({ - chainId: CHAIN_DETAILS.CHAIN_ID[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_ID], + chainId: CHAIN_DETAILS.CHAIN_ID, - chainName: CHAIN_DETAILS.CHAIN_NAME[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_NAME], + chainName: CHAIN_DETAILS.CHAIN_NAME, addressPrefix: CosmosNetworkConfig.BECH32_PREFIX_ACC_ADDR, @@ -31,7 +31,7 @@ export const connectCosmostationLedger = async (chosenNetwork: string): Promise< displayDenom: CosmosNetworkConfig.CURRENCY_DISPLAY_NAME, - restURL: CHAIN_DETAILS.API_ADDRESS[chosenNetwork as keyof typeof CHAIN_DETAILS.API_ADDRESS], + restURL: CHAIN_DETAILS.API_ADDRESS, decimals: 18, @@ -49,7 +49,7 @@ export const connectCosmostationLedger = async (chosenNetwork: string): Promise< // Although the method suggests CHAIN_NAME as parameter only, it can work with CHAIN_ID too! const acccount = await provider.requestAccount( - CHAIN_DETAILS.CHAIN_ID[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_ID] + CHAIN_DETAILS.CHAIN_ID ) userAccountAddress = acccount.address diff --git a/src/ledgers/KeplrLedger.tsx b/src/ledgers/KeplrLedger.tsx index d074e3e..03516bc 100644 --- a/src/ledgers/KeplrLedger.tsx +++ b/src/ledgers/KeplrLedger.tsx @@ -12,19 +12,19 @@ declare global { } } -export const connectKeplrLedger = async (chosenNetwork: string) => { +export const connectKeplrLedger = async () => { const wallet = new KeplrWallet({ - CHAIN_ID: CHAIN_DETAILS.CHAIN_ID[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_ID], - CHAIN_NAME: CHAIN_DETAILS.CHAIN_NAME[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_NAME], - RPC: CHAIN_DETAILS.RPC_ADDRESS[chosenNetwork as keyof typeof CHAIN_DETAILS.RPC_ADDRESS], - API: CHAIN_DETAILS.API_ADDRESS[chosenNetwork as keyof typeof CHAIN_DETAILS.API_ADDRESS], - STAKING: CHAIN_DETAILS.STAKING_URL[chosenNetwork as keyof typeof CHAIN_DETAILS.API_ADDRESS], - GAS_PRICE: CHAIN_DETAILS.GAS_PRICE + CHAIN_ID: CHAIN_DETAILS.CHAIN_ID, + CHAIN_NAME: CHAIN_DETAILS.CHAIN_NAME, + RPC: CHAIN_DETAILS.RPC_ADDRESS, + API: CHAIN_DETAILS.API_ADDRESS, + STAKING: CHAIN_DETAILS.STAKING_URL, + GAS_PRICE: CHAIN_DETAILS.GAS_PRICE.toString() }) await wallet.connect() - const key = await window.keplr.getKey(CHAIN_DETAILS.CHAIN_ID[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_ID]) + const key = await window.keplr.getKey(CHAIN_DETAILS.CHAIN_ID) return { address: key.bech32Address, accountName: key.name } } diff --git a/src/ledgers/transactions.ts b/src/ledgers/transactions.ts index 15d68e2..792a1e2 100644 --- a/src/ledgers/transactions.ts +++ b/src/ledgers/transactions.ts @@ -71,13 +71,12 @@ export const calculateFee = (gasLimit: number, gasPrice: string | GasPrice) => { } export const getFee = async ( - chosenNetwork: string, address: string, ledgerType: SUPPORTED_WALLET, message: any[], memo: string ) => { - const client = await signingClient(chosenNetwork, ledgerType) + const client = await signingClient(ledgerType) const gasUsed = await client.simulate(address, message, memo) const gasLimit = Math.round(gasUsed * DEFAULT_GAS_MULTIPLIER) @@ -88,7 +87,6 @@ export const getFee = async ( } export const delegate = async ( - chosenNetwork: string, delegatorAddress: string, validatorAddress: string, amount: string, @@ -118,9 +116,9 @@ export const delegate = async ( value: msg } - const fee = await getFee(chosenNetwork, delegatorAddress, ledgerType, [msgAny], memo) + const fee = await getFee(delegatorAddress, ledgerType, [msgAny], memo) - const client = await signingClient(chosenNetwork, ledgerType) + const client = await signingClient(ledgerType) const result = await client.delegateTokens( delegatorAddress, @@ -134,7 +132,6 @@ export const delegate = async ( } export const undelegate = async ( - chosenNetwork: string, delegatorAddress: string, validatorAddress: string, amount: string, @@ -164,9 +161,9 @@ export const undelegate = async ( value: msg } - const fee = await getFee(chosenNetwork, delegatorAddress, ledgerType, [msgAny], memo) + const fee = await getFee(delegatorAddress, ledgerType, [msgAny], memo) - const client = await signingClient(chosenNetwork, ledgerType) + const client = await signingClient(ledgerType) const result = await client.undelegateTokens( delegatorAddress, @@ -180,7 +177,6 @@ export const undelegate = async ( } export const redelegate = async ( - chosenNetwork: string, delegatorAddress: string, validatorSrcAddress: string, validatorDstAddress: string, @@ -205,9 +201,9 @@ export const redelegate = async ( value: msg } - const fee = await getFee(chosenNetwork, delegatorAddress, ledgerType, [msgAny], memo) + const fee = await getFee(delegatorAddress, ledgerType, [msgAny], memo) - const client = await signingClient(chosenNetwork, ledgerType) + const client = await signingClient(ledgerType) const result = await client.signAndBroadcast( delegatorAddress, @@ -220,7 +216,6 @@ export const redelegate = async ( } export const claimRewards = async ( - chosenNetwork: string, stakedValidators: { address: string; amount: string }[], address: string, options: { @@ -280,9 +275,9 @@ export const claimRewards = async ( }) } - fee = await getFee(chosenNetwork, address, ledgerType, [...msgAny], msgMemo) + fee = await getFee(address, ledgerType, [...msgAny], msgMemo) - const client = await signingClient(chosenNetwork, ledgerType) + const client = await signingClient(ledgerType) const result = await client.signAndBroadcast(address, msgAny, fee, msgMemo) @@ -307,9 +302,9 @@ export const claimRewards = async ( } }) - const client = await signingClient(chosenNetwork, ledgerType) + const client = await signingClient(ledgerType) - restakeFee = await getFee(chosenNetwork, address, ledgerType, [...msgRestake], msgMemo) + restakeFee = await getFee(address, ledgerType, [...msgRestake], msgMemo) restakeTx = await client.signAndBroadcast( address, @@ -329,7 +324,6 @@ export const claimRewards = async ( } export const voteProposal = async ( - chosenNetwork: string, voterAddress: string, proposalId: number | undefined, votingOption: number, @@ -348,9 +342,9 @@ export const voteProposal = async ( const memo = 'Sent via CUDOS Dashboard' - const fee = await getFee(chosenNetwork, voterAddress, ledgerType, [msgAny], memo) + const fee = await getFee(voterAddress, ledgerType, [msgAny], memo) - const client = await signingClient(chosenNetwork, ledgerType) + const client = await signingClient(ledgerType) const result = await client.signAndBroadcast( voterAddress, @@ -366,7 +360,6 @@ export const voteProposal = async ( } export const depositProposal = async ( - chosenNetwork: string, depositorAddress: string, proposalId: number | undefined, amount: string, @@ -392,9 +385,9 @@ export const depositProposal = async ( const memo = 'Sent via CUDOS Dashboard' - const fee = await getFee(chosenNetwork, depositorAddress, ledgerType, [msgAny], memo) + const fee = await getFee(depositorAddress, ledgerType, [msgAny], memo) - const client = await signingClient(chosenNetwork, ledgerType) + const client = await signingClient(ledgerType) const result = await client.signAndBroadcast( depositorAddress, @@ -506,12 +499,11 @@ export const getProposalContent = (proposalData: any) => { } export const createProposal = async ( - chosenNetwork: string, proposalData: any, proposerAddress: string, ledgerType: SUPPORTED_WALLET ) => { - const client = await signingClient(chosenNetwork, ledgerType) + const client = await signingClient(ledgerType) const content = getProposalContent(proposalData) @@ -535,7 +527,7 @@ export const createProposal = async ( const memo = 'Sent via CUDOS Dashboard' - const fee = await getFee(chosenNetwork, proposerAddress, ledgerType, [msgAny], memo) + const fee = await getFee(proposerAddress, ledgerType, [msgAny], memo) const result = await client.signAndBroadcast( proposerAddress, diff --git a/src/ledgers/utils.ts b/src/ledgers/utils.ts index 800ebd4..aff20fa 100644 --- a/src/ledgers/utils.ts +++ b/src/ledgers/utils.ts @@ -532,27 +532,26 @@ export const unknownMessage = { displayName: 'Unknown' } -export const switchLedgerType = async (chosenNetwork: string, walletName: SUPPORTED_WALLET) => { +export const switchLedgerType = async (walletName: SUPPORTED_WALLET) => { const isInstalled = isExtensionEnabled(walletName) if (walletName === SUPPORTED_WALLET.Keplr && isInstalled) { - return connectKeplrLedger(chosenNetwork) + return connectKeplrLedger() } if (walletName === SUPPORTED_WALLET.Cosmostation && isInstalled) { - return connectCosmostationLedger(chosenNetwork) + return connectCosmostationLedger() } throw new Error("Invalid ledger") } export const getLedgerSigner = async ( - chosenNetwork: string, connector: Cosmos, accountInfo: RequestAccountResponse ) => { - const chainName = CHAIN_DETAILS.CHAIN_NAME[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_NAME] + const chainName = CHAIN_DETAILS.CHAIN_NAME const signer: OfflineAminoSigner = { getAccounts: async () => { return [ @@ -582,29 +581,28 @@ export const getLedgerSigner = async ( } const switchSigningClient = async ( - chosenNetwork: string, walletName: SUPPORTED_WALLET ): Promise => { let client switch (walletName) { case SUPPORTED_WALLET.Keplr: client = await window.getOfflineSignerAuto( - CHAIN_DETAILS.CHAIN_ID[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_ID] + CHAIN_DETAILS.CHAIN_ID ) return client case SUPPORTED_WALLET.Cosmostation: { const connector = await cosmos() const connectedAccount = await connector.requestAccount( - CHAIN_DETAILS.CHAIN_NAME[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_NAME] + CHAIN_DETAILS.CHAIN_NAME ) if (connectedAccount.isLedger) { - client = await getLedgerSigner(chosenNetwork, connector, connectedAccount) + client = await getLedgerSigner(connector, connectedAccount) return client } - client = await cosmostationSigner(CHAIN_DETAILS.CHAIN_ID[chosenNetwork as keyof typeof CHAIN_DETAILS.CHAIN_ID]) + client = await cosmostationSigner(CHAIN_DETAILS.CHAIN_ID) return client } @@ -613,8 +611,8 @@ const switchSigningClient = async ( } } -export const signingClient = async (chosenNetwork: string, walletName: SUPPORTED_WALLET) => { - const offlineSigner = await switchSigningClient(chosenNetwork, walletName) +export const signingClient = async (walletName: SUPPORTED_WALLET) => { + const offlineSigner = await switchSigningClient(walletName) if (isExtensionEnabled(walletName)) { window.keplr.defaultOptions = { @@ -629,15 +627,15 @@ export const signingClient = async (chosenNetwork: string, walletName: SUPPORTED } return SigningStargateClient.connectWithSigner( - CHAIN_DETAILS.RPC_ADDRESS[chosenNetwork as keyof typeof CHAIN_DETAILS.RPC_ADDRESS], + CHAIN_DETAILS.RPC_ADDRESS, offlineSigner ) } -export const getQueryClient = async (chosenNetwork: string): Promise => { +export const getQueryClient = async (): Promise => { try { - const client = await StargateClient.connect(CHAIN_DETAILS.RPC_ADDRESS[chosenNetwork! as keyof typeof CHAIN_DETAILS.RPC_ADDRESS]) + const client = await StargateClient.connect(CHAIN_DETAILS.RPC_ADDRESS) return client } catch (error) { diff --git a/src/store/index.ts b/src/store/index.ts index 2f5747d..35b3b41 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -12,6 +12,7 @@ import userTransactionsReducer from './userTransactions' import validatorDetailsReducer from './validatorDetails' import notificationsReducer from './notifications' import modalReducer from './modal' +import { APP_DETAILS } from 'utils/constants' const rootReducer = combineReducers({ profile: profileReducer, @@ -48,7 +49,7 @@ export const store = configureStore({ getDefaultMiddleware({ serializableCheck: false }), - devTools: import.meta.env.NODE_ENV !== 'production' + devTools: APP_DETAILS.NODE_ENV.toLowerCase() !== 'production' }) // Infer the `RootState` and `AppDispatch` types from the store itself diff --git a/src/store/profile.ts b/src/store/profile.ts index eb51717..0f0459b 100644 --- a/src/store/profile.ts +++ b/src/store/profile.ts @@ -14,7 +14,6 @@ export interface WalletState { address: string accountName: string connectedLedger: SUPPORTED_WALLET | undefined - chosenNetwork: string loadingState: boolean lastLoggedAddress: string balance: BigNumber @@ -39,7 +38,6 @@ const initialState: WalletState = { address: '', accountName: '', connectedLedger: undefined, - chosenNetwork: CHAIN_DETAILS.DEFAULT_NETWORK, loadingState: false, lastLoggedAddress: '', balance: new BigNumber(0), diff --git a/src/utils/constants.tsx b/src/utils/constants.tsx index d28537e..159cfc2 100644 --- a/src/utils/constants.tsx +++ b/src/utils/constants.tsx @@ -1,116 +1,24 @@ // APP SPECIFIC CHAIN CONFIGURATIONS export const CHAIN_DETAILS = { GAS_PRICE: import.meta.env.VITE_APP_GAS_PRICE || process.env.VITE_APP_GAS_PRICE || "", - DEFAULT_NETWORK: import.meta.env.VITE_APP_DEFAULT_NETWORK || process.env.VITE_APP_DEFAULT_NETWORK || "", - CAPTCHA_SITE_KEY: { - LOCAL: import.meta.env.VITE_APP_LOCAL_CAPTCHA_SITE_KEY || process.env.VITE_APP_LOCAL_CAPTCHA_SITE_KEY || "", - DEV: import.meta.env.VITE_APP_DEV_CAPTCHA_SITE_KEY || process.env.VITE_APP_DEV_CAPTCHA_SITE_KEY || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_CAPTCHA_SITE_KEY || process.env.VITE_APP_PRIVATE_CAPTCHA_SITE_KEY || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_CAPTCHA_SITE_KEY || process.env.VITE_APP_PUBLIC_CAPTCHA_SITE_KEY || "", - MAINNET: '' - }, - FAUCET_URL: { - LOCAL: import.meta.env.VITE_APP_LOCAL_FAUCET_URL || process.env.VITE_APP_LOCAL_FAUCET_URL || "", - DEV: import.meta.env.VITE_APP_DEV_FAUCET_URL || process.env.VITE_APP_DEV_FAUCET_URL || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_FAUCET_URL || process.env.VITE_APP_PRIVATE_FAUCET_URL || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_FAUCET_URL || process.env.VITE_APP_PUBLIC_FAUCET_URL || "", - MAINNET: '' - }, - FAUCET_ADDRESS: { - LOCAL: import.meta.env.VITE_APP_LOCAL_FAUCET_ADDRESS || process.env.VITE_APP_LOCAL_FAUCET_ADDRESS || "", - DEV: import.meta.env.VITE_APP_DEV_FAUCET_ADDRESS || process.env.VITE_APP_DEV_FAUCET_ADDRESS || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_FAUCET_ADDRESS || process.env.VITE_APP_PRIVATE_FAUCET_ADDRESS || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_FAUCET_ADDRESS || process.env.VITE_APP_PUBLIC_FAUCET_ADDRESS || "", - MAINNET: '' - }, - BRIDGE_URL: { - LOCAL: import.meta.env.VITE_APP_LOCAL_BRIDGE_URL || process.env.VITE_APP_LOCAL_BRIDGE_URL || "", - DEV: import.meta.env.VITE_APP_DEV_BRIDGE_URL || process.env.VITE_APP_DEV_BRIDGE_URL || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_BRIDGE_URL || process.env.VITE_APP_PRIVATE_BRIDGE_URL || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_BRIDGE_URL || process.env.VITE_APP_PUBLIC_BRIDGE_URL || "", - MAINNET: import.meta.env.VITE_APP_MAINNET_BRIDGE_URL || process.env.VITE_APP_MAINNET_BRIDGE_URL || "", - }, - GRAPHQL_URL: { - LOCAL: import.meta.env.VITE_APP_LOCAL_GRAPHQL_URL || process.env.VITE_APP_LOCAL_GRAPHQL_URL || "", - DEV: import.meta.env.VITE_APP_DEV_GRAPHQL_URL || process.env.VITE_APP_DEV_GRAPHQL_URL || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_GRAPHQL_URL || process.env.VITE_APP_PRIVATE_GRAPHQL_URL || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_GRAPHQL_URL || process.env.VITE_APP_PUBLIC_GRAPHQL_URL || "", - MAINNET: import.meta.env.VITE_APP_MAINNET_GRAPHQL_URL || process.env.VITE_APP_MAINNET_GRAPHQL_URL || "" - }, - GRAPHQL_WS: { - LOCAL: import.meta.env.VITE_APP_LOCAL_GRAPHQL_WS || process.env.VITE_APP_LOCAL_GRAPHQL_WS || "", - DEV: import.meta.env.VITE_APP_DEV_GRAPHQL_WS || process.env.VITE_APP_DEV_GRAPHQL_WS || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_GRAPHQL_WS || process.env.VITE_APP_PRIVATE_GRAPHQL_WS || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_GRAPHQL_WS || process.env.VITE_APP_PUBLIC_GRAPHQL_WS || "", - MAINNET: import.meta.env.VITE_APP_MAINNET_GRAPHQL_WS || process.env.VITE_APP_MAINNET_GRAPHQL_WS || "" - }, - RPC_ADDRESS: { - LOCAL: import.meta.env.VITE_APP_LOCAL_RPC || process.env.VITE_APP_LOCAL_RPC || "", - DEV: import.meta.env.VITE_APP_DEV_RPC || process.env.VITE_APP_DEV_RPC || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_RPC || process.env.VITE_APP_PRIVATE_RPC || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_RPC || process.env.VITE_APP_PUBLIC_RPC || "", - MAINNET: import.meta.env.VITE_APP_MAINNET_RPC || process.env.VITE_APP_MAINNET_RPC || "" - }, - API_ADDRESS: { - LOCAL: import.meta.env.VITE_APP_LOCAL_API || process.env.VITE_APP_LOCAL_API || "", - DEV: import.meta.env.VITE_APP_DEV_API || process.env.VITE_APP_DEV_API || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_API || process.env.VITE_APP_PRIVATE_API || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_API || process.env.VITE_APP_PUBLIC_API || "", - MAINNET: import.meta.env.VITE_APP_MAINNET_API || process.env.VITE_APP_MAINNET_API || "" - }, - STAKING_URL: { - LOCAL: import.meta.env.VITE_APP_LOCAL_STAKING_URL || process.env.VITE_APP_LOCAL_STAKING_URL || "", - DEV: import.meta.env.VITE_APP_DEV_STAKING_URL || process.env.VITE_APP_DEV_STAKING_URL || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_STAKING_URL || process.env.VITE_APP_PRIVATE_STAKING_URL || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_STAKING_URL || process.env.VITE_APP_PUBLIC_STAKING_URL || "", - MAINNET: import.meta.env.VITE_APP_MAINNET_STAKING_URL || process.env.VITE_APP_MAINNET_STAKING_URL || "" - }, - EXPLORER_URL: { - LOCAL: import.meta.env.VITE_APP_LOCAL_EXPLORER_URL || process.env.VITE_APP_LOCAL_EXPLORER_URL || "", - DEV: import.meta.env.VITE_APP_DEV_EXPLORER_URL || process.env.VITE_APP_DEV_EXPLORER_URL || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_EXPLORER_URL || process.env.VITE_APP_PRIVATE_EXPLORER_URL || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_EXPLORER_URL || process.env.VITE_APP_PUBLIC_EXPLORER_URL || "", - MAINNET: import.meta.env.VITE_APP_MAINNET_EXPLORER_URL || process.env.VITE_APP_MAINNET_EXPLORER_URL || "" - }, - CHAIN_NAME: { - LOCAL: import.meta.env.VITE_APP_LOCAL_CHAIN_NAME || process.env.VITE_APP_LOCAL_CHAIN_NAME || "", - DEV: import.meta.env.VITE_APP_DEV_CHAIN_NAME || process.env.VITE_APP_DEV_CHAIN_NAME || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_CHAIN_NAME || process.env.VITE_APP_PRIVATE_CHAIN_NAME || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_CHAIN_NAME || process.env.VITE_APP_PUBLIC_CHAIN_NAME || "", - MAINNET: import.meta.env.VITE_APP_MAINNET_CHAIN_NAME || process.env.VITE_APP_MAINNET_CHAIN_NAME || "" - }, - CHAIN_ID: { - LOCAL: import.meta.env.VITE_APP_LOCAL_CHAIN_ID || process.env.VITE_APP_LOCAL_CHAIN_ID || "", - DEV: import.meta.env.VITE_APP_DEV_CHAIN_ID || process.env.VITE_APP_DEV_CHAIN_ID || "", - PRIVATE: import.meta.env.VITE_APP_PRIVATE_CHAIN_ID || process.env.VITE_APP_PRIVATE_CHAIN_ID || "", - PUBLIC: import.meta.env.VITE_APP_PUBLIC_CHAIN_ID || process.env.VITE_APP_PUBLIC_CHAIN_ID || "", - MAINNET: import.meta.env.VITE_APP_MAINNET_CHAIN_ID || process.env.VITE_APP_MAINNET_CHAIN_ID || "" - }, - LOCAL: { - ALIAS_NAME: 'Local Testnet', - SHORT_NAMES: ['local'] - }, - DEV: { - ALIAS_NAME: 'DEV Environment', - SHORT_NAMES: ['cudos-dev-test-network', 'dev-network'] - }, - PRIVATE: { - ALIAS_NAME: 'Private Testnet', - SHORT_NAMES: ['private', 'dev-test'] - }, - PUBLIC: { - ALIAS_NAME: 'Public Testnet', - SHORT_NAMES: ['public'] - }, - MAINNET: { - ALIAS_NAME: 'Main Network', - SHORT_NAMES: ['mainnet', 'cudos-1'] - } + CAPTCHA_SITE_KEY: import.meta.env.VITE_APP_CAPTCHA_SITE_KEY || process.env.VITE_APP_CAPTCHA_SITE_KEY || "", + FAUCET_URL: import.meta.env.VITE_APP_FAUCET_URL || process.env.VITE_APP_FAUCET_URL || "", + FAUCET_ADDRESS: import.meta.env.VITE_APP_FAUCET_ADDRESS || process.env.VITE_APP_FAUCET_ADDRESS || "", + BRIDGE_URL: import.meta.env.VITE_APP_BRIDGE_URL || process.env.VITE_APP_BRIDGE_URL || "", + GRAPHQL_URL: import.meta.env.VITE_APP_GRAPHQL_URL || process.env.VITE_APP_GRAPHQL_URL || "", + GRAPHQL_WS: import.meta.env.VITE_APP_GRAPHQL_WS || process.env.VITE_APP_GRAPHQL_WS || "", + RPC_ADDRESS: import.meta.env.VITE_APP_RPC || process.env.VITE_APP_RPC || "", + API_ADDRESS: import.meta.env.VITE_APP_API || process.env.VITE_APP_API || "", + STAKING_URL: import.meta.env.VITE_APP_STAKING_URL || process.env.VITE_APP_STAKING_URL || "", + EXPLORER_URL: import.meta.env.VITE_APP_EXPLORER_URL || process.env.VITE_APP_EXPLORER_URL || "", + CHAIN_NAME: import.meta.env.VITE_APP_CHAIN_NAME || process.env.VITE_APP_CHAIN_NAME || "", + CHAIN_ID: import.meta.env.VITE_APP_CHAIN_ID || process.env.VITE_APP_CHAIN_ID || "" } // GENERAL APP CONFIGURATIONS export const APP_DETAILS = { - DEPLOYMENT_VERSION: import.meta.env.VITE_APP_DEPLOYMENT_VERSION || process.env.VITE_APP_DEPLOYMENT_VERSION || "" + DEPLOYMENT_VERSION: import.meta.env.VITE_APP_DEPLOYMENT_VERSION || process.env.VITE_APP_DEPLOYMENT_VERSION || "", + NODE_ENV: import.meta.env.VITE_APP_NODE_ENV || process.env.VITE_APP_NODE_ENV || "", } export const SCREEN_RESOLUTIONS = { diff --git a/src/utils/projectUtils.tsx b/src/utils/projectUtils.tsx index d2eb43d..f255a1b 100644 --- a/src/utils/projectUtils.tsx +++ b/src/utils/projectUtils.tsx @@ -9,8 +9,6 @@ import { fetchDelegations } from 'api/getAccountDelegations' import { fetchRedelegations } from 'api/getAccountRedelegations' import { fetchUndedelegations } from 'api/getAccountUndelegations' import { getUnbondingBalance } from 'api/getUnbondingBalance' -import { CHAIN_DETAILS } from './constants' -import { detect as detectBrowser } from 'detect-browser' import CosmostationLogo from 'assets/vectors/cosmostation-logo.svg' import KeplrLogo from 'assets/vectors/keplr-logo.svg' import { styles } from 'containers/ConnectWallet/styles' @@ -45,8 +43,8 @@ export const formatAddress = (text: string, sliceIndex: number): string => { return `${text.slice(0, sliceIndex)}...${text.slice(len - 4, len)}` } -export const getWalletBalance = async (chosenNetwork: string, address: string) => { - const queryClient = await getQueryClient(chosenNetwork) +export const getWalletBalance = async (address: string) => { + const queryClient = await getQueryClient() const updateWalletBalance = await queryClient.getBalance(address, CosmosNetworkConfig.CURRENCY_DENOM) return new BigNumber(updateWalletBalance.amount) @@ -54,8 +52,8 @@ export const getWalletBalance = async (chosenNetwork: string, address: string) = .toString(10) } -export const getStakedBalance = async (chosenNetwork: string, address: string) => { - const queryClient = await getQueryClient(chosenNetwork) +export const getStakedBalance = async (address: string) => { + const queryClient = await getQueryClient() const updateWalletBalance = await queryClient.getBalanceStaked(address) if (updateWalletBalance === null) { @@ -94,21 +92,20 @@ export const addEndingEllipsis = ( return input } -export const connectUser = async (chosenNetwork: string, walletName: SUPPORTED_WALLET): Promise => { +export const connectUser = async (walletName: SUPPORTED_WALLET): Promise => { try { - const { address, accountName } = await switchLedgerType(chosenNetwork!, walletName) - const balance = await getWalletBalance(chosenNetwork, address!) - const stakedAmountBalance = await getStakedBalance(chosenNetwork, address!) - const { totalRewards, validatorArray } = await fetchRewards(chosenNetwork, address!) - const { delegationsArray } = await fetchDelegations(chosenNetwork, address) - const { redelegationsArray } = await fetchRedelegations(chosenNetwork, address) - const { undelegationsArray } = await fetchUndedelegations(chosenNetwork, address) - const { unbondingBalance } = await getUnbondingBalance(chosenNetwork, address) + const { address, accountName } = await switchLedgerType(walletName) + const balance = await getWalletBalance(address!) + const stakedAmountBalance = await getStakedBalance(address!) + const { totalRewards, validatorArray } = await fetchRewards(address!) + const { delegationsArray } = await fetchDelegations(address) + const { redelegationsArray } = await fetchRedelegations(address) + const { undelegationsArray } = await fetchUndedelegations(address) + const { unbondingBalance } = await getUnbondingBalance(address) const connectedUser = { - chosenNetwork, address, lastLoggedAddress: address, connectedLedger: walletName, @@ -131,23 +128,19 @@ export const connectUser = async (chosenNetwork: string, walletName: SUPPORTED_W } -export const handleAvailableNetworks = (defaultNetwork: string): networkToDisplay[] => { +export const getChainPrettyName = (chainId: string): string => { + switch (chainId) { + case 'cudos-testnet-private-3': + return 'Private Testnet' - if ( - CHAIN_DETAILS[defaultNetwork as keyof typeof CHAIN_DETAILS].ALIAS_NAME === - CHAIN_DETAILS.LOCAL.ALIAS_NAME - ) { - return [CHAIN_DETAILS.LOCAL] - } + case 'cudos-testnet-public-3': + return 'Public Testnet' - if ( - CHAIN_DETAILS[defaultNetwork as keyof typeof CHAIN_DETAILS].ALIAS_NAME === - CHAIN_DETAILS.PRIVATE.ALIAS_NAME - ) { - return [CHAIN_DETAILS.PRIVATE] - } + case 'cudos-1': + return 'Main Network' - return [CHAIN_DETAILS.PUBLIC, CHAIN_DETAILS.MAINNET] + default: return chainId + } } export const delay = (ms: number) => { diff --git a/types/global.d.ts b/types/global.d.ts index c6d2818..992d9c5 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -143,21 +143,21 @@ declare global { } interface ImportMetaEnv { - VITE_APP_CHAIN_ID: string + VITE_APP_DEPLOYMENT_VERSION: string + VITE_APP_NODE_ENV: string + VITE_APP_GAS_PRICE: number + VITE_APP_CAPTCHA_SITE_KEY: string + VITE_APP_FAUCET_URL: string + VITE_APP_FAUCET_ADDRESS: string + VITE_APP_BRIDGE_URL: string + VITE_APP_GRAPHQL_URL: string + VITE_APP_GRAPHQL_WS: string VITE_APP_RPC: string - VITE_GRAPHQL_URL: string - VITE_GRAPHQL_WS: string - VITE_APP_GAS_PRICE: decimal - VITE_APP_CHAIN_NAME: string VITE_APP_API: string - VITE_APP_EXPLORER_V2: string - VITE_APP_FEE_MULTIPLIER: number - VITE_BRIDGE_URL: string - VITE_FAUCET_ADDRESS: string - VITE_CHAIN_STATUS: string - VITE_CAPTCHA_SITE_KEY: string - VITE_FAUCET_URL: string VITE_APP_STAKING_URL: string + VITE_APP_EXPLORER_URL: string + VITE_APP_CHAIN_NAME: string + VITE_APP_CHAIN_ID: string } interface SxMap {