chore(ui): move existing inline null/empty and typeof checks to the guards

Open
#937 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@bitcoinbrisbane is already working on this.

Since Nov 1, 2026.

Assessment

This issue has not been assessed yet.

Description

refactor tech debt UI

Why

UI Architecture Commandment 8 (CLAUDE.md) says null, empty and length checks go through src/utils/guards.ts. Since #933, the Guards CI job (yarn check:guards) enforces this, but only on lines a PR adds. Older code was never moved over, so it doesn't match the rule. Any PR that touches those files either inherits the old checks or ends up mixing unrelated guard fixes into its diff (as #936 did; now closed).

The last adoption pass was #449 (#451, #453, #459, #473).

What's left on main (9420ff5)

Counted with the same rules check:guards uses (scripts/guards/rules.ts), over whole files. Comments and // guards-ok lines are skipped.

136 hand-written null/empty/length checks in 63 files

Use instead Count
hasValue(x) 64
isNullish(x) 48
isEmpty(x) / isBlank(x) 12
hasElements(x) / hasContent(x) 12

Densest files: pages/TableAdminPage.tsx (15), bus/GameMessageBus.ts (8), components/bridge/StuckPaymentsPanel.tsx (8), pages/Dashboard.tsx (6), submit/ActionSubmitController.ts (5), utils/turnClock.ts (5).

30 typeof checks in 19 files, mostly narrowing an unknown reply field, e.g.

const msg = typeof raw?.message === "string" ? raw.message : response.statusText; // hooks/game/useFetchSngClaimSignature.ts
rawLog: typeof rawLog === "string" ? rawLog : "",                               // submit/txVerdict.ts
if (typeof err === "object" && err !== null) {                                  // apis/HTTPClient.ts

There are no guards for these yet. Most are in constants/currency.ts, submit/txVerdict.ts, components/explorer/ClickableAddress.tsx, audio/actionSoundPlayer.ts and apis/HTTPClient.ts.

Scope

  1. Replace the 136 checks with the existing guards. Where null and undefined mean different things, keep the strict check and end the line with // guards-ok. Example: #919's ante rule, where null means "antes off" and undefined means "not set". isNullish would merge them.
  2. Add type guards for the typeof cases, with tests in guards.test.ts: isString, isNumber, isBoolean, and isRecord for "non-null object whose fields can be read". Then switch the 30 sites to them and list the new guards in Commandment 8.
  3. Teach check:guards the typeof pattern so new ones are flagged once the guards exist.

How

  • Its own PRs, split by directory (bus/ + submit/, hooks/, components/, pages/, utils/ + apis/), not folded into feature PRs.
  • No behaviour change. Each PR passes tsc -b, the full jest suite and check:guards.
  • No visible change, so no screenshots.
Dominant language
TypeScript
Stars
2
Forks
5
Avg merge
23h 23m
Merged PRs (30d)
97

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from block52/ui

All issues in block52/ui

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.