Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
type DynamicFormFormInit,
} from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores";
import { Protobuf } from "@meshtastic/core";
import { deepCompareConfig } from "@core/utils/deepCompareConfig.ts";
import { useTranslation } from "react-i18next";
import { useCallback } from "react";

interface RangeTestModuleConfigProps {
onFormInit: DynamicFormFormInit<RangeTestValidation>;
Expand All @@ -18,9 +20,26 @@ interface RangeTestModuleConfigProps {
export const RangeTest = ({ onFormInit }: RangeTestModuleConfigProps) => {
useWaitForConfig({ moduleConfigCase: "rangeTest" });

const { moduleConfig, setChange, getEffectiveModuleConfig, removeChange } =
const { moduleConfig, channels, activeNode, setChange, getEffectiveModuleConfig, removeChange } =
useDevice();

const primaryChannel = channels.get(0 as Protobuf.Types.ChannelNumber);

const isChannelPublic = useCallback(
(channel?: Protobuf.Channel.Channel): boolean => {
if (!channel) return false;

const pskBytes = channel.settings?.psk;
const hexLen = pskBytes instanceof Uint8Array ? pskBytes.length : 0;

// Treat very short/absent keys as effectively "public"/unencrypted.
return hexLen === 0 || hexLen === 1;
},
[],
);

const isPrimaryChannelPublic = isChannelPublic(primaryChannel);

const { t } = useTranslation("moduleConfig");

const onSubmit = (data: RangeTestValidation) => {
Expand Down Expand Up @@ -82,6 +101,7 @@ export const RangeTest = ({ onFormInit }: RangeTestModuleConfigProps) => {
],
},
]}
isDisabled={isPrimaryChannelPublic}
/>
);
};
Loading