Skip to content

Commit

Permalink
Error & Format fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
KomelT committed Aug 21, 2024
1 parent ebd5a3d commit 8ed3ce8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
21 changes: 11 additions & 10 deletions src/components/PageComponents/Config/Network.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type { NetworkValidation } from "@app/validation/config/network.js";
import { DynamicForm } from "@components/Form/DynamicForm.js";
import { useDevice } from "@core/stores/deviceStore.js";
import {
convertIntToIpAddress,
convertIpAddressToInt,
} from "@core/utils/ip.js";
import { Protobuf } from "@meshtastic/js";
import { convertIntToIpAddress, convertIpAddressToInt } from "@core/utils/ip.js";

export const Network = (): JSX.Element => {
const { config, setWorkingConfig } = useDevice();
Expand All @@ -21,7 +24,7 @@ export const Network = (): JSX.Element => {
},
ntpServer: config.network?.ntpServer,
rsyslogServer: config.network?.rsyslogServer,
}
};

const onSubmit = (data: NetworkValidation) => {
setWorkingConfig(
Expand All @@ -30,14 +33,12 @@ export const Network = (): JSX.Element => {
case: "network",
value: {
...data,
ipv4Config: new Protobuf.Config.Config_NetworkConfig_IpV4Config(
{
ip: convertIpAddressToInt(data.ipv4Config.ip) ?? 0,
gateway: convertIpAddressToInt(data.ipv4Config.gateway) ?? 0,
subnet: convertIpAddressToInt(data.ipv4Config.subnet) ?? 0,
dns: convertIpAddressToInt(data.ipv4Config.dns) ?? 0,
},
),
ipv4Config: new Protobuf.Config.Config_NetworkConfig_IpV4Config({
ip: convertIpAddressToInt(data.ipv4Config.ip) ?? 0,
gateway: convertIpAddressToInt(data.ipv4Config.gateway) ?? 0,
subnet: convertIpAddressToInt(data.ipv4Config.subnet) ?? 0,
dns: convertIpAddressToInt(data.ipv4Config.dns) ?? 0,
}),
},
},
}),
Expand Down
6 changes: 3 additions & 3 deletions src/core/utils/ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ export function convertIntToIpAddress(int: number): string {
}

export function convertIpAddressToInt(ip: string): number | null {
const parts = ip.split('.').map(Number).reverse(); // little-endian byte order
const parts = ip.split(".").map(Number).reverse(); // little-endian byte order

if (parts.some(Number.isNaN)) {
return null;
return null;
}

return parts.reduce((total, part) => (total << 8) | part, 0);
}
}
5 changes: 4 additions & 1 deletion src/validation/config/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export class NetworkValidation

export class NetworkValidationIpV4Config
implements
Omit<Protobuf.Config.Config_NetworkConfig_IpV4Config, keyof Message>
Omit<
Protobuf.Config.Config_NetworkConfig_IpV4Config,
keyof Message | "ip" | "gateway" | "subnet" | "dns"
>
{
@IsIP()
@IsOptional()
Expand Down

0 comments on commit 8ed3ce8

Please sign in to comment.