Skip to content

fix: merchant types info #1383

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

Merged
merged 2 commits into from
Apr 28, 2025
Merged

fix: merchant types info #1383

merged 2 commits into from
Apr 28, 2025

Conversation

Syn-McJ
Copy link
Member

@Syn-McJ Syn-McJ commented Apr 27, 2025

The Merchant Types dialog is missing.

Issue being fixed or feature implemented

  • Restore the dialog
  • Restore the info button on the Search screen
  • Some refactoring

Related PR's and Dependencies

Screenshots / Videos

How Has This Been Tested?

  • QA (Mobile Team)

Checklist:

  • I have performed a self-review of my own code and added comments where necessary
  • I have added or updated relevant unit/integration/functional/e2e tests

Summary by CodeRabbit

  • New Features

    • Added an info button to the search screen toolbar, allowing users to view additional information via a dialog.
    • Introduced a new ViewModel to manage and display staking APY and blockchain sync status in the Explore section.
  • Improvements

    • The info dialog now supports a completion callback, enhancing user flow after dismissing the dialog.
    • The Explore section now checks if informational content has already been shown before navigating, improving user experience.
  • Bug Fixes

    • Improved accessibility for the info button with a content description.
  • Refactor

    • Updated navigation and internal logic to streamline how informational dialogs are shown and tracked.
    • Removed staking APY and related blockchain sync logic from the main ViewModel to better separate concerns.

@Syn-McJ Syn-McJ requested a review from HashEngineering April 27, 2025 09:23
@Syn-McJ Syn-McJ self-assigned this Apr 27, 2025
Copy link
Contributor

coderabbitai bot commented Apr 27, 2025

Walkthrough

This update introduces a new ExploreEntryViewModel to manage the logic and state for the Explore feature, moving related responsibilities out of the shared MainViewModel. The Explore info dialog is now shown directly from UI code, with a new completion callback mechanism for post-dismissal actions. The navigation graph and fragment logic are updated to remove the previous dialog navigation and replace it with direct dialog invocation. The layout for the search fragment is updated to include an info button, and an unused database prefix constant is removed from the configuration.

Changes

File(s) Change Summary
features/exploredash/.../SearchFragment.kt, fragment_search.xml, nav_explore.xml Added an info button to the search fragment UI and layout; removed navigation-based dialog invocation and replaced with direct dialog display via a button click.
features/exploredash/.../dialogs/ExploreDashInfoDialog.kt Enhanced the info dialog to support an optional completion callback and added an overloaded show method.
features/exploredash/.../utils/ExploreConfig.kt Removed the unused EXPLORE_DB_PREFIX constant from configuration.
wallet/src/de/schildbach/wallet/ui/explore/ExploreEntryViewModel.kt Introduced a new ViewModel to handle Explore feature logic, including staking APY, blockchain sync status, info dialog state, and analytics.
wallet/src/de/schildbach/wallet/ui/explore/ExploreFragment.kt Switched to using ExploreEntryViewModel; updated merchant button logic to show info dialog if needed before navigation.
wallet/src/de/schildbach/wallet/ui/main/MainViewModel.kt Removed all Explore-related logic, including staking APY, CrowdNode API usage, and testnet detection.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExploreFragment
    participant ExploreEntryViewModel
    participant ExploreDashInfoDialog

    User->>ExploreFragment: Clicks "Merchants" button
    ExploreFragment->>ExploreEntryViewModel: isInfoShown()
    alt Info has been shown
        ExploreFragment->>ExploreFragment: Navigate to Merchants Search
    else Info has not been shown
        ExploreFragment->>ExploreDashInfoDialog: Show dialog with completion callback
        ExploreDashInfoDialog-->>ExploreFragment: Dialog dismissed
        ExploreFragment->>ExploreEntryViewModel: setIsInfoShown(true)
        ExploreFragment->>ExploreFragment: Navigate to Merchants Search
    end
Loading

Suggested reviewers

  • HashEngineering

