Updated on 2026-08-14
This commit is contained in:
parent
b88de49ba3
commit
664e71b782
11 changed files with 307 additions and 4 deletions
|
|
@ -22,6 +22,7 @@ internal object NetworkStatusDataModelConverter : Converter<NetworkStatus, Netwo
|
|||
selectedAddress = address.selectedAddress,
|
||||
availableAddresses = address.addresses,
|
||||
amounts = NetworkAmountsConverter.convertBack(value = status.amounts),
|
||||
yieldSupplyStatuses = NetworkYieldSupplyStatusConverter.convertBack(status.yieldSupplyStatuses),
|
||||
)
|
||||
}
|
||||
is NetworkStatus.NoAccount -> {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package com.tangem.data.networks.converters
|
||||
|
||||
import com.tangem.datasource.local.network.entity.NetworkStatusDM
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import com.tangem.utils.converter.TwoWayConverter
|
||||
import com.tangem.utils.extensions.mapNotNullValues
|
||||
|
||||
private typealias YieldSupplyStatusDataModel = Map<String, NetworkStatusDM.YieldSupplyStatus?>
|
||||
private typealias YieldSupplyStatusDomainModel = Map<CryptoCurrency.ID, YieldSupplyStatus?>
|
||||
|
||||
internal object NetworkYieldSupplyStatusConverter :
|
||||
TwoWayConverter<YieldSupplyStatusDataModel, YieldSupplyStatusDomainModel> {
|
||||
|
||||
override fun convert(value: YieldSupplyStatusDataModel): YieldSupplyStatusDomainModel {
|
||||
return value
|
||||
.mapKeys { CryptoCurrency.ID.fromValue(value = it.key) }
|
||||
.mapValues { (_, yieldSupplyStatus) ->
|
||||
if (yieldSupplyStatus != null) {
|
||||
YieldSupplyStatus(
|
||||
isActive = yieldSupplyStatus.isActive,
|
||||
isInitialized = yieldSupplyStatus.isInitialized,
|
||||
isAllowedToSpend = yieldSupplyStatus.isAllowedToSpend,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun convertBack(value: YieldSupplyStatusDomainModel): YieldSupplyStatusDataModel {
|
||||
return value
|
||||
.mapKeys { (id, _) -> id.value }
|
||||
.mapNotNullValues { (_, yieldSupplyStatus) ->
|
||||
if (yieldSupplyStatus != null) {
|
||||
NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = yieldSupplyStatus.isActive,
|
||||
isInitialized = yieldSupplyStatus.isInitialized,
|
||||
isAllowedToSpend = yieldSupplyStatus.isAllowedToSpend,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ internal object SimpleNetworkStatusConverter : Converter<NetworkStatusDM, Simple
|
|||
amounts = NetworkAmountsConverter.convert(value = value.amounts),
|
||||
pendingTransactions = emptyMap(),
|
||||
source = StatusSource.CACHE,
|
||||
yieldSupplyStatuses = NetworkYieldSupplyStatusConverter.convert(value = value.yieldSupplyStatuses),
|
||||
)
|
||||
}
|
||||
is NetworkStatusDM.NoAccount -> {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.tangem.domain.models.network.Network
|
|||
import com.tangem.domain.models.network.NetworkAddress
|
||||
import com.tangem.domain.models.network.NetworkStatus
|
||||
import com.tangem.domain.models.network.NetworkStatus.Amount
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
|
|
@ -59,6 +60,22 @@ internal class NetworkStatusDataModelConverterTest {
|
|||
) to Amount.NotFound,
|
||||
),
|
||||
pendingTransactions = mapOf(), // doesn't matter
|
||||
yieldSupplyStatuses = mapOf(
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "BCH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "bitcoin-cash"),
|
||||
) to YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "BTC"),
|
||||
suffix = ID.Suffix.RawID(rawId = "bitcoin"),
|
||||
) to null,
|
||||
),
|
||||
source = StatusSource.ACTUAL, // doesn't matter
|
||||
),
|
||||
),
|
||||
|
|
@ -76,6 +93,13 @@ internal class NetworkStatusDataModelConverterTest {
|
|||
),
|
||||
),
|
||||
amounts = mapOf("coin⟨BCH⟩bitcoin-cash" to BigDecimal.ZERO),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
"coin⟨BCH⟩bitcoin-cash" to NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// endregion
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
package com.tangem.data.networks.converters
|
||||
|
||||
import com.google.common.truth.Truth
|
||||
import com.tangem.datasource.local.network.entity.NetworkStatusDM
|
||||
import com.tangem.domain.models.currency.CryptoCurrency.ID
|
||||
import com.tangem.domain.models.currency.CryptoCurrency.ID.Body
|
||||
import com.tangem.domain.models.currency.CryptoCurrency.ID.Prefix
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
internal class NetworkYieldSupplyStatusConverterTest {
|
||||
|
||||
@Test
|
||||
fun convert() {
|
||||
// Arrange
|
||||
val value = mapOf(
|
||||
"coin⟨ETH⟩ethereum" to NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
"coin⟨ETH→12367123⟩ethereum" to null,
|
||||
)
|
||||
|
||||
// Act
|
||||
val actual = NetworkYieldSupplyStatusConverter.convert(value)
|
||||
|
||||
// Assert
|
||||
val expected = mapOf(
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "ETH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkIdWithDerivationPath(rawId = "ETH", derivationPathHashCode = 12367123),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to null,
|
||||
)
|
||||
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun convertBack() {
|
||||
// Arrange
|
||||
val value = mapOf(
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "ETH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkIdWithDerivationPath(rawId = "ETH", derivationPathHashCode = 12367123),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to null,
|
||||
)
|
||||
|
||||
// Act
|
||||
val actual = NetworkYieldSupplyStatusConverter.convertBack(value)
|
||||
|
||||
// Assert
|
||||
val expected = mapOf(
|
||||
"coin⟨ETH⟩ethereum" to NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
)
|
||||
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import com.tangem.domain.models.network.Network
|
|||
import com.tangem.domain.models.network.NetworkAddress
|
||||
import com.tangem.domain.models.network.NetworkStatus
|
||||
import com.tangem.domain.models.network.NetworkStatus.Amount
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
|
|
@ -68,6 +69,14 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
"coin⟨BCH⟩bitcoin-cash" to BigDecimal.ZERO,
|
||||
"coin⟨ETH→12367123⟩ethereum" to BigDecimal.ONE,
|
||||
),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
"coin⟨ETH⟩ethereum" to NetworkStatusDM.YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
"coin⟨ETH⟩ethereum" to null,
|
||||
),
|
||||
),
|
||||
expected = SimpleNetworkStatus(
|
||||
id = Network.ID(
|
||||
|
|
@ -104,6 +113,22 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
) to Amount.Loaded(value = BigDecimal.ONE),
|
||||
),
|
||||
pendingTransactions = emptyMap(),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "ETH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "ETH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to null,
|
||||
),
|
||||
source = StatusSource.CACHE,
|
||||
),
|
||||
).let(Result.Companion::success),
|
||||
|
|
@ -178,6 +203,7 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
),
|
||||
),
|
||||
amounts = emptyMap(),
|
||||
yieldSupplyStatuses = emptyMap(),
|
||||
),
|
||||
expected = Result.failure(
|
||||
exception = IllegalArgumentException("Selected address must not be null"),
|
||||
|
|
@ -193,6 +219,7 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
selectedAddress = "0x1",
|
||||
availableAddresses = setOf(),
|
||||
amounts = emptyMap(),
|
||||
yieldSupplyStatuses = emptyMap(),
|
||||
),
|
||||
expected = Result.failure(
|
||||
exception = IllegalArgumentException("Selected address must not be null"),
|
||||
|
|
@ -217,6 +244,7 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
),
|
||||
),
|
||||
amounts = emptyMap(),
|
||||
yieldSupplyStatuses = emptyMap(),
|
||||
),
|
||||
expected = Result.failure(
|
||||
exception = IllegalArgumentException("Selected address must not be null"),
|
||||
|
|
|
|||
|
|
@ -149,6 +149,11 @@ internal class CommonNetworkStatusFetcherTest {
|
|||
pendingTransactions = mapOf(
|
||||
CryptoCurrency.ID.fromValue(value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND") to emptySet(),
|
||||
),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
CryptoCurrency.ID.fromValue(
|
||||
value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND",
|
||||
) to null,
|
||||
),
|
||||
)
|
||||
},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.tangem.domain.models.network.NetworkAddress
|
|||
import com.tangem.domain.models.network.NetworkStatus
|
||||
import com.tangem.domain.models.network.NetworkStatus.Amount
|
||||
import com.tangem.domain.models.network.TxInfo
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
|
@ -222,6 +223,57 @@ internal class NetworkStatusFactoryTest(private val model: Model) {
|
|||
currencies.last().id to setOf(),
|
||||
),
|
||||
source = StatusSource.ACTUAL,
|
||||
yieldSupplyStatuses = mapOf(),
|
||||
),
|
||||
),
|
||||
createSuccess(
|
||||
result = updateWalletManagerResultFactory.createVerifiedWithToken(),
|
||||
currencies = currencies,
|
||||
status = NetworkStatus.Verified(
|
||||
address = NetworkAddress.Single(
|
||||
defaultAddress = NetworkAddress.Address(
|
||||
value = "0x1",
|
||||
type = NetworkAddress.Address.Type.Primary,
|
||||
),
|
||||
),
|
||||
amounts = mapOf(
|
||||
currencies.first().id to Amount.Loaded(BigDecimal.ONE),
|
||||
currencies.last().id to Amount.NotFound,
|
||||
),
|
||||
pendingTransactions = mapOf(
|
||||
currencies.first().id to setOf(txInfo),
|
||||
currencies.last().id to setOf(txInfo),
|
||||
),
|
||||
source = StatusSource.ACTUAL,
|
||||
yieldSupplyStatuses = mapOf(),
|
||||
),
|
||||
),
|
||||
createSuccess(
|
||||
result = updateWalletManagerResultFactory.createVerifiedWithSuppliedToken(),
|
||||
currencies = currencies,
|
||||
status = NetworkStatus.Verified(
|
||||
address = NetworkAddress.Single(
|
||||
defaultAddress = NetworkAddress.Address(
|
||||
value = "0x1",
|
||||
type = NetworkAddress.Address.Type.Primary,
|
||||
),
|
||||
),
|
||||
amounts = mapOf(
|
||||
currencies.first().id to Amount.Loaded(BigDecimal.ONE),
|
||||
currencies.last().id to Amount.NotFound,
|
||||
),
|
||||
pendingTransactions = mapOf(
|
||||
currencies.first().id to setOf(txInfo),
|
||||
currencies.last().id to setOf(txInfo),
|
||||
),
|
||||
source = StatusSource.ACTUAL,
|
||||
yieldSupplyStatuses = mapOf(
|
||||
currencies.first().id to YieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// endregion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue