Updated on 2026-08-14
This commit is contained in:
parent
fdfb07ee33
commit
f3bbae831a
13 changed files with 59 additions and 58 deletions
|
|
@ -1,13 +1,13 @@
|
|||
package com.tangem.data.networks.converters
|
||||
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyAmountStatus
|
||||
import com.tangem.domain.tokens.model.NetworkStatus
|
||||
import com.tangem.utils.converter.TwoWayConverter
|
||||
import com.tangem.utils.extensions.mapNotNullValues
|
||||
import java.math.BigDecimal
|
||||
|
||||
private typealias AmountsDataModel = Map<String, BigDecimal>
|
||||
private typealias AmountsDomainModel = Map<CryptoCurrency.ID, CryptoCurrencyAmountStatus>
|
||||
private typealias AmountsDomainModel = Map<CryptoCurrency.ID, NetworkStatus.Amount>
|
||||
|
||||
/**
|
||||
* Converter from [AmountsDataModel] to [AmountsDomainModel] and vice versa
|
||||
|
|
@ -19,7 +19,7 @@ internal object NetworkAmountsConverter : TwoWayConverter<AmountsDataModel, Amou
|
|||
override fun convert(value: AmountsDataModel): AmountsDomainModel {
|
||||
return value
|
||||
.mapKeys { CryptoCurrency.ID.fromValue(value = it.key) }
|
||||
.mapValues { (_, amount) -> CryptoCurrencyAmountStatus.Loaded(value = amount) }
|
||||
.mapValues { (_, amount) -> NetworkStatus.Amount.Loaded(value = amount) }
|
||||
}
|
||||
|
||||
override fun convertBack(value: AmountsDomainModel): AmountsDataModel {
|
||||
|
|
@ -27,8 +27,8 @@ internal object NetworkAmountsConverter : TwoWayConverter<AmountsDataModel, Amou
|
|||
.mapKeys { (id, _) -> id.value }
|
||||
.mapNotNullValues { (_, amount) ->
|
||||
when (amount) {
|
||||
is CryptoCurrencyAmountStatus.Loaded -> amount.value
|
||||
is CryptoCurrencyAmountStatus.NotFound -> null
|
||||
is NetworkStatus.Amount.Loaded -> amount.value
|
||||
is NetworkStatus.Amount.NotFound -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import com.tangem.domain.models.StatusSource
|
|||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.network.TxInfo
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyAmountStatus
|
||||
import com.tangem.domain.tokens.model.NetworkAddress
|
||||
import com.tangem.domain.tokens.model.NetworkStatus
|
||||
import com.tangem.domain.walletmanager.model.Address
|
||||
|
|
@ -89,7 +88,7 @@ object NetworkStatusFactory {
|
|||
private fun formatAmounts(
|
||||
amounts: Set<CryptoCurrencyAmount>,
|
||||
currencies: Set<CryptoCurrency>,
|
||||
): Map<CryptoCurrency.ID, CryptoCurrencyAmountStatus> {
|
||||
): Map<CryptoCurrency.ID, NetworkStatus.Amount> {
|
||||
return currencies.associate { currency ->
|
||||
val amount = when (currency) {
|
||||
is CryptoCurrency.Coin -> {
|
||||
|
|
@ -106,9 +105,9 @@ object NetworkStatusFactory {
|
|||
|
||||
if (amount == null) {
|
||||
Timber.w("Unable to find amount for cryptocurrency: $currency")
|
||||
currency.id to CryptoCurrencyAmountStatus.NotFound
|
||||
currency.id to NetworkStatus.Amount.NotFound
|
||||
} else {
|
||||
currency.id to CryptoCurrencyAmountStatus.Loaded(amount.value)
|
||||
currency.id to NetworkStatus.Amount.Loaded(amount.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import com.google.common.truth.Truth
|
|||
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.tokens.model.CryptoCurrencyAmountStatus
|
||||
import com.tangem.domain.tokens.model.NetworkStatus.Amount
|
||||
import com.tangem.domain.tokens.model.NetworkStatus.Amount.Loaded
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.math.BigDecimal
|
||||
|
||||
|
|
@ -30,12 +31,12 @@ internal class NetworkAmountsConverterTest {
|
|||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "BCH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "bitcoin-cash"),
|
||||
) to CryptoCurrencyAmountStatus.Loaded(value = BigDecimal.ZERO),
|
||||
) to Loaded(value = BigDecimal.ZERO),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkIdWithDerivationPath(rawId = "ETH", derivationPathHashCode = 12367123),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to CryptoCurrencyAmountStatus.Loaded(value = BigDecimal.ONE),
|
||||
) to Loaded(value = BigDecimal.ONE),
|
||||
)
|
||||
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
|
|
@ -49,17 +50,17 @@ internal class NetworkAmountsConverterTest {
|
|||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "BCH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "bitcoin-cash"),
|
||||
) to CryptoCurrencyAmountStatus.Loaded(value = BigDecimal.ZERO),
|
||||
) to Loaded(value = BigDecimal.ZERO),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkIdWithDerivationPath(rawId = "ETH", derivationPathHashCode = 12367123),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to CryptoCurrencyAmountStatus.Loaded(value = BigDecimal.ONE),
|
||||
) to Loaded(value = BigDecimal.ONE),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "BTC"),
|
||||
suffix = ID.Suffix.RawID(rawId = "bitcoin"),
|
||||
) to CryptoCurrencyAmountStatus.NotFound,
|
||||
) to Amount.NotFound,
|
||||
)
|
||||
|
||||
// Act
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ 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.network.Network
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyAmountStatus
|
||||
import com.tangem.domain.tokens.model.NetworkAddress
|
||||
import com.tangem.domain.tokens.model.NetworkStatus
|
||||
import com.tangem.domain.tokens.model.NetworkStatus.Amount
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
|
|
@ -51,12 +51,12 @@ internal class NetworkStatusDataModelConverterTest {
|
|||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "BCH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "bitcoin-cash"),
|
||||
) to CryptoCurrencyAmountStatus.Loaded(value = BigDecimal.ZERO),
|
||||
) to Amount.Loaded(value = BigDecimal.ZERO),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "BTC"),
|
||||
suffix = ID.Suffix.RawID(rawId = "bitcoin"),
|
||||
) to CryptoCurrencyAmountStatus.NotFound,
|
||||
) to Amount.NotFound,
|
||||
),
|
||||
pendingTransactions = mapOf(), // doesn't matter
|
||||
source = StatusSource.ACTUAL, // doesn't matter
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ 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.network.Network
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyAmountStatus
|
||||
import com.tangem.domain.tokens.model.NetworkAddress
|
||||
import com.tangem.domain.tokens.model.NetworkStatus
|
||||
import com.tangem.domain.tokens.model.NetworkStatus.Amount
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
|
|
@ -96,12 +96,12 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkId(rawId = "BCH"),
|
||||
suffix = ID.Suffix.RawID(rawId = "bitcoin-cash"),
|
||||
) to CryptoCurrencyAmountStatus.Loaded(value = BigDecimal.ZERO),
|
||||
) to Amount.Loaded(value = BigDecimal.ZERO),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
body = Body.NetworkIdWithDerivationPath(rawId = "ETH", derivationPathHashCode = 12367123),
|
||||
suffix = ID.Suffix.RawID(rawId = "ethereum"),
|
||||
) to CryptoCurrencyAmountStatus.Loaded(value = BigDecimal.ONE),
|
||||
) to Amount.Loaded(value = BigDecimal.ONE),
|
||||
),
|
||||
pendingTransactions = emptyMap(),
|
||||
source = StatusSource.CACHE,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import com.tangem.data.networks.store.NetworksStatusesStoreV2
|
|||
import com.tangem.data.networks.store.setSourceAsOnlyCache
|
||||
import com.tangem.data.networks.store.storeStatus
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyAmountStatus
|
||||
import com.tangem.domain.tokens.model.NetworkAddress
|
||||
import com.tangem.domain.tokens.model.NetworkStatus
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
|
|
@ -144,7 +143,7 @@ internal class CommonNetworkStatusFetcherTest {
|
|||
amounts = mapOf(
|
||||
CryptoCurrency.ID.fromValue(
|
||||
value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND",
|
||||
) to CryptoCurrencyAmountStatus.NotFound,
|
||||
) to NetworkStatus.Amount.NotFound,
|
||||
),
|
||||
pendingTransactions = mapOf(
|
||||
CryptoCurrency.ID.fromValue(value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND") to emptySet(),
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import com.tangem.domain.models.StatusSource
|
|||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.network.TxInfo
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyAmountStatus
|
||||
import com.tangem.domain.tokens.model.NetworkAddress
|
||||
import com.tangem.domain.tokens.model.NetworkStatus
|
||||
import com.tangem.domain.tokens.model.NetworkStatus.Amount
|
||||
import com.tangem.domain.walletmanager.model.Address
|
||||
import com.tangem.domain.walletmanager.model.UpdateWalletManagerResult
|
||||
import org.junit.Test
|
||||
|
|
@ -214,8 +214,8 @@ internal class NetworkStatusFactoryTest(private val model: Model) {
|
|||
),
|
||||
),
|
||||
amounts = mapOf(
|
||||
currencies.first().id to CryptoCurrencyAmountStatus.Loaded(BigDecimal.ONE),
|
||||
currencies.last().id to CryptoCurrencyAmountStatus.NotFound,
|
||||
currencies.first().id to Amount.Loaded(BigDecimal.ONE),
|
||||
currencies.last().id to Amount.NotFound,
|
||||
),
|
||||
pendingTransactions = mapOf(
|
||||
currencies.first().id to setOf(txInfo),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue