@@ -8,6 +8,7 @@ import validator from "validator";
88import PublicIPCard from "@components/PublicIPCard" ;
99import TailscaleCard from "@components/TailscaleCard" ;
1010import { NetworkSettings , NetworkState , useNetworkStateStore , useRTCStore } from "@hooks/stores" ;
11+ import { useShallow } from "zustand/shallow" ;
1112import { JsonRpcResponse , useJsonRpc } from "@hooks/useJsonRpc" ;
1213import AutoHeight from "@components/AutoHeight" ;
1314import { Button } from "@components/Button" ;
@@ -33,32 +34,13 @@ dayjs.extend(relativeTime);
3334
3435const isLLDPAvailable = false ; // LLDP is not supported yet
3536
36- const resolveOnRtcReady = ( ) => {
37- return new Promise ( resolve => {
38- // Check if RTC is already connected
39- const currentState = useRTCStore . getState ( ) ;
40- if ( currentState . rpcDataChannel ?. readyState === "open" ) {
41- // Already connected, fetch data immediately
42- return resolve ( void 0 ) ;
43- }
44-
45- // Not connected yet, subscribe to state changes
46- const unsubscribe = useRTCStore . subscribe ( state => {
47- if ( state . rpcDataChannel ?. readyState === "open" ) {
48- unsubscribe ( ) ; // Clean up subscription
49- return resolve ( void 0 ) ;
50- }
51- } ) ;
52- } ) ;
53- } ;
54-
5537export function LifeTimeLabel ( { lifetime } : Readonly < { lifetime : string } > ) {
5638 const [ remaining , setRemaining ] = useState < string | null > ( null ) ;
5739
58- // rrecalculate remaining time every 30 seconds
40+ // recalculate remaining time every 30 seconds
5941 useEffect ( ( ) => {
60- // schedule immediate initial update
61- setInterval ( ( ) => setRemaining ( dayjs ( lifetime ) . fromNow ( ) ) , 0 ) ;
42+ // immediate initial update
43+ setRemaining ( dayjs ( lifetime ) . fromNow ( ) ) ;
6244
6345 const interval = setInterval ( ( ) => {
6446 setRemaining ( dayjs ( lifetime ) . fromNow ( ) ) ;
@@ -85,7 +67,16 @@ const NonCustomDomainOptions = ["dhcp", "local"];
8567export default function SettingsNetworkRoute ( ) {
8668 const { send } = useJsonRpc ( ) ;
8769
88- const networkState = useNetworkStateStore ( state => state ) ;
70+ const networkState = useNetworkStateStore (
71+ useShallow ( state => ( {
72+ mac_address : state . mac_address ,
73+ hostname : state . hostname ,
74+ dhcp_lease : state . dhcp_lease ,
75+ ipv6_addresses : state . ipv6_addresses ,
76+ ipv6_link_local : state . ipv6_link_local ,
77+ ipv6_gateway : state . ipv6_gateway ,
78+ } ) ) ,
79+ ) ;
8980 const setNetworkState = useNetworkStateStore ( state => state . setNetworkState ) ;
9081
9182 // Some input needs direct state management. Mostly options that open more details
@@ -164,8 +155,6 @@ export default function SettingsNetworkRoute() {
164155 mode : "onBlur" ,
165156
166157 defaultValues : async ( ) => {
167- // Ensure data channel is ready, before fetching network data from the device
168- await resolveOnRtcReady ( ) ;
169158 const { settings } = await fetchNetworkData ( ) ;
170159 return settings ;
171160 } ,
@@ -215,7 +204,6 @@ export default function SettingsNetworkRoute() {
215204 } catch ( error ) {
216205 console . error ( "Failed to fetch network data:" , error ) ;
217206 }
218- notifications . success ( m . network_dhcp_lease_renew_success ( ) ) ;
219207 }
220208 } ) ;
221209 } ,
@@ -270,7 +258,11 @@ export default function SettingsNetworkRoute() {
270258 } ) ;
271259 }
272260
273- if ( dirty . ipv4_static ?. dns && dirty . ipv4_static . dns . length > 0 && dirty . ipv4_static . dns . every ( dirty => dirty ) ) {
261+ if (
262+ dirty . ipv4_static ?. dns &&
263+ dirty . ipv4_static . dns . length > 0 &&
264+ dirty . ipv4_static . dns . every ( dirty => dirty )
265+ ) {
274266 changes . push ( {
275267 label : m . network_ipv4_dns ( ) ,
276268 from : initialSettingsRef . current ?. ipv4_static ?. dns . join ( ", " ) . toString ( ) ?? "" ,
@@ -302,7 +294,11 @@ export default function SettingsNetworkRoute() {
302294 } ) ;
303295 }
304296
305- if ( dirty . ipv6_static ?. dns && dirty . ipv6_static . dns . length > 0 && dirty . ipv6_static . dns . every ( dirty => dirty ) ) {
297+ if (
298+ dirty . ipv6_static ?. dns &&
299+ dirty . ipv6_static . dns . length > 0 &&
300+ dirty . ipv6_static . dns . every ( dirty => dirty )
301+ ) {
306302 changes . push ( {
307303 label : m . network_ipv6_dns ( ) ,
308304 from : initialSettingsRef . current ?. ipv6_static ?. dns . join ( ", " ) . toString ( ) ?? "" ,
0 commit comments