Skip to content
Open
Changes from 1 commit
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,6 +8,7 @@ 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";

Expand All @@ -18,8 +19,16 @@ 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 isPrimaryChannelPublic = (() => {
if (!primaryChannel) return false;
const pskBytes = primaryChannel.settings?.psk;
const hexLen = pskBytes instanceof Uint8Array ? pskBytes.length : 0;
// Treat very short/absent keys as effectively "public"/unencrypted.
return hexLen === 0 || hexLen === 1;
})();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, wanted to understand why an IIFE was used here though, maybe I'm missing something about how this is designed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, how does this channel custom channels 0-9?

Copy link
Author

@dubsector dubsector Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only treat Range Test as blocked when channel 0 is effectively “public” (no PSK or a 1-byte PSK). Additional custom channels (1–9) are untouched by this check, and Range Test isn’t gated on them here.

I originally used an IIFE here to keep the logic self-contained and allow early returns without needing a mutable variable. I did pull requests for web, android, and apple, so i was trying to keep the code consistent.

Could switch this to a local helper function. Let me know and I can update it.

const isChannelPublic = (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 primaryChannel = channels.get(0 as Protobuf.Types.ChannelNumber);
const isPrimaryChannelPublic = isChannelPublic(primaryChannel);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, yeah I dont think we use IIFE's anywhere else in the web code base. So lets switch to an arrow function wrapped with "useCallback" to make sure its reference is stable during rendering.


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

Expand All @@ -38,11 +47,24 @@ export const RangeTest = ({ onFormInit }: RangeTestModuleConfigProps) => {

return (
<DynamicForm<RangeTestValidation>
isDisabled={isPrimaryChannelPublic}
onSubmit={onSubmit}
onFormInit={onFormInit}
validationSchema={RangeTestValidationSchema}
defaultValues={moduleConfig.rangeTest}
values={getEffectiveModuleConfig("rangeTest")}
defaultValues={{
...moduleConfig.rangeTest,
enabled:
isPrimaryChannelPublic
? false
: moduleConfig.rangeTest?.enabled ?? false,
}}
values={{
...getEffectiveModuleConfig("rangeTest"),
enabled:
isPrimaryChannelPublic
? false
: getEffectiveModuleConfig("rangeTest")?.enabled ?? false,
}}
fieldGroups={[
{
label: t("rangeTest.title"),
Expand Down