Skip to content

Commit

Permalink
feat: add clear states
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Nov 16, 2024
1 parent 7f468b1 commit 2c7d644
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/adena-extension/src/App/use-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useLocation } from 'react-router-dom';
import { useAccountName } from '@hooks/use-account-name';
import { useWalletContext } from '@hooks/use-context';
import { useCurrentAccount } from '@hooks/use-current-account';
import { useLoadImages } from '@hooks/use-load-images';
import { useNetwork } from '@hooks/use-network';
import useScrollHistory from '@hooks/use-scroll-history';
import { useTokenMetainfo } from '@hooks/use-token-metainfo';
Expand All @@ -14,6 +15,7 @@ const useApp = (): void => {
const { currentAccount } = useCurrentAccount();
const { currentNetwork, checkNetworkState } = useNetwork();
const { initTokenMetainfos } = useTokenMetainfo();
const { clear: clearLoadingImages } = useLoadImages();
const { pathname, key } = useLocation();
const { scrollMove } = useScrollHistory();

Expand All @@ -34,6 +36,7 @@ const useApp = (): void => {
return;
}

clearLoadingImages();
initTokenMetainfos();
}, [currentAccount?.id, currentNetwork.networkId]);

Expand Down
8 changes: 7 additions & 1 deletion packages/adena-extension/src/hooks/use-load-images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type UseLoadAccountsReturn = {
isLoading: boolean;
addLoadingImages: (imageUrls: string[]) => void;
completeImageLoading: (imageUrl: string) => void;
clear: () => void;
};

export const useLoadImages = (): UseLoadAccountsReturn => {
Expand All @@ -28,5 +29,10 @@ export const useLoadImages = (): UseLoadAccountsReturn => {
setLoadedImageUrls((prev) => [...new Set([...prev, imageUrl])]);
};

return { isLoading, addLoadingImages, completeImageLoading };
const clear = (): void => {
setLoadingImageUrls([]);
setLoadedImageUrls([]);
};

return { isLoading, addLoadingImages, completeImageLoading, clear };
};

0 comments on commit 2c7d644

Please sign in to comment.