Skip to content

Conversation

@gemdev111
Copy link
Contributor

@gemdev111 gemdev111 commented Dec 24, 2025

Summary

  • Refactor AmountSceneViewModel using Strategy pattern (~700 → ~260 lines)
  • Extract logic into AmountTransferViewModel, AmountStakeViewModel, AmountFreezeViewModel, AmountPerpetualViewModel
  • Introduce AmountDataProvidable protocol and AmountDataProvider enum
  • Replace ValidatorSelection, LeverageSelection, ResourceSelection with generic SelectionState<T>

Test plan

  • Transfer/deposit/withdraw flows
  • Stake/unstake/redelegate/withdraw flows
  • TRX freeze/unfreeze
  • Perpetual open/increase/reduce positions

🤖 Generated with Claude Code

Introduces a strategy pattern for amount handling by adding AmountStrategy and related classes for transfer, stake, and perpetual actions. Refactors AmountScene, AmountNavigationView, and AmountSceneViewModel to use the new strategy abstraction, improving modularity and maintainability.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gemdev111, 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 introduces a significant architectural improvement by refactoring the AmountSceneViewModel to use the Strategy pattern. This change aims to enhance modularity, maintainability, and testability by separating concerns related to different transaction types (transfers, staking, perpetuals) into distinct strategy objects. The ViewModel now acts as a coordinator, delegating specific logic to the appropriate strategy, resulting in a much cleaner and more focused implementation.

Highlights

  • Strategy Pattern Implementation: The AmountSceneViewModel has been refactored to utilize the Strategy pattern, abstracting transaction-type-specific logic into dedicated strategy classes.
  • Reduced ViewModel Complexity: The AmountSceneViewModel has been significantly streamlined, reducing its line count from approximately 700 to 200 by delegating complex logic to new strategy objects.
  • New Strategy Architecture: Introduced AmountStrategy protocol, AmountStrategyType enum, and concrete implementations: AmountTransferStrategy, AmountStakeStrategy, and AmountPerpetualStrategy to handle different transaction types.
  • Supporting Types for UI State: New observable types like ValidatorSelection, ResourceSelection, and LeverageSelection have been added to encapsulate and manage UI-related state for staking and perpetual operations.
  • UI Adaptation: The AmountNavigationView and AmountScene views have been updated to interact with the new strategy architecture, accessing data and logic through the unified strategy object.

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

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

This pull request introduces a significant and well-executed refactoring of the AmountSceneViewModel by applying the Strategy design pattern. The logic for different transaction types (transfer, stake, perpetual) has been cleanly separated into dedicated strategy classes, which dramatically simplifies the view model and improves modularity and maintainability. The introduction of AmountStrategy, AmountStrategyFactory, and supporting state-holder classes like ValidatorSelection is a great improvement to the architecture. The changes in the views and tests are consistent with this new design. My feedback includes a couple of minor suggestions to improve code clarity and adopt more idiomatic Swift constructs in the new strategy classes.

Comment on lines 34 to 36
var isAutocloseEnabled: Bool {
if case .open = data.positionAction { true } else { false }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This if case expression to return a boolean can be made more explicit and arguably more readable by using a switch statement. This ensures all cases of PerpetualPositionAction are explicitly handled, improving clarity and maintainability.

    var isAutocloseEnabled: Bool {
        switch data.positionAction {
        case .open:
            true
        case .increase, .reduce:
            false
        }
    }

Comment on lines 21 to 27
var freezeData: FreezeData? {
if case .freeze(let data) = self {
data
} else {
nil
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This if case block can be simplified using a guard case statement, which is more idiomatic in Swift for extracting an associated value from an enum case and returning early if it doesn't match. This improves conciseness and readability.

    var freezeData: FreezeData? {
        guard case .freeze(let data) = self else {
            return nil
        }
        return data
    }

@gemdev111 gemdev111 self-assigned this Dec 24, 2025
Copy link
Contributor

@DRadmir DRadmir left a comment

Choose a reason for hiding this comment

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

No need to use *Strategy in the naming

case unstake(Delegation)
case redelegate(Delegation, validators: [DelegationValidator], recommended: DelegationValidator?)
case withdraw(Delegation)
case freeze(FreezeData)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we treat freeze as an edge case for staking?

LeveragePickerSheet(
title: perpetual.leverageTitle,
leverageOptions: leverageSelection.options,
selectedLeverage: Binding(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we incapsulate this binding to model?

  struct LeverageSheetModel {
      let title: String
      let options: [LeverageOption]
      let binding: Binding<LeverageOption>
  }

then create this model in AmountPerpetualStrategy

var minimumValue: BigInt {
switch action {
case .send: .zero
case .deposit: asset.symbol == "USDC" ? BigInt(5_000_000) : .zero
Copy link
Contributor

Choose a reason for hiding this comment

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

  enum PerpetualLimits {
      static let minDepositUSDC = BigInt(5_000_000)
      static let minWithdrawUSDC = BigInt(2_000_000)
  }

Names update
Improved file structure
MInor refactoring
Moved freeze and unfreeze logic from AmountStakeViewModel to a new AmountFreezeViewModel. Updated AmountDataProvider and AmountScene to use the new model for freeze actions. Adjusted related tests and removed resource selection handling from AmountStakeViewModel to improve separation of concerns.
Refactored protocol and related conformances from AmountViewModeling to AmountDataProvidable for improved naming consistency. Introduced AmountPerpetualLimits struct for minimum deposit and withdraw values, and updated usages in AmountStakeViewModel and AmountTransferViewModel. Minor logic simplifications in AmountFreezeViewModel and AmountPerpetualViewModel.
Refactored AmountSheetType to pass required data for leverage selector and updated related view logic to use new bindings and onChange handlers. Improved resource selection in AmountScene to use @bindable and onChange, and updated ViewModel methods for resource and leverage changes to match new signature.
Updated multiple files to consistently use the 'case let' pattern matching syntax for improved readability and Swift best practices. Also made minor test improvements and refactored variable extraction in view models.
Updated LeverageSelection, ResourceSelection, and ValidatorSelection to accept explicit options and selected values in their initializers, improving flexibility and consistency. Adjusted related view models and scene code to use the new initializers and removed static options usage.
@gemdev111 gemdev111 requested a review from DRadmir December 30, 2025 14:46
@gemdev111 gemdev111 marked this pull request as draft December 30, 2025 18:31
@gemdev111 gemdev111 marked this pull request as ready for review December 30, 2025 18:33
Replaces LeverageSelection, ResourceSelection, and ValidatorSelection with a generic SelectionState<T> class to unify selection logic across the app. Updates all related view models and views to use the new SelectionState, simplifying code and improving maintainability.
@gemdev111 gemdev111 merged commit 61d532d into main Dec 30, 2025
1 of 3 checks passed
@gemdev111 gemdev111 deleted the amount-scene-refactor branch December 30, 2025 20:27
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.

3 participants