perf: remove extra spread operators from the combine maps function
This commit is contained in:
parent
634d010d92
commit
3686506f2a
@ -47,16 +47,29 @@ export function useAllLists(): AppState['lists']['byUrl'] {
|
||||
return useAppSelector((state) => state.lists.byUrl)
|
||||
}
|
||||
|
||||
// TODO: return a proxy instead of doing a reduce
|
||||
/**
|
||||
* Combine the tokens in map2 with the tokens on map1, where tokens on map1 take precedence
|
||||
* @param map1 the base token map
|
||||
* @param map2 the map of additioanl tokens to add to the base map
|
||||
*/
|
||||
export function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddressMap {
|
||||
const chainIds = Object.keys({ ...map1, ...map2 }).map((id) => parseInt(id))
|
||||
return chainIds.reduce(
|
||||
(acc, chainId) => ({
|
||||
...acc,
|
||||
[chainId]: { ...map2[chainId], ...map1[chainId] },
|
||||
}),
|
||||
{}
|
||||
)
|
||||
const chainIds = Object.keys(
|
||||
Object.keys(map1)
|
||||
.concat(Object.keys(map2))
|
||||
.reduce<{ [chainId: string]: true }>((memo, value) => {
|
||||
memo[value] = true
|
||||
return memo
|
||||
}, {})
|
||||
).map((id) => parseInt(id))
|
||||
|
||||
return chainIds.reduce<Mutable<TokenAddressMap>>((memo, chainId) => {
|
||||
memo[chainId] = {
|
||||
...map2[chainId],
|
||||
// map1 takes precedence
|
||||
...map1[chainId],
|
||||
}
|
||||
return memo
|
||||
}, {}) as TokenAddressMap
|
||||
}
|
||||
|
||||
// merge tokens contained within lists from urls
|
||||
|
Loading…
Reference in New Issue
Block a user