Check if accounts are loaded before hiding a tab (#5177)

This commit is contained in:
Krzysztof Jelski 2021-05-01 06:45:34 +02:00 committed by GitHub
parent d49852eda3
commit 6bac862800
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -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}
/>

View File

@ -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 });
}
});