Skip to content

Earn yielder integration#1787

Open
gemdev111 wants to merge 22 commits intomainfrom
earn-yielder-integration
Open

Earn yielder integration#1787
gemdev111 wants to merge 22 commits intomainfrom
earn-yielder-integration

Conversation

@gemdev111
Copy link
Contributor

No description provided.

Introduce EarnBalanceUpdatable protocol and have BalanceService conform to it so earn balances can be updated via a shared interface. EarnService now accepts an EarnBalanceUpdatable dependency and triggers an earn balance refresh after updating positions. ServicesFactory is updated to inject the balance service into EarnService, and Package.swift adds the BalanceService dependency for the EarnService target. BalanceStore gains hasEarnBalance(...) to gate earn updates, the TransactionStateService testkit adds an EarnBalanceUpdaterMock and updated mock constructor, and a small UI label change for earn deposit was applied. Also bumps core submodule commit.
Show provider/earn-specific labels and capitalize names across stake/transaction/transfer views. Changes include: capitalizing validator name for .earn; adding earnProviderItemModel and routing .earnDeposit/.earnWithdraw to it in TransactionParticipantViewModel (and using Localized.Common.provider as the label); and updating ConfirmRecipientViewModel to use the provider title for .earn and make recipient input visible for earn flows. Files updated: ValidatorViewModel.swift, TransactionParticipantViewModel.swift, ConfirmRecipientViewModel.swift.
@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 integration of 'Earn yielder' functionality by introducing a new protocol for managing earn balance updates, refactoring the EarnService to utilize this protocol, and updating the BalanceService accordingly. It also includes several UI adjustments to accurately display earn-related transaction details and validator names, ensuring a consistent and robust user experience for earn features.

Highlights

  • Earn Balance Update Protocol: Introduced a new EarnBalanceUpdatable protocol to standardize and abstract the process of updating earn balances, promoting a more modular architecture.
  • Earn Service Refactoring: Refactored the EarnService to depend on the new EarnBalanceUpdatable protocol, allowing for flexible and testable earn balance updates.
  • Balance Service Integration: Updated BalanceService to conform to the EarnBalanceUpdatable protocol and adjusted its logic to conditionally update earn balances based on existing records.
  • UI Text and Participant Handling: Enhanced transaction and recipient view models to correctly display 'Earn' related transaction participants and titles, including capitalizing validator names for earn cases and showing 'Provider' for earn deposits/withdrawals.
  • Balance Store Utility: Added a hasEarnBalance utility function to BalanceStore to efficiently check for the existence of earn balances for a given wallet and chain.

🧠 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/Stake/Sources/ViewModels/ValidatorViewModel.swift
    • Capitalized the validator name for .earn cases.
  • Features/Transactions/Sources/ViewModels/TransactionParticipantViewModel.swift
    • Updated itemModel to use earnProviderItemModel for earnDeposit and earnWithdraw transaction types.
    • Added a private computed property earnProviderItemModel.
    • Modified title to return Localized.Common.provider for earnDeposit and earnWithdraw types.
  • Features/Transfer/Sources/ViewModels/ConfirmRecipientViewModel.swift
    • Changed the recipient title for .earn type to Localized.Common.provider.
    • Adjusted the isEditable logic for .earn type.
  • Gem/Services/ServicesFactory.swift
    • Modified EarnService initialization to pass balanceService as earnBalanceUpdater.
  • Packages/FeatureServices/BalanceService/BalanceService.swift
    • Modified updateAllBalances to conditionally update earn balances based on hasEarnBalance.
    • Removed the private updateEarnBalance function.
    • Extended BalanceService to conform to EarnBalanceUpdatable and implemented its updateEarnBalance method.
  • Packages/FeatureServices/BalanceService/Protocols/EarnBalanceUpdatable.swift
    • Added a new public protocol EarnBalanceUpdatable.
  • Packages/FeatureServices/EarnService/EarnService.swift
    • Imported BalanceService.
    • Added earnBalanceUpdater property and updated the initializer.
    • Called earnBalanceUpdater.updateEarnBalance after updating positions.
  • Packages/FeatureServices/Package.swift
    • Added BalanceService as a dependency for EarnService.
  • Packages/FeatureServices/TransactionStateService/TestKit/TransactionStateService+TestKit.swift
    • Added earnBalanceUpdater parameter to EarnService.mock.
    • Introduced EarnBalanceUpdaterMock for testing.
  • Packages/PrimitivesComponents/Sources/ViewModels/TransactionViewModel.swift
    • Changed the title for earnDeposit to Localized.Common.earn.
  • Packages/Store/Sources/Stores/BalanceStore.swift
    • Added a hasEarnBalance function to check for existing earn balances.
  • core
    • Updated the submodule commit hash.
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 integrates the 'Earn' yielder functionality across various features. The changes include UI updates for displaying earn-related information, service layer modifications to handle earn logic, and database extensions to support earn balances. A notable improvement is the refactoring in EarnService and BalanceService to use the EarnBalanceUpdatable protocol, which decouples the services and improves modularity. My review includes one suggestion for improving code style and readability.

}

// earn balance
if (try? balanceStore.hasEarnBalance(walletId: walletId, chain: chain)) == true {
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 condition is functionally correct, but it can be written more concisely and idiomatically in Swift. Using the nil-coalescing operator ?? can make the intent clearer by treating a nil result from the throwing function as false.

Suggested change
if (try? balanceStore.hasEarnBalance(walletId: walletId, chain: chain)) == true {
if (try? balanceStore.hasEarnBalance(walletId: walletId, chain: chain)) ?? false {

public struct EarnService: Sendable {
private let store: StakeStore
private let gatewayService: GatewayService
private let earnBalanceUpdater: any EarnBalanceUpdatable
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private let earnBalanceUpdater: any EarnBalanceUpdatable
private let balanceUpdater: any EarnBalanceUpdatable


try updatePositions(walletId: walletId, assetId: assetId, positions: positions)

await earnBalanceUpdater.updateEarnBalance(walletId: walletId, chain: assetId.chain, address: address)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
await earnBalanceUpdater.updateEarnBalance(walletId: walletId, chain: assetId.chain, address: address)
await balanceUpdater.updateEarnBalance(walletId: walletId, chain: assetId.chain, address: address)

) -> EarnService {
let provider = NativeProvider(url: Constants.apiURL, requestInterceptor: EmptyRequestInterceptor())
return EarnService(store: store, gatewayService: GatewayService(provider: provider))
return EarnService(store: store, gatewayService: GatewayService(provider: provider), earnBalanceUpdater: earnBalanceUpdater)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return EarnService(store: store, gatewayService: GatewayService(provider: provider), earnBalanceUpdater: earnBalanceUpdater)
return EarnService(store: store, gatewayService: GatewayService(provider: provider), balanceUpdater: balanceUpdater)

try db.read { db in
try BalanceRecord
.filter(BalanceRecord.Columns.walletId == walletId.id)
.filter(BalanceRecord.Columns.assetId.like("\(chain.rawValue)%"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.filter(BalanceRecord.Columns.assetId.like("\(chain.rawValue)%"))
.filter(BalanceRecord.Columns.chain = chain.rawValue )

private var earnProviderItemModel: TransactionItemModel {
let address = transactionViewModel.participant
let addressName = transactionViewModel.getAddressName(address: address)
let name = (addressName?.name ?? address).capitalized
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let name = (addressName?.name ?? address).capitalized

return validator.name
case .earn:
return validator.name
return validator.name.capitalized
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return validator.name.capitalized
return validator.name

@gemdev111 gemdev111 marked this pull request as ready for review March 18, 2026 18:56
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