MDK Logo

General

General-purpose utility functions

General-purpose helper functions.

Package

@tetherto/mdk-ui-foundation

Utilities

@tetherto/mdk-ui-foundation

Import the public APIs on this page from @tetherto/mdk-ui-foundation.

ALERT_TYPE_POOL_NAME

Display names for each pool alert condition.

Constant

{ readonly ip_worker_name: "IP worker name"; readonly wrong_miner_pool: "Wrong miner pool"; readonly wrong_worker_name: "Wrong worker name"; readonly wrong_miner_subaccount: "Wrong miner subaccount";…

ALERT_TYPE_POOL_VALUE

The pool misconfiguration conditions that can raise an alert, such as a miner pointing at the wrong pool or reporting an unexpected worker name.

Constant

{ readonly IP_WORKER_NAME: "ip_worker_name"; readonly WRONG_MINER_POOL: "wrong_miner_pool"; readonly WRONG_WORKER_NAME: "wrong_worker_name"; readonly WRONG_MINER_SUBACCOUNT: "wrong_miner_subaccount";…

appendContainerToTag

Builds a container device type by prefixing a device id with container-.

Function

(deviceId: string) => string

appendIdToTag

Builds a device's own search tag by prefixing its id with id-.

Function

(deviceId: string) => string

appendIdToTags

Builds the search tag for each device id in a list.

Function

(deviceIdList: string[]) => string[]

AUTH_LEVELS

The access levels a permission grants, used as the part after the :. Levels are single characters and combine, so rw is read and write.

Constant

{ readonly READ: "r"; readonly WRITE: "w"; }

AUTH_PERMISSIONS

The resources a permission can be granted over, used as the part before the : in a permission string such as miner:rw.

Constant

{ readonly TEMP: "temp"; readonly MINER: "miner"; readonly USERS: "users"; readonly ALERTS: "alerts"; readonly TICKETS: "tickets"; readonly ACTIONS: "actions"; readonly REVENUE: "revenue"; readonly F…

AUTH_TOKEN_QUERY_PARAM

Pure URL helpers shared by the auth flow. Kept framework-agnostic so the react-adapter (and any future framework adapter) can call them without pulling in router-specific APIs.

Constant

"authToken"

CABINET_DEVICES_TYPES_NAME_MAP

Display names for each low-voltage cabinet device type.

Constant

{ readonly "powermeter-abb-b24": "Powermeter ABB B24"; readonly "sensor-temp-seneca": "Sensor Temp Seneca"; readonly "powermeter-abb-m4m20": "Powermeter ABB M4M20"; readonly "powermeter-abb-m1m20": "…

checkPermission

Check if user has the requested permission

Function

(config: AuthConfig | null | undefined, { perm, write, cap }: PermissionCheck) => boolean

COMPLETE_CONTAINER_TYPE

Full device type identifiers for each supported container model, as they appear on a device.

Constant

{ readonly BITMAIN_HYDRO: "container-as-hk3"; readonly BITDEER_M30: "container-bd-d40-m30"; readonly BITDEER_M56: "container-bd-d40-m56"; readonly MICROBT_ALPHA: "container-mbt-alpha"; readonly BITDE…

COMPLETE_MINER_TYPES

Full device type identifiers for each supported miner model, as they appear on a device.

Constant

{ readonly ANTMINER_AM_S21: "miner-am-s21"; readonly WHATSMINER_WM_63: "miner-wm-m63"; readonly WHATSMINER_WM_53: "miner-wm-m53s"; readonly AVALON_AV_a1346: "miner-av-a1346"; readonly WHATSMINER_WM_5…

CONTAINER_MODEL

Container tag / type / threshold literals. Data-layer contracts shared across the toolkit — owned by ui-foundation so the React layers stay free of tag strings.

Constant

{ readonly M221: "m221"; readonly GAMMA: "gamma"; readonly BITDEER: "bitdeer"; readonly BITMAIN: "bitmain"; readonly MICROBT: "microbt"; readonly ANTSPACE: "antspace"; readonly BITMAIN_IMM: "bitmain-…

CONTAINER_SETTINGS_MODEL

The container families that have their own settings screens: Bitdeer, MicroBT, hydro, and immersion.

Constant

{ BITDEER: string; MICROBT: string; HYDRO: string; IMMERSION: string; }

CONTAINER_STATUS

The states a container reports: running, offline, or stopped.

Constant

{ readonly RUNNING: "running"; readonly OFFLINE: "offline"; readonly STOPPED: "stopped"; }

CONTAINER_TAB

Container detail-view tab keys. The per-model availability matrix lives in utils/container-tabs.ts.

Constant

{ readonly PDU: "pdu"; readonly HOME: "home"; readonly ALARM: "alarm"; readonly CHARTS: "charts"; readonly HEATMAP: "heatmap"; readonly CONTROLS: "controls"; readonly SETTINGS: "settings"; readonly P…

CONTAINER_TACTICS_TYPE

What a container optimises for when curtailing: coin price, electricity price, or disabled.

Constant

{ readonly COIN: "coin"; readonly DISABLED: "disabled"; readonly ELECTRICITY: "electricity"; }

CONTAINER_TYPE

Short codes identifying a container family in device tags and types.

Constant

{ readonly BITDEER: "bd"; readonly ANTSPACE: "as"; readonly MICROBT: "mbt"; readonly ANTSPACE_HYDRO: "as-hk3"; readonly ANTSPACE_IMMERSION: "as-immersion"; }

CONTAINER_TYPE_NAME_MAP

Display names for each supported container model, such as Bitdeer M30.

Constant

{ readonly "container-bd-d40-m30": "Bitdeer M30"; readonly "container-bd-d40-m56": "Bitdeer M56"; readonly "container-bd-d40-s19xp": "Bitdeer S19XP"; readonly "container-as-hk3": "Bitmain Hydro"; rea…

CONTAINERS_MINER_TYPE

Short miner model codes used when describing what a container holds.

Constant

{ readonly M56: "m56"; readonly M30: "m30"; readonly A1346: "a1346"; readonly S19XP: "s19xp"; }

CUSTOM_PERIOD

A range of whole days chosen by hand, rather than a rolling preset.

Constant

"custom"

DEFAULT_GRANULARITY

The granularity used when nothing else decides: a preset's own, or one that fits the range.

Constant

Granularity

exportSettingsToFile

Downloads the given settings as a JSON file and returns the filename written.

Function

(data: SettingsExportData) => string

filterUsers

Narrows a user list by email substring, by role, or by both. Omitted filters are ignored, and the email match is case-insensitive.

Function

({ users, email, role }: FilterUsersParams) => SettingsUser[]

formatLastActive

Formats a timestamp as MM/DD/YYYY - HH:mm. Returns - when the timestamp is missing or unparseable.

Function

(timestamp: string | undefined) => string

formatRoleLabel

Turns a role key into a readable label, so site_manager becomes Site Manager.

Function

(role: string) => string

GATEWAY_REFRESH_INTERVAL_MS

Refresh cadence — 250 s. The Gateway's token TTL defaults to 5 min, so this refreshes comfortably inside the window.

Constant

250000

getRolesFromAuthToken

Extract roles from authentication token

Function

(authToken?: string) => string[]

GRANULARITIES

Every granularity, finest first.

Constant

readonly ["hour", "day", "week", "month"]

GRANULARITY_LABELS

How each granularity is labelled in a control.

Constant

Record<Granularity, string>

isAntminer

True when a device type is a miner of the Antminer brand.

Function

(type: string | undefined) => boolean

isAvalon

True when a device type is a miner of the Avalon brand.

Function

(type: string | undefined) => boolean

isContainer

True when a device type is a container, meaning it starts with container-.

Function

(type: string | undefined) => boolean

isMiner

True when a device type is a miner, meaning it starts with miner-.

Function

(type: string | undefined) => boolean

isWhatsminer

True when a device type is a miner of the Whatsminer brand.

Function

(type: string | undefined) => boolean

LV_CABINET_DEVICES_TAG

The tags marking a device as a power meter or a temperature sensor.

Constant

{ readonly POWERMETER: "t-powermeter"; readonly SENSOR_TEMP: "t-sensor-temp"; }

LV_CABINET_DEVICES_TYPE

Full device type identifiers for the power meters and temperature sensors found in a low-voltage cabinet.

Constant

{ readonly POWERMETER_ABB_B24: "powermeter-abb-b24"; readonly SENSOR_TEMP_SENECA: "sensor-temp-seneca"; readonly POWERMETER_ABB_M1M20: "powermeter-abb-m1m20"; readonly POWERMETER_ABB_M4M20: "powermet…

MAINTENANCE_CONTAINER

The tag marking a container as being in maintenance.

Constant

"maintenance"

MINER_BRAND_NAMES

Display names for each miner brand code, for showing a brand in the UI.

Constant

{ readonly av: "Avalon"; readonly am: "Antminer"; readonly wm: "Whatsminer"; }

MINER_MODEL

Device / miner / power-meter tag + type literals. These are data-layer contracts shared between the API surface and the UI — owned by ui-foundation so the React layers can stay free of tag strings.

Constant

{ readonly AVALON: "avalon"; readonly ANTMINER: "antminer"; readonly WHATSMINER: "whatsminer"; }

MINER_MODEL_TO_TYPE_MAP

Maps a two-letter miner type code to its full model name.

Constant

{ readonly av: "avalon"; readonly am: "antminer"; readonly wm: "whatsminer"; }

MINER_POWER_MODE

The power modes a miner can be set to, from sleep through to high.

Constant

{ readonly SLEEP: "sleep"; readonly LOW: "low"; readonly NORMAL: "normal"; readonly HIGH: "high"; }

MINER_TYPE

The two-letter codes identifying a miner brand in device tags and types.

Constant

{ readonly AVALON: "av"; readonly ANTMINER: "am"; readonly WHATSMINER: "wm"; }

MINER_TYPE_MESSAGE

Caveats to show alongside a miner model, where the hardware limits what can be reported. The A1346 entry explains why its average efficiency is unavailable.

Constant

{ readonly "miner-av-a1346": "A1346 miners do not report consumption individually, so Avg. efficiency cannot be calculated"; }

MINER_TYPE_NAME_MAP

Display names for each supported miner model, such as Antminer S21.

Constant

{ readonly "miner-av-a1346": "Avalon A1346"; readonly "miner-am-s21": "Antminer S21"; readonly "miner-wm-m63": "Whatsminer M63"; readonly "miner-wm-m56s": "Whatsminer M56S"; readonly "miner-wm-m53s":…

MinerStatuses

The states a miner reports, from mining through to error and maintenance.

Constant

{ readonly MINING: "mining"; readonly OFFLINE: "offline"; readonly SLEEPING: "sleeping"; readonly ERROR: "error"; readonly NOT_MINING: "not_mining"; readonly MAINTENANCE: "maintenance"; readonly ALER…

NO_MAINTENANCE_CONTAINER

The tag marking a container as not in maintenance.

Constant

"no_maintenance"

ONE_DAY_MS

One day in milliseconds.

Constant

number

parseSettingsFile

Reads a settings file the user picked and resolves its parsed contents, rejecting if the file cannot be read or does not validate.

Function

(file: File) => Promise<SettingsExportData>

PERIOD_PRESETS

The rolling presets, shortest first, each with the granularity it opens with.

Constant

readonly [{ readonly id: "24h"; readonly label: "Last 24 hours"; readonly granularity: "hour"; }, { readonly id: "7d"; readonly label: "Last 7 days"; readonly granularity: "day"; }, { readonly id: "3…

PM_ATTRIBUTE_LABEL_MAP

Display labels for the raw power meter reading names, turning I1 a into Current L1.

Constant

{ readonly 'I1 a': "Current L1"; readonly 'I2 a': "Current L2"; readonly 'I3 a': "Current L3"; readonly 'V3 n v': "Voltage L3-N"; readonly 'V2 n v': "Voltage L2-N"; readonly 'V1 n v': "Voltage L1-N";…

presetGranularity

The granularity a rolling preset opens with.

Function

(preset: RollingPresetId) => Granularity

removeContainerPrefix

Strips the leading container- from a device type, leaving the model part.

Function

(text: string) => string

SITE_OVERVIEW_STATUSES

The headline states a site reports on the overview: offline, empty, not mining, or mining.

Constant

{ readonly OFFLINE: "offline"; readonly EMPTY: "empty"; readonly NOT_MINING: "not_mining"; readonly MINING: "mining"; }

SOCKET_STATUSES

Every state a socket can show, combining the miner statuses and power modes with the connection states a socket adds: mining error, disconnected, and connecting.

Constant

{ readonly ERROR_MINING: "errorMining"; readonly MINER_DISCONNECTED: "disconnected"; readonly CONNECTING: "connecting"; readonly SLEEP: "sleep"; readonly LOW: "low"; readonly NORMAL: "normal"; readon…

THRESHOLD_LEVEL

The severity bands a measurement can fall into, from normal through alert and alarm to the critical high and low limits.

Constant

{ readonly ALERT: "alert"; readonly ALARM: "alarm"; readonly NORMAL: "normal"; readonly ALARM_LOW: "alarmLow"; readonly ALARM_HIGH: "alarmHigh"; readonly CRITICAL_LOW: "criticalLow"; readonly CRITICA…

THRESHOLD_TYPE

The cooling measurements a container can hold thresholds against: tank pressure, oil and water temperature, and supply liquid pressure.

Constant

{ readonly TANK_PRESSURE: "tankPressure"; readonly OIL_TEMPERATURE: "oilTemperature"; readonly WATER_TEMPERATURE: "waterTemperature"; readonly SUPPLY_LIQUID_PRESSURE: "supplyLiquidPressure"; }

USER_ROLE

The roles a user account can hold. A role carries its own set of permissions.

Constant

{ readonly ADMIN: "admin"; readonly READ_ONLY: "read_only_user"; readonly SITE_MANAGER: "site_manager"; readonly SITE_OPERATOR: "site_operator"; readonly FIELD_OPERATOR: "field_operator"; readonly RE…

validateSettingsJson

Type guard checking that parsed JSON looks like an exported settings file, meaning it carries header controls, feature flags, or a timestamp.

Function

(data: unknown) => data is SettingsExportData

WEBAPP_DISPLAY_NAME

The full product name, for headings and body copy.

Constant

"Application"

WEBAPP_NAME

Neutral application display names used anywhere the toolkit needs to refer to the running product (header labels, chart legends, settings copy). Single source of truth — rebrands change these three values only.

Constant

"Appl."

WEBAPP_SHORT_NAME

The short product name, for tight spaces such as chart legends and column headers.

Constant

"APP"

On this page