Skip to content

fix(analytics): convert decimal channel hashes to hex format in UI - #192

Merged
diffwireauto merged 1 commit into
masterfrom
bug-190_incorrect_decimal_channel_hashes
Oct 12, 2026
Merged

diffwireauto merged 1 commit into
masterfrom
bug-190_incorrect_decimal_channel_hashes

Conversation

@Jeymz

@Jeymz Jeymz commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Summary

fixes #190

The Hash column in Analytics → Channels showed decimal values (17, 129) instead of hexadecimal.

Root cause

channelRowHtml in public/analytics.js only formatted the hash as hex when c.hash was a JavaScript number. /api/analytics/channels sends it as a decimal string ("17"), so it took the fallback branch and was printed as-is. The Go tests assert this string format (channel_analytics_test.go), so the API is unchanged and the fix is in the frontend.

Changes

public/analytics.js

  • Added channelHashNum(h), which turns a number or an all-digits string into a number and returns NaN for anything else.
  • Added formatChannelHash(h), which renders 0xNN (uppercase, zero-padded to 2 digits) for numeric values. Non-numeric ids such as enc_A1B2 pass through esc(). They were previously printed unescaped.
  • channelRowHtml uses formatChannelHash(c.hash) for the Hash cell.
  • The hash case in sortChannels compares numerically when both hashes are numeric, so the order is 0x05 < 0x11 < 0x81. Previously decimal strings sorted as text. Non-numeric hashes keep the old string compare.
  • The #/channels?ch=<hash> deep link still uses the decimal value, so existing bookmarks keep working.

tests/unit/test-frontend-helpers.js

  • "17", "129" and "5" render as 0x11, 0x81 and 0x05. Decimal is not displayed, and the deep link keeps ?ch=17.
  • enc_A1B2 is unchanged and <b> is HTML-escaped.
  • The hash sort is numeric for decimal-string hashes.

Testing

  • node tests/unit/test-frontend-helpers.js: 729 passed, 0 failed.
  • No Go files changed.
  • Not yet done: browser validation of Analytics → Channels

Performance

No hot-path impact. This is one regex and one toString(16) per rendered row, and the sort comparator does a cheap parse per comparison.

Follow-ups (not in this PR)

  • Send the hash as a typed integer, or add a hashHex field, so clients stop converting a string themselves. This is a good moment to move the channels analytics response to a named struct, in line with the map[string]interface{} rule in AGENTS.md.
  • Check whether public/channels.js shows the same decimal value anywhere.

@Jeymz Jeymz added the type:bug Work item type label Oct 10, 2026
@Jeymz Jeymz self-assigned this Oct 10, 2026
@ITblacksheep

Copy link
Copy Markdown
Contributor

Can you go ahead and open an enhancement to fix this on the backend also?

@Jeymz

Jeymz commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Can you go ahead and open an enhancement to fix this on the backend also?

Follow-up items documented in #193

@Strycher
Strycher force-pushed the bug-190_incorrect_decimal_channel_hashes branch from 9c884f6 to 7440c6b Compare October 12, 2026 01:33
@diffwireauto

Copy link
Copy Markdown
Contributor

Human approval received from Strycher in session 64287058 ("Merge #192."). Re-validated against the remote immediately prior: state=OPEN, mergeable=MERGEABLE, mergeStateStatus=CLEAN, reviewDecision=APPROVED (ITblacksheep), head 7440c6b39465a803cd6d1baf79a5248c1cb426ac, base 448745c9 (current master, 0 commits behind).

Rebased earlier tonight onto the #194 staging fix. The rebase preserved content exactly — diff hash fbbbc2539e66dd6dd211a607176e3774ae439828 before and after — and kept Jeymz Simmons as commit author.

@diffwireauto
diffwireauto merged commit 030be43 into master Oct 12, 2026
9 checks passed
@diffwireauto
diffwireauto deleted the bug-190_incorrect_decimal_channel_hashes branch October 12, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Work item type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Channel hashes in Channel Analytics are being displayed as a decimal value rather than hexadecimal

3 participants