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(dashpay): improve restore username #1361

Merged
merged 4 commits into from
Mar 25, 2025
Merged

Conversation

HashEngineering
Copy link
Collaborator

@HashEngineering HashEngineering commented Mar 18, 2025

Issue being fixed or feature implemented

kotlin platform:

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

    • Introduced a refreshed menu subtitle style for improved visual consistency.
    • Added a refined retry mechanism for handling username creation errors.
  • Bug Fixes

    • Strengthened application stability through enhanced checks in balance observation and recent transactions.
    • Improved identity management and synchronization logic to reduce potential hiccups.
  • Chores

    • Updated dependency versions and streamlined resource settings.
    • Removed an obsolete background service to optimize overall performance.

@HashEngineering HashEngineering self-assigned this Mar 18, 2025
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

Walkthrough

This pull request introduces several changes across the project. The dependency version in the Gradle build file was updated to a snapshot release, and a new UI style was added. Adjustments to XML resources include updated styles and string attributes. The Android manifest has a service declaration removed. In addition, various Java and Kotlin files received enhanced null safety, refined logging, and updated control flow—especially in identity creation, restoration, and transaction display—ensuring that the application handles error scenarios and lifecycle conditions more robustly.

Changes

Files Change Summary
build.gradle Updated the dppVersion dependency from "1.7.3" to "1.7.4-SNAPSHOT".
common/src/main/res/values/styles.xml
wallet/res/layout/fragment_more.xml
wallet/res/values/strings-dashpay.xml
wallet/res/values/strings.xml
Added a new style MenuRowSubTitleWithoutLines and updated the layout to use it, including the addition of a design-time tools:text attribute. Also, string resources were updated with the attribute formatted="false" for proper formatting control.
wallet/AndroidManifest.xml Removed the <service> declaration for androidx.work.impl.foreground.SystemForegroundService.
wallet/src/de/schildbach/wallet/WalletApplication.java
wallet/src/de/schildbach/wallet/service/BlockchainServiceImpl.kt
wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt
Enhanced null safety and logging: added a check for walletBalanceObserver, replaced a non-null assertion with a safe call operator, and updated log statements with contextual information and a safe default for votingPeriodStart.
wallet/src/de/schildbach/wallet/service/platform/work/RestoreIdentityWorker.kt
wallet/src/de/schildbach/wallet/ui/dashpay/CreateIdentityService.kt
wallet/src/de/schildbach/wallet/ui/more/MoreFragment.kt
Updated identity restoration and creation flows: introduced conditional checks for blockchainIdentity.currentUsername in state updates, modified state transitions to progress from name checking to link saving, and removed the redundant restoration method. In addition, a new retry method centralizes error handling for username creation.
wallet/src/de/schildbach/wallet/ui/main/WalletTransactionsFragment.kt Introduced a lifecycle state check using a new currentLifecycle variable to ensure that showTransactionList() is called only when the fragment is in a valid state.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant MF as MoreFragment
    participant VM as CreateIdentityViewModel
    participant CA as CreateUsernameActivity

    U->>MF: Tap on Request/Retrial
    MF->>MF: Execute retry(errorMessage)
    alt New username required?
        MF->>CA: Start CreateUsernameActivity
    else
        MF->>VM: retryCreateIdentity()
    end
Loading

Possibly related PRs

Suggested reviewers

  • Syn-McJ

Poem

I'm a nimble rabbit, hopping through code,
Upgrading dependencies on my winding road.
New styles bloom as my footsteps tap,
With logs and checks closing every gap.
I nibble on bugs, and with a joyful cheer,
CodeRabbit celebrates these changes here!
🐇✨

✨ 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Comment on lines -428 to -433
<!-- WorkManager -->
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
android:exported="false" />

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was duplicated

