-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle fetching token images (#643)
- Loading branch information
Showing
10 changed files
with
147 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 21 additions & 4 deletions
25
...ages/adena-extension/src/components/pages/wallet-main/token-list-item/token-list-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 14 additions & 4 deletions
18
packages/adena-extension/src/components/pages/wallet-main/token-list/token-list.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useRecoilState } from 'recoil'; | ||
|
||
import { CommonState } from '@states'; | ||
import { useMemo } from 'react'; | ||
|
||
export type UseLoadAccountsReturn = { | ||
isLoading: boolean; | ||
addLoadingImages: (imageUrls: string[]) => void; | ||
completeImageLoading: (imageUrl: string) => void; | ||
clear: () => void; | ||
}; | ||
|
||
export const useLoadImages = (): UseLoadAccountsReturn => { | ||
const [loadingImageUrls, setLoadingImageUrls] = useRecoilState(CommonState.loadingImageUrls); | ||
const [loadedImageUrls, setLoadedImageUrls] = useRecoilState(CommonState.loadedImageUrls); | ||
|
||
const isLoading = useMemo(() => { | ||
if (loadedImageUrls.length === 0) { | ||
return true; | ||
} | ||
return loadedImageUrls.length < loadingImageUrls.length; | ||
}, [loadedImageUrls, loadingImageUrls]); | ||
|
||
const addLoadingImages = (imageUrls: string[]): void => { | ||
setLoadingImageUrls([...new Set(imageUrls.filter((url) => !!url))]); | ||
}; | ||
|
||
const completeImageLoading = (imageUrl: string): void => { | ||
setLoadedImageUrls((prev) => [...new Set([...prev, imageUrl])]); | ||
}; | ||
|
||
const clear = (): void => { | ||
setLoadingImageUrls([]); | ||
setLoadedImageUrls([]); | ||
}; | ||
|
||
return { isLoading, addLoadingImages, completeImageLoading, clear }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters