diff --git a/.env.adpr b/.env.adpr index 13c6631414..66d33fd4bb 100644 --- a/.env.adpr +++ b/.env.adpr @@ -18,7 +18,7 @@ VITE_TYPE_AND_SWAP_URL=https://type-swap.dev.kyberengineering.io/api VITE_TRANSAK_URL=https://staging-global.transak.com VITE_TRANSAK_API_KEY=327b8b63-626b-4376-baf2-70a304c48488 -VITE_KS_SETTING_API=https://ks-setting.stg.kyberengineering.io/api +VITE_KS_SETTING_API=https://ks-setting.dev.kyberengineering.io/api VITE_GTM_ID= diff --git a/src/components/SearchModal/CurrencySearch.tsx b/src/components/SearchModal/CurrencySearch.tsx index 681bbcb4a9..7a77c1bdfa 100644 --- a/src/components/SearchModal/CurrencySearch.tsx +++ b/src/components/SearchModal/CurrencySearch.tsx @@ -277,8 +277,14 @@ export function CurrencySearch({ const addressesToFetch: string[] = [] favoriteTokens?.forEach(address => { - if (defaultTokens[address]) { - result.push(defaultTokens[address]) + let token + Object.entries(defaultTokens).forEach(([add, t]) => { + if (add.toLowerCase() === address.toLowerCase()) { + token = t + } + }) + if (token) { + result.push(token) return } addressesToFetch.push(address) diff --git a/src/state/index.ts b/src/state/index.ts index a6fcc30fb9..46fc7dea4e 100644 --- a/src/state/index.ts +++ b/src/state/index.ts @@ -54,7 +54,7 @@ if ('user' in preloadedState) { (acc, [chainId, obj]) => { acc[chainId] = {} obj.addresses.forEach((address: string) => { - acc[chainId][address] = true + acc[chainId][address.toLowerCase()] = true }) return acc }, diff --git a/src/state/user/actions.ts b/src/state/user/actions.ts index 1a8a5cf9b1..3ecef491bb 100644 --- a/src/state/user/actions.ts +++ b/src/state/user/actions.ts @@ -50,6 +50,7 @@ export const toggleTopTrendingTokens = createAction('user/toggleTopTrendin export type ToggleFavoriteTokenPayload = { chainId: ChainId address: string + newValue?: boolean } export const toggleFavoriteToken = createAction('user/toggleFavoriteToken') export const updateChainId = createAction('user/updateChainId') diff --git a/src/state/user/hooks.tsx b/src/state/user/hooks.tsx index d8867dad34..c09e01719e 100644 --- a/src/state/user/hooks.tsx +++ b/src/state/user/hooks.tsx @@ -405,26 +405,27 @@ export const useUserFavoriteTokens = (chainId: ChainId) => { }, [commonTokens, chainId]) const favoriteTokens = useMemo(() => { - if (!chainId || !defaultTokens) return undefined + if (!chainId) return undefined const favoritedTokens = favoriteTokensByChainId?.[chainId] || {} const favoritedTokenAddresses = defaultTokens - .filter(address => favoritedTokens[address] !== false) + .filter(address => favoritedTokens[address.toLowerCase()] !== false) .concat(Object.keys(favoritedTokens).filter(address => favoritedTokens[address])) - return [...new Set(favoritedTokenAddresses)] + return [...new Set(favoritedTokenAddresses.map(a => a.toLowerCase()))] }, [chainId, favoriteTokensByChainId, defaultTokens]) const toggleFavoriteToken = useCallback( (payload: ToggleFavoriteTokenPayload) => { + if (!favoriteTokens) return + const address = payload.address.toLowerCase() // Is adding favorite and reached max limit - if ( - favoriteTokens && - favoriteTokens?.indexOf(payload.address) < 0 && - favoriteTokens.length >= MAX_FAVORITE_LIMIT - ) { + if (favoriteTokens.indexOf(address) < 0 && favoriteTokens.length >= MAX_FAVORITE_LIMIT) { return } - dispatch(toggleFavoriteTokenAction(payload)) + const newValue = favoriteTokens.indexOf(address) < 0 + console.log('🚀 ~ file: hooks.tsx:425 ~ useUserFavoriteTokens ~ newValue:', newValue, address, favoriteTokens) + + dispatch(toggleFavoriteTokenAction({ ...payload, newValue })) }, [dispatch, favoriteTokens], ) diff --git a/src/state/user/reducer.ts b/src/state/user/reducer.ts index dccb3a3ee0..741993fd37 100644 --- a/src/state/user/reducer.ts +++ b/src/state/user/reducer.ts @@ -302,18 +302,20 @@ export default createReducer(initialState, builder => .addCase(toggleKyberAIBanner, state => { state.showKyberAIBanner = !state.showKyberAIBanner }) - .addCase(toggleFavoriteToken, (state, { payload: { chainId, address } }) => { + .addCase(toggleFavoriteToken, (state, { payload: { chainId, address, newValue } }) => { if (!state.favoriteTokensByChainIdv2) { state.favoriteTokensByChainIdv2 = {} } - let favoriteTokens = state.favoriteTokensByChainIdv2[chainId] - - if (!favoriteTokens) { - favoriteTokens = {} + if (!state.favoriteTokensByChainIdv2[chainId]) { + state.favoriteTokensByChainIdv2[chainId] = {} } - favoriteTokens[address] = !favoriteTokens[address] + const favoriteTokens = state.favoriteTokensByChainIdv2[chainId] + const lowercaseAddress = address.toLowerCase() + if (favoriteTokens) { + favoriteTokens[lowercaseAddress] = newValue !== undefined ? newValue : !favoriteTokens[lowercaseAddress] + } }) .addCase(updateChainId, (state, { payload: chainId }) => { state.chainId = chainId