Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fetch data on initial render of app #1413

Merged
merged 10 commits into from
Sep 6, 2024
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<div className="flex pt-10 gap-10">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ const SingleProposal: React.FC<SingleProposalProps> = ({
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}
</p>
Expand Down
27 changes: 1 addition & 26 deletions frontend/src/app/(routes)/governance/popups/DialogDeposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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('');
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand All @@ -26,14 +25,12 @@ interface DelegateProps {
}

const Delegate: React.FC<DelegateProps> = (props) => {
const dispatch = useAppDispatch();
const {
chainID,
address,
onDelegate,
currency,
availableBalance,
baseURLs,
feeAmount,
} = props;
const {
Expand Down Expand Up @@ -110,15 +107,6 @@ const Delegate: React.FC<DelegateProps> = (props) => {
}
};

useEffect(() => {
dispatch(
getAllValidators({
baseURLs: baseURLs,
chainID,
})
);
}, [chainID]);

return (
<form
onSubmit={handleSubmit(onSubmit)}
Expand Down Expand Up @@ -228,10 +216,7 @@ const Delegate: React.FC<DelegateProps> = (props) => {
</div>
</div>
</div>
<button
type="submit"
className="add-txn-btn primary-gradient"
>
<button type="submit" className="add-txn-btn primary-gradient">
Add
</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -48,7 +45,7 @@ const isValueExists = (
};

const Redelegate: React.FC<RedelegateProps> = (props) => {
const { chainID, address, onRedelegate, currency, baseURLs } = props;
const { chainID, address, onRedelegate, currency } = props;
const { getChainInfo } = useGetChainInfo();
const { restURLs } = getChainInfo(chainID);
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -185,12 +182,6 @@ const Redelegate: React.FC<RedelegateProps> = (props) => {

useEffect(() => {
dispatch(getDelegations({ address, chainID, baseURLs: restURLs }));
dispatch(
getAllValidators({
baseURLs: baseURLs,
chainID,
})
);
}, [chainID]);

return (
Expand Down Expand Up @@ -396,10 +387,7 @@ const Redelegate: React.FC<RedelegateProps> = (props) => {
</div>
</div>
</div>
<button
type="submit"
className="add-txn-btn primary-gradient"
>
<button type="submit" className="add-txn-btn primary-gradient">
Add
</button>
</form>
Expand Down
Loading
Loading