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

fix: validator details page loading #1316

Merged
merged 7 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/proud-onions-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ui': patch
---

fix validator details page loading
11 changes: 8 additions & 3 deletions apps/web-crescent/src/screens/validator_details/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ export const useValidatorDetails = () => {
skip: !extra.profile || !state.overview.selfDelegateAddress,
});
useEffect(
() => setState((prevState) => ({ ...prevState, desmosProfile: dataDesmosProfile?.[0] })),
[dataDesmosProfile]
() =>
setState((prevState) => ({
...prevState,
desmosProfile: dataDesmosProfile?.[0],
loading: loadingDesmosProfile,
})),
[dataDesmosProfile, loadingDesmosProfile]
);

return { state, loading: loading || loadingDesmosProfile };
return { state, loading };
};

// ============================
Expand Down
11 changes: 8 additions & 3 deletions apps/web-emoney/src/screens/validator_details/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ export const useValidatorDetails = () => {
skip: !extra.profile || !state.overview.selfDelegateAddress,
});
useEffect(
() => setState((prevState) => ({ ...prevState, desmosProfile: dataDesmosProfile?.[0] })),
[dataDesmosProfile]
() =>
setState((prevState) => ({
...prevState,
desmosProfile: dataDesmosProfile?.[0],
loading: loadingDesmosProfile,
})),
[dataDesmosProfile, loadingDesmosProfile]
);

return { state, loading: loading || loadingDesmosProfile };
return { state, loading };
};

// ============================
Expand Down
11 changes: 7 additions & 4 deletions apps/web-neutron/src/screens/account_details/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,13 @@ export const useAccountDetails = () => {
skip: !extra.profile || !address,
});
useEffect(
() => setState((prevState) => ({ ...prevState, desmosProfile: dataDesmosProfile?.[0] })),
[dataDesmosProfile]
() =>
setState((prevState) => ({
...prevState,
desmosProfile: dataDesmosProfile?.[0],
loading: loadingDesmosProfile,
})),
[dataDesmosProfile, loadingDesmosProfile]
);

const commission = useCommission(providerAddress);
Expand Down Expand Up @@ -351,7 +356,5 @@ export const useAccountDetails = () => {
providerAddress,
]);

if (loadingDesmosProfile) state.loading = true;

return { state };
};
11 changes: 8 additions & 3 deletions apps/web-neutron/src/screens/validator_details/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,16 @@ export const useValidatorDetails = () => {
skip: !extra.profile || !state.overview.selfDelegateAddress,
});
useEffect(
() => setState((prevState) => ({ ...prevState, desmosProfile: dataDesmosProfile?.[0] })),
[dataDesmosProfile]
() =>
setState((prevState) => ({
...prevState,
desmosProfile: dataDesmosProfile?.[0],
loading: loadingDesmosProfile,
})),
[dataDesmosProfile, loadingDesmosProfile]
);

return { state, loading: loading || loadingDesmosProfile };
return { state, loading };
};

function formatAccountQuery(data: ValidatorDetailsQuery): Partial<ValidatorDetailsState> {
Expand Down
25 changes: 7 additions & 18 deletions apps/web-nomic/src/screens/account_details/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@ export const useAccountDetails = () => {
skip: !extra.profile || !address,
});
useEffect(
() => setState((prevState) => ({ ...prevState, desmosProfile: dataDesmosProfile?.[0] })),
[dataDesmosProfile]
() =>
setState((prevState) => ({
...prevState,
desmosProfile: dataDesmosProfile?.[0],
loading: loadingDesmosProfile,
})),
[dataDesmosProfile, loadingDesmosProfile]
);

const available = useAvailableBalances(address);
Expand All @@ -175,21 +180,5 @@ export const useAccountDetails = () => {
handleSetState((prevState) => ({ ...prevState, ...formatAllBalance(formattedRawData) }));
}, [available, delegation, handleSetState]);

// // ==========================
// // Fetch Data
// // ==========================
// const withdrawalAddress = useWithdrawalAddress(address);
// useEffect(() => {
// handleSetState((prevState) => ({
// ...prevState,
// overview: {
// address: address ?? '',
// withdrawalAddress: withdrawalAddress?.withdrawalAddress?.address ?? '',
// },
// }));
// }, [address, handleSetState, withdrawalAddress]);

if (loadingDesmosProfile) state.loading = true;

return { state };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import Tooltip from '@mui/material/Tooltip';
import Typography from '@mui/material/Typography';
import useAppTranslation from '@/hooks/useAppTranslation';
import numeral from 'numeral';
import { FC } from 'react';
import Loading from '@/components/loading';
import AvatarName from '@/components/avatar_name';
import Box from '@/components/box';
import Result from '@/components/result';
import { useProfileRecoil } from '@/recoil/profiles/hooks';
import { useBlocks } from '@/screens/validator_details/components/blocks/hooks';
import useStyles from '@/screens/validator_details/components/blocks/styles';

type BlockBoxProps = {
i: number;
item: ReturnType<typeof useBlocks>['state'][number];
state: ReturnType<typeof useBlocks>['state'];
};

const BlockBox: FC<BlockBoxProps> = ({ i, item, state }) => {
const { address, imageUrl, name } = useProfileRecoil(item.proposer);
const { t } = useAppTranslation('validators');
const { classes, cx } = useStyles();
return (
<Tooltip
enterTouchDelay={50}
title={
<Box className={classes.toolTip}>
<div className={classes.item}>
<Typography variant="h4" className="label">
{t('proposer')}
</Typography>
<AvatarName address={address} imageUrl={imageUrl} name={name} />
</div>
<div className={classes.item}>
<Typography variant="h4" className="label">
{t('block')}
</Typography>
<Typography variant="body1" className="value">
{numeral(item.height).format('0,0')}
</Typography>
</div>
<div className={classes.item}>
<Typography variant="h4" className="label">
{t('txs')}
</Typography>
<Typography variant="body1" className="value">
{numeral(item.txs).format('0,0')}
</Typography>
</div>
<div className={classes.item}>
<Typography variant="h4" className="label">
{t('signed')}
</Typography>
<Result success={item.signed} />
</div>
</Box>
}
placement="top"
>
<div
className={cx(classes.singleBlock, {
signed: state[i].signed,
})}
/>
</Tooltip>
);
};

const Blocks: FC<ComponentDefault> = ({ className }) => {
const { t } = useAppTranslation('validators');
const { state, loading } = useBlocks();
const { classes, cx } = useStyles();
return (
<Box className={cx(classes.root, className)}>
<Typography variant="h2">{t('lastBlocks')}</Typography>
{loading && <Loading />}
<div className={classes.blocks}>
{state.map((x, i) => (
<BlockBox key={x.height} i={i} item={x} state={state} />
))}
</div>
</Box>
);
};

export default Blocks;
11 changes: 8 additions & 3 deletions apps/web-nomic/src/screens/validator_details/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ export const useValidatorDetails = () => {
skip: !extra.profile || !state.overview.selfDelegateAddress,
});
useEffect(
() => setState((prevState) => ({ ...prevState, desmosProfile: dataDesmosProfile?.[0] })),
[dataDesmosProfile]
() =>
setState((prevState) => ({
...prevState,
desmosProfile: dataDesmosProfile?.[0],
loading: loadingDesmosProfile,
})),
[dataDesmosProfile, loadingDesmosProfile]
);

return { state, loading: loading || loadingDesmosProfile };
return { state, loading };
};

// ============================
Expand Down
Loading
Loading