Skip to content

Commit

Permalink
Simplify enabledLayers in graph
Browse files Browse the repository at this point in the history
  • Loading branch information
lubej committed Jul 12, 2023
1 parent 470725c commit ce7306a
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/app/pages/HomePage/Graph/Graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
memo,
MouseEventHandler,
PropsWithChildren,
useCallback,
useEffect,
useMemo,
useState,
Expand Down Expand Up @@ -263,30 +262,18 @@ const GraphCmp: ForwardRefRenderFunction<SVGSVGElement, GraphProps> = (
setOutOfDateMap({})
}, [network])

const isLayerDisabled = useCallback(
(Layer: Layer) => {
return !RouteUtils.getEnabledLayersForNetwork(network).includes(Layer)
},
[network],
)
const isLayerDisabled = (Layer: Layer) => {
return !RouteUtils.getEnabledLayersForNetwork(network).includes(Layer)
}

const disabledMap: Record<Layer, boolean> = useMemo(
() => ({
[Layer.emerald]: isLayerDisabled(Layer.emerald),
[Layer.consensus]: isLayerDisabled(Layer.consensus),
[Layer.cipher]: isLayerDisabled(Layer.cipher),
[Layer.sapphire]: isLayerDisabled(Layer.sapphire),
}),
[isLayerDisabled],
)
const disabledMap: Record<Layer, boolean> = {
[Layer.emerald]: isLayerDisabled(Layer.emerald),
[Layer.consensus]: isLayerDisabled(Layer.consensus),
[Layer.cipher]: isLayerDisabled(Layer.cipher),
[Layer.sapphire]: isLayerDisabled(Layer.sapphire),
}

const enabledLayers: Layer[] = useMemo(
() =>
Object.keys(disabledMap)
.filter(layer => !disabledMap[layer as Layer])
.map(layer => layer as Layer),
[disabledMap],
)
const enabledLayers: Layer[] = useMemo(() => RouteUtils.getEnabledLayersForNetwork(network), [network])

const onSelectLayer = (layer: Layer) => {
if (isMobile && isZoomedIn) {
Expand Down

0 comments on commit ce7306a

Please sign in to comment.