@@ -5,6 +5,7 @@ import Eligibility from '@/components/node-details/eligibility';
55import { useP2P } from '@/contexts/P2PContext' ;
66import { useOceanAccount } from '@/lib/use-ocean-account' ;
77import { ComputeEnvironment } from '@/types/environments' ;
8+ import { NodeConfig } from '@/types/node-config' ;
89import { Node } from '@/types/nodes' ;
910import { useAuthModal } from '@account-kit/react' ;
1011import CancelIcon from '@mui/icons-material/Cancel' ;
@@ -32,14 +33,14 @@ const NodeInfo: React.FC<NodeInfoProps> = ({ envs, node, nodeOnline }) => {
3233 const { closeAuthModal, isOpen : isAuthModalOpen , openAuthModal } = useAuthModal ( ) ;
3334
3435 const { account, ocean, signMessage, user } = useOceanAccount ( ) ;
35- const { config , fetchConfig, getNodeLogs, pushConfig } = useP2P ( ) ;
36+ const { fetchConfig, getNodeLogs, pushConfig } = useP2P ( ) ;
3637
3738 const [ fetchingConfig , setFetchingConfig ] = useState < boolean > ( false ) ;
3839 const [ pushingConfig , setPushingConfig ] = useState < boolean > ( false ) ;
3940 const [ isEditConfigDialogOpen , setIsEditConfigDialogOpen ] = useState < boolean > ( false ) ;
4041 const [ isDownloadLogsDialogOpen , setIsDownloadLogsDialogOpen ] = useState < boolean > ( false ) ;
4142 const [ downloadingLogs , setDownloadingLogs ] = useState < boolean > ( false ) ;
42- const [ editedConfig , setEditedConfig ] = useState < Record < string , any > > ( { } ) ;
43+ const [ editedConfig , setEditedConfig ] = useState < NodeConfig > ( { } ) ;
4344
4445 // TODO: replace this
4546 // This is temporary, used for local testing because `node` from props was
@@ -78,12 +79,6 @@ const NodeInfo: React.FC<NodeInfoProps> = ({ envs, node, nodeOnline }) => {
7879 }
7980 } , [ account . isConnected , closeAuthModal , isAuthModalOpen ] ) ;
8081
81- useEffect ( ( ) => {
82- if ( config ) {
83- setEditedConfig ( config ) ;
84- }
85- } , [ config ] ) ;
86-
8782 async function handleFetchConfig ( ) {
8883 if ( ! account . isConnected ) {
8984 openAuthModal ( ) ;
@@ -94,20 +89,21 @@ const NodeInfo: React.FC<NodeInfoProps> = ({ envs, node, nodeOnline }) => {
9489 }
9590 setFetchingConfig ( true ) ;
9691 try {
97- await fetchConfig ( {
92+ const fetchedConfig = await fetchConfig ( {
9893 consumerAddress : account . address ,
9994 expiryTimestamp : Date . now ( ) + 5 * 60 * 1000 , // 5 minutes expiry
10095 nodeUri : node . id ,
10196 signMessage,
10297 } ) ;
98+ setEditedConfig ( fetchedConfig as NodeConfig ) ;
10399 } catch ( error ) {
104100 console . error ( 'Error fetching node config :' , error ) ;
105101 } finally {
106102 setFetchingConfig ( false ) ;
107103 }
108104 }
109105
110- async function handlePushConfig ( config : Record < string , any > ) {
106+ async function handlePushConfig ( config : NodeConfig ) {
111107 let success = false ;
112108 if ( ! account . isConnected ) {
113109 openAuthModal ( ) ;
@@ -140,10 +136,10 @@ const NodeInfo: React.FC<NodeInfoProps> = ({ envs, node, nodeOnline }) => {
140136 }
141137
142138 function handleOpenEditConfigModal ( ) {
143- if ( ! config || Object . keys ( config ) . length === 0 ) {
144- handleFetchConfig ( ) ;
145- }
146-
139+ // Always refetch so the modal shows the current node's config, not a
140+ // config left over from a previously opened node.
141+ setEditedConfig ( { } ) ;
142+ handleFetchConfig ( ) ;
147143 setIsEditConfigDialogOpen ( true ) ;
148144 }
149145
@@ -256,7 +252,6 @@ const NodeInfo: React.FC<NodeInfoProps> = ({ envs, node, nodeOnline }) => {
256252 isOpen = { isEditConfigDialogOpen }
257253 fetchingConfig = { fetchingConfig }
258254 pushingConfig = { pushingConfig }
259- config = { config }
260255 editedConfig = { editedConfig }
261256 setEditedConfig = { setEditedConfig }
262257 handlePushConfig = { handlePushConfig }
0 commit comments