Skip to content

refactor(wallet-flow): stable signerIds for React keys; tripwire test#247

Merged
jinglescode merged 1 commit into
mainfrom
refactor/wallet-flow-shared
May 10, 2026
Merged

refactor(wallet-flow): stable signerIds for React keys; tripwire test#247
jinglescode merged 1 commit into
mainfrom
refactor/wallet-flow-shared

Conversation

@jinglescode
Copy link
Copy Markdown
Member

Summary

Re-opening as new PR — original #238 was auto-closed when its base branch (feat/server-hardening-and-audit-log) was deleted on merge of #237. Same diff, now targeting main.

Introduces stable opaque signerId generators for the wallet creation flow's parallel arrays (signersAddresses, signersStakeKeys, signersDRepKeys, signersDescriptions), so React keys are no longer derived from raw addresses. Includes a source-regex tripwire test that fails if anyone reverts to using address as a React key in the review-signers card.

See original #238 for full discussion.

Test plan

  • New wallet creation flow renders correctly
  • Adding/removing signer rows preserves stable keys (no React duplicate-key warnings in console)
  • Tripwire test passes: npm run test -- reviewSignersCardKey

🤖 Generated with Claude Code

The new-wallet-flow and wallet-migration flow used the raw signer
address as a React key in ReviewSignersCard. Two issues:

1. The address can be empty/undefined while the user is editing, which
   makes the key non-unique → React reuses inputs across rows, swapping
   names and addresses while typing.
2. Two signers can momentarily share the same partial input, again
   producing duplicate keys.

Fix: every row gets a stable opaque `signerId` generated when the row
is created; the component uses `signerId` as the React key. Address
becomes regular state, free to be empty/duplicate transiently without
breaking React identity.

The same fix applied to both `useWalletFlowState` (new wallet) and
`useMigrationWalletFlowState` (migration). The shared `signerRows.ts`
module emits the id and keeps the parallel arrays in sync.

`reviewSignersCardKey.test.ts` is a tripwire suite that:
- greps the source to assert the raw address is never used as a key
- verifies both flow-state hooks expose signerIds parallel to
  signersAddresses

This catches future regressions structurally — the type system can't
enforce \"don't use address as key\", but a regex over source can.

Test plan
- 171/171 tests pass deterministically on top of #237
- Typecheck clean

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jinglescode jinglescode merged commit 94cd08e into main May 10, 2026
5 checks passed
@jinglescode jinglescode deleted the refactor/wallet-flow-shared branch May 10, 2026 08:59
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.

1 participant