-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: make config init optional by always providing default chains #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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>
There was a problem hiding this 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
ConfigStoremethods 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 || {} |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
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.
| const customChains = configStore.getConfig().chains || {} | |
| const customChains = configStore.store.get('chains', {}) |
| return | ||
| } | ||
| const manageChains = await p.confirm({ | ||
| message: 'Would you like to reset all custom chains to defaults?', |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
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.
| message: 'Would you like to reset all custom chains to defaults?', | |
| message: 'Would you like to remove all custom chains?', |
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>
Summary
This PR makes
safe config initoptional by ensuring default chains are always available. Previously, users had to runconfig initbefore 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 chainsgetChain()falls back to default chains if not found in storeisCustomChain()method to distinguish custom vs default chainsdeleteChain()to only delete custom chains (can't delete defaults)Command Updates
config initmessaging to emphasize it's optionalconfig chains removeto only show custom chainsBenefits
Better First-Run Experience
Automation & CI/CD Ready
Still Fully Customizable
Backward Compatible
Testing
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