Skip to content

Commit

Permalink
Merge pull request #775 from radixdlt/bugfix/ABW-2846-ui-discrepancies
Browse files Browse the repository at this point in the history
Consolidate UI in transfer and account screen for the same types of assets
  • Loading branch information
micbakos-rdx authored Jan 30, 2024
2 parents 6d20840 + 688844d commit 343ae28
Show file tree
Hide file tree
Showing 53 changed files with 1,770 additions and 2,279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum class ExplicitMetadataKey(val key: String) {

val forPools: Set<ExplicitMetadataKey> = setOf(
NAME,
SYMBOL,
ICON_URL,
POOL_UNIT,
DAPP_DEFINITION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,23 @@ data class AccountWithAssets(
get() = details?.accountType == AccountType.DAPP_DEFINITION
}

interface Asset {
sealed interface Asset {
val resource: Resource

// Asset that can have an amount like
// - token
// - LSU
// - pool unit
sealed interface Fungible : Asset {
override val resource: Resource.FungibleResource
}

// Asset that is non fungible and needs a local id from a collection
// - NFT
// - stake claim
sealed interface NonFungible : Asset {
override val resource: Resource.NonFungibleResource
}
}

data class Assets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import java.math.BigDecimal
data class LiquidStakeUnit(
val fungibleResource: Resource.FungibleResource,
val validator: ValidatorDetail
) : Asset {
) : Asset.Fungible {

override val resource: Resource
override val resource: Resource.FungibleResource
get() = fungibleResource

val validatorAddress: String
Expand All @@ -30,6 +30,8 @@ data class LiquidStakeUnit(
return fungibleResource.ownedAmount?.divide(fungibleResource.currentSupply, fungibleResource.mathContext)
}

fun stakeValue(): BigDecimal? = stakeValueInXRD(validator.totalXrdStake)

fun stakeValueInXRD(totalXrdStake: BigDecimal?): BigDecimal? {
if (totalXrdStake == null) return null
return percentageOwned?.multiply(totalXrdStake, fungibleResource.mathContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.babylon.wallet.android.domain.model.resources.Resource

data class NonFungibleCollection(
val collection: Resource.NonFungibleResource
) : Asset {
override val resource: Resource
) : Asset.NonFungible {
override val resource: Resource.NonFungibleResource
get() = collection
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import java.math.BigDecimal
data class PoolUnit(
val stake: Resource.FungibleResource,
val pool: Pool? = null
) : Asset {
) : Asset.Fungible {

override val resource: Resource
override val resource: Resource.FungibleResource
get() = stake

val resourceAddress: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.babylon.wallet.android.domain.model.resources.Resource
data class StakeClaim(
val nonFungibleResource: Resource.NonFungibleResource,
val validator: ValidatorDetail
) : Asset {
) : Asset.NonFungible {

override val resource: Resource
override val resource: Resource.NonFungibleResource
get() = nonFungibleResource

val validatorAddress: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import com.babylon.wallet.android.domain.model.resources.Resource

data class Token(
override val resource: Resource.FungibleResource
) : Asset
) : Asset.Fungible
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import com.radixdlt.ret.NonFungibleLocalId
import com.radixdlt.ret.knownAddresses
import com.radixdlt.ret.nonFungibleLocalIdAsStr
import com.radixdlt.ret.nonFungibleLocalIdFromStr
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import rdx.works.profile.data.model.apppreferences.Radix
import rdx.works.profile.derivation.model.NetworkId
import java.math.BigDecimal
Expand Down Expand Up @@ -70,7 +72,7 @@ sealed class Resource {
metadata.poolAddress()
}

val tags: List<Tag> by lazy {
val tags: ImmutableList<Tag> by lazy {
if (isXrd) {
metadata.tags()?.map {
Tag.Dynamic(name = it.truncate(maxNumberOfCharacters = TAG_MAX_CHARS))
Expand All @@ -79,7 +81,7 @@ sealed class Resource {
metadata.tags()?.map {
Tag.Dynamic(name = it.truncate(maxNumberOfCharacters = TAG_MAX_CHARS))
}.orEmpty()
}.take(TAGS_MAX)
}.take(TAGS_MAX).toImmutableList()
}

val behaviours: AssetBehaviours? = if (assetBehaviours != null && isXrd) {
Expand Down Expand Up @@ -163,10 +165,10 @@ sealed class Resource {
metadata.iconUrl()
}

val tags: List<Tag> by lazy {
val tags: ImmutableList<Tag> by lazy {
metadata.tags().orEmpty().map {
Tag.Dynamic(name = it.truncate(maxNumberOfCharacters = TAG_MAX_CHARS))
}.take(TAGS_MAX)
}.take(TAGS_MAX).toImmutableList()
}

val validatorAddress: String? by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ fun AccountScreen(
onNavigateToMnemonicRestore: () -> Unit,
onFungibleResourceClick: (Resource.FungibleResource, Network.Account) -> Unit,
onNonFungibleResourceClick: (Resource.NonFungibleResource, Resource.NonFungibleResource.Item, Network.Account) -> Unit,
onPoolUnitClick: (PoolUnit, Network.Account) -> Unit,
onLSUClick: (LiquidStakeUnit, Network.Account) -> Unit,
onTransferClick: (String) -> Unit
) {
val state by viewModel.state.collectAsStateWithLifecycle()
Expand All @@ -99,8 +97,6 @@ fun AccountScreen(
is AccountEvent.NavigateToMnemonicRestore -> onNavigateToMnemonicRestore()
is AccountEvent.OnFungibleClick -> onFungibleResourceClick(it.resource, it.account)
is AccountEvent.OnNonFungibleClick -> onNonFungibleResourceClick(it.resource, it.item, it.account)
is AccountEvent.OnPoolUnitClick -> onPoolUnitClick(it.poolUnit, it.account)
is AccountEvent.OnLSUClick -> onLSUClick(it.liquidStakeUnit, it.account)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ class AccountViewModel @Inject constructor(
val account = _state.value.accountWithAssets?.account ?: return

viewModelScope.launch {
sendEvent(AccountEvent.OnLSUClick(liquidStakeUnit = liquidStakeUnit, account = account))
sendEvent(AccountEvent.OnFungibleClick(resource = liquidStakeUnit.fungibleResource, account = account))
}
}

fun onPoolUnitClicked(poolUnit: PoolUnit) {
val account = _state.value.accountWithAssets?.account ?: return

viewModelScope.launch {
sendEvent(AccountEvent.OnPoolUnitClick(poolUnit, account))
sendEvent(AccountEvent.OnFungibleClick(resource = poolUnit.resource, account))
}
}

Expand Down Expand Up @@ -272,8 +272,6 @@ internal sealed interface AccountEvent : OneOffEvent {
val item: Resource.NonFungibleResource.Item,
val account: Network.Account
) : AccountEvent
data class OnPoolUnitClick(val poolUnit: PoolUnit, val account: Network.Account) : AccountEvent
data class OnLSUClick(val liquidStakeUnit: LiquidStakeUnit, val account: Network.Account) : AccountEvent
}

data class AccountUiState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ import com.babylon.wallet.android.presentation.settings.personas.createpersona.p
import com.babylon.wallet.android.presentation.settings.personas.personadetail.personaDetailScreen
import com.babylon.wallet.android.presentation.settings.personas.personaedit.personaEditScreen
import com.babylon.wallet.android.presentation.settings.settingsNavGraph
import com.babylon.wallet.android.presentation.status.assets.fungible.fungibleAssetDialog
import com.babylon.wallet.android.presentation.status.assets.lsu.lsuAssetDialog
import com.babylon.wallet.android.presentation.status.assets.nonfungible.nonFungibleAssetDialog
import com.babylon.wallet.android.presentation.status.assets.pool.poolUnitAssetDialog
import com.babylon.wallet.android.presentation.status.assets.assetDialog
import com.babylon.wallet.android.presentation.status.assets.fungibleAssetDialog
import com.babylon.wallet.android.presentation.status.assets.nftAssetDialog
import com.babylon.wallet.android.presentation.status.dapp.dAppDetailsDialog
import com.babylon.wallet.android.presentation.status.dapp.dappInteractionDialog
import com.babylon.wallet.android.presentation.status.transaction.transactionStatusDialog
Expand Down Expand Up @@ -217,21 +216,19 @@ fun NavigationHost(
)
},
onFungibleResourceClick = { resource, account ->
navController.fungibleAssetDialog(resource.resourceAddress, account.address)
navController.fungibleAssetDialog(
resourceAddress = resource.resourceAddress,
amount = resource.ownedAmount,
underAccountAddress = account.address
)
},
onNonFungibleResourceClick = { resource, item, account ->
navController.nonFungibleAssetDialog(
navController.nftAssetDialog(
resourceAddress = resource.resourceAddress,
localId = item.localId.code,
accountAddress = account.address
underAccountAddress = account.address
)
},
onPoolUnitClick = { poolUnit, account ->
navController.poolUnitAssetDialog(poolUnit.resourceAddress, account.address)
},
onLSUClick = { liquidStakeUnit, account ->
navController.lsuAssetDialog(liquidStakeUnit.resourceAddress, account.address)
},
onTransferClick = { accountId ->
navController.transfer(accountId = accountId)
}
Expand Down Expand Up @@ -317,15 +314,15 @@ fun NavigationHost(
onFungibleClick = { resource, isNewlyCreated ->
navController.fungibleAssetDialog(
resourceAddress = resource.resourceAddress,
amount = resource.ownedAmount,
isNewlyCreated = isNewlyCreated
)
},
onNonFungibleClick = { resource, item, isNewlyCreated, showStakeClaimButton ->
navController.nonFungibleAssetDialog(
onNonFungibleClick = { resource, item, isNewlyCreated ->
navController.nftAssetDialog(
resourceAddress = resource.resourceAddress,
localId = item.localId.code,
isNewlyCreated = isNewlyCreated,
showStakeClaimButton = showStakeClaimButton
isNewlyCreated = isNewlyCreated
)
},
onDAppClick = { dApp ->
Expand Down Expand Up @@ -428,22 +425,7 @@ fun NavigationHost(
navController.popBackStack()
}
)
fungibleAssetDialog(
onDismiss = {
navController.popBackStack()
}
)
nonFungibleAssetDialog(
onDismiss = {
navController.popBackStack()
}
)
poolUnitAssetDialog(
onDismiss = {
navController.popBackStack()
}
)
lsuAssetDialog(
assetDialog(
onDismiss = {
navController.popBackStack()
}
Expand All @@ -453,7 +435,7 @@ fun NavigationHost(
navController.fungibleAssetDialog(resourceAddress = it.resourceAddress)
},
onNonFungibleClick = {
navController.nonFungibleAssetDialog(resourceAddress = it.resourceAddress)
navController.nftAssetDialog(resourceAddress = it.resourceAddress)
},
onDismiss = {
navController.popBackStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import com.babylon.wallet.android.presentation.settings.authorizeddapps.dappdeta
import com.babylon.wallet.android.presentation.settings.debug.debugSettings
import com.babylon.wallet.android.presentation.settings.personas.createpersona.personasScreen
import com.babylon.wallet.android.presentation.settings.personas.personaedit.personaEditScreen
import com.babylon.wallet.android.presentation.status.assets.fungible.fungibleAssetDialog
import com.babylon.wallet.android.presentation.status.assets.nonfungible.nonFungibleAssetDialog
import com.babylon.wallet.android.presentation.status.assets.fungibleAssetDialog
import com.babylon.wallet.android.presentation.status.assets.nftAssetDialog

@Suppress("LongMethod")
fun NavGraphBuilder.settingsNavGraph(
Expand Down Expand Up @@ -49,9 +49,7 @@ fun NavGraphBuilder.settingsNavGraph(
navController.fungibleAssetDialog(resourceAddress = resource.resourceAddress)
},
onNonFungibleClick = { resource ->
navController.nonFungibleAssetDialog(
resourceAddress = resource.resourceAddress
)
navController.nftAssetDialog(resourceAddress = resource.resourceAddress)
}
)
accountSecurityNavGraph(navController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@ private fun DappDetails(
itemsIndexed(dAppWithResources?.fungibleResources.orEmpty()) { _, fungibleToken ->
GrayBackgroundWrapper {
FungibleCard(
modifier = Modifier.throttleClickable {
onFungibleTokenClick(fungibleToken)
},
fungible = fungibleToken,
showChevron = false
showChevron = false,
onClick = {
onFungibleTokenClick(fungibleToken)
}
)
Spacer(modifier = Modifier.height(dimensions.paddingDefault))
}
Expand All @@ -396,11 +396,11 @@ private fun DappDetails(
items(dAppWithResources?.nonFungibleResources.orEmpty()) { nonFungibleResource ->
GrayBackgroundWrapper {
NonFungibleCard(
modifier = Modifier.throttleClickable {
onNonFungibleClick(nonFungibleResource)
},
nonFungible = nonFungibleResource,
showChevron = false
showChevron = false,
onClick = {
onNonFungibleClick(nonFungibleResource)
}
)
Spacer(modifier = Modifier.height(dimensions.paddingDefault))
}
Expand Down
Loading

0 comments on commit 343ae28

Please sign in to comment.