Skip to content
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

Fix non-reactive activeNetworkConfig #343

Conversation

SilentRhetoric
Copy link
Contributor

No description provided.

* feat(*): migrate to algosdk v3.0.0

BREAKING CHANGE: Update transaction handling to support algosdk v3.x API
- Transaction properties renamed (from -> sender, firstRound -> firstValid)
- New transaction construction format using type and params objects
- Modified transaction signing and verification logic

- Update all package.json files to use algosdk v3.0.0
- Refactor transaction creation and handling across all wallet implementations
- Update test cases to use new transaction format and API

* fix(examples): update transaction params for algosdk v3

Update transaction parameter names in all example projects to match algosdk v3:
- Rename 'from' to 'sender'
- Rename 'to' to 'receiver'

Affects examples in Next.js, Nuxt, React, Solid, Vue, and vanilla TS
* feat(network): add network config builder for custom configurations

Introduce `NetworkConfigBuilder` to enable customizable network configurations
and support for custom networks. This change provides a more flexible way to
configure network settings, including CAIP-2 chain IDs, and allows applications to
define their own networks beyond the default mainnet/testnet options.

- Add `NetworkConfigBuilder` for creating and customizing network configurations
- Update all wallet implementations to use new network config system
- Add support for CAIP-2 chain IDs in network configurations
- Add `isTestnet` flag to network configurations
- Update all tests to use string literals for network names
- Add `network` property to wallet provider constructor calls
- Update `WalletManager` tests to use new network configuration approach
- Add support for custom networks via `NetworkConfigBuilder`
- Update network-related test assertions
- Add proper genesis hash/ID handling from network configs
- Maintain `NetworkId` enum for defaultNetwork configuration
- Rename config property `network` to `defaultNetwork`
- Rename config property `algod` to `networks`

BREAKING CHANGE: Network configuration now requires using
`NetworkConfigBuilder` instead of the `NetworkId`-keyed mapped object from v3.
While `NetworkId` is still exported for use with the `defaultNetwork` property,
network configurations must be created using the new builder pattern.

* refactor(store): rename defaultState constant to DEFAULT_STATE

* fix(network): update framework adapters for new network config structure

Update framework adapters to handle the new nested algod configuration
structure and `defaultNetwork` property name change. This includes:

- Fix destructuring of algod config in React, Vue, and Solid adapters
- Update all example apps to use `defaultNetwork` instead of network
- Update test files to include networks in wallet constructor params
- Export `DEFAULT_NETWORKS` from core package
- Fix `NetworkId` type in `setActiveNetwork` method signatures

BREAKING CHANGE: The `network` property in `WalletManagerConfig`
has been renamed to `defaultNetwork` to better reflect its purpose.

* refactor(network): improve network config type safety and validation

Enhance the `NetworkConfigBuilder` and network config validation:
- Update builder methods to accept full network config instead of just algod config
- Add `DefaultNetworkConfig` type for partial network configs
- Add robust token validation for all possible algosdk token types
- Improve type guard to validate all network config properties
- Allow full network config customization for localnet

* fix(network): update test cases to reflect new network config structure

* fix(solid): revert to inline default state in wallet tests

Replace imported `DEFAULT_STATE` with inline state definition to prevent test
state pollution. This reverts a change made in 2bb91e4.

- Remove `DEFAULT_STATE` import
- Define default state directly in `beforeEach` block
- Ensure clean store initialization between tests
- Fix regression in 'updates wallets when store state changes' test

* refactor(adapters): change setActiveNetwork to accept string network ID

- Replace `NetworkId` type with string for `networkId` parameter
- Add network existence validation in `setActiveNetwork`
- Add tests for invalid network and custom network scenarios

* chore(test): update test scripts to use vitest run

- Change test script from "vitest" to "vitest run" in all packages
- Ensures tests run once and exit instead of watching by default

* refactor(wallets): move networkConfig getter to BaseWallet class

- Move `networkConfig` getter from `WalletConnect` to `BaseWallet`
- Make networks accessible for testing in all wallet implementations

* fix(test): use DEFAULT_NETWORKS in CustomWallet test mocks

- Replace empty networks object with `DEFAULT_NETWORKS` in Custom wallet tests
- Ensure consistent network configuration across all wallet tests

* style(imports): reorder imports for consistency

- Move DEFAULT_NETWORKS import to top of `LuteWallet` test file
- Group related imports together
- Sort type imports alphabetically
- Follow project import ordering conventions
* refactor(wallets): create extendable AVMProvider for Kibisis client

This refactors the Kibisis wallet client to use an extendable `AVMProvider` class, laying the groundwork for future wallet implementations that also use `@agoralabs-sh/avm-web-provider`.

- Created new `AVMProvider` abstract class
- Refactored `KibisisWallet` to extend `AVMProvider`
- Moved common AVM Web Provider functionality to `AVMProvider`
- Implemented abstract methods in `KibisisWallet` for Kibisis-specific behavior

* feat: add Defly Web Wallet initial support

- Created new `DeflyWebWallet` class extending `AVMProvider`
- Implemented Defly-specific methods for enable, disable, and sign transactions
- Added `DEFLY_WEB` to `WalletId` enum and `WalletMap`
- Updated utility functions to include Defly Web Wallet

* fix(avm): resolve dynamic import issues with AVM Web Provider

This addresses an issue where certain frameworks are unable to dynamically import `@agoralabs-sh/avm-web-provider` due to module format incompatibilities.