@@ -1432,7 +1432,7 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService {
override fun getRecentBlocks(maxBlocks: Int): List<StoredBlock> {
val blocks: MutableList<StoredBlock> = ArrayList(maxBlocks)
try {
var block = blockChain!!.chainHead
var block = blockChain?.chainHead
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should prevent a crash on the Network Monitor | Blocks.

Comment on lines +296 to +320
if (blockchainIdentity.currentUsername != null) {

platformRepo.updateIdentityCreationState(
blockchainIdentityData,
BlockchainIdentityData.CreationState.REQUESTED_NAME_CHECKED
)
platformRepo.updateBlockchainIdentityData(blockchainIdentityData, blockchainIdentity)
platformRepo.updateIdentityCreationState(
blockchainIdentityData,
BlockchainIdentityData.CreationState.REQUESTED_NAME_CHECKING
)

// recover the verification link
platformRepo.updateIdentityCreationState(
blockchainIdentityData,
BlockchainIdentityData.CreationState.REQUESTED_NAME_CHECKED
)
platformRepo.updateBlockchainIdentityData(blockchainIdentityData, blockchainIdentity)
// set voting state
platformRepo.updateIdentityCreationState(
blockchainIdentityData,
BlockchainIdentityData.CreationState.VOTING
)
platformRepo.updateBlockchainIdentityData(blockchainIdentityData, blockchainIdentity)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will prevent a crash or other errors when restoring an identity that doesn't have a username.

Comment on lines -795 to -803
private fun handleRestoreIdentityAction(identity: ByteArray) {
workInProgress = true
serviceScope.launch(createIdentityExceptionHandler) {
restoreIdentity(identity)
workInProgress = false
stopSelf()
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not used.

Comment on lines +174 to +179
adapter.submitList(groupedByDate) {
// Check again if the view is still in a valid state before any post-update operations
if (isAdded && currentLifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
showTransactionList()
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is supposed to prevent a crash, if the view is invalid.

@@ -294,6 +296,18 @@ class MoreFragment : Fragment(R.layout.fragment_more) {
}
}

private fun retry(errorMessage: String) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The more screen will support retry that can allow the user to choose a new name under some circumstances.

@HashEngineering HashEngineering marked this pull request as ready for review March 25, 2025 14:43
@HashEngineering HashEngineering requested a review from Syn-McJ March 25, 2025 14:43
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 (2)
wallet/res/values/strings-dashpay.xml (1)

392-393: Clarify the Intent Behind Disabling Formatting for the Username Disclaimer.
The string resource now includes formatted="false":

<string name="welcome_request_username_min_balance_disclaimer_all" formatted="false">You have %s Dash.  Some usernames cost up to %s Dash.</string>

This change ensures that the placeholders (%s) are treated as literal text rather than triggering runtime formatting. Please verify that this is the intended behavior—if the UI is meant to show the literal %s (perhaps as part of a documentation or demo message) then this is correct; however, if the code expects dynamic substitution for the dash balance and cost, removing formatting might cause the substitution not to occur.

wallet/res/values/strings.xml (1)

46-46: Ensure Consistent Handling of the CoinJoin Timeskew Message.
The updated string now explicitly disables formatting:

<string name="wallet_coinjoin_timeskew_dialog_msg" formatted="false">Your device time is %s by %d seconds. You cannot use CoinJoin due to this difference.

The time settings on your device needs to be changed to “Set time automatically” to use CoinJoin.</string>

By adding formatted="false", the placeholders (%s and %d) will be rendered literally. As with the username disclaimer, please verify that this is intentional. If these placeholders are meant for dynamic substitution at runtime, removing formatting support might lead to unexpected display issues. Otherwise, if you want to show the literal markers to the user (or if substitution is handled differently), this change is consistent with similar modifications elsewhere in the project.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 702c86d and d5b49e2.

📒 Files selected for processing (13)
  • build.gradle (1 hunks)
  • common/src/main/res/values/styles.xml (1 hunks)
  • wallet/AndroidManifest.xml (0 hunks)
  • wallet/res/layout/fragment_more.xml (1 hunks)
  • wallet/res/values/strings-dashpay.xml (1 hunks)
  • wallet/res/values/strings.xml (1 hunks)
  • wallet/src/de/schildbach/wallet/WalletApplication.java (4 hunks)
  • wallet/src/de/schildbach/wallet/service/BlockchainServiceImpl.kt (1 hunks)
  • wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt (2 hunks)
  • wallet/src/de/schildbach/wallet/service/platform/work/RestoreIdentityWorker.kt (2 hunks)
  • wallet/src/de/schildbach/wallet/ui/dashpay/CreateIdentityService.kt (2 hunks)
  • wallet/src/de/schildbach/wallet/ui/main/WalletTransactionsFragment.kt (2 hunks)
  • wallet/src/de/schildbach/wallet/ui/more/MoreFragment.kt (3 hunks)
💤 Files with no reviewable changes (1)
  • wallet/AndroidManifest.xml
🧰 Additional context used
🧬 Code Definitions (1)
wallet/src/de/schildbach/wallet/WalletApplication.java (5)
common/src/main/java/org/dash/wallet/common/WalletDataProvider.kt (1)
  • wallet (33-81)
wallet/src/de/schildbach/wallet/transactions/WalletObserver.kt (1)
  • wallet (40-179)
wallet/src/de/schildbach/wallet/transactions/WalletMostRecentTransactionsObserver.kt (1)
  • wallet (34-98)
wallet/src/de/schildbach/wallet/transactions/WalletBalanceObserver.kt (1)
  • wallet (45-189)
wallet/src/de/schildbach/wallet/transactions/coinjoin/CoinJoinMixingTxSet.kt (1)
  • wallet (10-54)
🔇 Additional comments (20)
build.gradle (1)

7-7: Verify compatibility with snapshot dependency version.

The change updates the dppVersion from a stable release (1.7.3) to a development snapshot (1.7.4-SNAPSHOT). While this may be intentional to incorporate needed features for username restoration, snapshot versions can introduce instability since they're development builds.

Please ensure that this snapshot version is:

  1. Compatible with the rest of the dependencies
  2. Stable enough for your deployment target
  3. Not causing unexpected behavior in the username restoration process

When this PR is merged, consider setting a reminder to update to a stable release when 1.7.4 is officially released.

common/src/main/res/values/styles.xml (1)

168-175: Appropriate style addition for multi-line text.

The new style removes the android:lines="1" constraint from the parent style while keeping other styling consistent, allowing text to wrap across multiple lines instead of being truncated.

This style addition makes sense for displaying potentially longer error messages in the username restoration UI, which is consistent with the PR objective of improving this feature.

wallet/res/layout/fragment_more.xml (1)

233-238: Good UI improvement for error message display.

Applying the new MenuRowSubTitleWithoutLines style to the username restoration status text will provide better user experience by allowing error messages to display across multiple lines (up to 3 as set in maxLines) rather than truncating longer messages.

The addition of a descriptive tools:text attribute also improves the design-time preview for developers, making it easier to visualize how error messages will appear without affecting the runtime behavior.

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

159-159: Good practice: Capturing lifecycle state.

Storing the current lifecycle state when the observer is triggered ensures consistent behavior even if the lifecycle changes during asynchronous operations.

This is a defensive programming technique that makes the code more robust against timing issues.


174-179: Improved lifecycle-aware handling for async callback.

This change ensures that showTransactionList() is only called if the fragment is still added to its activity and its lifecycle is at least in the STARTED state when the adapter's async operation completes.

This prevents potential crashes that could occur if the fragment's view is destroyed or detached by the time the adapter finishes processing the list data. The solution correctly addresses the issue noted in the previous review comment.

wallet/src/de/schildbach/wallet/service/BlockchainServiceImpl.kt (1)

1435-1435: Good safety improvement

Changed from using non-null assertion operator (!!) to safe call operator (?.), which prevents potential NullPointerException if blockChain is null.

wallet/src/de/schildbach/wallet/WalletApplication.java (4)

1126-1127: Improved null safety check

Added null check for walletBalanceObserver to prevent potential NullPointerException when accessing the total balance flow.


1136-1137: Improved null safety check

Added null check for walletBalanceObserver to prevent potential NullPointerException when accessing the mixed balance flow.


1149-1150: Improved null safety check

Added null check for walletBalanceObserver to prevent potential NullPointerException when accessing the general balance flow.


1159-1160: Improved null safety check

Added null check for walletBalanceObserver to prevent potential NullPointerException when accessing the spendable balance flow.

wallet/src/de/schildbach/wallet/service/platform/work/RestoreIdentityWorker.kt (2)

296-320: Improved error handling for identities without usernames

Added a conditional check for blockchainIdentity.currentUsername before executing updates to the identity creation state and blockchain identity data. This prevents potential null pointer exceptions when restoring an identity that doesn't have a username.


329-329: Added missing data update for identities without usernames

Added a line to update the blockchain identity data when identity is not null but username is null, ensuring data consistency in this edge case.

wallet/src/de/schildbach/wallet/ui/more/MoreFragment.kt (3)

188-194: Improved error handling for username creation

Updated the click handler to use the new centralized error handling logic in the retry method, which intelligently determines whether a new username is needed based on the specific error.


287-290: Enhanced retry button logic

Updated the retry button click handler to use the centralized retry method that provides smarter recovery from username creation errors.


299-309: Added smart retry functionality for username errors

Created a new retry method that analyzes error messages to determine whether the user needs to select a new username or can simply retry with the existing one. This significantly improves the user experience by guiding users to the appropriate action based on the specific error.

wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt (2)

219-219: Enhanced logging with contextual information.

The log statement has been improved by including the lastPreBlockStage variable, which provides valuable context about the current state when contact requests are already running.


234-235: Improved null safety handling for votingPeriodStart.

The code now safely handles potential null values for votingPeriodStart by using the Elvis operator to provide a default value of 0L. This prevents NullPointerExceptions when checking voting period completion.

wallet/src/de/schildbach/wallet/ui/dashpay/CreateIdentityService.kt (3)

736-738: Fixed state transition for verification link saving.

The state transition has been corrected to move from REQUESTED_NAME_CHECKED to REQUESTED_NAME_LINK_SAVING instead of staying in the same state. This properly reflects the actual flow of the verification link saving process.


752-754: Fixed state transition after saving verification link.

The state transition has been corrected to move from REQUESTED_NAME_LINK_SAVING to REQUESTED_NAME_LINK_SAVED instead of reverting to REQUESTED_NAME_CHECKING. This ensures proper linear progression through the identity creation states.


794-1030: Removed unused method handleRestoreIdentityAction.

The method for handling identity restoration from a byte array has been removed. This is appropriate since the functionality is now handled directly by the restoreIdentity method.

Copy link
Member

@Syn-McJ Syn-McJ left a comment

Choose a reason for hiding this comment

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

Looks good

@HashEngineering HashEngineering merged commit d3eb2e8 into master Mar 25, 2025
4 checks passed
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