Skip to content

Comments

Refactor: Consolidate duplicate code patterns across forms and builders#44

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/refactor-duplicated-code
Draft

Refactor: Consolidate duplicate code patterns across forms and builders#44
Copilot wants to merge 4 commits intomasterfrom
copilot/refactor-duplicated-code

Conversation

Copy link

Copilot AI commented Feb 11, 2026

Identified and eliminated ~100 lines of duplicated code across utility functions, form components, and builder hero sections.

Changes

Removed unused duplicate utilities

  • Deleted weiToEth.ts and formatWei.ts (identical to existing formatEtherPrice.ts, unused)
  • Deleted apps/web/src/utils/logEvent.ts (inferior duplicate of libs/base-ui/utils/logEvent)

Extracted shared form patterns

  • Created basenameFormUtils.ts with reusable hooks:
    • useSwitchToBasenameChain - network switching callback
    • useYearSelectionCallbacks - year increment/decrement with optional event logging
  • Applied to RegistrationForm and RenewalForm

Consolidated copy-to-clipboard logic

  • Created useCopyToClipboard hook with proper async error handling
  • Replaced 6 duplicate implementations across AgentKit, OnchainKit, MiniKit hero components

Before/After

// Before: Duplicated across 6 components
const [hasCopied, setHasCopied] = useState(false);
const handleCopy = useCallback(() => {
  void navigator.clipboard.writeText('npm create onchain');
  setHasCopied(true);
  setTimeout(() => setHasCopied(false), 2000);
}, []);

// After: Single hook with error handling
const { hasCopied, copyToClipboard } = useCopyToClipboard();
const handleCopy = useCallback(() => {
  copyToClipboard('npm create onchain');
}, [copyToClipboard]);

Impact

  • 3 files deleted, 2 utility hooks added
  • Consistent patterns across registration/renewal flows
  • Single source of truth for clipboard operations

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 11, 2026 04:51
Co-authored-by: Kushmanmb <193178375+Kushmanmb@users.noreply.github.com>
…board logic

Co-authored-by: Kushmanmb <193178375+Kushmanmb@users.noreply.github.com>
…ency issues

Co-authored-by: Kushmanmb <193178375+Kushmanmb@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Refactor: Consolidate duplicate code patterns across forms and builders Feb 11, 2026
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