Skip to content

Commit

Permalink
ABW-2691 - Connected dApps section redesigned to show Unknown Compone…
Browse files Browse the repository at this point in the history
…nts bottom sheet. (#735)

* ABW-2691 - Connected dApps section redesigned to show Unknown Components bottom sheet.

* ABW-2691 - Crowdin replaced with string copy.

* ABW-2691 - Fix for bottom sheet title added.

* ABW-2691 - Dotted line restored.

* Merge main into task/AVW-2691-Using-DApps

* ABW-2691 - Removed unused vals.

* ABW-2691 - Var moved to backing variable

* Merge branch 'main' into task/ABW-2691-Using-DApps

# Conflicts:
#	app/src/main/java/com/babylon/wallet/android/presentation/transaction/TransactionReviewViewModel.kt
#	app/src/main/java/com/babylon/wallet/android/presentation/transaction/composables/StakeTypeContent.kt
#	app/src/main/java/com/babylon/wallet/android/presentation/transaction/composables/TransferTypeContent.kt
#	app/src/main/java/com/babylon/wallet/android/presentation/transaction/composables/ValidatorsContent.kt
  • Loading branch information
raf-rdx authored Jan 18, 2024
1 parent b88e4d9 commit 2ce93f2
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ data class DApp(
val claimedEntities: List<String>
get() = metadata.claimedEntities().orEmpty()

val componentAddresses: List<String>
get() = claimedEntities.filter { it.startsWith("component_") }

@Suppress("SwallowedException")
fun isRelatedWith(origin: String): Boolean {
return claimedWebsites.any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.babylon.wallet.android.domain.model.resources.XrdResource.addressesPe
import com.babylon.wallet.android.domain.model.resources.metadata.Metadata
import com.babylon.wallet.android.domain.model.resources.metadata.claimAmount
import com.babylon.wallet.android.domain.model.resources.metadata.claimEpoch
import com.babylon.wallet.android.domain.model.resources.metadata.dAppDefinitions
import com.babylon.wallet.android.domain.model.resources.metadata.description
import com.babylon.wallet.android.domain.model.resources.metadata.iconUrl
import com.babylon.wallet.android.domain.model.resources.metadata.keyImageUrl
Expand Down Expand Up @@ -72,10 +71,6 @@ sealed class Resource {
metadata.poolAddress()
}

val dappDefinitions: List<String> by lazy {
metadata.dAppDefinitions()
}

val tags: List<Tag> by lazy {
if (isXrd) {
metadata.tags()?.map {
Expand Down Expand Up @@ -179,10 +174,6 @@ sealed class Resource {
metadata.validatorAddress()
}

val dappDefinitions: List<String> by lazy {
metadata.dAppDefinitions()
}

val behaviours: AssetBehaviours? = assetBehaviours

override fun compareTo(other: NonFungibleResource): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ fun List<Metadata>.dAppDefinitions(): List<String> {
key = ExplicitMetadataKey.DAPP_DEFINITION,
type = MetadataType.Address
)?.value

return if (single != null) {
dAppDefinitions + single
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.babylon.wallet.android.presentation.settings.authorizeddapps.dappdetail

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.babylon.wallet.android.R
import com.babylon.wallet.android.designsystem.theme.RadixTheme
import com.babylon.wallet.android.designsystem.theme.RadixWalletTheme
import com.babylon.wallet.android.presentation.ui.composables.ActionableAddressView
import com.babylon.wallet.android.presentation.ui.composables.BottomDialogHeader
import com.babylon.wallet.android.presentation.ui.composables.Thumbnail
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf

@Composable
fun UnknownDAppComponentsSheetContent(
onBackClick: () -> Unit,
modifier: Modifier = Modifier,
unknownDAppComponents: ImmutableList<String>
) {
Column(modifier = modifier) {
val title = stringResource(id = R.string.transactionReview_unknownComponents, unknownDAppComponents.size)
BottomDialogHeader(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = RadixTheme.dimensions.paddingSmall),
title = title,
onDismissRequest = onBackClick
)
HorizontalDivider(color = RadixTheme.colors.gray5)
val lastItem = unknownDAppComponents.last()
LazyColumn(
contentPadding = PaddingValues(vertical = RadixTheme.dimensions.paddingDefault),
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxSize()
.padding(RadixTheme.dimensions.paddingDefault)
) {
items(unknownDAppComponents) { unknownComponentAddress ->
Column {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(RadixTheme.dimensions.paddingSmall)
.padding(vertical = RadixTheme.dimensions.paddingDefault),
verticalAlignment = Alignment.CenterVertically
) {
Thumbnail.DApp(
modifier = Modifier.size(44.dp),
dapp = null,
shape = RadixTheme.shapes.roundedRectXSmall
)
Spacer(modifier = Modifier.width(RadixTheme.dimensions.paddingDefault))
Column {
Text(
text = stringResource(id = R.string.common_component),
style = RadixTheme.typography.body1Header,
color = RadixTheme.colors.gray1,
overflow = TextOverflow.Ellipsis
)

ActionableAddressView(
address = unknownComponentAddress,
textStyle = RadixTheme.typography.body2Regular,
textColor = RadixTheme.colors.gray1
)
}
}

if (lastItem != unknownComponentAddress) {
HorizontalDivider(
modifier = Modifier
.fillMaxWidth(),
color = RadixTheme.colors.gray5
)
}
}
}
}
}
}

@Preview(showBackground = true)
@Composable
fun UnknownDAppComponentsSheetContentPreview() {
RadixWalletTheme {
UnknownDAppComponentsSheetContent(
onBackClick = {},
unknownDAppComponents = persistentListOf(
"component_tdx_b_1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq8z96qp",
"component_tdx_b_1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq8z16qp"
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.babylon.wallet.android.domain.model.TransactionManifestData
import com.babylon.wallet.android.domain.model.resources.Resource
import com.babylon.wallet.android.domain.userFriendlyMessage
import com.babylon.wallet.android.presentation.common.FullscreenCircularProgressContent
import com.babylon.wallet.android.presentation.settings.authorizeddapps.dappdetail.UnknownDAppComponentsSheetContent
import com.babylon.wallet.android.presentation.status.signing.FactorSourceInteractionBottomDialog
import com.babylon.wallet.android.presentation.transaction.TransactionReviewViewModel.State
import com.babylon.wallet.android.presentation.transaction.composables.AccountDepositSettingsTypeContent
Expand All @@ -61,6 +62,7 @@ import com.babylon.wallet.android.presentation.ui.composables.ReceiptEdge
import com.babylon.wallet.android.presentation.ui.composables.SlideToSignButton
import com.babylon.wallet.android.presentation.ui.composables.SnackbarUIMessage
import com.babylon.wallet.android.utils.biometricAuthenticateSuspend
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.launch
import rdx.works.profile.data.model.apppreferences.Radix
Expand Down Expand Up @@ -101,11 +103,12 @@ fun TransactionReviewScreen(
promptForGuarantees = viewModel::promptForGuaranteesClick,
onCustomizeClick = viewModel::onCustomizeClick,
onGuaranteesApplyClick = viewModel::onGuaranteesApplyClick,
onGuaranteesCloseClick = viewModel::onGuaranteesCloseClick,
onCloseBottomSheetClick = viewModel::onCloseBottomSheetClick,
onGuaranteeValueChanged = viewModel::onGuaranteeValueChange,
onGuaranteeValueIncreased = viewModel::onGuaranteeValueIncreased,
onGuaranteeValueDecreased = viewModel::onGuaranteeValueDecreased,
onDAppClick = onDAppClick,
onUnknownDAppsClick = viewModel::onUnknownDAppsClick,
onFungibleResourceClick = viewModel::onFungibleResourceClick,
onNonFungibleResourceClick = viewModel::onNonFungibleResourceClick,
onChangeFeePayerClick = viewModel::onChangeFeePayerClick,
Expand Down Expand Up @@ -158,11 +161,12 @@ private fun TransactionPreviewContent(
promptForGuarantees: () -> Unit,
onCustomizeClick: () -> Unit,
onGuaranteesApplyClick: () -> Unit,
onGuaranteesCloseClick: () -> Unit,
onCloseBottomSheetClick: () -> Unit,
onGuaranteeValueChanged: (AccountWithPredictedGuarantee, String) -> Unit,
onGuaranteeValueIncreased: (AccountWithPredictedGuarantee) -> Unit,
onGuaranteeValueDecreased: (AccountWithPredictedGuarantee) -> Unit,
onDAppClick: (DApp) -> Unit,
onUnknownDAppsClick: (ImmutableList<String>) -> Unit,
onFungibleResourceClick: (Resource.FungibleResource, Boolean) -> Unit,
onNonFungibleResourceClick: (Resource.NonFungibleResource, Resource.NonFungibleResource.Item, Boolean) -> Unit,
onChangeFeePayerClick: () -> Unit,
Expand Down Expand Up @@ -291,7 +295,8 @@ private fun TransactionPreviewContent(
state = state,
preview = preview,
onPromptForGuarantees = promptForGuarantees,
onDappClick = onDAppClick,
onDAppClick = onDAppClick,
onUnknownDAppsClick = onUnknownDAppsClick,
onFungibleResourceClick = onFungibleResourceClick,
onNonFungibleResourceClick = onNonFungibleResourceClick
)
Expand Down Expand Up @@ -364,7 +369,7 @@ private fun TransactionPreviewContent(
sheetState = state.sheetState,
transactionFees = state.transactionFees,
insufficientBalanceToPayTheFee = state.isBalanceInsufficientToPayTheFee,
onGuaranteesCloseClick = onGuaranteesCloseClick,
onCloseBottomSheetClick = onCloseBottomSheetClick,
onGuaranteesApplyClick = onGuaranteesApplyClick,
onGuaranteeValueChanged = onGuaranteeValueChanged,
onGuaranteeValueIncreased = onGuaranteeValueIncreased,
Expand All @@ -390,7 +395,7 @@ private fun BottomSheetContent(
sheetState: State.Sheet,
transactionFees: TransactionFees,
insufficientBalanceToPayTheFee: Boolean,
onGuaranteesCloseClick: () -> Unit,
onCloseBottomSheetClick: () -> Unit,
onGuaranteesApplyClick: () -> Unit,
onGuaranteeValueChanged: (AccountWithPredictedGuarantee, String) -> Unit,
onGuaranteeValueIncreased: (AccountWithPredictedGuarantee) -> Unit,
Expand All @@ -408,7 +413,7 @@ private fun BottomSheetContent(
GuaranteesSheet(
modifier = modifier,
state = sheetState,
onClose = onGuaranteesCloseClick,
onClose = onCloseBottomSheetClick,
onApplyClick = onGuaranteesApplyClick,
onGuaranteeValueChanged = onGuaranteeValueChanged,
onGuaranteeValueIncreased = onGuaranteeValueIncreased,
Expand All @@ -422,7 +427,7 @@ private fun BottomSheetContent(
state = sheetState,
transactionFees = transactionFees,
insufficientBalanceToPayTheFee = insufficientBalanceToPayTheFee,
onClose = onGuaranteesCloseClick,
onClose = onCloseBottomSheetClick,
onChangeFeePayerClick = onChangeFeePayerClick,
onSelectFeePayerClick = onSelectFeePayerClick,
onPayerSelected = onPayerSelected,
Expand All @@ -433,6 +438,14 @@ private fun BottomSheetContent(
)
}

is State.Sheet.UnknownDAppComponents -> {
UnknownDAppComponentsSheetContent(
modifier = modifier,
onBackClick = onCloseBottomSheetClick,
unknownDAppComponents = sheetState.unknownComponentAddresses
)
}

is State.Sheet.None -> {}
}
}
Expand Down Expand Up @@ -487,10 +500,11 @@ fun TransactionPreviewContentPreview() {
onRawManifestToggle = {},
onMessageShown = {},
onGuaranteesApplyClick = {},
onGuaranteesCloseClick = {},
onCloseBottomSheetClick = {},
promptForGuarantees = {},
onCustomizeClick = {},
onDAppClick = {},
onUnknownDAppsClick = {},
onFungibleResourceClick = { _, _ -> },
onNonFungibleResourceClick = { _, _, _ -> },
onGuaranteeValueChanged = { _, _ -> },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.babylon.wallet.android.presentation.transaction.guarantees.Transactio
import com.babylon.wallet.android.presentation.transaction.submit.TransactionSubmitDelegate
import com.radixdlt.ret.AccountDefaultDepositRule
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import rdx.works.core.mapWhen
Expand Down Expand Up @@ -148,7 +149,9 @@ class TransactionReviewViewModel @Inject constructor(

fun onGuaranteesApplyClick() = guarantees.onApply()

fun onGuaranteesCloseClick() = guarantees.onClose()
fun onCloseBottomSheetClick() {
_state.update { it.copy(sheetState = State.Sheet.None) }
}

fun onCustomizeClick() {
viewModelScope.launch {
Expand Down Expand Up @@ -214,6 +217,12 @@ class TransactionReviewViewModel @Inject constructor(
}
}

fun onUnknownDAppsClick(unknownComponentAddresses: ImmutableList<String>) {
_state.update {
it.copy(sheetState = State.Sheet.UnknownDAppComponents(unknownComponentAddresses))
}
}

fun onFungibleResourceClick(fungibleResource: FungibleResource, isNewlyCreated: Boolean) {
viewModelScope.launch {
sendEvent(Event.OnFungibleClick(fungibleResource, isNewlyCreated))
Expand Down Expand Up @@ -393,6 +402,14 @@ class TransactionReviewViewModel @Inject constructor(
return xrdInCandidateAccount - xrdUsed < transactionFees.transactionFeeToLock
}

val showDottedLine: Boolean
get() = when (previewType) {
is PreviewType.Transfer -> {
previewType.from.isNotEmpty() && previewType.to.isNotEmpty()
}
else -> false
}

sealed interface Sheet {

data object None : Sheet
Expand Down Expand Up @@ -427,6 +444,10 @@ class TransactionReviewViewModel @Inject constructor(
Default, Advanced
}
}

data class UnknownDAppComponents(
val unknownComponentAddresses: ImmutableList<String>
) : Sheet
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.babylon.wallet.android.designsystem.theme.RadixTheme
import com.babylon.wallet.android.domain.model.resources.Resource
import com.babylon.wallet.android.presentation.transaction.PreviewType
import com.babylon.wallet.android.presentation.transaction.TransactionReviewViewModel
import com.babylon.wallet.android.presentation.ui.composables.assets.strokeLine
import com.babylon.wallet.android.presentation.ui.modifier.applyIf
import kotlinx.collections.immutable.toPersistentList

@Composable
Expand Down Expand Up @@ -47,25 +49,28 @@ fun CommonTransferContent(
}
)

middleSection()

DepositAccountContent(
modifier = Modifier.padding(
start = RadixTheme.dimensions.paddingDefault,
end = RadixTheme.dimensions.paddingDefault,
bottom = RadixTheme.dimensions.paddingLarge
),
to = previewType.to.toPersistentList(),
promptForGuarantees = onPromptForGuarantees,
showStrokeLine = true,
onFungibleResourceClick = { fungibleResource, isNewlyCreated ->
onFungibleResourceClick(fungibleResource, isNewlyCreated)
},
onNonFungibleResourceClick = { nonFungibleResource, nonFungibleResourceItem, isNewlyCreated ->
onNonFungibleResourceClick(nonFungibleResource, nonFungibleResourceItem, isNewlyCreated)
}
)
Column(
modifier = Modifier
.applyIf(condition = state.showDottedLine, modifier = Modifier.strokeLine())
.padding(top = RadixTheme.dimensions.paddingXLarge)
) {
middleSection()

DepositAccountContent(
modifier = Modifier.padding(
start = RadixTheme.dimensions.paddingDefault,
end = RadixTheme.dimensions.paddingDefault
),
to = previewType.to.toPersistentList(),
promptForGuarantees = onPromptForGuarantees,
onFungibleResourceClick = { fungibleResource, isNewlyCreated ->
onFungibleResourceClick(fungibleResource, isNewlyCreated)
},
onNonFungibleResourceClick = { nonFungibleResource, nonFungibleResourceItem, isNewlyCreated ->
onNonFungibleResourceClick(nonFungibleResource, nonFungibleResourceItem, isNewlyCreated)
}
)
}
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingLarge))
}
}
Expand Down
Loading

0 comments on commit 2ce93f2

Please sign in to comment.