Skip to content

Comments

Remove WalletsService facade, inject services directly into consumers#1730

Open
DRadmir wants to merge 1 commit intomainfrom
remove-wallets-service-facade
Open

Remove WalletsService facade, inject services directly into consumers#1730
DRadmir wants to merge 1 commit intomainfrom
remove-wallets-service-facade

Conversation

@DRadmir
Copy link
Contributor

@DRadmir DRadmir commented Feb 24, 2026

Replace the monolithic WalletsService facade with direct injection of focused services: AssetsEnabler, AssetSyncServiceable, BalanceService, WalletSetupService, and WalletSessionService. Each consumer now depends only on the protocols it actually uses.

  • Test

Replace the monolithic WalletsService facade with direct injection of
focused services: AssetsEnabler, AssetSyncServiceable, BalanceService,
WalletSetupService, and WalletSessionService. Each consumer now depends
only on the protocols it actually uses.
@DRadmir DRadmir self-assigned this Feb 24, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @DRadmir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a significant refactoring of the wallet-related services. The primary goal is to decompose the large WalletsService into smaller, more specialized components. This change enhances the architecture by promoting single responsibility, reducing coupling, and making the system more maintainable and testable. Each part of the application now interacts with precisely the service it needs, rather than a broad facade.

Highlights

  • Refactoring WalletsService: The monolithic WalletsService facade has been removed and its responsibilities have been broken down into several more focused services: AssetsEnabler, AssetSyncServiceable, BalanceService, WalletSetupService, and WalletSessionService.
  • Direct Dependency Injection: Consumers of the former WalletsService now directly inject only the specific protocols they require, adhering to the principle of least privilege and improving modularity.
  • New Service Implementations: New services like AssetsEnablerService, BalanceUpdateService, WalletAssetSyncService, and WalletSetupService have been introduced to handle specific functionalities previously encapsulated within WalletsService.
  • Testability Improvements: The refactoring to smaller, more focused services and direct injection inherently improves the testability of the codebase, as evidenced by updates to various TestKit modules and test files.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • Features/Assets/Package.resolved
    • Removed the package resolution file, likely due to dependency changes.
  • Features/Assets/Package.swift
    • Added BalanceService and BalanceServiceTestKit as dependencies for the Assets feature.
  • Features/Assets/Sources/ViewModels/AssetSceneViewModel.swift
    • Replaced WalletsService with direct injections of AssetsEnabler, AssetSyncService, and BalanceService.
    • Updated method calls to use the new, specific service instances for asset pinning, enabling, and updating.
  • Features/Assets/Sources/ViewModels/SelectAssetViewModel.swift
    • Replaced WalletsService with AssetsEnabler for managing asset enablement.
  • Features/Assets/TestKit/SelectAssetViewModel+AssetsTestKit.swift
    • Updated the mock for SelectAssetViewModel to use AssetsEnabler.mock() instead of WalletsService.mock().
  • Features/Assets/Tests/AssetsTests/AssetSceneViewModelTests.swift
    • Added import for BalanceServiceTestKit.
    • Updated the AssetSceneViewModel.mock() initializer to reflect the new service dependencies.
  • Features/Settings/Package.swift
    • Added WalletSessionService as a dependency for the Settings feature.
  • Features/Settings/Sources/Settings/ViewModels/SettingsViewModel.swift
    • Replaced WalletsService with WalletSessionService for wallet count and multicoin wallet checks.
  • Features/Swap/Package.swift
    • Added PreferencesTestKit as a dependency for the Swap feature's tests.
  • Features/Swap/Sources/ViewModels/SwapSceneViewModel.swift
    • Replaced WalletsService with AssetSyncServiceable for asset price and update operations.
  • Features/Swap/Tests/SwapTests/SwapSceneViewModelTests.swift
    • Added import for PreferencesTestKit.
    • Updated the SwapSceneViewModel.mock() initializer to use AssetSyncService.mock().
  • Features/Transfer/Sources/Services/ConfirmServiceFactory.swift
    • Modified the create method to accept AssetsEnabler instead of WalletsService.
  • Features/Transfer/Sources/Services/TransferExecutor.swift
    • Imported BalanceService.
    • Replaced WalletsService with AssetsEnabler and BalanceService in the initializer and usage.
    • Updated post-transfer asset update logic to use balanceService.addAssetsBalancesIfMissing and assetsEnabler.enableAssets.
  • Features/Transfer/Sources/ViewModels/ReceiveViewModel.swift
    • Replaced WalletsService with AssetsEnabler for enabling assets.
  • Features/Transfer/Tests/Services/TransferExecutorTests.swift
    • Added import for BalanceServiceTestKit.
    • Updated TransferExecutor mocks to use AssetsEnabler.mock() and BalanceService.mock().
  • Features/Transfer/Tests/ViewModels/ConfirmTransferSceneViewModelTests.swift
    • Updated ConfirmServiceFactory.create mock to use AssetsEnabler.mock().
  • Features/WalletTab/Package.swift
    • Added BalanceService and BalanceServiceTestKit as dependencies for the WalletTab feature.
  • Features/WalletTab/Sources/ViewModels/AssetsResultsSceneViewModel.swift
    • Replaced WalletsService with AssetsEnabler and BalanceService for asset management and pinning.
  • Features/WalletTab/Sources/ViewModels/WalletSceneViewModel.swift
    • Imported BalanceService.
    • Replaced WalletsService with AssetSyncServiceable and BalanceService for asset synchronization, hiding, and pinning.
  • Features/WalletTab/Sources/ViewModels/WalletSearchSceneViewModel.swift
    • Imported BalanceService.
    • Replaced WalletsService with AssetsEnabler and BalanceService for asset management and pinning.
  • Features/WalletTab/TestKit/WalletSceneViewModel+TestKit.swift
    • Added import for BalanceServiceTestKit.
    • Updated WalletSceneViewModel.mock() to use AssetSyncService.mock() and BalanceService.mock().
  • Features/WalletTab/TestKit/WalletSearchSceneViewModel+TestKit.swift
    • Added imports for BalanceService and BalanceServiceTestKit.
    • Updated WalletSearchSceneViewModel.mock() to use AssetsEnabler.mock() and BalanceService.mock().
  • Features/WalletTab/Tests/WalletSceneViewModelTests.swift
    • Added import for BalanceServiceTestKit.
  • Gem/App.swift
    • Replaced walletsService with walletSetupService in the GemApp initializer.
  • Gem/Navigation/Assets/SelectAssetSceneNavigationStack.swift
    • Replaced walletsService with assetsEnabler in environment and service factory calls.
  • Gem/Navigation/Assets/SelectedAssetNavigationStack.swift
    • Replaced walletsService with assetsEnabler in environment and service factory calls.
  • Gem/Navigation/NFT/CollectionsNavigationStack.swift
    • Replaced walletsService with assetsEnabler in environment and service factory calls.
  • Gem/Navigation/Price Alerts/PriceAlertsNavigationView.swift
    • Replaced walletsService with assetsEnabler in environment and service factory calls.
  • Gem/Navigation/Settings/SettingsNavigationStack.swift
    • Added import for WalletSessionService.
    • Replaced walletsService with assetsEnabler and walletSessionService in environment and view model initialization.
  • Gem/Navigation/Swap/SwapNavigationView.swift
    • Added assetsEnabler to the environment.
    • Updated SelectAssetViewModel initialization to use assetsEnabler.
  • Gem/Navigation/Transactions/TransactionsNavigationStack.swift
    • Replaced walletsService with assetsEnabler in environment and service factory calls.
  • Gem/Navigation/Wallet/WalletNavigationStack.swift
    • Replaced walletsService with assetsEnabler, assetSyncService, and balanceService in environment and view model initializations.
  • Gem/Services/AppResolver+Services.swift
    • Added import for WalletSessionService.
    • Updated the Services struct and its initializers to replace walletsService with walletSessionService, assetsEnabler, assetSyncService, and walletSetupService.
  • Gem/Services/AppResolver+ViewInjection.swift
    • Replaced the walletsService environment injection with walletSessionService, assetsEnabler, assetSyncService, and walletSetupService.
  • Gem/Services/ServicesFactory.swift
    • Refactored the creation of WalletsService into separate BalanceUpdateService, AssetsEnablerService, WalletAssetSyncService, and WalletSetupService instances.
    • Updated the ServicesFactory to provide these new, granular services.
    • Removed the private makeWalletsService helper function.
  • Gem/Services/ViewModelFactory.swift
    • Replaced walletsService with assetsEnabler and assetSyncService in the struct properties and initializers.
    • Updated ConfirmServiceFactory.create call to use assetsEnabler.
  • Gem/Types/Environment.swift
    • Added import for WalletSessionService.
    • Replaced the walletsService environment entry with assetsEnabler, assetSyncService, walletSetupService, and walletSessionService.
  • Gem/ViewModels/RootSceneViewModel.swift
    • Replaced walletsService with walletSetupService in properties, initializers, and setup calls.
  • Gem/Views/MainTabView.swift
    • Replaced walletsService with assetSyncService and balanceService in environment and view model initialization.
  • Packages/FeatureServices/BalanceService/BalanceService.swift
    • Added a public setPinned method to consolidate pin/unpin logic.
  • Packages/FeatureServices/Package.swift
    • Simplified dependencies for WalletsServiceTestKit.
    • Removed several dependencies from WalletsServiceTests to reflect the refactoring.
  • Packages/FeatureServices/WalletSessionService/WalletSessionService.swift
    • Added public walletsCount() and hasMulticoinWallet() methods, moving functionality previously in WalletsService.
  • Packages/FeatureServices/WalletsService/AssetsEnablerService.swift
    • Made AssetsEnablerService and its methods public, allowing external access.
  • Packages/FeatureServices/WalletsService/BalanceUpdateService.swift
    • Made BalanceUpdateService and its methods public, allowing external access.
  • Packages/FeatureServices/WalletsService/Protocols/AssetSyncServiceable.swift
    • Added a new public protocol AssetSyncServiceable to define asset synchronization operations.
  • Packages/FeatureServices/WalletsService/Protocols/AssetVisibilityManageable.swift
    • Removed the AssetVisibilityServiceable protocol and its extension for BalanceService.
  • Packages/FeatureServices/WalletsService/Protocols/BalanceUpdater.swift
    • Made the BalanceUpdater protocol public.
  • Packages/FeatureServices/WalletsService/Protocols/PriceUpdater.swift
    • Made the PriceUpdater protocol and its PriceObserverService extension public.
  • Packages/FeatureServices/WalletsService/TestKit/AssetSyncServiceMock.swift
    • Added a new mock implementation for AssetSyncServiceable to facilitate testing.
  • Packages/FeatureServices/WalletsService/TestKit/AssetsEnablerMock.swift
    • Added a new mock implementation for AssetsEnabler to facilitate testing.
  • Packages/FeatureServices/WalletsService/TestKit/WalletsService+TestKit.swift
    • Removed the WalletsService+TestKit.swift file as WalletsService is being removed.
  • Packages/FeatureServices/WalletsService/Tests/WalletsServiceTests.swift
    • Renamed the test struct from WalletsServiceTests to WalletSetupServiceTests.
    • Updated the test setup to use WalletSetupService and its new dependencies, reflecting the refactoring.
  • Packages/FeatureServices/WalletsService/WalletAssetSyncService.swift
    • Made WalletAssetSyncService public and conform to AssetSyncServiceable.
    • Made its initializer and methods public.
  • Packages/FeatureServices/WalletsService/WalletSetupService.swift
    • Added a new public struct WalletSetupService responsible for initial wallet setup logic.
  • Packages/FeatureServices/WalletsService/WalletsService.swift
    • Removed the WalletsService.swift file, completing the removal of the facade.
Activity
  • The author, DRadmir, has indicated that testing is pending for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully removes the monolithic WalletsService facade and replaces it with direct injection of more focused services: AssetsEnabler, AssetSyncServiceable, BalanceService, WalletSetupService, and WalletSessionService. This refactoring significantly improves the modularity and testability of the codebase by adhering to the Interface Segregation Principle. The changes are thorough, covering view models, navigation stacks, and service factories, while maintaining existing logic and ensuring that consumers only depend on the protocols they actually use.

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.

1 participant