Poem

In the garden of Explore, a new ViewModel grows,
With info dialogs popping up as the user flows.
The old paths are trimmed, navigation made neat,
An info button shines where toolbar and users meet.
With callbacks and coroutines, the journey’s now bright—
The wallet hops forward, guided by code’s gentle light.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64c364c and 70e1e33.

📒 Files selected for processing (1)
  • features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/explore/SearchFragment.kt (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/explore/SearchFragment.kt
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

import javax.inject.Inject

@HiltViewModel
class ExploreEntryViewModel @Inject constructor(
Copy link
Member Author

Choose a reason for hiding this comment

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

Moving some code out of the MainViewModel to avoid bloating it

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
wallet/src/de/schildbach/wallet/ui/explore/ExploreEntryViewModel.kt (1)

77-86: Comprehensive sync status update logic.

This suspend function not only updates the sync status LiveData but also calculates and updates the staking APY when the blockchain is synced. This encapsulates the sync and APY logic that was previously spread across MainViewModel.

One minor observation: while _isBlockchainSynced.value is used for direct assignment, _stakingAPY.postValue is used for posting values. Consider using consistent update methods for better readability.

- _isBlockchainSynced.value = state.isSynced()
+ _isBlockchainSynced.postValue(state.isSynced())

Or:

- _stakingAPY.postValue(withoutFees * blockchainStateProvider.getMasternodeAPY())
+ _stakingAPY.value = withoutFees * blockchainStateProvider.getMasternodeAPY()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e7bca1 and 64c364c.

📒 Files selected for processing (8)
  • features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/explore/SearchFragment.kt (2 hunks)
  • features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/explore/dialogs/ExploreDashInfoDialog.kt (3 hunks)
  • features/exploredash/src/main/java/org/dash/wallet/features/exploredash/utils/ExploreConfig.kt (0 hunks)
  • features/exploredash/src/main/res/layout/fragment_search.xml (1 hunks)
  • features/exploredash/src/main/res/navigation/nav_explore.xml (0 hunks)
  • wallet/src/de/schildbach/wallet/ui/explore/ExploreEntryViewModel.kt (1 hunks)
  • wallet/src/de/schildbach/wallet/ui/explore/ExploreFragment.kt (3 hunks)
  • wallet/src/de/schildbach/wallet/ui/main/MainViewModel.kt (2 hunks)
💤 Files with no reviewable changes (2)
  • features/exploredash/src/main/java/org/dash/wallet/features/exploredash/utils/ExploreConfig.kt
  • features/exploredash/src/main/res/navigation/nav_explore.xml
🧰 Additional context used
🧬 Code Graph Analysis (1)
wallet/src/de/schildbach/wallet/ui/explore/ExploreEntryViewModel.kt (1)
wallet/src/de/schildbach/wallet/ui/main/MainViewModel.kt (1)
  • updateSyncStatus (742-749)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (20)
features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/explore/dialogs/ExploreDashInfoDialog.kt (4)

22-22: Added import for FragmentActivity.

The import of FragmentActivity enables direct dialog presentation from the fragment, supporting the new pattern of showing the dialog directly from UI code instead of through the navigation graph.


37-37: Added callback mechanism for dialog completion.

A nullable lambda property allows callers to provide actions that should occur after the dialog is dismissed, improving flexibility of the dialog's usage.


47-47: Invoke completion callback after dismissal.

The dialog now executes the provided callback when the user dismisses it via the continue button, enabling post-dismissal actions like navigation or state updates.


51-54: Added helper method for showing dialog with completion callback.

This new overloaded show method simplifies dialog instantiation with a completion callback, providing a cleaner API for the dialog's consumers.

features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/explore/SearchFragment.kt (2)

67-67: Added import for ExploreDashInfoDialog.

This import enables direct use of the dialog class, supporting the transition from navigation-based dialog presentation to direct dialog instantiation.


173-175: Added info button click handler to show Merchant Types dialog.

This implementation restores the missing Merchant Types dialog functionality by showing the ExploreDashInfoDialog directly when the user taps the info button, addressing the main issue in the PR.

features/exploredash/src/main/res/layout/fragment_search.xml (1)

50-59: Added info button to the toolbar.

Added an info button with appropriate styling and positioning in the toolbar. The button has proper accessibility attributes and uses standard material design patterns for info buttons.

wallet/src/de/schildbach/wallet/ui/explore/ExploreFragment.kt (4)

28-28: Switched to using fragment-scoped ViewModel.

Changed from activityViewModels() to viewModels() to prepare for using a dedicated ViewModel instead of sharing the MainViewModel.


43-43: Added import for ExploreDashInfoDialog.

This import enables direct instantiation of the dialog, supporting the revised dialog presentation pattern.


49-49: Using dedicated ExploreEntryViewModel instead of shared MainViewModel.

This change improves separation of concerns by moving explore-specific state management to a dedicated ViewModel rather than using the shared MainViewModel.


64-73: Enhanced Merchants button click handler to conditionally show the info dialog.

The updated implementation checks if the info dialog has been shown before using the ViewModel. If not, it shows the dialog with a completion callback that updates the state and navigates; otherwise, it navigates directly. This creates a better UX by only showing the info dialog once.

wallet/src/de/schildbach/wallet/ui/main/MainViewModel.kt (2)

141-142: Constructor parameter list cleanup.

The crowdNodeApi parameter has been removed from the constructor as part of moving the staking APY functionality to the new ExploreEntryViewModel.


742-749: Good refactoring of sync status update logic.

The updateSyncStatus method has been changed from a suspend function to a regular function. The staking APY update logic that was previously here has been properly moved to the new ExploreEntryViewModel class, keeping this function focused on just updating sync status.

wallet/src/de/schildbach/wallet/ui/explore/ExploreEntryViewModel.kt (7)

1-33: Good implementation of a feature-specific ViewModel.

This new ExploreEntryViewModel class follows the single responsibility principle by encapsulating the Explore feature's logic that was previously in MainViewModel. The dependencies are properly injected and the class is correctly annotated with @HiltViewModel for Hilt dependency injection.


35-41: Proper exposing of LiveData properties.

The ViewModel correctly implements the LiveData pattern by exposing read-only LiveData properties with private mutable backing fields, following best practices for encapsulation.


43-50: Effective initialization and flow handling.

Good use of filterNotNull(), onEach(), and launchIn() to observe blockchain state changes. The ViewModel properly uses coroutines scoped to the viewModelScope to ensure cleanup when the ViewModel is cleared.


52-58: Method for manual APY updates.

This method allows for explicitly fetching the latest staking APY. It correctly uses viewModelScope.launch with the IO dispatcher for the network call, showing good coroutine usage for asynchronous operations.


60-67: Merchant types info dialog state management.

These methods handle persistence of whether the merchant types info dialog has been shown to the user. The suspend function for reading is appropriate, and the writing method correctly uses a coroutine to perform the storage operation asynchronously.


69-71: Simple analytics event logging.

The method correctly delegates to the injected analytics service without adding unnecessary complexity.


73-75: Network type detection.

Simple utility method to determine if the wallet is connected to a test network. This is useful for conditional UI behavior based on network type.

Copy link
Collaborator

@HashEngineering HashEngineering left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@HashEngineering HashEngineering left a comment

Choose a reason for hiding this comment

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

@Syn-McJ Can you change fix the format issue(s)?

@Syn-McJ Syn-McJ requested a review from HashEngineering April 28, 2025 04:35
Copy link
Collaborator

@HashEngineering HashEngineering left a comment

Choose a reason for hiding this comment

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

LGTM

@HashEngineering HashEngineering merged commit abc1e6a into master Apr 28, 2025
3 checks passed
@Syn-McJ Syn-McJ deleted the fix/merchant-types-info branch April 29, 2025 13:31
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