Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(network): enable runtime connection to custom Algorand nodes (#339)
* feat(network): add ability to update network algod config at runtime Add `updateNetworkAlgod` method to `WalletManager` to allow updating algod configuration for any network at runtime. This enables users to connect to their own Algorand nodes by modifying the network configuration after initialization. - Add `updateNetworkAlgod` method to `WalletManager` class - Add comprehensive test suite for the new method - Handle validation of updated configurations - Automatically update active algod client when modifying active network - Preserve existing configuration when partially updating * refactor(react): separate network functionality into useNetwork hook - Move network functionality (`activeNetwork`, `algodClient`, `setActiveNetwork`, etc.) to `useNetwork` - Reorganize exports to match logical grouping (Provider, Network, Wallet) - Update tests to reflect new hook separation - Add comprehensive test coverage for `useNetwork` hook - Remove network-related properties from `useWallet` tests - Export additional network types from `use-wallet` package BREAKING CHANGE: Network-related properties and methods have been moved from `useWallet` to the new `useNetwork` hook. * feat(solid): separate network functionality into useNetwork function - Move network functionality (`activeNetwork`, `algodClient`, `setActiveNetwork`) to `useNetwork` - Reorganize exports to match logical grouping (Provider, Network, Wallet) - Update tests to reflect new function separation - Add comprehensive test coverage for `useNetwork` - Remove network-related properties from `useWallet` tests - Export additional network types from `use-wallet` package - Improve test organization and setup BREAKING CHANGE: Network-related properties and methods have been moved from `useWallet` to the new `useNetwork` function. * feat(vue): split network functionality into useNetwork composable Move network-related functionality from `useWallet` to `useNetwork` composable to improve code organization and separation of concerns. Update tests to reflect the new structure. - Move `algodClient` and `setAlgodClient` to `useNetwork` - Move `setActiveNetwork` and `activeNetwork` to `useNetwork` - Split network-related tests into `useNetwork.test.ts` - Update `useWallet` tests to remove network assertions - Improve test setup with better mock organization BREAKING CHANGE: Network-related properties (`algodClient`, `setAlgodClient`, `activeNetwork`, `setActiveNetwork`) have been moved from `useWallet` to a new `useNetwork` composable. * fix(tests): remove name property from NetworkConfig in tests Remove `name` property from `NetworkConfig` in tests to match updated type definition. This aligns test fixtures with the core `NetworkConfig` type that no longer includes the optional name field. * fix(adapters): add updateNetworkAlgod to Vue and Solid adapters Add `updateNetworkAlgod` function to Vue adapter and test coverage for both Vue and Solid adapters. This completes the network configuration functionality across all framework adapters, ensuring consistent behavior for runtime algod config updates. * fix(vue): export useNetwork from src/index.ts * refactor(examples): split network functionality into useNetwork Split network-related functionality from `useWallet` into separate `useNetwork` hook across all framework examples. - Move `algodClient`, `activeNetwork`, and `setActiveNetwork` to `useNetwork` - Update Next.js example to use split hooks - Update Nuxt example to use split hooks - Update React example to use split hooks - Update Solid example to use split hooks - Update Vue example to use split hooks * fix(solid): update reactive algodClient when network config changes When updating network configuration through `updateNetworkAlgod`, ensure the `algodClient` is also updated in the store if the modified network is currently active. * feat(*): add activeNetworkConfig to WalletManager and useNetwork Add `activeNetworkConfig` to `useNetwork` across React, Vue, and Solid implementations: - Add `activeNetworkConfig` property to `WalletManager` in core library - Expose current network configuration through `useNetwork` hook - Add tests to verify network config updates correctly - Ensure reactivity when switching networks or updating config at runtime * feat(network): persist user network customizations Add support for persisting user-modified network configurations while preserving developer-provided defaults. This enables users to customize network settings that persist between sessions without affecting the base configuration. - Add `customNetworkConfigs` to persisted state - Store base network config separately from runtime config - Compare against base config to identify user customizations - Update tests to verify persistence behavior * feat(network): add resetNetworkConfig functionality Add `resetNetworkConfig` method to `WalletManager` and expose it through framework adapters. This allows resetting a network's configuration to its default state, removing any customizations. - Add `resetNetworkConfig` method to `WalletManager` class - Add tests for `WalletManager` `resetNetworkConfig` functionality - Expose `resetNetworkConfig` through React, Vue, and Solid adapters - Add comprehensive tests for each adapter implementation * fix(react): update algodClient when modifying network config Update the `algodClient` state when updating network configuration to ensure UI reflects the current network state. This fixes an issue where the UI would not update after resetting network configuration. * refactor(react): move algodClient back to useWallet hook Move `algodClient` and `setAlgodClient` from `useNetwork` to `useWallet` to better align with their usage patterns. Update tests to handle shared context between hooks and fix assertions around loading states. - Remove `algodClient` and `setAlgodClient` from `useNetwork` return value - Add `algodClient` and `setAlgodClient` to `useWallet` return value - Update tests to use combined hooks when testing cross-hook interactions - Fix integration test to properly handle loading states * refactor(solid): move algodClient back to useWallet hook Move `algodClient` from `useNetwork` to `useWallet` to maintain consistency with React adapter changes. Update tests to reflect new hook structure. - Remove `algodClient` from `useNetwork` return value - Add `algodClient` to `useWallet` return value - Update test components to access `algodClient` through `useWallet` * refactor(vue): move algodClient back to useWallet Move `algodClient` from `useNetwork` to `useWallet` composable to better align with component responsibilities. Update tests to reflect new dependency structure and improve injection mocking setup. - Move `algodClient` computed property from `useNetwork` to `useWallet` - Update `useNetwork` tests to get `algodClient` from `useWallet` - Add `algodClient` injection handling in `useWallet` tests - Move inject mock setup into `setupMocks` for consistent dependency initialization * feat(examples): add network config UI to React and Vue examples Add network configuration forms to React and Vue examples with styling: - Add config form component with server/port/token inputs - Add form styling for light/dark modes - Move network controls to separate component - Update imports and component structure The network configuration UI allows users to view and modify the algod node configuration for each network. * fix(examples): update algodClient import location in example apps Update Next, Nuxt, and Solid example apps to reflect the movement of `algodClient` from `useNetwork` back to `useWallet`. * chore(examples): fix Prettier issues * refactor(core): move network config to reactive store state Move network configuration from `WalletManager` instance to store state to support runtime network configuration updates and ensure reactivity across framework adapters. This change enables the new feature that lets users modify network settings at runtime while ensuring those updates are properly tracked in the reactive store. - Adds `networkConfig` to store state - Updates all references to use `store.state.networkConfig` - Removes `networks` prop from wallet constructors - Simplifies `algodClient` creation by passing config directly * refactor(adapters): update network config references Update React and Vue adapters and examples to use `networkConfig` from store state instead of the removed `networks` property. This change follows up on moving network configuration to the reactive store. - Update `useNetwork` hook/composable to return `networkConfig` instead of `networks` - Update `NetworkControls` components in React/Vue examples - Fix affected tests in both adapter packages * refactor(solid): update network config handling and add example UI Update Solid adapter to use reactive store for network configuration and add `NetworkControls` component to demonstrate runtime network configuration. This change improves reactivity in the Solid example project to match React and Vue implementations. - Add `NetworkControls` component with config form UI - Update `useNetwork` function to use store state for better reactivity - Remove network controls from `Connect` component - Add styles for network configuration UI - Update tests to reflect new network config handling * style(adapters): improve algodClient creation logs Make logging more consistent across framework adapters when creating new `algodClient` instances. This change: - Standardize log message format across React/Vue/Solid - Add missing log statements for client creation - Add clarifying comments about `algodClient` updates * refactor(core): rename DEFAULT_NETWORKS to DEFAULT_NETWORK_CONFIG Rename constant to better reflect its purpose as configuration data rather than network instances. * refactor(core): rename updateNetworkAlgod to updateAlgodConfig Rename method to better reflect its purpose of updating algod configuration rather than the entire network. - Rename `updateNetworkAlgod` to `updateAlgodConfig` in `WalletManager` - Update method name in React/Vue/Solid adapters - Update all test files to use new method name - Update example projects to use renamed method
- Loading branch information