({
initialAddresses,
initialPaths,
onAutoSave,
onLocalSave,
})
| 145 | */ |
| 146 | |
| 147 | const Graph: FC<GraphProps> = ({ |
| 148 | initialAddresses, |
| 149 | initialPaths, |
| 150 | onAutoSave, |
| 151 | onLocalSave, |
| 152 | }) => { |
| 153 | // Grab all initial addresses and create nodes for them |
| 154 | const initialNodes = useMemo(() => { |
| 155 | const nodes: Node[] = []; |
| 156 | const expandNodeAutomatically = initialAddresses.length === 1; // Only expand if there's one address |
| 157 | |
| 158 | initialAddresses.forEach((address) => { |
| 159 | nodes.push( |
| 160 | createAddressNode( |
| 161 | address, |
| 162 | AddressNodeState.MINIMIZED, |
| 163 | true, |
| 164 | 0, |
| 165 | 0, |
| 166 | expandNodeAutomatically, |
| 167 | ), |
| 168 | ); |
| 169 | }); |
| 170 | |
| 171 | return nodes; |
| 172 | }, [initialAddresses]); |
| 173 | |
| 174 | const initialEdges = useMemo(() => { |
| 175 | const edges: Edge[] = []; |
| 176 | initialPaths.forEach((path) => { |
| 177 | const [source, target] = path.split("-"); |
| 178 | if (source && target) { |
| 179 | edges.push({ |
| 180 | id: `${source}-${target}`, |
| 181 | source: source, |
| 182 | target: target, |
| 183 | sourceHandle: "a", |
| 184 | targetHandle: "a", |
| 185 | type: "TransfershipEdge", |
| 186 | data: { |
| 187 | state: TransfershipEdgeStates.REVEALED, |
| 188 | volume: 0, |
| 189 | }, |
| 190 | }); |
| 191 | } |
| 192 | }); |
| 193 | return edges; |
| 194 | }, [initialPaths]); |
| 195 | |
| 196 | const initialLayoutedNodes = useMemo(() => { |
| 197 | if (initialNodes.length === 0) return []; |
| 198 | |
| 199 | return calculateLayoutedElements(initialNodes, initialEdges); |
| 200 | }, [initialNodes, initialEdges]); |
| 201 | |
| 202 | // We make sure to calculate the layouted nodes and edges before rendering |
| 203 | return ( |
| 204 | <> |
nothing calls this directly
no test coverage detected