Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.runtime.remember
import androidx.navigation3.runtime.NavBackStack
import androidx.navigation3.runtime.NavKey
import com.gemwallet.android.application.confirm.coordinators.ConfirmTransaction.FinishRoute
import com.gemwallet.android.domains.transaction.isPerpetual
import com.gemwallet.android.features.asset_select.presents.navigation.AssetsManageRoute
import com.gemwallet.android.features.asset_select.presents.navigation.AssetsSearchRoute
import com.gemwallet.android.features.create_wallet.navigation.CreateWalletAlertRoute
Expand Down Expand Up @@ -46,7 +45,6 @@ import com.gemwallet.android.ui.navigation.routes.NftAssetRoute
import com.gemwallet.android.ui.navigation.routes.NftCollectionRoute
import com.gemwallet.android.ui.navigation.routes.NftUnverifiedCollectionsRoute
import com.gemwallet.android.ui.navigation.routes.NotificationsRoute
import com.gemwallet.android.ui.navigation.routes.PerpetualAmountRoute
import com.gemwallet.android.ui.navigation.routes.PerpetualPositionRoute
import com.gemwallet.android.ui.navigation.routes.PerpetualRoute
import com.gemwallet.android.ui.navigation.routes.PreferencesRoute
Expand Down Expand Up @@ -203,7 +201,7 @@ class WalletNavigator(
fun openNftRecipient(assetId: AssetId, nftAssetId: String) = push(RecipientInputRoute(assetId, nftAssetId))
fun openAmount(params: AmountParams) {
val pack = params.pack() ?: return
push(if (params.txType.isPerpetual) PerpetualAmountRoute(pack) else AmountRoute(pack))
push(AmountRoute(pack))
}
fun openSwap() {
clearSwapSelections()
Expand Down Expand Up @@ -315,7 +313,6 @@ internal fun NavKey.isConfirmFlowSegmentRoute(): Boolean {
SwapRoute -> true
is AmountRoute,
is ConfirmRoute,
is PerpetualAmountRoute,
is RecipientInputRoute,
is StakeRoute,
is SwapPairRoute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ package com.gemwallet.android.ui.navigation.routes

import androidx.navigation3.runtime.EntryProviderScope
import androidx.navigation3.runtime.NavKey
import com.gemwallet.android.model.ConfirmParams
import com.gemwallet.android.features.transfer_amount.presents.AmountPerpetualNavScreen
import com.gemwallet.android.features.transfer_amount.presents.AmountScreen
import com.gemwallet.android.model.ConfirmParams
import com.gemwallet.android.ui.navigation.paramsArgument
import com.gemwallet.android.ui.navigation.routeArguments
import kotlinx.serialization.Serializable

@Serializable
data class AmountRoute(val params: String) : NavKey

@Serializable
data class PerpetualAmountRoute(val params: String) : NavKey

fun EntryProviderScope<NavKey>.amount(
onCancel: () -> Unit,
onConfirm: (ConfirmParams) -> Unit,
Expand All @@ -24,13 +20,4 @@ fun EntryProviderScope<NavKey>.amount(
) {
AmountScreen(onCancel = onCancel, onConfirm = onConfirm)
}

entry<PerpetualAmountRoute>(
metadata = { key -> routeArguments(paramsArgument(key.params)) },
) {
AmountPerpetualNavScreen(
onConfirm = onConfirm,
onClose = onCancel
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.gemwallet.android.ui.navigation.routes.FiatInputRoute
import com.gemwallet.android.ui.navigation.routes.FiatSelectRoute
import com.gemwallet.android.ui.navigation.routes.NftAssetRoute
import com.gemwallet.android.ui.navigation.routes.NftCollectionRoute
import com.gemwallet.android.ui.navigation.routes.PerpetualAmountRoute
import com.gemwallet.android.ui.navigation.routes.PriceAlertsRoute
import com.gemwallet.android.ui.navigation.routes.RecipientInputRoute
import com.gemwallet.android.ui.navigation.routes.ReceiveRoute
Expand Down Expand Up @@ -197,7 +196,7 @@ class WalletNavigatorTest {
WalletPhraseRoute(walletId, WalletType.Multicoin),
RecipientInputRoute(assetId, nftAssetId = null),
AmountRoute("amount"),
PerpetualAmountRoute("perpetual"),
AmountRoute("perpetual"),
ConfirmRoute("confirm"),
).dropNonRestorableRoutes(WalletRootRoute)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TransactionBalanceService @Inject constructor(
resource: Resource? = null,
): BigInteger {
return assetInfo.balance(
txType = params.txType,
txType = params.transactionType,
context = getContext(assetInfo, params, delegation, resource),
)
}
Expand All @@ -70,7 +70,7 @@ class TransactionBalanceService @Inject constructor(
delegation: Delegation? = null,
resource: Resource? = null,
): TransactionBalanceContext {
return when (params.txType) {
return when (params.transactionType) {
TransactionType.StakeRewards -> TransactionBalanceContext(
rewardsBalance = delegation?.rewardsBalance() ?: getRewardsBalance(assetInfo),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.gemwallet.android.testkit.mockAssetInfo
import com.gemwallet.android.testkit.mockDelegation
import com.gemwallet.android.testkit.mockDelegationValidator
import com.gemwallet.android.testkit.mockAssetMonad
import com.wallet.core.primitives.TransactionType
import io.mockk.coEvery
import io.mockk.every
import io.mockk.mockk
Expand Down Expand Up @@ -43,7 +42,7 @@ class TransactionBalanceServiceTest {
)
coEvery { stakeRepository.getRewards(asset.id, "wallet-address") } returns rewards

val amountParams = AmountParams.buildStake(asset.id, TransactionType.StakeRewards)
val amountParams = AmountParams.Stake.Rewards(asset.id)
val confirmParams = ConfirmParams.Builder(
asset = asset,
from = requireNotNull(assetInfo.owner),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.gemwallet.android.features.earn.delegation.models.DelegationProperty
import com.gemwallet.android.features.earn.delegation.models.HeadDelegationInfo
import com.wallet.core.primitives.DelegationState
import com.wallet.core.primitives.StakeChain
import com.wallet.core.primitives.TransactionType
import com.wallet.core.primitives.WalletType
import dagger.hilt.android.lifecycle.HiltViewModel
import uniffi.gemstone.Explorer
Expand Down Expand Up @@ -173,14 +172,14 @@ class DelegationViewModel @Inject constructor(
.stateIn(viewModelScope, SharingStarted.Eagerly, null)

fun onStake(call: AmountTransactionAction) {
buildStake(TransactionType.StakeDelegate)?.let { call(it) }
buildDelegate()?.let { call(it) }
}

fun onUnstake(amountCall: AmountTransactionAction, confirmCall: ConfirmTransactionAction) {
val assetInfo = assetInfo.value ?: return
val delegation = delegation.value ?: return
if (assetInfo.chain.changeAmountOnUnstake) {
buildStake(TransactionType.StakeUndelegate)?.let { amountCall(it) }
buildUndelegate()?.let { amountCall(it) }
return
}
val from = assetInfo.owner ?: return
Expand All @@ -191,7 +190,7 @@ class DelegationViewModel @Inject constructor(
}

fun onRedelegate(call: AmountTransactionAction) {
buildStake(TransactionType.StakeRedelegate)?.let { call(it) }
buildRedelegate()?.let { call(it) }
}

fun onWithdraw(call: ConfirmTransactionAction) {
Expand All @@ -218,12 +217,27 @@ class DelegationViewModel @Inject constructor(
)
}

private fun buildStake(type: TransactionType): AmountParams? {
private fun buildDelegate(): AmountParams.Stake.Delegate? {
val assetId = assetInfo.value?.asset?.id ?: return null
val delegation = delegation.value ?: return null
return AmountParams.buildStake(
return AmountParams.Stake.Delegate(assetId, validatorId = delegation.validator.id)
}

private fun buildUndelegate(): AmountParams.Stake.Undelegate? {
val assetId = assetInfo.value?.asset?.id ?: return null
val delegation = delegation.value ?: return null
return AmountParams.Stake.Undelegate(
assetId = assetId,
validatorId = delegation.validator.id,
delegationId = delegation.base.delegationId,
)
}

private fun buildRedelegate(): AmountParams.Stake.Redelegate? {
val assetId = assetInfo.value?.asset?.id ?: return null
val delegation = delegation.value ?: return null
return AmountParams.Stake.Redelegate(
assetId = assetId,
txType = type,
validatorId = delegation.validator.id,
delegationId = delegation.base.delegationId,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,14 @@ internal fun LazyListScope.stakeActions(
StakeAction.Unfreeze -> R.string.transfer_unfreeze_title
}
val onClick = when (item) {
StakeAction.Stake,
StakeAction.Freeze,
StakeAction.Stake -> {
{ amountAction(AmountParams.Stake.Delegate(assetId)) }
}
StakeAction.Freeze -> {
{ amountAction(AmountParams.Freeze(assetId, AmountParams.Freeze.Direction.Freeze)) }
}
StakeAction.Unfreeze -> {
{
amountAction(
AmountParams.Companion.buildStake(
assetId = assetId,
txType = item.transactionType,
)
)
}
{ amountAction(AmountParams.Freeze(assetId, AmountParams.Freeze.Direction.Unfreeze)) }
}
is StakeAction.Rewards -> onRewards
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.gemwallet.android.ui.models.navigation.RouteArgument
import com.gemwallet.android.features.stake.models.StakeAction
import com.wallet.core.primitives.Delegation
import com.wallet.core.primitives.DelegationState
import com.wallet.core.primitives.TransactionType
import com.wallet.core.primitives.WalletType
import com.gemwallet.android.ext.isViewOnly
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -186,10 +185,7 @@ class StakeViewModel @Inject constructor(
)
} else {
onAmount(
AmountParams.buildStake(
assetId = assetInfo.asset.id,
txType = TransactionType.StakeRewards,
)
AmountParams.Stake.Rewards(assetInfo.asset.id)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ fun PerpetualPositionNavScreen(
onOpenPosition = { direction ->
val currentPerpetual = perpetual ?: return@PerpetualPositionScene
onOpenPosition(
AmountParams.buildPerpetualOpenPosition(
currentPerpetual.asset.id,
currentPerpetual.id,
direction,
AmountParams.Perpetual(
assetId = currentPerpetual.asset.id,
perpetualId = currentPerpetual.id,
direction = direction,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class RecipientViewModel @Inject constructor(
when (type) {
is RecipientType.Nft -> onNftConfirm(type.nftAsset, destination, confirmAction)
is RecipientType.Asset -> amountAction(
AmountParams.buildTransfer(type.assetInfo.id(), destination, memo.value)
AmountParams.Transfer(type.assetInfo.id(), destination, memo.value)
)
}
}
Expand Down

This file was deleted.

Loading