Skip to content

Conversation

@katspaugh
Copy link
Member

Summary

This PR makes safe config init optional by ensuring default chains are always available. Previously, users had to run config init before using any commands, creating a poor first-run experience and blocking automation use cases.

Changes

ConfigStore Updates

  • getAllChains() now returns default chains merged with custom chains
  • getChain() falls back to default chains if not found in store
  • Added isCustomChain() method to distinguish custom vs default chains
  • Updated deleteChain() to only delete custom chains (can't delete defaults)

Command Updates

  • Removed "No chains configured" validation from commands
  • Updated config init messaging to emphasize it's optional
  • Updated config chains remove to only show custom chains

Benefits

Better First-Run Experience

  • CLI works immediately without any setup
  • 18 chains available out-of-the-box

Automation & CI/CD Ready

  • No config init prerequisite for scripts
  • Can go straight to wallet create and start working

Still Fully Customizable

  • Users can override default chains
  • Users can add custom chains
  • Config init still useful for API keys

Backward Compatible

  • Existing configs continue to work
  • No breaking changes

Testing

  • TypeScript compilation passes
  • Pre-commit hooks pass
  • Manual testing recommended: try commands without running config init first

Related

This is a prerequisite for the automation improvements planned in the roadmap. With this change, scripts can immediately use the CLI without needing to initialize config first.

🤖 Generated with Claude Code

Previously, users were required to run `safe config init` before using any commands because chain configurations were not available until explicitly set. This created a poor first-run experience.

Changes:
- ConfigStore now always returns default chains via getAllChains() and getChain()
- Default chains are merged with any custom chains, allowing overrides
- Removed "No chains configured" validation from commands
- Updated config init to focus on API keys and customization
- Added isCustomChain() method to distinguish custom vs default chains
- Updated chain removal to only allow deleting custom chains

Benefits:
- CLI works immediately without config init (better UX)
- 18 chains available out-of-the-box
- Config init becomes optional (only for API keys/customization)
- Better for automation and CI/CD (no setup step required)
- Maintains backward compatibility

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings November 7, 2025 14:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors chain configuration management to ensure default chains are always available while allowing users to add custom chains or override defaults. The changes eliminate scenarios where "No chains configured" errors could occur by making DEFAULT_CHAINS (18 built-in networks) always accessible through the storage layer.

Key Changes:

  • Modified ConfigStore methods to merge DEFAULT_CHAINS with custom chains from storage
  • Updated config initialization flow to focus on managing custom chains rather than all chains
  • Removed validation that prevented opening Safes when no custom chains are configured

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/storage/config-store.ts Enhanced getChain(), getAllChains(), and deleteChain() to always include DEFAULT_CHAINS; added isCustomChain() method to distinguish custom from default chains
src/commands/config/init.ts Updated initialization wizard to manage only custom chains rather than all chains; revised messaging to clarify default chains are always available
src/commands/config/chains.ts Modified removeChain() to filter and display only custom chains, preventing deletion of default chains
src/commands/account/open.ts Removed "No chains configured" validation since DEFAULT_CHAINS are now always available

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const existingChains = configStore.getAllChains()
const hasExistingChains = Object.keys(existingChains).length > 0
// Check if custom chains already exist in store
const customChains = configStore.getConfig().chains || {}
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getConfig().chains returns all chains including DEFAULT_CHAINS from the store defaults. This means hasCustomChains will always be true even when no custom chains have been added.

To check only for custom chains that were explicitly added by the user, use this.store.get('chains', {}) directly (similar to how deleteChain(), getAllChains(), and isCustomChain() work in config-store.ts), or add a new method like getCustomChains() to ConfigStore.

Suggested change
const customChains = configStore.getConfig().chains || {}
const customChains = configStore.store.get('chains', {})

Copilot uses AI. Check for mistakes.
return
}
const manageChains = await p.confirm({
message: 'Would you like to reset all custom chains to defaults?',
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message "Would you like to reset all custom chains to defaults?" is potentially confusing. The action being performed is removing/clearing custom chains (line 51 calls configStore.reset()), not resetting them to default values.

Consider rephrasing to: "Would you like to remove all custom chains?" or "Would you like to clear all custom chain configurations?" to more accurately describe the operation.

Suggested change
message: 'Would you like to reset all custom chains to defaults?',
message: 'Would you like to remove all custom chains?',

Copilot uses AI. Check for mistakes.
Updated tests to match new behavior where default chains are always available:
- Renamed 'empty-chains' tests to 'default-chains' tests
- Changed expectations from empty {} to default chains
- Updated test assertions to expect EIP-3770 format using default chains
- Fixed config.test.ts to test custom chain deletion properly
- Fixed eslint error in argument-parser.ts

All tests now correctly validate that:
- Default chains are always present
- Custom chains can be added and deleted
- Default chains cannot be deleted (they always exist)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@katspaugh katspaugh merged commit d8d5aaa into main Nov 7, 2025
4 checks passed
@katspaugh katspaugh deleted the refactor/optional-config-init branch November 7, 2025 14:58
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