-
-
-
- {isSuccess ? 'Transaction Successful' : 'Transaction Failed'}
-
+
+
+
+
+ {isSuccess ? 'Transaction Successful' : 'Transaction Failed'}
- {!isSuccess &&
}
-
-
+ {!isSuccess &&
}
+ {
+ !isSuccess &&
+
+ {isSuccess ? null : rawLog}
+
+
+
|| null
+ }
+
-
- {isSearchPage ? null : (
-
- )}
- {mintscanURL ? (
-
-
View on Mintscan
-
+ {isSearchPage ? null : (
+
-
- ) : null}
+ )}
+ {mintscanURL ? (
+
+ View on Mintscan
+
+
+ ) : 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,