@@ -28,7 +28,7 @@ import {
2828import { } from "components/contract-components/contract-deploy-form/modular-contract-default-modules-fieldset" ;
2929import { useTxNotifications } from "hooks/useTxNotifications" ;
3030import Link from "next/link" ;
31- import { useState } from "react" ;
31+ import { useEffect , useMemo , useState } from "react" ;
3232import { useForm } from "react-hook-form" ;
3333import {
3434 defineChain ,
@@ -96,7 +96,37 @@ export function DataTable({
9696 "Successfully deployed contract" ,
9797 "Failed to deploy contract" ,
9898 ) ;
99- const [ tableData , setTableData ] = useState ( data ) ;
99+
100+ const [ customChainData , setCustomChainData ] = useState < CrossChain [ ] > ( ( ) => {
101+ try {
102+ const storedData = window . localStorage . getItem (
103+ `crosschain-${ coreContract . address } ` ,
104+ ) ;
105+ return storedData ? JSON . parse ( storedData ) : [ ] ;
106+ } catch ( error ) {
107+ console . error ( "Failed to read from localStorage" , error ) ;
108+ return [ ] ;
109+ }
110+ } ) ;
111+
112+ useEffect ( ( ) => {
113+ try {
114+ window . localStorage . setItem (
115+ `crosschain-${ coreContract . address } ` ,
116+ JSON . stringify ( customChainData ) ,
117+ ) ;
118+ } catch ( error ) {
119+ console . error ( "Failed to write to localStorage" , error ) ;
120+ }
121+ } , [ customChainData , coreContract . address ] ) ;
122+
123+ const mergedChainData = useMemo ( ( ) => {
124+ const chainMap = new Map < number , CrossChain > ( ) ;
125+ for ( const item of [ ...data , ...customChainData ] ) {
126+ chainMap . set ( item . chainId , item ) ; // Deduplicate by chainId
127+ }
128+ return Array . from ( chainMap . values ( ) ) ;
129+ } , [ data , customChainData ] ) ;
100130
101131 const form = useForm < FormSchema > ( {
102132 resolver : zodResolver ( formSchema ) ,
@@ -156,7 +186,7 @@ export function DataTable({
156186 ] ;
157187
158188 const table = useReactTable ( {
159- data : tableData ,
189+ data : mergedChainData ,
160190 columns,
161191 getCoreRowModel : getCoreRowModel ( ) ,
162192 } ) ;
@@ -246,14 +276,9 @@ export function DataTable({
246276 ) ;
247277 deployStatusModal . close ( ) ;
248278
249- setTableData ( ( prevData ) =>
279+ setCustomChainData ( ( prevData ) =>
250280 prevData . map ( ( row ) =>
251- row . chainId === chainId
252- ? {
253- ...row ,
254- status : "DEPLOYED" ,
255- }
256- : row ,
281+ row . chainId === chainId ? { ...row , status : "DEPLOYED" } : row ,
257282 ) ,
258283 ) ;
259284 } catch ( e ) {
@@ -264,7 +289,7 @@ export function DataTable({
264289 } ;
265290
266291 const handleAddRow = ( chain : { chainId : number ; name : string } ) => {
267- const existingChain = tableData . find (
292+ const existingChain = customChainData . find (
268293 ( row ) => row . chainId === chain . chainId ,
269294 ) ;
270295 if ( existingChain ) {
@@ -278,7 +303,9 @@ export function DataTable({
278303 status : "NOT_DEPLOYED" ,
279304 } ;
280305
281- setTableData ( ( prevData ) => [ ...prevData , newRow ] ) ;
306+ if ( ! customChainData . some ( ( row ) => row . chainId === chain . chainId ) ) {
307+ setCustomChainData ( ( prevData ) => [ ...prevData , newRow ] ) ;
308+ }
282309 } ;
283310
284311 return (
0 commit comments