Skip to content

Amount route consolidation#281

Open
gemdev111 wants to merge 24 commits into
mainfrom
android-amount-route-consolidation
Open

Amount route consolidation#281
gemdev111 wants to merge 24 commits into
mainfrom
android-amount-route-consolidation

Conversation

@gemdev111
Copy link
Copy Markdown
Contributor

@gemdev111 gemdev111 commented May 7, 2026

Replaces the dual-route amount flow (AmountRoute + PerpetualAmountRoute backed by AmountViewModel + AmountBaseViewModel + PerpetualAmountViewModel) with a single AmountRoute, AmountScreen, and AmountViewModel that delegates per-flow logic to a sealed AmountDataProvider strategy. Mirrors iOS's AmountSceneViewModel + AmountDataProvidable architecture using Kotlin idioms (sealed interfaces, Hilt, StateFlow).

AmountParams becomes a sealed interface with one variant per flow (Transfer, Stake.Delegate/Undelegate/Redelegate/Withdraw/Rewards, Freeze, Perpetual); polymorphic JSON via @SerialName preserves route packing. Each provider (AmountTransferProvider, AmountStakeProvider, AmountFreezeProvider, AmountPerpetualProvider) owns its title, capability flags, balance flow, and ConfirmParams construction. AmountProviderFactory dispatches variants to the right provider via Hilt.

AmountViewModel holds amount input, validation, currency toggle, and max/equivalent state and forwards everything else to the injected provider. Read-only flows (Withdraw, Rewards) auto-prefill via combine(provider.assetInfo.filterNotNull(), provider.availableBalance) so subsequent balance updates keep the displayed amount in sync. AmountScene takes canSwitchInputType, readOnly, and showsAssetBalance booleans plus a slot for provider-specific controls (validator picker for Stake, Bandwidth/Energy tabs for Freeze, leverage row for Perpetual). The validator picker overlay moved to AmountScreen via AnimatedContent + BackHandler. Stake.Rewards keeps the balance row visible to mirror iOS.

Other fixes:

  • Stake.Undelegate and Stake.Withdraw carry validatorId; the DAO query joins delegation_id and validator.id, so the previously-empty validator argument returned null. DelegationViewModel.buildUndelegate now passes delegation.validator.id.
  • AmountStakeProvider falls back to stakeRepository.getRecommended(chain) when the user opens Stake.Delegate without an explicit validator and refreshes the rewards delegation when the user picks a different validator on Stake.Rewards.
  • AmountDataProvider.buildConfirmParams is suspend so a future AmountEarnProvider can fetch yield data before constructing ConfirmParams (mirrors iOS async makeTransferData).

Removes AmountBaseViewModel, PerpetualAmountViewModel, PerpetualAmountRoute, and the obsolete txType helpers and presentation models.

closes #258

@gemdev111 gemdev111 changed the title Android amount route consolidation Amount route consolidation May 7, 2026
@gemdev111 gemdev111 self-assigned this May 7, 2026
@gemdev111 gemdev111 marked this pull request as ready for review May 11, 2026 15:20

private val perpetual = getPerpetual.getPerpetual(params.perpetualId)
.onEach { current ->
val session = sessionRepository.session().firstOrNull() ?: return@onEach
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you just need to get this perpetual, no need to do anything else

val leverage: StateFlow<Int> = selectedLeverage.asStateFlow()
fun setLeverage(value: Int) { selectedLeverage.update { value } }

val availableLeverages: StateFlow<List<Int>> = perpetual.filterNotNull().map { current ->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

reuse with settings

)
}

private fun perpetualUsdcAssetId(chain: Chain): AssetId = when (chain) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we already have this somwhere else, reuse

transactionBalanceService = transactionBalanceService,
scope = scope,
)
is AmountParams.Freeze -> AmountFreezeProvider(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you merge AmountFreezeProvider into AmountStakeProvider


private val delegation: StateFlow<Delegation?> = run {
val source = when (params) {
is AmountParams.Stake.Undelegate ->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

merge 3 cases into one

val currentDelegation = delegation.value ?: throw AmountError.NoDelegationSelected
builder.redelegate(validator, currentDelegation)
}
is AmountParams.Stake.Undelegate -> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

merge cases

}
}

private fun initialValidatorId(params: AmountParams.Stake): String? = when (params) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this needed?

@OptIn(ExperimentalCoroutinesApi::class)
class AmountStakeProvider(
private val params: AmountParams.Stake,
assetsRepository: AssetsRepository,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use coordinator instead of injecting repositories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove PerpetualAmountRoute and consolidate with AmountRoute

2 participants