Skip to content

Auto-activate asset when buying crypto#1824

Closed
gemdev111 wants to merge 1 commit intomainfrom
auto-activate-buy
Closed

Auto-activate asset when buying crypto#1824
gemdev111 wants to merge 1 commit intomainfrom
auto-activate-buy

Conversation

@gemdev111
Copy link
Contributor

closes #1820

Summary

  • Auto-enable the purchased asset when the user presses Continue on the buy screen
  • Fires asset activation in parallel with opening the payment URL (no latency on Continue)
  • Works for all buy entry points: wallet tab, deep links, insufficient balance flow
  • Follows the same AssetsEnabler pattern used in ReceiveViewModel

Changes

  • Inject Wallet + AssetsEnabler into FiatSceneViewModel
  • Call enableAsset() as fire-and-forget Task in onSelectContinue()
  • Update AmountSheetType / ConfirmTransferSheetType to carry Wallet instead of WalletId
  • Update all call sites (ViewModelFactory, navigation stacks, scenes)
  • Add BalanceService dependency to FiatConnect package

- Enable asset automatically when user presses Continue on buy screen
- Inject AssetsEnabler into FiatSceneViewModel, fire-and-forget on continue
- Update all call sites to pass Wallet instead of WalletId
- Add BalanceService dependency to FiatConnect package
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 significantly enhances the user experience by automating the activation of newly purchased cryptocurrency assets. Previously, users might have needed to manually enable an asset after buying it. Now, the system automatically activates the asset in the background as soon as the user proceeds with the purchase, ensuring the asset is immediately visible and usable without any additional steps. This change streamlines the user journey for buying crypto across all entry points and leverages existing asset management patterns for consistency.

Highlights

  • Automated Asset Activation: Implemented automatic activation of purchased cryptocurrency assets when a user confirms a buy, eliminating the need for manual enablement post-purchase.
  • Performance Optimization: Enabled parallel execution of asset activation and payment URL opening, ensuring no additional latency is introduced when the user presses 'Continue'.
  • Broad Applicability: Ensured the auto-activation functionality works consistently across all cryptocurrency buying entry points, including the wallet tab, deep links, and insufficient balance flows.
  • Architectural Alignment: Adopted the existing AssetsEnabler pattern, maintaining consistency with other asset management logic within the application.
  • Dependency Injection Refinement: Refactored FiatSceneViewModel to directly accept Wallet and AssetsEnabler dependencies, improving modularity and testability.
  • Data Model Enhancement: Updated AmountSheetType and ConfirmTransferSheetType to pass the full Wallet object instead of just WalletId, providing richer context.
  • New Package Dependency: Integrated BalanceService into the FiatConnect package to support necessary balance-related functionalities.

🧠 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.

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.

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

This pull request refactors the FiatConnect feature by replacing direct usage of WalletId with a Wallet object and introducing an AssetsEnabler service. This change allows the FiatSceneViewModel to manage asset enabling, specifically by calling enableAsset() after a successful fiat buy operation. The review comments suggest an improvement to prevent potential UI blocking by ensuring the enableAsset() logic is executed on a background thread using Task.detached.

}

urlState = .data(())
Task { await enableAsset() }
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To avoid potential UI blocking, it's safer to run the asset enabling logic on a background thread. The current implementation with Task inherits the main actor context, which could lead to UI freezes if enableAsset() performs synchronous I/O operations.

I'm suggesting a change to the enableAsset() function to make it synchronous and launch a Task.detached for background execution. Consequently, this call site should be updated to a direct synchronous call.

Suggested change
Task { await enableAsset() }
enableAsset()

Comment on lines +252 to +259
private func enableAsset() async {
guard type == .buy else { return }
do {
try await assetsEnabler.enableAssets(wallet: wallet, assetIds: [asset.id], enabled: true)
} catch {
debugLog("FiatSceneViewModel enableAsset error: \(error)")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To prevent potential UI blocking from synchronous I/O operations within assetsEnabler.enableAssets, this logic should be executed on a background thread.

I recommend changing this function to be synchronous and using Task.detached to perform the asset enabling work in the background. This ensures the main thread remains responsive.

    private func enableAsset() {
        guard type == .buy else { return }

        // Capture properties to use in the detached task
        let wallet = self.wallet
        let asset = self.asset
        let assetsEnabler = self.assetsEnabler

        Task.detached {
            do {
                try await assetsEnabler.enableAssets(wallet: wallet, assetIds: [asset.id], enabled: true)
            } catch {
                debugLog("FiatSceneViewModel enableAsset error: \(error)")
            }
        }
    }

@gemdev111 gemdev111 closed this Mar 24, 2026
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.

Auto-activate asset when buying crypto

1 participant