-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor wallet avatar to have cache (#958)
- Loading branch information
1 parent
c6cf622
commit 2bf5f48
Showing
39 changed files
with
260 additions
and
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import create from 'zustand'; | ||
|
||
import { createStore } from '~/core/state/internal/createStore'; | ||
|
||
type ColorCacheStore = { | ||
colorCache: Record<string, string | null>; | ||
setColorCache: (imageUrl: string, color: string | null) => void; | ||
}; | ||
|
||
export const colorCacheStore = createStore<ColorCacheStore>( | ||
(set) => ({ | ||
colorCache: {}, | ||
setColorCache: (imageUrl, color) => | ||
set((state) => ({ | ||
colorCache: { ...state.colorCache, [imageUrl]: color }, | ||
})), | ||
}), | ||
{ | ||
persist: { | ||
name: 'dominantColorStore', | ||
version: 0, | ||
}, | ||
}, | ||
); | ||
|
||
export const useColorCacheStore = create(colorCacheStore); |
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,43 @@ | ||
import create from 'zustand'; | ||
|
||
import { createStore } from '~/core/state/internal/createStore'; | ||
|
||
export interface WalletAvatar { | ||
color?: string; | ||
imageUrl?: string; | ||
emoji?: string; | ||
} | ||
|
||
type WalletAvatarStore = { | ||
walletAvatar: Record<string, WalletAvatar>; | ||
setWalletAvatar: ({ | ||
addressOrName, | ||
walletAvatar, | ||
}: { | ||
addressOrName: string; | ||
walletAvatar: WalletAvatar; | ||
}) => void; | ||
}; | ||
|
||
export const walletAvatarStore = createStore<WalletAvatarStore>( | ||
(set, get) => ({ | ||
walletAvatar: {}, | ||
setWalletAvatar: ({ addressOrName, walletAvatar }) => { | ||
const { walletAvatar: oldWalletAvatar } = get(); | ||
set({ | ||
walletAvatar: { | ||
...oldWalletAvatar, | ||
[addressOrName]: walletAvatar, | ||
}, | ||
}); | ||
}, | ||
}), | ||
{ | ||
persist: { | ||
name: 'walletAvatarStore', | ||
version: 0, | ||
}, | ||
}, | ||
); | ||
|
||
export const useWalletAvatarStore = create(walletAvatarStore); |
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
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
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
Oops, something went wrong.