Skip to content

Commit

Permalink
Implement estimated text
Browse files Browse the repository at this point in the history
  • Loading branch information
micbakos-rdx committed Feb 21, 2025
1 parent 03a5fe6 commit 27ca6b0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import rdx.works.core.domain.resources.Resource

data class NonFungibleAmount(
val certain: List<Resource.NonFungibleResource.Item>,
val predicted: List<Resource.NonFungibleResource.Item> = emptyList(),
val additional: BoundedAmount? = null
) {

fun isPredicted(item: Resource.NonFungibleResource.Item): Boolean = predicted.any { it.globalId == item.globalId }

init {
additional?.let {
require(it !is BoundedAmount.Predicted) { "Predicted additional amount not supported for non-fungibles" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.radixdlt.sargon.ExecutionSummary
import com.radixdlt.sargon.FungibleResourceIndicator
import com.radixdlt.sargon.NewlyCreatedResource
import com.radixdlt.sargon.NonFungibleGlobalId
import com.radixdlt.sargon.NonFungibleResourceIndicator
import com.radixdlt.sargon.Profile
import com.radixdlt.sargon.ResourceIndicator
import com.radixdlt.sargon.ResourceOrNonFungible
Expand Down Expand Up @@ -266,13 +267,25 @@ private fun ResourceIndicator.Fungible.amount(
private fun ResourceIndicator.NonFungible.amount(asset: Asset.NonFungible): NonFungibleAmount {
val onLedgerItems = asset.resource.items

val items = indicator.ids.map { localId ->
onLedgerItems.find { it.localId == localId } ?: Item(
collectionAddress = asset.resource.address, localId = localId
return when (val ind = indicator) {
is NonFungibleResourceIndicator.Guaranteed -> NonFungibleAmount(
certain = ind.ids.map { localId ->
onLedgerItems.find { it.localId == localId } ?: Item(
collectionAddress = asset.resource.address, localId = localId
)
},
additional = null
)
is NonFungibleResourceIndicator.Predicted -> NonFungibleAmount(
certain = emptyList(),
predicted = ind.predictedIds.value.map { localId ->
onLedgerItems.find { it.localId == localId } ?: Item(
collectionAddress = asset.resource.address, localId = localId
)
},
additional = null
)
}

return NonFungibleAmount(certain = items)
}

private fun ExecutionSummary.resolveAsset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ fun TransactionAccountCard(
item,
hiddenResourceIds
) { item.collectionAddress in hiddenResourceIds.nonFungibles() },
isEstimated = remember(transferable.amount, item) {
transferable.amount.isPredicted(item)
},
hiddenResourceWarning = hiddenResourceWarning
)

Expand Down Expand Up @@ -172,6 +175,7 @@ fun TransactionAccountCard(
.padding(vertical = RadixTheme.dimensions.paddingMedium)
.throttleClickable { onTransferableNonFungibleByAmountClick(transferable, amount) },
transferableStakeClaim = transferable,
isEstimated = false,
additionalAmount = amount
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fun TransferableNonFungibleItemContent(
transferableNFTCollection: Transferable.NonFungibleType.NFTCollection,
nftItem: Resource.NonFungibleResource.Item,
isHidden: Boolean,
isEstimated: Boolean,
hiddenResourceWarning: String
) {
TransferableNonFungibleContent(
Expand All @@ -54,6 +55,7 @@ fun TransferableNonFungibleItemContent(
nftItem = nftItem,
additionalAmount = null,
isHidden = isHidden,
isEstimated = isEstimated,
hiddenResourceWarning = hiddenResourceWarning
)
}
Expand All @@ -74,6 +76,7 @@ fun TransferableNonFungibleAmountContent(
nftItem = null,
additionalAmount = amount,
isHidden = isHidden,
isEstimated = false,
hiddenResourceWarning = hiddenResourceWarning
)
}
Expand All @@ -86,6 +89,7 @@ private fun TransferableNonFungibleContent(
nftItem: Resource.NonFungibleResource.Item?,
additionalAmount: BoundedAmount?,
isHidden: Boolean,
isEstimated: Boolean,
hiddenResourceWarning: String
) {
Column(
Expand Down Expand Up @@ -135,10 +139,19 @@ private fun TransferableNonFungibleContent(
)
}

additionalAmount?.let {
Spacer(modifier = Modifier.width(RadixTheme.dimensions.paddingMedium))
if (isEstimated) {
Text(
modifier = Modifier.padding(horizontal = RadixTheme.dimensions.paddingMedium),
text = stringResource(R.string.interactionReview_estimated),
color = RadixTheme.colors.gray1,
style = RadixTheme.typography.body3Regular
)
} else {
additionalAmount?.let {
Spacer(modifier = Modifier.width(RadixTheme.dimensions.paddingMedium))

BoundedAmountSection(boundedAmount = it)
BoundedAmountSection(boundedAmount = it)
}
}
}

Expand Down Expand Up @@ -179,6 +192,7 @@ private fun TransferableNftItemPreview() {
nftItem = Resource.NonFungibleResource.sampleMainnet().items.first(),
shape = RectangleShape,
isHidden = false,
isEstimated = false,
hiddenResourceWarning = stringResource(id = R.string.interactionReview_hiddenAsset_deposit),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ fun TransferableStakeClaimNftItemContent(
) {
TransferableStakeClaimItemHeader(
transferableStakeClaim = transferableStakeClaim,
isEstimated = remember(transferableStakeClaim.amount, item) {
transferableStakeClaim.amount.isPredicted(item)
},
additionalAmount = null
)

Expand Down Expand Up @@ -103,8 +106,6 @@ fun TransferableStakeClaimNftItemContent(
Row(
verticalAlignment = CenterVertically,
) {
Spacer(modifier = Modifier.width(RadixTheme.dimensions.paddingMedium))

Icon(
painter = painterResource(id = com.babylon.wallet.android.designsystem.R.drawable.ic_xrd_token),
contentDescription = null,
Expand Down Expand Up @@ -136,6 +137,14 @@ fun TransferableStakeClaimNftItemContent(
maxLines = 2
)
}

if (item.claimAmountXrd == null) {
UnknownAmount(
modifier = Modifier
.padding(top = RadixTheme.dimensions.paddingSmall),
amount = BoundedAmount.Unknown
)
}
}
}
}
Expand All @@ -157,10 +166,11 @@ fun TransferableStakeClaimNftItemContent(
fun TransferableStakeClaimItemHeader(
modifier: Modifier = Modifier,
transferableStakeClaim: Transferable.NonFungibleType.StakeClaim,
isEstimated: Boolean,
additionalAmount: BoundedAmount?
) {
Column(
modifier = modifier.padding(horizontal = RadixTheme.dimensions.paddingMedium)
modifier = modifier.padding(horizontal = RadixTheme.dimensions.paddingDefault)
) {
Row(
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -192,10 +202,19 @@ fun TransferableStakeClaimItemHeader(
)
}

additionalAmount?.let {
Spacer(modifier = Modifier.width(RadixTheme.dimensions.paddingMedium))
if (isEstimated) {
Text(
modifier = Modifier.padding(horizontal = RadixTheme.dimensions.paddingMedium),
text = stringResource(R.string.interactionReview_estimated),
color = RadixTheme.colors.gray1,
style = RadixTheme.typography.body3Regular
)
} else {
additionalAmount?.let {
Spacer(modifier = Modifier.width(RadixTheme.dimensions.paddingMedium))

BoundedAmountSection(boundedAmount = it)
BoundedAmountSection(boundedAmount = it)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ data class RadixTypography(
var body2Header: TextStyle = bold.copy(fontSize = 14.sp, lineHeight = 18.sp),
var body2HighImportance: TextStyle = medium.copy(fontSize = 14.sp, lineHeight = 18.sp),
var body2Regular: TextStyle = regular.copy(fontSize = 14.sp, lineHeight = 18.sp),
var body3Regular: TextStyle = regular.copy(fontSize = 12.sp, lineHeight = 23.sp),
var body2Link: TextStyle = medium.copy(fontSize = 14.sp, lineHeight = 18.sp),
var button: TextStyle = bold.copy(fontSize = 16.sp, lineHeight = 18.sp),
) {
Expand Down

0 comments on commit 27ca6b0

Please sign in to comment.