- Modified `_initializeAVMWebProviderSDK` method to handle both default and named exports
- Ensured compatibility between CommonJS (AVM Web Provider) and ESM (use-wallet)

* chore: restore comments and JSDoc blocks

* docs(avm): update comments for abstract and common methods

* chore: fix import order

* test(kibisis): fix failing test

* fix(defly-web): use correct provider ID in constructor

* feat(examples): add Defly Web provider

* test(defly-web): add tests for Defly Web provider

* refactor(provider): extract shared AVM provider functionality

Extract common AVM Web Provider functionality into abstract base class to support
both Kibisis and Defly Web providers. Update implementations to use `algosdk` v3
and new network configuration system.

- Create abstract `AVMProvider` class with shared provider logic
- Move common methods from Kibisis to `AVMProvider`
- Update transaction handling for `algosdk` v3 API
- Add network configuration and genesis hash fallback
- Implement Defly Web provider using shared base class

* refactor(tests): remove ts-nocheck from AVM wallet provider tests

Enable proper TypeScript type checking in AVM provider tests by introducing
type-safe utility types for testing protected methods.

- Remove `@ts-nocheck` comments from Defly Web and Kibisis tests
- Add `TestableDeflyWebWallet` and `TestableKibisisWallet` utility types
- Update `vi.spyOn` calls to use proper type assertions
- Remove unnecessary type assertions from mock implementations
- Add proper return type to `mockSignTransactionsResponseOnce`
Two tests that were added upstream in PR TxnLab#322 instantiate wallets without the
`networks` property, introduced on the current `v4` branch. This change adds
the `networks` property to `MnemonicWallet` and `KmdWallet`, ensuring proper
initialization and tests passing.
* feat(pera): add auto-connect for Pera Discover browser

Add automatic connection attempt when Pera wallet is initialized in the Pera
Discover browser environment. The connection attempt is handled silently with
appropriate logging for success and failure cases.

* fix(pera): add window check to prevent SSR errors

Add type check for window and navigator objects to prevent errors during
server-side rendering. This ensures the Pera auto-connect feature only
runs in browser environments.

* refactor(pera): extract auto-connect logic into private method

Extract auto-connect logic from constructor into a private async method for better
error handling and testability. Update tests to use prototype mocking pattern
consistent with other wallet implementations.

- Move auto-connect logic into private `autoConnect` method
- Use async/await with try/catch for better error handling
- Update tests to mock method on prototype before wallet creation
- Align test patterns with other wallet implementations

* refactor(pera): move Pera auto-connect to resumeSession

Move auto-connect logic from constructor to `resumeSession` method in Pera wallet
implementations to fix SSR compatibility issues. Auto-connect now only triggers
when no other wallet is active and after client-side hydration.

* refactor(pera): remove unused autoConnect method

Remove private `autoConnect` method from Pera wallet implementations since the
functionality is now handled directly in resumeSession.
Update `@blockshake/defly-connect` dependency to version 1.2.0 across all packages
and examples to ensure compatibility with `algosdk` v3.0.0
Update `@perawallet/connect` dependency to version 1.4.0 across all packages
and examples to ensure compatibility with `algosdk` v3.0.0
Remove support for `@perawallet/connect-beta` package and `PERA2` wallet type.
Users should migrate to the stable `@perawallet/connect@^1.4.0` package and
`PERA` wallet provider.
Update `@blockshake/defly-connect` from 1.2.0 to 1.2.1 and `@perawallet/connect`
from 1.4.0 to 1.4.1 across all packages and examples to support ESM imports
Update test to use `DEFAULT_STATE` instead of `defaultState` after it was
incorrectly retained during the merge from `main` into `v4` branch
Remove Liquid Auth provider and its dependencies due to incompatibility with `algosdk` v3.
The provider will be reintroduced in a future v4 release once the client has been updated.

- Remove `liquid-auth-use-wallet-client` dependency from all examples
- Delete `liquid-auth-backend example` and configuration files
- Remove Liquid Auth from Renovate config
- Update documentation to indicate temporary removal in v4
- Keep Liquid Auth in supported wallets docs with deprecation notice
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
…xnLab#338)

* refactor(network): remove unused name property from NetworkConfig

Remove the unused `name` property from `NetworkConfig` interface and all related
code. This property was not serving any functional purpose in the network
configuration system.

- Remove `name` field from `NetworkConfig` interface
- Remove `name` property from all default network configurations
- Update tests to remove name-related assertions and test cases

* fix(network): allow custom network IDs in setActiveNetwork

Update type signature of `setActiveNetwork` to accept both `NetworkId` enum values
and custom string network IDs. This change is necessary to support custom
networks while maintaining backwards compatibility with the predefined `NetworkId`
enum values.

- Update type signature in React, Solid, and Vue adapters
- Update core `WalletManager` and store types
- Maintain existing runtime behavior while improving type flexibility
- 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.
- 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.
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.
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.
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.
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
When updating network configuration through `updateNetworkAlgod`, ensure the
`algodClient` is also updated in the store if the modified network is currently
active.
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
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
drichar and others added 10 commits January 20, 2025 22:57
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
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.
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
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`
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
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.
Update Next, Nuxt, and Solid example apps to reflect the movement of `algodClient`
from `useNetwork` back to `useWallet`.
@drichar
Copy link
Collaborator

drichar commented Jan 22, 2025

Thanks again for your help debugging this! 🙏

@drichar drichar closed this Jan 22, 2025
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