Check if accounts are loaded before hiding a tab (#5177)
This commit is contained in:
parent
d49852eda3
commit
6bac862800
@ -37,7 +37,7 @@ const transformElection = {
|
||||
function StakingApp ({ basePath, className = '' }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const { hasAccounts } = useAccounts();
|
||||
const { areAccountsLoaded, hasAccounts } = useAccounts();
|
||||
const { pathname } = useLocation();
|
||||
const [withLedger, setWithLedger] = useState(false);
|
||||
const [favorites, toggleFavorite] = useFavorites(STORE_FAVS_BASE);
|
||||
@ -103,9 +103,9 @@ function StakingApp ({ basePath, className = '' }: Props): React.ReactElement<Pr
|
||||
<Tabs
|
||||
basePath={basePath}
|
||||
hidden={
|
||||
hasAccounts
|
||||
? undefined
|
||||
: HIDDEN_ACC
|
||||
areAccountsLoaded && !hasAccounts
|
||||
? HIDDEN_ACC
|
||||
: undefined
|
||||
}
|
||||
items={items}
|
||||
/>
|
||||
|
||||
@ -9,11 +9,12 @@ import { useIsMountedRef } from './useIsMountedRef';
|
||||
|
||||
interface UseAccounts {
|
||||
allAccounts: string[];
|
||||
areAccountsLoaded: boolean
|
||||
hasAccounts: boolean;
|
||||
isAccount: (address?: string | null) => boolean;
|
||||
}
|
||||
|
||||
const EMPTY: UseAccounts = { allAccounts: [], hasAccounts: false, isAccount: () => false };
|
||||
const EMPTY: UseAccounts = { allAccounts: [], areAccountsLoaded: false, hasAccounts: false, isAccount: () => false };
|
||||
|
||||
export function useAccounts (): UseAccounts {
|
||||
const mountedRef = useIsMountedRef();
|
||||
@ -26,7 +27,7 @@ export function useAccounts (): UseAccounts {
|
||||
const hasAccounts = allAccounts.length !== 0;
|
||||
const isAccount = (address?: string | null) => !!address && allAccounts.includes(address);
|
||||
|
||||
setState({ allAccounts, hasAccounts, isAccount });
|
||||
setState({ allAccounts, areAccountsLoaded: true, hasAccounts, isAccount });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user