Skip to content

Project improvements: correctness fixes, DRY refactors, logger, tests/CI, tooling#52

Merged
Nebyt merged 19 commits into
mainfrom
refactor/project-improvements
Jul 8, 2026
Merged

Project improvements: correctness fixes, DRY refactors, logger, tests/CI, tooling#52
Nebyt merged 19 commits into
mainfrom
refactor/project-improvements

Conversation

@Nebyt

@Nebyt Nebyt commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Correctness fixes, DRY refactors, a debug-gated logger, tests + CI, error toasts, tooling/docs, and a light shared chain abstraction — plus two UI/util fixes found while testing. Behavior-preserving throughout (or better); reviewed and verified.

What's included

Correctness

  • ApiCard height via a static Tailwind class map (dynamic h-${n} was being purged).
  • useContext guards === undefined!context (default was null, so they never fired).
  • connect() param requestIdrequestIdentification.
  • Network toggle was unclickable on the titles — inactive Material Tailwind TabPanels overlaid the page; now render only the active tab's content.

Refactors (DRY)

  • Renamed yoroiProvidercardanoProvider / useYoroiuseCardano.
  • Memoized cardanoProvider; shared useConnectionState state machine adopted by all providers; documented ChainProvider contract.
  • runApiCall helper (22 cards), useResponseState (7 subtabs), buildCert (8 gov panels), hexArrayToBech32Addresses/hexArrayToUtxos, parseCredential, ChainStatusMessage, AccessButtonShell, InputWithLabel extended (routed ~22 input blocks), shared chunkMessageTo64Bytes.

Logging

  • Debug-gated logger replacing 159 console.* calls; runtime toggle via window.dappLogs (persisted in localStorage) — flip logs on a deployed build without rebuilding.

Tests & CI

  • Jest + RTL suites (39 tests): utils, logger, toast, connection-state, runApiCall, ApiCard.
  • test.yml runs format/lint/tests on push+PR; build.yml writes a production .env (REACT_APP_DEBUG=false).

Error UX

  • Toast system for wallet-connect failures (previously console-only).

Tooling / docs

  • prettier dep + lint/format scripts; expanded README; .env.example.

Notes

  • Step "Bitcoin implementation" was intentionally deferred (BTC support undecided).
  • Verified: npm run lint, npm run format:check, npm run test:ci (39 pass), CI=true build all green.

🤖 Generated with Claude Code


Note

Medium Risk
Wide touch across wallet API cards and providers with behavior intended to stay the same; tab and Tailwind fixes are localized UI risks, while refactors could subtly change error/waiting handling if runApiCall options differ per card.

Overview
This release (2.4.0) is a broad maintainability and correctness pass: shared helpers and hooks, a debug-gated logger, visible error toasts, automated checks in CI, and a couple of UI fixes—without changing the dApp’s core wallet flows.

Correctness & UI: ApiCard now maps heights to static Tailwind classes so production builds don’t strip dynamic h-${n} classes. tabsComponent only mounts the active tab (fixes Material Tailwind panels overlaying the network toggle). Provider hooks use !context for missing-provider errors. Cardano connect uses requestIdentification instead of requestId.

Architecture: yoroiProvider is renamed to cardanoProvider / useCardano. Shared useConnectionState, useResponseState, runApiCall (many API cards), buildCert (gov panels), parseCredential, AccessButtonShell, ChainStatusMessage, and extended InputWithLabel cut duplicated code. console.* is replaced by logger with REACT_APP_DEBUG and runtime dappLogs toggles. Wallet connect failures surface via ToastProvider.

Tooling: New test.yml (format, lint, test:ci); build.yml writes production .env; Prettier/lint scripts, .env.example, and README updates. Adds unit tests (e.g. ApiCard, hooks, logger).

Reviewed by Cursor Bugbot for commit 56a23dc. Bugbot is set up for automated code reviews on this repo. Configure here.

