Skip to content

Commit

Permalink
Fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
micbakos-rdx committed Jun 26, 2024
1 parent 3557529 commit 2dd5e5b
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ data class MetadataColumn(
*/
@Serializable
@SerialName("unknown")
data object Unknown: ImplicitMetadataState
data object Unknown : ImplicitMetadataState

/**
* We have received an answer from a details request and we know that the [MetadataColumn.metadata]
* are complete.
*/
@Serializable
@SerialName("complete")
data object Complete: ImplicitMetadataState
data object Complete : ImplicitMetadataState

/**
* We have received an answer from a details request and we know that the [MetadataColumn.metadata]
Expand All @@ -76,7 +76,7 @@ data class MetadataColumn(
data class Incomplete(
@SerialName("next_cursor")
val nextCursor: String
): ImplicitMetadataState
) : ImplicitMetadataState
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ data class ResourceEntity(
)
}

@Suppress("LongParameterList")
private fun from(
address: ResourceAddress,
explicitMetadata: EntityMetadataCollection?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ interface StateDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertDApps(dApps: List<DAppEntity>)


@Query(
"""
UPDATE ResourceEntity SET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,62 +233,47 @@ class AccountsStateCache @Inject constructor(
result
}

private fun Flow<MutableMap<AccountAddress, AccountCachedData>>.compileAccountAddressAssets(): Flow<List<AccountAddressWithAssets>> =
transform { cached ->
val stateVersion = cached.values.mapNotNull { it.stateVersion }.maxOrNull() ?: run {
emit(emptyList())
return@transform
private fun Flow<MutableMap<AccountAddress, AccountCachedData>>.compileAccountAddressAssets() = transform { cached ->
val stateVersion = cached.values.mapNotNull { it.stateVersion }.maxOrNull() ?: run {
emit(emptyList())
return@transform
}

val allValidatorAddresses = cached.map { it.value.validatorAddresses() }.flatten().toSet()
val cachedValidators = dao.getCachedValidators(allValidatorAddresses, stateVersion).toMutableMap()
val newValidators = runCatching {
val validatorItems = api.fetchValidators(
allValidatorAddresses - cachedValidators.keys,
stateVersion
).validators

val syncInfo = SyncInfo(InstantGenerator(), stateVersion)
validatorItems.map {
it.asValidatorEntity(syncInfo)
}.onEach { entity ->
cachedValidators[entity.address] = entity.asValidatorDetail()
}
}.onFailure { cacheErrors.value = it }.getOrNull() ?: return@transform

val allValidatorAddresses = cached.map { it.value.validatorAddresses() }.flatten().toSet()
val cachedValidators = dao.getCachedValidators(allValidatorAddresses, stateVersion).toMutableMap()
val newValidators = runCatching {
val validatorItems = api.fetchValidators(
allValidatorAddresses - cachedValidators.keys,
stateVersion
).validators

val syncInfo = SyncInfo(InstantGenerator(), stateVersion)
validatorItems.map {
it.asValidatorEntity(syncInfo)
}.onEach { entity ->
cachedValidators[entity.address] = entity.asValidatorDetail()
}
if (newValidators.isNotEmpty()) {
logger.d("\uD83D\uDCBD Inserting validators")
dao.insertValidators(newValidators)
}

val allPoolAddresses = cached.map { it.value.poolAddresses() }.flatten().toSet()
val cachedPools = dao.getCachedPools(allPoolAddresses, stateVersion).toMutableMap()
val unknownPools = allPoolAddresses - cachedPools.keys
if (unknownPools.isNotEmpty()) {
logger.d("\uD83D\uDCBD Inserting pools")
val newPools = runCatching {
api.fetchPools(unknownPools.toSet(), stateVersion)
}.onFailure { error ->
cacheErrors.value = error
}.getOrNull() ?: return@transform

if (newValidators.isNotEmpty()) {
logger.d("\uD83D\uDCBD Inserting validators")
dao.insertValidators(newValidators)
}

val allPoolAddresses = cached.map { it.value.poolAddresses() }.flatten().toSet()
val cachedPools = dao.getCachedPools(allPoolAddresses, stateVersion).toMutableMap()
val unknownPools = allPoolAddresses - cachedPools.keys
if (unknownPools.isNotEmpty()) {
logger.d("\uD83D\uDCBD Inserting pools")

val newPools = runCatching {
api.fetchPools(unknownPools.toSet(), stateVersion)
}.onFailure { error ->
cacheErrors.value = error
}.getOrNull() ?: return@transform

if (newPools.poolItems.isNotEmpty()) {
val join = newPools.poolItems.asPoolsResourcesJoin(SyncInfo(InstantGenerator(), stateVersion))
dao.updatePools(pools = join)
} else {
emit(
cached.mapNotNull {
it.value.toAccountAddressWithAssets(
accountAddress = it.key,
pools = cachedPools,
validators = cachedValidators
)
}
)
}
if (newPools.poolItems.isNotEmpty()) {
val join = newPools.poolItems.asPoolsResourcesJoin(SyncInfo(InstantGenerator(), stateVersion))
dao.updatePools(pools = join)
} else {
emit(
cached.mapNotNull {
Expand All @@ -300,7 +285,18 @@ class AccountsStateCache @Inject constructor(
}
)
}
} else {
emit(
cached.mapNotNull {
it.value.toAccountAddressWithAssets(
accountAddress = it.key,
pools = cachedPools,
validators = cachedValidators
)
}
)
}
}

private data class AccountCachedData(
val stateVersion: Long?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class StateRepositoryImpl @Inject constructor(
} else {
cachedValidators
}
}.mapCatching { entities ->
}.mapCatching { entities ->
entities.map { it.asValidatorDetail() }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,21 @@ fun MetadataValueView(
},
style = RadixTheme.typography.body1StandaloneLink,
color = RadixTheme.colors.blue1,
inlineContent = mapOf("link_icon" to InlineTextContent(
Placeholder(
RadixTheme.typography.body1StandaloneLink.fontSize,
RadixTheme.typography.body1StandaloneLink.fontSize,
PlaceholderVerticalAlign.TextCenter
)
) {
Icon(
painter = painterResource(id = R.drawable.ic_external_link),
contentDescription = null,
tint = color
)
})
inlineContent = mapOf(
"link_icon" to InlineTextContent(
Placeholder(
RadixTheme.typography.body1StandaloneLink.fontSize,
RadixTheme.typography.body1StandaloneLink.fontSize,
PlaceholderVerticalAlign.TextCenter
)
) {
Icon(
painter = painterResource(id = R.drawable.ic_external_link),
contentDescription = null,
tint = color
)
}
)
)
}
}
Expand All @@ -297,6 +299,6 @@ fun MetadataValueView(
private const val ASSET_METADATA_SHORT_STRING_THRESHOLD = 40
private val Metadata.isRenderedInNewLine: Boolean
get() = this is Metadata.Primitive && (
valueType is MetadataType.Url ||
(valueType is MetadataType.String && value.length > ASSET_METADATA_SHORT_STRING_THRESHOLD)
)
valueType is MetadataType.Url ||
(valueType is MetadataType.String && value.length > ASSET_METADATA_SHORT_STRING_THRESHOLD)
)
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ fun DescriptionSection(
HorizontalDivider(Modifier.fillMaxWidth(), color = RadixTheme.colors.gray4)
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingDefault))
}

}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,9 @@ fun FungibleDialogContent(
),
horizontalAlignment = Alignment.CenterHorizontally
) {
if (token?.resource != null) {
Thumbnail.Fungible(
modifier = Modifier.size(104.dp),
token = token.resource
)
} else {
Box(
modifier = Modifier
.size(104.dp)
.radixPlaceholder(
visible = true,
shape = CircleShape
)
)
}
FungibleIconSection(token = token)
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingDefault))

if (amount != null) {
TokenBalance(
modifier = Modifier
Expand Down Expand Up @@ -169,3 +156,25 @@ fun FungibleDialogContent(
}
}
}

@Composable
private fun FungibleIconSection(
modifier: Modifier = Modifier,
token: Token?
) {
if (token?.resource != null) {
Thumbnail.Fungible(
modifier = modifier.size(104.dp),
token = token.resource
)
} else {
Box(
modifier = modifier
.size(104.dp)
.radixPlaceholder(
visible = true,
shape = CircleShape
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,9 @@ fun LSUDialogContent(
),
horizontalAlignment = Alignment.CenterHorizontally
) {
if (lsu != null) {
Thumbnail.LSU(
modifier = Modifier.size(104.dp),
liquidStakeUnit = lsu
)
} else {
Box(
modifier = Modifier
.size(104.dp)
.radixPlaceholder(
visible = true,
shape = CircleShape
)
)
}
LSUIconSection(lsu = lsu)
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingDefault))

TokenBalance(
modifier = Modifier
.fillMaxWidth(fraction = if (lsu == null) 0.5f else 1f)
Expand Down Expand Up @@ -238,6 +225,28 @@ fun LSUDialogContent(
}
}

@Composable
private fun LSUIconSection(
modifier: Modifier = Modifier,
lsu: LiquidStakeUnit?
) {
if (lsu != null) {
Thumbnail.LSU(
modifier = modifier.size(104.dp),
liquidStakeUnit = lsu
)
} else {
Box(
modifier = modifier
.size(104.dp)
.radixPlaceholder(
visible = true,
shape = CircleShape
)
)
}
}

@Composable
private fun LSUResourceValue(
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

package com.babylon.wallet.android.presentation.ui.composables.actionableaddress

import android.content.ClipData
import android.content.Context
import android.net.Uri
import android.os.Build
import android.widget.Toast
import androidx.annotation.DrawableRes
import androidx.annotation.VisibleForTesting
Expand Down Expand Up @@ -45,7 +43,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import com.babylon.wallet.android.R
import com.babylon.wallet.android.designsystem.theme.RadixTheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ class SearchFeePayersUseCaseTest {
override suspend fun getResources(
addresses: Set<ResourceAddress>,
underAccountAddress: AccountAddress?,
withDetails: Boolean
withDetails: Boolean,
withAllMetadata: Boolean
): Result<List<Resource>> {
TODO("Not yet implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,23 @@ open class StateRepositoryFake : StateRepository {
override suspend fun updateStakeClaims(account: Account, claims: List<StakeClaim>): Result<List<StakeClaim>> =
Result.success(claims)

override suspend fun getResources(addresses: Set<ResourceAddress>, underAccountAddress: AccountAddress?, withDetails: Boolean): Result<List<Resource>> =
override suspend fun getResources(
addresses: Set<ResourceAddress>,
underAccountAddress: AccountAddress?,
withDetails: Boolean,
withAllMetadata: Boolean
): Result<List<Resource>> =
Result.failure(RuntimeException("Not implemented"))

override suspend fun getPools(poolAddresses: Set<PoolAddress>): Result<List<Pool>> = Result.failure(RuntimeException("Not implemented"))

override suspend fun getValidators(validatorAddresses: Set<ValidatorAddress>): Result<List<Validator>> =
Result.failure(RuntimeException("Not implemented"))

override suspend fun getNFTDetails(resourceAddress: ResourceAddress, localIds: Set<NonFungibleLocalId>): Result<List<Resource.NonFungibleResource.Item>> =
override suspend fun getNFTDetails(
resourceAddress: ResourceAddress,
localIds: Set<NonFungibleLocalId>
): Result<List<Resource.NonFungibleResource.Item>> =
Result.failure(RuntimeException("Not implemented"))

override suspend fun getOwnedXRD(accounts: List<Account>): Result<Map<Account, Decimal192>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ class DAppAuthorizedLoginViewModelTest : StateViewModelTest<DAppAuthorizedLoginV
override suspend fun getResources(
addresses: Set<ResourceAddress>,
underAccountAddress: AccountAddress?,
withDetails: Boolean
withDetails: Boolean,
withAllMetadata: Boolean
): Result<List<Resource>> {
TODO("Not yet implemented")
}
Expand Down

0 comments on commit 2dd5e5b

Please sign in to comment.