-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set nft as user profile avatar (#1048)
- Loading branch information
1 parent
5b1cb9b
commit 30324be
Showing
13 changed files
with
119 additions
and
34 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
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
37 changes: 37 additions & 0 deletions
37
apps/browser-extension-wallet/src/hooks/useWalletAvatar.ts
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,37 @@ | ||
import { useLocalStorage } from '@hooks/useLocalStorage'; | ||
import { getAssetImageUrl } from '@utils/get-asset-image-url'; | ||
import { useWalletStore } from '@stores'; | ||
import { useGetHandles } from '@hooks/useGetHandles'; | ||
import { useCallback } from 'react'; | ||
|
||
interface UseWalletAvatar { | ||
activeWalletAvatar: string; | ||
setAvatar: (image: string) => void; | ||
getAvatar: (walletId: string) => string; | ||
} | ||
|
||
export const useWalletAvatar = (): UseWalletAvatar => { | ||
const { cardanoWallet, environmentName } = useWalletStore(); | ||
const [handle] = useGetHandles(); | ||
const [avatars, { updateLocalStorage: setUserAvatar }] = useLocalStorage('userAvatar'); | ||
|
||
const activeWalletId = cardanoWallet.source.wallet.walletId; | ||
const handleImage = handle?.profilePic; | ||
const activeWalletAvatar = | ||
(environmentName && avatars?.[`${environmentName}${activeWalletId}`]) || | ||
(handleImage && getAssetImageUrl(handleImage)); | ||
|
||
const setAvatar = useCallback( | ||
(image: string) => { | ||
setUserAvatar({ ...avatars, [`${environmentName}${activeWalletId}`]: image }); | ||
}, | ||
[setUserAvatar, avatars, environmentName, activeWalletId] | ||
); | ||
|
||
const getAvatar = useCallback( | ||
(walletId: string) => avatars?.[`${environmentName}${walletId}`], | ||
[avatars, environmentName] | ||
); | ||
|
||
return { activeWalletAvatar, setAvatar, getAvatar }; | ||
}; |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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