diff --git a/frontend/src/app/(routes)/(overview)/overview-components/OverviewDashboard.tsx b/frontend/src/app/(routes)/(overview)/overview-components/OverviewDashboard.tsx index 8a1d79c51..c480ef140 100644 --- a/frontend/src/app/(routes)/(overview)/overview-components/OverviewDashboard.tsx +++ b/frontend/src/app/(routes)/(overview)/overview-components/OverviewDashboard.tsx @@ -1,82 +1,11 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import AssetsTable from './AssetsTable'; import TokenAllocation from './TokenAllocation'; import BalanceSummary from './BalanceSummary'; import GovernanceView from './GovernanceView'; -import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; -import { getBalances } from '@/store/features/bank/bankSlice'; -import { - getDelegations, - getUnbonding, -} from '@/store/features/staking/stakeSlice'; -import { getAccountInfo } from '@/store/features/auth/authSlice'; -import { getDelegatorTotalRewards } from '@/store/features/distribution/distributionSlice'; -import { RootState } from '@/store/store'; import PageHeader from '@/components/common/PageHeader'; const OverviewDashboard = ({ chainIDs }: { chainIDs: string[] }) => { - const dispatch = useAppDispatch(); - const networks = useAppSelector((state) => state.wallet.networks); - useEffect(() => { - chainIDs.forEach((chainID) => { - const allChainInfo = networks[chainID]; - const chainInfo = allChainInfo.network; - const address = allChainInfo?.walletInfo?.bech32Address; - - const minimalDenom = - allChainInfo.network.config.stakeCurrency.coinMinimalDenom; - const basicChainInputs = { - baseURL: chainInfo.config.rest, - baseURLs: chainInfo.config.restURIs, - address, - chainID, - }; - // dispatch(getBalances(basicChainInputs)); - dispatch(getDelegations(basicChainInputs)); - dispatch(getAccountInfo(basicChainInputs)); - dispatch( - getDelegatorTotalRewards({ - baseURLs: chainInfo.config.restURIs, - baseURL: chainInfo.config.rest, - address: address, - chainID: chainID, - denom: minimalDenom, - }) - ); - dispatch( - getUnbonding({ - baseURLs: chainInfo.config.restURIs, - address: address, - chainID, - }) - ); - }); - }, []); - - const allNameToChainIDs = useAppSelector( - (state: RootState) => state.wallet.nameToChainIDs - ); - - useEffect(() => { - const allChainIDs = Object.keys(allNameToChainIDs).map( - (chainName) => allNameToChainIDs[chainName] - ); - - allChainIDs.forEach((chainID) => { - const allChainInfo = networks[chainID]; - const chainInfo = allChainInfo.network; - const address = allChainInfo?.walletInfo?.bech32Address; - const basicChainInputs = { - baseURL: chainInfo.config.rest, - baseURLs: chainInfo.config.restURIs, - address, - chainID, - }; - - dispatch(getBalances(basicChainInputs)); - }); - }, []); - return (
diff --git a/frontend/src/app/(routes)/(overview)/overview-components/OverviewTable.tsx b/frontend/src/app/(routes)/(overview)/overview-components/OverviewTable.tsx deleted file mode 100644 index e9d80468c..000000000 --- a/frontend/src/app/(routes)/(overview)/overview-components/OverviewTable.tsx +++ /dev/null @@ -1,125 +0,0 @@ -'use client'; - -import React, { useEffect } from 'react'; -import { RootState } from '../../../../store/store'; -import { getBalances } from '@/store/features/bank/bankSlice'; -import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; -import { - getDelegations, - getUnbonding, -} from '@/store/features/staking/stakeSlice'; -// import WalletSummery from './WalletSummery'; -// import TopNav from './TopNav'; -// import History from './History'; -// import PageAd from './PageAd'; -// import AssetsTable from './AssetsTable'; -// import AccountSummery from './AccountSummary'; -import { getAccountInfo } from '@/store/features/auth/authSlice'; -import { getDelegatorTotalRewards } from '@/store/features/distribution/distributionSlice'; -import useInitAuthzForOverview from '@/custom-hooks/useInitAuthzForOverview'; -// import AuthzToast from '@/components/AuthzToast'; -// import AuthzExecLoader from '@/components/AuthzExecLoader'; -// import FeegrantToast from '@/components/FeegrantToast'; -// import { getRecentTransactions } from '@/store/features/recent-transactions/recentTransactionsSlice'; -import useGetChainInfo from '@/custom-hooks/useGetChainInfo'; -import Image from 'next/image'; -import BalanceSummary from './BalanceSummary'; -import { setError } from '@/store/features/common/commonSlice'; -import { copyToClipboard } from '@/utils/copyToClipboard'; -import AssetsTable from './AssetsTable'; -import { shortenAddress } from '@/utils/util'; - -const OverviewTable = ({ chainIDs }: { chainIDs: string[] }) => { - const dispatch = useAppDispatch(); - - const networks = useAppSelector((state: RootState) => state.wallet.networks); - // const isAuthzMode = useAppSelector((state) => state.authz.authzModeEnabled); - // const isFeegrantMode = useAppSelector( - // (state) => state.feegrant.feegrantModeEnabled - // ); - const { getAllChainAddresses, getCosmosAddress } = useGetChainInfo(); - - const addresses = getAllChainAddresses(chainIDs); - - useInitAuthzForOverview(chainIDs); - useEffect(() => { - chainIDs.forEach((chainID) => { - const allChainInfo = networks[chainID]; - const chainInfo = allChainInfo.network; - const address = allChainInfo?.walletInfo?.bech32Address; - - const minimalDenom = - allChainInfo.network.config.stakeCurrency.coinMinimalDenom; - const basicChainInputs = { - baseURL: chainInfo.config.rest, - baseURLs: chainInfo.config.restURIs, - address, - chainID, - }; - dispatch(getBalances(basicChainInputs)); - dispatch(getDelegations(basicChainInputs)); - dispatch(getAccountInfo(basicChainInputs)); - dispatch( - getDelegatorTotalRewards({ - baseURLs: chainInfo.config.restURIs, - baseURL: chainInfo.config.rest, - address: address, - chainID: chainID, - denom: minimalDenom, - }) - ); - dispatch( - getUnbonding({ - baseURLs: chainInfo.config.restURIs, - address: address, - chainID, - }) - ); - }); - }, []); - - return ( -
-
-
-
-
-

- {shortenAddress(getCosmosAddress(), 20)} -

- { - copyToClipboard(addresses?.[0]?.address); - dispatch( - setError({ - type: 'success', - message: 'Copied', - }) - ); - e.preventDefault(); - e.stopPropagation(); - }} - src="/copy.svg" - width={24} - height={24} - alt="copy" - draggable={false} - className="cursor-pointer" - /> -
-
-
- Summary of your assets across all chains -
-
-
- - -
- - -
- ); -}; - -export default OverviewTable; diff --git a/frontend/src/app/(routes)/governance/[network]/[proposalId]/SingleProposal.tsx b/frontend/src/app/(routes)/governance/[network]/[proposalId]/SingleProposal.tsx index 62dfd8e04..a2ebb2117 100644 --- a/frontend/src/app/(routes)/governance/[network]/[proposalId]/SingleProposal.tsx +++ b/frontend/src/app/(routes)/governance/[network]/[proposalId]/SingleProposal.tsx @@ -321,7 +321,7 @@ const SingleProposal: React.FC = ({ padding: 8, whiteSpace: 'pre-line', }} - className={`proposal-description-markdown h-[42vh] secondary-text ${contentLength > 900 ? (showFullText ? 'overflow-scroll' : 'overflow-hidden') : 'overflow-scroll'}`} + className={`proposal-description-markdown h-[42vh] ${contentLength > 900 ? (showFullText ? 'overflow-scroll' : 'overflow-hidden') : 'overflow-scroll'}`} > {proposalMarkdown}

diff --git a/frontend/src/app/(routes)/governance/popups/DialogDeposit.tsx b/frontend/src/app/(routes)/governance/popups/DialogDeposit.tsx index 431f953b3..c2f75e2f7 100644 --- a/frontend/src/app/(routes)/governance/popups/DialogDeposit.tsx +++ b/frontend/src/app/(routes)/governance/popups/DialogDeposit.tsx @@ -2,7 +2,6 @@ import CustomButton from '@/components/common/CustomButton'; import CustomDialog from '@/components/common/CustomDialog'; import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; import useGetChainInfo from '@/custom-hooks/useGetChainInfo'; -import { getAuthzBalances, getBalances } from '@/store/features/bank/bankSlice'; import { parseBalance } from '@/utils/denom'; import React, { useEffect, useState } from 'react'; import AmountInputWrapper from '../utils-components/AmountInputWrapper'; @@ -12,7 +11,6 @@ import useAuthzExecHelper from '@/custom-hooks/useAuthzExecHelper'; import useGetFeegranter from '@/custom-hooks/useGetFeegranter'; import { txDeposit } from '@/store/features/gov/govSlice'; import { MAP_TXN_MSG_TYPES } from '@/utils/feegrant'; -import useAddressConverter from '@/custom-hooks/useAddressConverter'; const DialogDeposit = ({ onClose, @@ -33,18 +31,11 @@ const DialogDeposit = ({ const { getChainInfo, getDenomInfo } = useGetChainInfo(); const { getVoteTxInputs } = useGetTxInputs(); const { txAuthzDeposit } = useAuthzExecHelper(); - const { convertAddress } = useAddressConverter(); const { decimals, minimalDenom, displayDenom } = getDenomInfo(chainID); - const { - address, - baseURL, - restURLs: baseURLs, - feeAmount, - } = getChainInfo(chainID); + const { feeAmount } = getChainInfo(chainID); const isAuthzMode = useAppSelector((state) => state.authz.authzModeEnabled); - const authzAddress = useAppSelector((state) => state.authz.authzAddress); const [availableBalance, setAvailableBalance] = useState(0); const [depositAmount, setDepositAmount] = useState(''); @@ -147,22 +138,6 @@ const DialogDeposit = ({ ); }; - useEffect(() => { - if (chainID) { - const authzGranterAddress = convertAddress(chainID, authzAddress); - dispatch( - isAuthzMode - ? getAuthzBalances({ - address: authzGranterAddress, - baseURL, - baseURLs, - chainID, - }) - : getBalances({ chainID, address, baseURL, baseURLs }) - ); - } - }, [chainID]); - useEffect(() => { if (balance) { setAvailableBalance( diff --git a/frontend/src/app/(routes)/multiops/components/Messages/Delegate.tsx b/frontend/src/app/(routes)/multiops/components/Messages/Delegate.tsx index fa7914cca..46de4137b 100644 --- a/frontend/src/app/(routes)/multiops/components/Messages/Delegate.tsx +++ b/frontend/src/app/(routes)/multiops/components/Messages/Delegate.tsx @@ -1,4 +1,4 @@ -import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; +import { useAppSelector } from '@/custom-hooks/StateHooks'; import { RootState } from '@/store/store'; import React, { useEffect, useState } from 'react'; import { Controller, useForm } from 'react-hook-form'; @@ -10,7 +10,6 @@ import { TextField, } from '@mui/material'; import { autoCompleteStyles, autoCompleteTextFieldStyles } from '../../styles'; -import { getAllValidators } from '@/store/features/staking/stakeSlice'; import AddressField from '../AddressField'; import AmountInputField from '../AmountInputField'; import { TxStatus } from '@/types/enums'; @@ -26,14 +25,12 @@ interface DelegateProps { } const Delegate: React.FC = (props) => { - const dispatch = useAppDispatch(); const { chainID, address, onDelegate, currency, availableBalance, - baseURLs, feeAmount, } = props; const { @@ -110,15 +107,6 @@ const Delegate: React.FC = (props) => { } }; - useEffect(() => { - dispatch( - getAllValidators({ - baseURLs: baseURLs, - chainID, - }) - ); - }, [chainID]); - return (
= (props) => {
- diff --git a/frontend/src/app/(routes)/multiops/components/Messages/Redelegate.tsx b/frontend/src/app/(routes)/multiops/components/Messages/Redelegate.tsx index 72612dbb0..aed84d933 100644 --- a/frontend/src/app/(routes)/multiops/components/Messages/Redelegate.tsx +++ b/frontend/src/app/(routes)/multiops/components/Messages/Redelegate.tsx @@ -10,10 +10,7 @@ import { TextField, } from '@mui/material'; import { autoCompleteStyles, autoCompleteTextFieldStyles } from '../../styles'; -import { - getAllValidators, - getDelegations, -} from '@/store/features/staking/stakeSlice'; +import { getDelegations } from '@/store/features/staking/stakeSlice'; import useGetChainInfo from '@/custom-hooks/useGetChainInfo'; import AddressField from '../AddressField'; import { TxStatus } from '@/types/enums'; @@ -48,7 +45,7 @@ const isValueExists = ( }; const Redelegate: React.FC = (props) => { - const { chainID, address, onRedelegate, currency, baseURLs } = props; + const { chainID, address, onRedelegate, currency } = props; const { getChainInfo } = useGetChainInfo(); const { restURLs } = getChainInfo(chainID); const dispatch = useAppDispatch(); @@ -185,12 +182,6 @@ const Redelegate: React.FC = (props) => { useEffect(() => { dispatch(getDelegations({ address, chainID, baseURLs: restURLs })); - dispatch( - getAllValidators({ - baseURLs: baseURLs, - chainID, - }) - ); }, [chainID]); return ( @@ -396,10 +387,7 @@ const Redelegate: React.FC = (props) => { - diff --git a/frontend/src/app/(routes)/multiops/components/Messages/Undelegate.tsx b/frontend/src/app/(routes)/multiops/components/Messages/Undelegate.tsx index df1e6f27f..66ff1c90a 100644 --- a/frontend/src/app/(routes)/multiops/components/Messages/Undelegate.tsx +++ b/frontend/src/app/(routes)/multiops/components/Messages/Undelegate.tsx @@ -1,9 +1,6 @@ import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; import useGetChainInfo from '@/custom-hooks/useGetChainInfo'; -import { - getAllValidators, - getDelegations, -} from '@/store/features/staking/stakeSlice'; +import { getDelegations } from '@/store/features/staking/stakeSlice'; import React, { useEffect, useState } from 'react'; import { Decimal } from '@cosmjs/math'; import { Controller, useForm } from 'react-hook-form'; @@ -67,12 +64,6 @@ const Undelegate = (props: UnDelegateProps) => { useEffect(() => { dispatch(getDelegations({ address, chainID, baseURLs: restURLs })); - dispatch( - getAllValidators({ - baseURLs: baseURLs, - chainID, - }) - ); }, [chainID]); const [selectedValBal, setSelectedValBal] = useState({ diff --git a/frontend/src/app/(routes)/multisig/components/multisig-account/MultisigAccount.tsx b/frontend/src/app/(routes)/multisig/components/multisig-account/MultisigAccount.tsx index 9f21691db..471293d0b 100644 --- a/frontend/src/app/(routes)/multisig/components/multisig-account/MultisigAccount.tsx +++ b/frontend/src/app/(routes)/multisig/components/multisig-account/MultisigAccount.tsx @@ -10,10 +10,7 @@ import { resetUpdateTxnState, setVerifyDialogOpen, } from '@/store/features/multisig/multisigSlice'; -import { - getAllValidators, - getDelegations, -} from '@/store/features/staking/stakeSlice'; +import { getDelegations } from '@/store/features/staking/stakeSlice'; import { useEffect, useState } from 'react'; import MultisigAccountHeader from './MultisigAccountHeader'; import Copy from '@/components/common/Copy'; @@ -101,7 +98,6 @@ const MultisigAccount = ({ chainID, }) ); - dispatch(getAllValidators({ baseURLs: restURLs, chainID })); dispatch(multisigByAddress({ address: multisigAddress })); dispatch(getMultisigAccounts(walletAddress)); } diff --git a/frontend/src/app/(routes)/settings/authz/new-authz/components/ValidatorAutoComplete.tsx b/frontend/src/app/(routes)/settings/authz/new-authz/components/ValidatorAutoComplete.tsx index 5b561a4a6..cea98a189 100644 --- a/frontend/src/app/(routes)/settings/authz/new-authz/components/ValidatorAutoComplete.tsx +++ b/frontend/src/app/(routes)/settings/authz/new-authz/components/ValidatorAutoComplete.tsx @@ -1,6 +1,5 @@ import useStaking from '@/custom-hooks/txn-builder/useStaking'; -import useGetChainInfo from '@/custom-hooks/useGetChainInfo'; -import React, { useEffect, useState } from 'react'; +import React, { useState } from 'react'; import ValidatorLogo from '@/app/(routes)/staking/components/ValidatorLogo'; import { customAutoCompleteStyles, @@ -14,9 +13,8 @@ import { Paper, TextField, } from '@mui/material'; -import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; +import { useAppSelector } from '@/custom-hooks/StateHooks'; import { TxStatus } from '@/types/enums'; -import { getAllValidators } from '@/store/features/staking/stakeSlice'; /** @jsxImportSource @emotion/react */ import { css } from '@emotion/react'; import { REMOVE_ICON_OUTLINED } from '@/constants/image-names'; @@ -35,9 +33,6 @@ const ValidatorAutoComplete = ({ chainID: string; handleSelectValidators: (data: string[]) => void; }) => { - const dispatch = useAppDispatch(); - const { getChainInfo } = useGetChainInfo(); - const { restURLs: baseURLs } = getChainInfo(chainID); const { getValidators } = useStaking(); const { validatorsList } = getValidators({ chainID }); const [selectedOptions, setSelectedOptions] = useState([]); @@ -67,10 +62,6 @@ const ValidatorAutoComplete = ({ handleSelectValidators(validators); }; - useEffect(() => { - if (chainID?.length) dispatch(getAllValidators({ chainID, baseURLs })); - }, []); - return (
{ - useInitStaking(chainID); const staking = useSingleStaking(chainID); const { totalStakedAmount, diff --git a/frontend/src/app/(routes)/staking/components/DelegatePopup.tsx b/frontend/src/app/(routes)/staking/components/DelegatePopup.tsx index 1a8b2b695..6ba620df6 100644 --- a/frontend/src/app/(routes)/staking/components/DelegatePopup.tsx +++ b/frontend/src/app/(routes)/staking/components/DelegatePopup.tsx @@ -36,7 +36,7 @@ const DelegatePopup: React.FC = ({ const denom = singleStake.getDenomWithChainID(chainID); // Custom hook to get staking information - const staking = useStaking({ isSingleChain: true }); + const staking = useStaking(); // Get the current validator's information from the staking module const stakeModule = staking.getAllDelegations(); diff --git a/frontend/src/app/(routes)/staking/components/NewDelegationDialog.tsx b/frontend/src/app/(routes)/staking/components/NewDelegationDialog.tsx index 7abd0a055..f954c18f0 100644 --- a/frontend/src/app/(routes)/staking/components/NewDelegationDialog.tsx +++ b/frontend/src/app/(routes)/staking/components/NewDelegationDialog.tsx @@ -43,7 +43,7 @@ const NewDelegationDialog: React.FC = ({ const denom = singleStake.getDenomWithChainID(chainID); // Custom hook to get staking information - const staking = useStaking({ isSingleChain: true }); + const staking = useStaking(); const availableAmount = singleStake.getAvaiailableAmount(chainID); diff --git a/frontend/src/app/(routes)/staking/components/ReDelegatePopup.tsx b/frontend/src/app/(routes)/staking/components/ReDelegatePopup.tsx index 9131e75bd..b6bc7f6df 100644 --- a/frontend/src/app/(routes)/staking/components/ReDelegatePopup.tsx +++ b/frontend/src/app/(routes)/staking/components/ReDelegatePopup.tsx @@ -1,7 +1,7 @@ 'use client'; import CustomDialog from '@/components/common/CustomDialog'; -import { useEffect, useState } from 'react'; +import { useState } from 'react'; import Image from 'next/image'; import AddressField from './AddressField'; import useSingleStaking from '@/custom-hooks/useSingleStaking'; @@ -11,9 +11,7 @@ import ValidatorLogo from './ValidatorLogo'; import { WalletAddress } from '@/components/main-layout/SelectNetwork'; import { Validator } from '@/types/staking'; import ValidatorName from './ValidatorName'; -import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; -import { getAllValidators } from '@/store/features/staking/stakeSlice'; -import useGetChainInfo from '@/custom-hooks/useGetChainInfo'; +import { useAppSelector } from '@/custom-hooks/StateHooks'; import { TxStatus } from '@/types/enums'; interface PopupProps { @@ -29,9 +27,6 @@ const ReDelegatePopup: React.FC = ({ openPopup, openReDelegatePopup, }) => { - const dispatch = useAppDispatch(); - const { getChainInfo } = useGetChainInfo(); - const { restURLs } = getChainInfo(chainID); const validatorsLoading = useAppSelector( (state) => state.staking.chains?.[chainID]?.validators.status ); @@ -47,7 +42,7 @@ const ReDelegatePopup: React.FC = ({ validator ); const denom = singleStake.getDenomWithChainID(chainID); - const staking = useStaking({ isSingleChain: true }); + const staking = useStaking(); const allVals = singleStake.getValidators()?.active; const stakeModule = staking.getAllDelegations(); const val = stakeModule[chainID]?.validators?.active?.[validator]; @@ -87,10 +82,6 @@ const ReDelegatePopup: React.FC = ({ setIsOpen(!isOpen); }; - useEffect(() => { - if (chainID) dispatch(getAllValidators({ baseURLs: restURLs, chainID })); - }, [chainID]); - return ( <> { const dispatch = useAppDispatch(); - const staking = useStaking({ isSingleChain: false }); + const staking = useStaking(); const { totalStakedAmount, rewardsAmount, diff --git a/frontend/src/app/(routes)/staking/components/StakingDelegations.tsx b/frontend/src/app/(routes)/staking/components/StakingDelegations.tsx index 9ee8d50c2..840c6dde4 100644 --- a/frontend/src/app/(routes)/staking/components/StakingDelegations.tsx +++ b/frontend/src/app/(routes)/staking/components/StakingDelegations.tsx @@ -20,7 +20,7 @@ function StakingDelegations({ delegations: Chains; isSingleChain: boolean; }) { - const staking = useStaking({ isSingleChain: isSingleChain }); + const staking = useStaking(); const validator = useValidator(); // Function to get the commission rate of a validator diff --git a/frontend/src/app/(routes)/staking/components/StakingUnDelegations.tsx b/frontend/src/app/(routes)/staking/components/StakingUnDelegations.tsx index 70798d45d..77421a974 100644 --- a/frontend/src/app/(routes)/staking/components/StakingUnDelegations.tsx +++ b/frontend/src/app/(routes)/staking/components/StakingUnDelegations.tsx @@ -18,7 +18,7 @@ function StakingUnDelegations({ undelegations: Chains; isSingleChain?: boolean; }) { - const staking = useStaking({ isSingleChain: true }); + const staking = useStaking(); const nameToChainIDs = useAppSelector( (state: RootState) => state.wallet.nameToChainIDs diff --git a/frontend/src/app/(routes)/staking/components/UndelegatePopup.tsx b/frontend/src/app/(routes)/staking/components/UndelegatePopup.tsx index 6d208fb4c..ccf832f2d 100644 --- a/frontend/src/app/(routes)/staking/components/UndelegatePopup.tsx +++ b/frontend/src/app/(routes)/staking/components/UndelegatePopup.tsx @@ -39,7 +39,7 @@ const UndelegatePopup: React.FC = ({ const denom = singleStake.getDenomWithChainID(chainID); // Custom hook to get staking information - const staking = useStaking({ isSingleChain: true }); + const staking = useStaking(); // Get the current validator's information from the staking module const stakeModule = staking.getAllDelegations(); diff --git a/frontend/src/app/(routes)/transactions/history/[network]/components/Transaction.tsx b/frontend/src/app/(routes)/transactions/history/[network]/components/Transaction.tsx index df0701ec5..f34ec8198 100644 --- a/frontend/src/app/(routes)/transactions/history/[network]/components/Transaction.tsx +++ b/frontend/src/app/(routes)/transactions/history/[network]/components/Transaction.tsx @@ -78,6 +78,7 @@ const Transaction = ({
= ({ @@ -25,6 +26,7 @@ const TransactionHeader: React.FC = ({ goBackUrl, isSearchPage, mintscanURL, + rawLog }) => { const isSuccess = status === 'success'; const textColorClass = isSuccess ? 'text-[#2BA472]' : 'text-[#FA5E42]'; @@ -37,56 +39,67 @@ const TransactionHeader: React.FC = ({ Go back )} -
-
-
- {isSuccess -
- {isSuccess ? 'Transaction Successful' : 'Transaction Failed'} -
+
+
+ {isSuccess +
+ {isSuccess ? 'Transaction Successful' : 'Transaction Failed'}
- {!isSuccess &&
} -
-
-
{hash}
- +
+ {!isSuccess &&
} + { + !isSuccess &&
+
+ {isSuccess ? null : rawLog} +
+
+
|| null + } +
+
+
+
+
{hash}
+ +
+
-
-
-
- {isSearchPage ? null : ( - - )} - {mintscanURL ? ( - -
View on Mintscan
- View Proposal + {isSearchPage ? null : ( + - - ) : null} + )} + {mintscanURL ? ( + +
View on Mintscan
+ View Proposal + + ) : null} +
+
); diff --git a/frontend/src/app/(routes)/transfers/components/TransfersPage.tsx b/frontend/src/app/(routes)/transfers/components/TransfersPage.tsx index 739d82406..d2bb93505 100644 --- a/frontend/src/app/(routes)/transfers/components/TransfersPage.tsx +++ b/frontend/src/app/(routes)/transfers/components/TransfersPage.tsx @@ -1,5 +1,4 @@ import React, { useEffect, useState } from 'react'; -import useInitBalances from '@/custom-hooks/useInitBalances'; import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; import useSortedAssets from '@/custom-hooks/useSortedAssets'; import { useSearchParams } from 'next/navigation'; @@ -22,8 +21,6 @@ const TransfersPage = ({ chainIDs }: { chainIDs: string[] }) => { const isAuthzMode = useAppSelector((state) => state.authz.authzModeEnabled); - useInitBalances({ chainIDs }); - const dispatch = useAppDispatch(); const isWalletConnected = useAppSelector((state) => state.wallet.connected); diff --git a/frontend/src/components/main-layout/FixedLayout.tsx b/frontend/src/components/main-layout/FixedLayout.tsx index c16e8881c..a37ebc525 100644 --- a/frontend/src/components/main-layout/FixedLayout.tsx +++ b/frontend/src/components/main-layout/FixedLayout.tsx @@ -4,7 +4,7 @@ import React, { useEffect } from 'react'; import TopBar from './TopBar'; import SideBar from './SideBar'; import '@/app/fixed-layout.css'; -import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; +import { useAppDispatch } from '@/custom-hooks/StateHooks'; import { networks } from '@/utils/chainsInfo'; import { connectSnap, @@ -25,24 +25,12 @@ import { setAllNetworksInfo } from '@/store/features/common/commonSlice'; import useShortCuts from '@/custom-hooks/useShortCuts'; import TransactionStatusPopup from '../txn-status-popups/TransactionStatusPopup'; import IBCSwapTxStatus from '../IBCSwapTxStatus'; -import useFetchPriceInfo from '@/custom-hooks/useFetchPriceInfo'; import Footer from '../common/Footer'; -import useInitFeegrant from '@/custom-hooks/useInitFeegrant'; -import useInitAuthz from '@/custom-hooks/useInitAuthz'; import DynamicSection from './DynamicSection'; +import useInitApp from '@/custom-hooks/common/useInitApp'; const FixedLayout = ({ children }: { children: React.ReactNode }) => { const dispatch = useAppDispatch(); - const nameToChainIDs = useAppSelector((state) => state.wallet.nameToChainIDs); - const isFeegrantModeEnabled = useAppSelector( - (state) => state.feegrant.feegrantModeEnabled - ); - const isAuthzModeEnabled = useAppSelector( - (state) => state.authz.authzModeEnabled - ); - const chainIDs = Object.keys(nameToChainIDs).map( - (chainName) => nameToChainIDs[chainName] - ); useShortCuts(); const tryConnectWallet = async (walletName: string) => { @@ -105,9 +93,8 @@ const FixedLayout = ({ children }: { children: React.ReactNode }) => { }; }, []); - useFetchPriceInfo(); - useInitFeegrant({ chainIDs, shouldFetch: isFeegrantModeEnabled }); - useInitAuthz({ chainIDs, shouldFetch: isAuthzModeEnabled }); + // Initialize the application state + useInitApp(); return (
diff --git a/frontend/src/components/txn-builder/messages/DelegateForm.tsx b/frontend/src/components/txn-builder/messages/DelegateForm.tsx index 891fc5d76..c97086089 100644 --- a/frontend/src/components/txn-builder/messages/DelegateForm.tsx +++ b/frontend/src/components/txn-builder/messages/DelegateForm.tsx @@ -1,12 +1,10 @@ import { customMUITextFieldStyles } from '@/app/(routes)/multiops/styles'; import { InputAdornment, TextField } from '@mui/material'; -import React, { useEffect, useState } from 'react'; +import React, { useState } from 'react'; import { Controller, useForm } from 'react-hook-form'; import CustomAutoComplete from '../components/CustomAutoComplete'; import useStaking from '@/custom-hooks/txn-builder/useStaking'; -import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; -import { getAllValidators } from '@/store/features/staking/stakeSlice'; -import useGetChainInfo from '@/custom-hooks/useGetChainInfo'; +import { useAppSelector } from '@/custom-hooks/StateHooks'; import { TxStatus } from '@/types/enums'; import { Decimal } from '@cosmjs/math'; import { formatCoin } from '@/utils/util'; @@ -31,9 +29,6 @@ const DelegateForm = (props: DelegateFormProps) => { availableBalance, cancelAddMsg, } = props; - const dispatch = useAppDispatch(); - const { getChainInfo } = useGetChainInfo(); - const { restURLs: baseURLs } = getChainInfo(chainID); const { getValidators } = useStaking(); const { validatorsList } = getValidators({ chainID }); const [selectedOption, setSelectedOption] = useState( @@ -57,12 +52,6 @@ const DelegateForm = (props: DelegateFormProps) => { setSelectedOption(option); }; - useEffect(() => { - if (chainID) { - dispatch(getAllValidators({ chainID, baseURLs })); - } - }, []); - const onSubmit = (data: { amount: string; validator: string; diff --git a/frontend/src/components/txn-builder/messages/RedelegateForm.tsx b/frontend/src/components/txn-builder/messages/RedelegateForm.tsx index e9c7aa0ea..aec7f1b55 100644 --- a/frontend/src/components/txn-builder/messages/RedelegateForm.tsx +++ b/frontend/src/components/txn-builder/messages/RedelegateForm.tsx @@ -5,10 +5,7 @@ import { Controller, useForm } from 'react-hook-form'; import CustomAutoComplete from '../components/CustomAutoComplete'; import useStaking from '@/custom-hooks/txn-builder/useStaking'; import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; -import { - getAllValidators, - getDelegations, -} from '@/store/features/staking/stakeSlice'; +import { getDelegations } from '@/store/features/staking/stakeSlice'; import useGetChainInfo from '@/custom-hooks/useGetChainInfo'; import { TxStatus } from '@/types/enums'; import { formatCoin } from '@/utils/util'; @@ -130,7 +127,6 @@ const RedelegateForm = (props: ReDelegateProps) => { useEffect(() => { if (chainID) { - dispatch(getAllValidators({ chainID, baseURLs })); dispatch(getDelegations({ chainID, baseURLs, address: fromAddress })); } }, []); diff --git a/frontend/src/components/txn-builder/messages/UndelegateForm.tsx b/frontend/src/components/txn-builder/messages/UndelegateForm.tsx index 2ec2cbf85..ff748b979 100644 --- a/frontend/src/components/txn-builder/messages/UndelegateForm.tsx +++ b/frontend/src/components/txn-builder/messages/UndelegateForm.tsx @@ -5,10 +5,7 @@ import { Controller, useForm } from 'react-hook-form'; import CustomAutoComplete from '../components/CustomAutoComplete'; import useStaking from '@/custom-hooks/txn-builder/useStaking'; import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; -import { - getAllValidators, - getDelegations, -} from '@/store/features/staking/stakeSlice'; +import { getDelegations } from '@/store/features/staking/stakeSlice'; import useGetChainInfo from '@/custom-hooks/useGetChainInfo'; import { TxStatus } from '@/types/enums'; import { formatCoin } from '@/utils/util'; @@ -117,7 +114,6 @@ const UndelegateForm = (props: UnDelegateProps) => { useEffect(() => { if (chainID) { - dispatch(getAllValidators({ chainID, baseURLs })); dispatch(getDelegations({ chainID, baseURLs, address: fromAddress })); } }, []); diff --git a/frontend/src/custom-hooks/common/useInitApp.ts b/frontend/src/custom-hooks/common/useInitApp.ts new file mode 100644 index 000000000..ea91d4cec --- /dev/null +++ b/frontend/src/custom-hooks/common/useInitApp.ts @@ -0,0 +1,101 @@ +import { useEffect } from 'react'; +import { RootState } from '@/store/store'; +import { + getAllValidators, + getAuthzDelegations, + getAuthzUnbonding, + getDelegations, + getUnbonding, +} from '@/store/features/staking/stakeSlice'; +import { + getAuthzDelegatorTotalRewards, + getDelegatorTotalRewards, +} from '@/store/features/distribution/distributionSlice'; +import { getAuthzBalances, getBalances } from '@/store/features/bank/bankSlice'; +import { useAppDispatch, useAppSelector } from '../StateHooks'; +import useAddressConverter from '../useAddressConverter'; +import useGetChainInfo from '../useGetChainInfo'; +import useFetchPriceInfo from '../useFetchPriceInfo'; +import useInitFeegrant from '../useInitFeegrant'; +import useInitAuthz from '../useInitAuthz'; + +/* eslint-disable react-hooks/rules-of-hooks */ +const useInitApp = () => { + const dispatch = useAppDispatch(); + const { convertAddress } = useAddressConverter(); + + const isFeegrantModeEnabled = useAppSelector( + (state) => state.feegrant.feegrantModeEnabled + ); + const isAuthzMode = useAppSelector((state) => state.authz.authzModeEnabled); + const authzAddress = useAppSelector((state) => state.authz.authzAddress); + const nameToChainIDs = useAppSelector( + (state: RootState) => state.wallet.nameToChainIDs + ); + const chainIDs = Object.values(nameToChainIDs); + + const isWalletConnected = useAppSelector( + (state: RootState) => state.wallet.connected + ); + + const { getChainInfo, getDenomInfo } = useGetChainInfo(); + + useEffect(() => { + if (chainIDs.length > 0 && isWalletConnected) { + chainIDs.forEach((chainID) => { + const { address, baseURL, restURLs } = getChainInfo(chainID); + const { minimalDenom } = getDenomInfo(chainID); + const authzGranterAddress = convertAddress(chainID, authzAddress); + const chainRequestData = { + baseURLs: restURLs, + address: isAuthzMode ? authzGranterAddress : address, + chainID, + }; + + // Fetch delegations + dispatch( + isAuthzMode + ? getAuthzDelegations(chainRequestData) + : getDelegations(chainRequestData) + ).then(); + + // Fetch available balances + dispatch( + isAuthzMode + ? getAuthzBalances({ ...chainRequestData, baseURL }) + : getBalances({ ...chainRequestData, baseURL }) + ); + + // Fetch rewards + dispatch( + isAuthzMode + ? getAuthzDelegatorTotalRewards({ + ...chainRequestData, + baseURL, + denom: minimalDenom, + }) + : getDelegatorTotalRewards({ + ...chainRequestData, + baseURL, + denom: minimalDenom, + }) + ); + + // Fetch unbonding delegations + dispatch( + isAuthzMode + ? getAuthzUnbonding(chainRequestData) + : getUnbonding(chainRequestData) + ); + + dispatch(getAllValidators({ baseURLs: restURLs, chainID })); + }); + } + }, [isWalletConnected, isAuthzMode]); + + useFetchPriceInfo(); + useInitFeegrant({ chainIDs, shouldFetch: isFeegrantModeEnabled }); + useInitAuthz({ chainIDs, shouldFetch: isAuthzMode }); +}; + +export default useInitApp; diff --git a/frontend/src/custom-hooks/useGetAuthzAssetsAmount.tsx b/frontend/src/custom-hooks/useGetAuthzAssetsAmount.tsx index 62a50a554..8987107c2 100644 --- a/frontend/src/custom-hooks/useGetAuthzAssetsAmount.tsx +++ b/frontend/src/custom-hooks/useGetAuthzAssetsAmount.tsx @@ -55,12 +55,15 @@ const useGetAuthzAssetsAmount = (chainIDs: string[]) => { const usdDenomPrice = usdPriceInfo?.usd || 0; for (let i = 0; i < ibcBalances?.length; i++) { + const ibcUsdPriceInfo: TokenInfo | undefined = + tokensPriceInfo?.[ibcBalances?.[i]?.balance.denom]?.info; + const ibcUsdDenomPrice = ibcUsdPriceInfo?.usd || 0; totalIBCBalance += parseBalance( [ibcBalances[i].balance], ibcBalances?.[i]?.decimals, ibcBalances?.[i]?.balance.denom - ) * usdDenomPrice; + ) * ibcUsdDenomPrice; } const balance = parseBalance( diff --git a/frontend/src/custom-hooks/useGetValidatorInfo.ts b/frontend/src/custom-hooks/useGetValidatorInfo.ts index 4392127cb..c9a2041c2 100644 --- a/frontend/src/custom-hooks/useGetValidatorInfo.ts +++ b/frontend/src/custom-hooks/useGetValidatorInfo.ts @@ -8,6 +8,7 @@ import { COIN_GECKO_IDS, OASIS_CONFIG, POLYGON_CONFIG, + VITWIT_VALIDATOR_NAMES, WITVAL, } from '@/utils/constants'; @@ -47,12 +48,20 @@ const useGetValidatorInfo = () => { const validator = Object.values( stakingData?.[chainID]?.validators.active ).find((v) => { - // For few networks supported by Vitwit Validator, Moniker name is still Witval, so considering that validator also const isMatchingMoniker = v.description.moniker.trim().toLowerCase() === moniker.trim().toLowerCase(); - const isWitval = v.description.moniker.trim().toLowerCase() === WITVAL; - return isMatchingMoniker || isWitval; + + if (isMatchingMoniker) { + return true; + } + + // Otherwise, check if it matches the Witval moniker + // For few networks supported by Vitwit Validator, Moniker name is still Witval, so considering that validator also + const isWitval = + v.description.moniker.trim().toLowerCase() === WITVAL && + moniker.trim().toLowerCase() === WITVAL; + return isWitval; }); if (validator) { @@ -125,15 +134,15 @@ const useGetValidatorInfo = () => { ? (totalStaked * usdPriceInfo.usd).toString() : '-'; - if (!validatorDescription && description) { + if (!validatorDescription?.length && description?.length) { validatorDescription = description; } - if (!validatorWebsite && website) { + if (!validatorWebsite?.length && website?.length) { validatorWebsite = website; } - if (!validatorIdentity && identity) { + if (!validatorIdentity?.length && identity?.length) { validatorIdentity = identity; } @@ -189,7 +198,7 @@ const useGetValidatorInfo = () => { } totalNetworks += 1; }); - if (moniker.toLowerCase() === WITVAL) { + if (VITWIT_VALIDATOR_NAMES.includes(moniker.toLowerCase())) { { const { commission, diff --git a/frontend/src/custom-hooks/useInitAllValidator.ts b/frontend/src/custom-hooks/useInitAllValidator.ts index 8dc9fe77f..fbf31ba59 100644 --- a/frontend/src/custom-hooks/useInitAllValidator.ts +++ b/frontend/src/custom-hooks/useInitAllValidator.ts @@ -1,46 +1,14 @@ -import { useEffect, useRef, useState } from 'react'; -import { useAppDispatch, useAppSelector } from './StateHooks'; +import { useEffect } from 'react'; +import { useAppDispatch } from './StateHooks'; import { - getAllValidators, getWitvalOasisDelegations, getWitvalPolygonDelegatorsCount, getWitvalPolygonValidator, } from '@/store/features/staking/stakeSlice'; -import useGetAllChainsInfo from './useGetAllChainsInfo'; import { OASIS_CONFIG, POLYGON_API, POLYGON_CONFIG } from '@/utils/constants'; const useInitAllValidator = () => { - const networks = useAppSelector((state) => state.common.allNetworksInfo); const dispatch = useAppDispatch(); - const chainIDs = Object.keys(networks); - const { getAllChainInfo } = useGetAllChainsInfo(); - const networksCount = chainIDs.length; - const [dataFetched, setDataFetched] = useState(false); - const fetchedChains = useRef<{ [key: string]: boolean }>({}); - - const allChainsFetched = chainIDs.every( - (chainID) => fetchedChains.current[chainID] - ); - - useEffect(() => { - if (networksCount > 0 && !dataFetched && !allChainsFetched) { - chainIDs.forEach((chainID) => { - if (!fetchedChains.current?.[chainID]) { - const { restURLs } = getAllChainInfo(chainID); - dispatch( - getAllValidators({ - baseURLs: restURLs, - chainID: chainID, - }) - ); - fetchedChains.current[chainID] = true; - } - }); - if (allChainsFetched) { - setDataFetched(true); - } - } - }, [chainIDs, networksCount]); useEffect(() => { dispatch( diff --git a/frontend/src/custom-hooks/useInitAuthzForOverview.tsx b/frontend/src/custom-hooks/useInitAuthzForOverview.tsx deleted file mode 100644 index f6a58b9ca..000000000 --- a/frontend/src/custom-hooks/useInitAuthzForOverview.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { useEffect } from 'react'; -import { useAppDispatch, useAppSelector } from './StateHooks'; -import useAddressConverter from './useAddressConverter'; -import { getAuthzBalances } from '@/store/features/bank/bankSlice'; -import { - getAuthzDelegations, - getAuthzUnbonding, -} from '@/store/features/staking/stakeSlice'; -import { getAuthzDelegatorTotalRewards } from '@/store/features/distribution/distributionSlice'; - -const useInitAuthzForOverview = (chainIDs: string[]) => { - const authzAddress = useAppSelector((state) => state.authz.authzAddress); - const networks = useAppSelector((state) => state.wallet.networks); - const { convertAddress } = useAddressConverter(); - const dispatch = useAppDispatch(); - - useEffect(() => { - if (authzAddress) { - chainIDs.forEach((chainID) => { - const allChainInfo = networks[chainID]; - const chainInfo = allChainInfo.network; - const address = convertAddress(chainID, authzAddress); - const minimalDenom = - allChainInfo.network.config.stakeCurrency.coinMinimalDenom; - const basicChainInputs = { - baseURL: chainInfo.config.rest, - address, - chainID, - baseURLs: chainInfo.config.restURIs, - }; - - dispatch(getAuthzBalances(basicChainInputs)); - dispatch(getAuthzDelegations(basicChainInputs)); - dispatch( - getAuthzDelegatorTotalRewards({ - baseURL: chainInfo.config.rest, - address: address, - chainID: chainID, - denom: minimalDenom, - baseURLs: chainInfo.config.restURIs, - }) - ); - dispatch( - getAuthzUnbonding({ - baseURLs: chainInfo.config.restURIs, - address: address, - chainID, - }) - ); - }); - } - }, [authzAddress]); -}; - -export default useInitAuthzForOverview; diff --git a/frontend/src/custom-hooks/useInitAuthzStaking.tsx b/frontend/src/custom-hooks/useInitAuthzStaking.tsx deleted file mode 100644 index 13a0d3e6a..000000000 --- a/frontend/src/custom-hooks/useInitAuthzStaking.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { useEffect } from 'react'; -import { useAppDispatch, useAppSelector } from './StateHooks'; -import useAddressConverter from './useAddressConverter'; -import useGetChainInfo from './useGetChainInfo'; -import { - getAuthzDelegations, - getAuthzUnbonding, - getAuthzValidator, -} from '@/store/features/staking/stakeSlice'; -import { - getAuthzDelegatorTotalRewards, - getAuthzWithdrawAddress, -} from '@/store/features/distribution/distributionSlice'; -import { getAuthzBalances } from '@/store/features/bank/bankSlice'; -import { getAddressByPrefix } from '@/utils/address'; - -const useInitAuthzStaking = (chainIDs: string[]) => { - const dispatch = useAppDispatch(); - const authzAddress = useAppSelector((state) => state.authz.authzAddress); - - const { convertAddress } = useAddressConverter(); - const { getChainInfo, getDenomInfo } = useGetChainInfo(); - - useEffect(() => { - if (authzAddress) { - chainIDs.forEach((chainID) => { - const { baseURL, restURLs, valPrefix } = getChainInfo(chainID); - const { minimalDenom } = getDenomInfo(chainID); - const address = convertAddress(chainID, authzAddress); - dispatch( - getAuthzDelegations({ - baseURLs: restURLs, - address, - chainID, - }) - ); - dispatch( - getAuthzUnbonding({ - baseURLs: restURLs, - address, - chainID, - }) - ); - dispatch( - getAuthzDelegatorTotalRewards({ - baseURL, - address, - chainID, - denom: minimalDenom, - baseURLs: restURLs, - }) - ); - dispatch( - getAuthzBalances({ - baseURLs: restURLs, - baseURL, - address, - chainID, - }) - ); - dispatch( - getAuthzValidator({ - baseURLs: restURLs, - chainID, - valoperAddress: getAddressByPrefix(address, valPrefix), - }) - ); - dispatch( - getAuthzWithdrawAddress({ - baseURLs: restURLs, - chainID, - delegator: address, - }) - ); - }); - } - }, [authzAddress]); -}; - -export default useInitAuthzStaking; diff --git a/frontend/src/custom-hooks/useInitBalances.ts b/frontend/src/custom-hooks/useInitBalances.ts deleted file mode 100644 index 6a4399832..000000000 --- a/frontend/src/custom-hooks/useInitBalances.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { useEffect } from 'react'; -import { useAppDispatch, useAppSelector } from './StateHooks'; -import { RootState } from '@/store/store'; -import { getAuthzBalances, getBalances } from '@/store/features/bank/bankSlice'; -import useAddressConverter from './useAddressConverter'; -import { getRecentTransactions } from '@/store/features/recent-transactions/recentTransactionsSlice'; -import useGetChainInfo from './useGetChainInfo'; - -const useInitBalances = ({ chainIDs }: { chainIDs: string[] }) => { - const dispatch = useAppDispatch(); - const networks = useAppSelector((state: RootState) => state.wallet.networks); - const authzAddress = useAppSelector((state) => state.authz.authzAddress); - const isWalletConnected = useAppSelector((state) => state.wallet.connected); - const { convertAddress } = useAddressConverter(); - const { getAllChainAddresses } = useGetChainInfo(); - - useEffect(() => { - if (isWalletConnected) { - chainIDs.forEach((chainID) => { - if (networks.hasOwnProperty(chainID)) { - const allChainInfo = networks[chainID]; - const chainInfo = allChainInfo.network; - const address = allChainInfo?.walletInfo?.bech32Address; - const basicChainInputs = { - baseURLs: chainInfo.config.restURIs, - baseURL: chainInfo.config.rest, - address, - chainID, - }; - dispatch(getBalances(basicChainInputs)); - } - }); - } - }, [chainIDs, isWalletConnected]); - - useEffect(() => { - if (authzAddress !== '') { - chainIDs.forEach((chainID) => { - if (networks.hasOwnProperty(chainID)) { - const allChainInfo = networks[chainID]; - const chainInfo = allChainInfo.network; - const address = convertAddress(chainID, authzAddress); - const basicChainInputs = { - baseURL: chainInfo.config.rest, - baseURLs: chainInfo.config.restURIs, - address, - chainID, - }; - dispatch(getAuthzBalances(basicChainInputs)); - } - }); - } - }, [chainIDs, authzAddress]); - - useEffect(() => { - if (chainIDs) { - dispatch( - getRecentTransactions({ - addresses: getAllChainAddresses(chainIDs), - module: 'bank', - }) - ); - } - }, []); -}; - -export default useInitBalances; diff --git a/frontend/src/custom-hooks/useInitStaking.ts b/frontend/src/custom-hooks/useInitStaking.ts index d9f5aae3c..b903954a6 100644 --- a/frontend/src/custom-hooks/useInitStaking.ts +++ b/frontend/src/custom-hooks/useInitStaking.ts @@ -1,90 +1,3 @@ -import { useEffect } from 'react'; -import useGetChainInfo from './useGetChainInfo'; -import { useAppDispatch, useAppSelector } from './StateHooks'; -import { - getAllValidators, - getAuthzDelegations, - getAuthzUnbonding, - // getAllValidators, - getDelegations, - getUnbonding, -} from '@/store/features/staking/stakeSlice'; -import { getAuthzBalances, getBalances } from '@/store/features/bank/bankSlice'; -import { - getAuthzDelegatorTotalRewards, - getDelegatorTotalRewards, -} from '@/store/features/distribution/distributionSlice'; -import useAddressConverter from './useAddressConverter'; - -const useInitStaking = (chainID: string) => { - const { getChainInfo, getDenomInfo } = useGetChainInfo(); - const { convertAddress } = useAddressConverter(); - - const dispatch = useAppDispatch(); - const isWalletConnected = useAppSelector((state) => state.wallet.connected); - const isAuthzMode = useAppSelector((state) => state.authz.authzModeEnabled); - const authzAddress = useAppSelector((state) => state.authz.authzAddress); - - const { address, baseURL, restURLs } = getChainInfo(chainID); - const { minimalDenom } = getDenomInfo(chainID); - - useEffect(() => { - if (isWalletConnected) { - const authzGranterAddress = convertAddress(chainID, authzAddress); - const chainRequestData = { - baseURLs: restURLs, - address: isAuthzMode ? authzGranterAddress : address, - chainID, - }; - - // Fetch delegations - dispatch( - isAuthzMode - ? getAuthzDelegations(chainRequestData) - : getDelegations(chainRequestData) - ).then(); - - // Fetch available balances - dispatch( - isAuthzMode - ? getAuthzBalances({ ...chainRequestData, baseURL }) - : getBalances({ ...chainRequestData, baseURL }) - ); - - // Fetch rewards - dispatch( - isAuthzMode - ? getAuthzDelegatorTotalRewards({ - ...chainRequestData, - baseURL, - denom: minimalDenom, - }) - : getDelegatorTotalRewards({ - ...chainRequestData, - baseURL, - denom: minimalDenom, - }) - ); - - // Fetch unbonding delegations - dispatch( - isAuthzMode - ? getAuthzUnbonding(chainRequestData) - : getUnbonding(chainRequestData) - ); - } - - // Fetch all validators - // if ( - // isEmpty(stakeData[chainID]?.validators?.active) || - // isEmpty(stakeData[chainID]?.validators?.inactive) - // ) - dispatch(getAllValidators({ baseURLs: restURLs, chainID })); - }, [isWalletConnected, chainID, isAuthzMode]); - - // useEffect(() => { - // if (chainID) dispatch(getAllValidators({ baseURLs: restURLs, chainID })); - // }, [chainID]); -}; +const useInitStaking = () => {}; export default useInitStaking; diff --git a/frontend/src/custom-hooks/useSingleStaking.tsx b/frontend/src/custom-hooks/useSingleStaking.tsx index 1a850ddc9..cc546d3f3 100644 --- a/frontend/src/custom-hooks/useSingleStaking.tsx +++ b/frontend/src/custom-hooks/useSingleStaking.tsx @@ -3,7 +3,6 @@ import { RootState } from '@/store/store'; import useGetChainInfo from './useGetChainInfo'; import { getValidator } from '@/store/features/staking/stakeSlice'; import useGetAssetsAmount from './useGetAssetsAmount'; -import useGetAuthzAssetsAmount from './useGetAuthzAssetsAmount'; /* eslint-disable react-hooks/rules-of-hooks */ const useSingleStaking = (chainID: string) => { @@ -28,9 +27,7 @@ const useSingleStaking = (chainID: string) => { availableAmount, rewardsAmount, totalUnStakedAmount, - ] = isAuthzMode - ? useGetAuthzAssetsAmount([chainID]) - : useGetAssetsAmount([chainID]); + ] = useGetAssetsAmount([chainID]); // const { getTokensByChainID } = useGetAssets(); diff --git a/frontend/src/custom-hooks/useStaking.ts b/frontend/src/custom-hooks/useStaking.ts index 611583e79..dc244ceb4 100644 --- a/frontend/src/custom-hooks/useStaking.ts +++ b/frontend/src/custom-hooks/useStaking.ts @@ -1,13 +1,7 @@ -import { useEffect } from 'react'; import { useAppDispatch, useAppSelector } from './StateHooks'; import { RootState } from '@/store/store'; import useGetChainInfo from './useGetChainInfo'; import { - getAllValidators, - getAuthzDelegations, - getAuthzUnbonding, - getDelegations, - getUnbonding, getValidator, txCancelUnbonding, txDelegate, @@ -15,30 +9,19 @@ import { txRestake, txUnDelegate, } from '@/store/features/staking/stakeSlice'; -import { - getAuthzDelegatorTotalRewards, - getDelegatorTotalRewards, - txWithdrawAllRewards, -} from '@/store/features/distribution/distributionSlice'; -import { getAuthzBalances, getBalances } from '@/store/features/bank/bankSlice'; -// import useGetAssets from "./useGetAssets"; -// import { Interface } from "readline"; +import { txWithdrawAllRewards } from '@/store/features/distribution/distributionSlice'; import useGetAssetsAmount from './useGetAssetsAmount'; import useGetTxInputs from './useGetTxInputs'; -import { isEmpty } from 'lodash'; import useGetFeegranter from './useGetFeegranter'; import { MAP_TXN_MSG_TYPES } from '@/utils/feegrant'; -import useGetAuthzAssetsAmount from './useGetAuthzAssetsAmount'; -import useAddressConverter from './useAddressConverter'; import useAuthzStakingExecHelper from './useAuthzStakingExecHelper'; import { UnbondingEncode } from '@/txns/staking/unbonding'; import { TxStatus } from '@/types/enums'; /* eslint-disable react-hooks/rules-of-hooks */ -const useStaking = ({ isSingleChain }: { isSingleChain: boolean }) => { +const useStaking = () => { const dispatch = useAppDispatch(); const { getFeegranter } = useGetFeegranter(); - const { convertAddress } = useAddressConverter(); const { txAuthzDelegate, txAuthzReDelegate, txAuthzUnDelegate } = useAuthzStakingExecHelper(); const { txAuthzRestake, txAuthzClaim, txAuthzCancelUnbond } = @@ -52,34 +35,19 @@ const useStaking = ({ isSingleChain }: { isSingleChain: boolean }) => { ); const chainIDs = Object.values(nameToChainIDs); - const isWalletConnected = useAppSelector( - (state: RootState) => state.wallet.connected - ); - - const { - getChainInfo, - getDenomInfo, - // getValueFromToken, getTokenValueByChainId - } = useGetChainInfo(); + const { getChainInfo, getDenomInfo } = useGetChainInfo(); const rewardsChains = useAppSelector((state: RootState) => isAuthzMode ? state.distribution.authzChains : state.distribution.chains ); - // const totalData = useAppSelector((state: RootState) => state.staking) - const [ totalStakedAmount, availableAmount, rewardsAmount, totalUnStakedAmount, - ] = isAuthzMode - ? useGetAuthzAssetsAmount(chainIDs) - : useGetAssetsAmount(chainIDs); + ] = useGetAssetsAmount(chainIDs); - // const { getTokensByChainID } = useGetAssets(); - - // get total staking data data from the state const stakeData = useAppSelector((state: RootState) => isAuthzMode ? state.staking.authz.chains : state.staking.chains ); @@ -97,8 +65,10 @@ const useStaking = ({ isSingleChain }: { isSingleChain: boolean }) => { ); const cancelUnbdongTxLoading = (chainID: string) => { - return stakeData[chainID].cancelUnbondingTxStatus === TxStatus.PENDING ? true : false; - } + return stakeData[chainID].cancelUnbondingTxStatus === TxStatus.PENDING + ? true + : false; + }; const totalUnbondedAmount = useAppSelector((state: RootState) => isAuthzMode @@ -113,63 +83,6 @@ const useStaking = ({ isSingleChain }: { isSingleChain: boolean }) => { txAuthzRestakeMsgs, } = useGetTxInputs(); - useEffect(() => { - if (chainIDs.length > 0 && isWalletConnected && !isSingleChain) { - chainIDs.forEach((chainID) => { - const { address, baseURL, restURLs } = getChainInfo(chainID); - const { minimalDenom } = getDenomInfo(chainID); - const authzGranterAddress = convertAddress(chainID, authzAddress); - const chainRequestData = { - baseURLs: restURLs, - address: isAuthzMode ? authzGranterAddress : address, - chainID, - }; - // Fetch delegations - dispatch( - isAuthzMode - ? getAuthzDelegations(chainRequestData) - : getDelegations(chainRequestData) - ).then(); - - // Fetch available balances - dispatch( - isAuthzMode - ? getAuthzBalances({ ...chainRequestData, baseURL }) - : getBalances({ ...chainRequestData, baseURL }) - ); - - // Fetch rewards - dispatch( - isAuthzMode - ? getAuthzDelegatorTotalRewards({ - ...chainRequestData, - baseURL, - denom: minimalDenom, - }) - : getDelegatorTotalRewards({ - ...chainRequestData, - baseURL, - denom: minimalDenom, - }) - ); - - // Fetch unbonding delegations - dispatch( - isAuthzMode - ? getAuthzUnbonding(chainRequestData) - : getUnbonding(chainRequestData) - ); - - // Fetch all validators - if ( - isEmpty(stakeData[chainID]?.validators?.active) || - isEmpty(stakeData[chainID]?.validators?.inactive) - ) - dispatch(getAllValidators({ baseURLs: restURLs, chainID })); - }); - } - }, [isWalletConnected, isAuthzMode]); - const fetchValidatorDetails = (valoperAddress: string, chainID: string) => { const { restURLs } = getChainInfo(chainID); dispatch( diff --git a/frontend/src/custom-hooks/useValidator.ts b/frontend/src/custom-hooks/useValidator.ts index e0efe1919..d9c774a87 100644 --- a/frontend/src/custom-hooks/useValidator.ts +++ b/frontend/src/custom-hooks/useValidator.ts @@ -1,27 +1,52 @@ -import { useCallback } from "react"; -import { useAppDispatch, useAppSelector } from "./StateHooks"; +import { useCallback } from 'react'; +import { useAppDispatch, useAppSelector } from './StateHooks'; import { RootState } from '@/store/store'; -import useGetChainInfo from "./useGetChainInfo"; -import { getValidator } from "@/store/features/staking/stakeSlice"; +import useGetChainInfo from './useGetChainInfo'; +import { getValidator } from '@/store/features/staking/stakeSlice'; const useValidator = () => { const dispatch = useAppDispatch(); - const isWalletConnected = useAppSelector((state: RootState) => state.wallet.connected); + const isWalletConnected = useAppSelector( + (state: RootState) => state.wallet.connected + ); const { getChainInfo } = useGetChainInfo(); const stakeData = useAppSelector((state: RootState) => state.staking.chains); - const fetchValidator = useCallback((valoperAddress: string, chainID: string) => { - if (isWalletConnected && valoperAddress && chainID) { - const { restURLs } = getChainInfo(chainID); - if (!stakeData[chainID]?.validator[valoperAddress]) - dispatch(getValidator({ baseURLs: restURLs, chainID, valoperAddress })); - } - }, []); + const fetchValidator = useCallback( + (valoperAddress: string, chainID: string) => { + if (isWalletConnected && valoperAddress && chainID) { + const { restURLs } = getChainInfo(chainID); + console.log( + 'staking------', + stakeData[chainID]?.validator[valoperAddress] + ); + if ( + ![ + ...(stakeData[chainID]?.validators?.activeSorted || []), + ...(stakeData[chainID]?.validators?.inactiveSorted || []), + ].includes(valoperAddress) + ) { + if (!stakeData[chainID]?.validator[valoperAddress]) + dispatch( + getValidator({ baseURLs: restURLs, chainID, valoperAddress }) + ); + } + } + }, + [] + ); - const getValidatorDetails = useCallback((valoperAddress: string, chainID: string) => { - return stakeData[chainID]?.validator[valoperAddress]; - }, [stakeData]); + const getValidatorDetails = useCallback( + (valoperAddress: string, chainID: string) => { + return ( + stakeData[chainID]?.validators.active?.[valoperAddress] || + stakeData[chainID]?.validators.inactive?.[valoperAddress] || + stakeData[chainID]?.validator?.[valoperAddress] + ); + }, + [stakeData] + ); return { fetchValidator,