Nebyt added 17 commits July 8, 2026 12:41
- apiCard: use static HEIGHT_CLASSES map so Tailwind JIT keeps h-10/16/24
  (dynamic h-${height} was purged, silently no-op'ing getAllInfoCard)
- providers: fix useContext guards (=== undefined -> !context; default is null)
- cardanoProvider: rename connect() param requestId -> requestIdentification
- rename yoroiProvider -> cardanoProvider, useYoroi -> useCardano across 13 files
- Wrap cardanoProvider callbacks in useCallback and context value in useMemo
  (match ethereumProvider; avoids re-rendering all consumers each render)
- Move connect() above the mount effect and add it to deps (stable identity)
- Fix provider nesting indentation in index.js
- Add src/utils/logger.js: debug/log/info gated on NODE_ENV==='development'
  or REACT_APP_DEBUG==='true'; warn/error always print
- Route all 159 console.* calls across 53 files through logger.*
- Persist an enabled override in localStorage (key 'dapp:debug')
- Expose window.dappLogs { on, off, toggle, status, reset } so logs can be
  toggled live from the console without rebuilding
- Falls back to build default (dev, or REACT_APP_DEBUG=true) when no override
- setupTests.js loads @testing-library/jest-dom
- ethereumUtils: chainName, wei/eth conversions, shortAddress, ERC-20 encoders
- utils: bytesToHex/hexToBytes round-trip
- logger: gating, always-on warn/error, persisted override, window.dappLogs toggle
- ApiCard: render, click, height class map, color prop
- add test:ci script and .github/workflows/test.yml (runs on push/PR)
- 24 tests across 4 suites, all passing
- Add src/utils/runApiCall.js: shared waiting/raw/response/error envelope with
  parse, rawText and stringify options (+ unit tests)
- Convert 22 API cards to runApiCall, removing the repeated then/catch boilerplate
- Left signTransactionCard (multi-step build) and cip95getRegisteredPubStakeKeys
  (per-branch stringify) on the explicit form to preserve exact behavior
- Extend InputWithLabel with placeholder, min, step, disabled and
  wrapperClassName props (disabled swaps to the disabled input style)
- Replace ~22 hand-rolled label+input blocks across 11 cards with InputWithLabel
- Removes duplicated CommonStyles.inputStyles / contentLabelStyle markup
- Add src/hooks/useResponseState.js (currentText/rawCurrentText/waiterState +
  setResponse/setRawCurrentText/setWaiterState)
- Replace the duplicated state + setResponse block in 7 subtabs
- Left testTxsTab (drives currentText directly) on its own state
- Skipped optional SubtabShell to avoid per-tab layout divergence
- Add src/utils/buildCert.js: shared onWaiting/getCertBuilder/try-catch(onError)
  envelope for the governance cert + vote panels
- Convert all 8 govActions panels to buildCert; early returns now still clear
  the waiting flag (previously left it stuck)
- Add both array-decode helpers to cslTools.js
- Replace the duplicated for-loops in helpFunctions.js (3 address + 1 utxo)
- Route the address/utxo cards through the named helpers instead of inline .map
- parseCredential() in cslTools: dedupe the two identical handleInputCreds copies
- ChainStatusMessage: shared status banner for the 3 chain main tabs
- AccessButtonShell: shared chrome for the 3 access buttons (eth had it 3x)
- Skipped CardCell (would require a context abstraction, against the project's
  explicit-over-abstraction philosophy for marginal gain)
- Add ToastProvider/useToast + ToastContainer (top-right auto-dismissing banners)
- Wrap the app in ToastProvider (outermost) so providers can surface errors
- Cardano + Ethereum connect failures now show a toast (Cardano stays silent on
  the background reconnect); previously connect errors only hit the console
- Add ToastProvider tests (show, manual dismiss, auto-dismiss, guard)
Format all source files per .prettierrc (printWidth 120, no semi, single
quotes, no bracket spacing, trailing commas). Formatting only, no logic changes.
(import-order plugin not installed, so import ordering unchanged.)
- Add prettier devDep + lint/lint:fix/format/format:check scripts
- Remove dead import-order options from .prettierrc (plugin was never installed)
- CI (test.yml): run format:check + lint before tests on push/PR
- CI (build.yml): write production .env (REACT_APP_DEBUG=false) before build
- Expand README (chains, stack, setup, scripts, structure, logging, testing)
- Add .env.example documenting REACT_APP_DEBUG
- logger.test.js: disable false-positive testing-library/no-debugging-utils
- Add useConnectionState(): shared NOT_CONNECTED/IN_PROGRESS/CONNECTED/NO_PROVIDER
  machine with named transitions (setConnected/setNotConnected/setInProgress/
  setNoProvider) + raw setter; keeps setter identities stable
- Adopt it in Cardano, Ethereum and Bitcoin providers (replaces per-provider
  useState + scattered setConnectionState calls); behavior unchanged
- Add chainProvider.js documenting the common ChainProvider contract (CLAUDE.md)
- Add useConnectionState tests. Kept providers otherwise explicit/separate per
  the project's clarity-over-abstraction philosophy (light step 9; step 10 BTC
  deferred pending a support decision)
…page

Material Tailwind keeps inactive <TabPanel>s mounted and absolutely positioned;
with no positioned ancestor they collapsed to the top-left of the viewport and
overlaid the network toggle, swallowing clicks on the Cardano/Ethereum titles.
Render only the active tab's content (keep the Material Tailwind header).
- Move chunkMessageTo64Bytes cslTools.js -> utils.js (pure fn; Buffer.byteLength
  instead of TextEncoder so it also runs under the jsdom test env)
- cip20Tab imports it from utils
- NFTTab: replace char-based sliceBy64Char (could exceed 64 bytes on multibyte
  text) with a thin adapter over the shared byte-based util, keeping CIP-25's
  string-or-array output
- Add chunkMessageTo64Bytes tests
Comment thread .github/workflows/test.yml Fixed
Nebyt and others added 2 commits July 8, 2026 18:43
…ntain permissions'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@Nebyt Nebyt merged commit e671ed2 into main Jul 8, 2026
5 checks passed
@Nebyt Nebyt deleted the refactor/project-improvements branch July 8, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants