Skip to content

fix(AccountCard): add clipboard error handling and memoize avatar hashing (#889) - #1009

Merged
k-deejah merged 4 commits into
Sorokit:mainfrom
bamiebot-maker:fix/889-account-card-clipboard-avatar
Oct 18, 2026
Merged

k-deejah merged 4 commits into
Sorokit:mainfrom
bamiebot-maker:fix/889-account-card-clipboard-avatar

Conversation

@bamiebot-maker

Copy link
Copy Markdown
Contributor

Description

Resolves #889.

Problem

  1. In src/components/AccountCard.tsx (AccountCard), the copy-to-clipboard button silently failed without visual feedback when navigator.clipboard.writeText rejected in non-HTTPS or permission-restricted environments.
  2. The avatar generator recomputed avatar initials and color arrays on every parent re-render rather than memoizing against the account public key.
  3. Avatar hash calculation produced identical color gradients for accounts with identical first 6 characters because prefix-only or truncated values were evaluated.

Solution & Implementation

  • Clipboard Error Handling & Fallback:
    • Enhanced AddressDisplay with an onCopyError callback invoked when both navigator.clipboard.writeText and document.execCommand('copy') fail.
    • Implemented copyToClipboard fallback utility handling synchronous and asynchronous clipboard rejection.
    • Wired onCopyError in AccountCard to display an error toast ("Copy Failed": "Failed to copy address to clipboard.").
  • Full Public Key Avatar Hashing:
    • Implemented 32-bit FNV-1a hash algorithm (fnv1aHash) that evaluates every character of the full public key string, guaranteeing distinct hashes and gradient palettes for accounts that share identical prefixes.
  • Memoization:
    • Memoized avatar initials and avatar gradient styles in AccountCard and AccountCardCompact using useMemo(..., [address]), preventing style recalculation when non-account props (e.g. onNavigate) change.
  • Unit Testing:
    • Added unit tests in src/components/AccountCard.test.tsx verifying:
      • Error toast is displayed when clipboard write fails.
      • Success toast is displayed when clipboard write succeeds.
      • copyToClipboard fallback behavior across modern Clipboard API and execCommand.
      • Full-key hashing avoids prefix collisions for accounts with identical first 6 characters.
      • Gradient consistency across renders and memoization when non-account props change.

Acceptance Criteria Checklist

  • Clipboard write failures display an error toast message.
  • Avatar hash calculation uses the full public key string.
  • Component does not recompute gradient styles when non-account props change.
  • Unit tests cover copy failure scenarios and avatar consistency.

…hing (Sorokit#889)

- Wrap clipboard writing with document.execCommand('copy') fallback and display error toast upon failure

- Add onCopyError callback support to AddressDisplay and wire into AccountCard

- Generate deterministic avatar gradients using full-address FNV-1a hashing to prevent prefix collisions

- Memoize avatar initials and gradient styles using useMemo to prevent recomputation on non-account prop changes

- Add unit tests covering clipboard failure, error toast triggering, avatar gradient memoization, and prefix collision avoidance
@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@bamiebot-maker Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@k-deejah
k-deejah merged commit e3d7978 into Sorokit:main Oct 18, 2026
4 checks passed
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.

Add clipboard error handling and memoize avatar hashing in AccountCard

2 participants