Updated on 2026-08-14

This commit is contained in:
Tangem 2026-04-09 18:57:53 +04:00
parent b58be5612e
commit 8966e28e29
55 changed files with 572 additions and 192 deletions

View file

@ -1,5 +1,6 @@
package com.tangem.data.networks.converters
import com.tangem.blockchainsdk.utils.toBlockchain
import com.tangem.datasource.local.network.entity.NetworkStatusDM
import com.tangem.domain.models.network.NetworkStatus
import com.tangem.utils.converter.Converter
@ -15,17 +16,18 @@ internal object NetworkStatusDataModelConverter : Converter<NetworkStatus, Netwo
return when (val status = value.value) {
is NetworkStatus.Verified -> {
val address = NetworkAddressConverter.convertBack(value = status.address)
val blockchainId = value.network.toBlockchain().id
val amountsConverter = NetworkAmountsConverter(
rawNetworkId = value.network.rawId,
rawNetworkId = blockchainId,
derivationPath = value.network.derivationPath,
)
val yieldSupplyStatusConverter = NetworkYieldSupplyStatusConverter(
rawNetworkId = value.network.rawId,
rawNetworkId = blockchainId,
derivationPath = value.network.derivationPath,
)
NetworkStatusDM.Verified(
networkId = NetworkStatusDM.ID(value = value.network.rawId),
networkId = NetworkStatusDM.ID(value = blockchainId),
derivationPath = NetworkDerivationPathConverter.convertBack(value = value.network.derivationPath),
selectedAddress = address.selectedAddress,
availableAddresses = address.addresses,
@ -35,9 +37,10 @@ internal object NetworkStatusDataModelConverter : Converter<NetworkStatus, Netwo
}
is NetworkStatus.NoAccount -> {
val address = NetworkAddressConverter.convertBack(value = status.address)
val blockchainId = value.network.toBlockchain().id
NetworkStatusDM.NoAccount(
networkId = NetworkStatusDM.ID(value = value.network.rawId),
networkId = NetworkStatusDM.ID(value = blockchainId),
derivationPath = NetworkDerivationPathConverter.convertBack(value = value.network.derivationPath),
selectedAddress = address.selectedAddress,
availableAddresses = address.addresses,

View file

@ -1,5 +1,7 @@
package com.tangem.data.networks.converters
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchainsdk.utils.toNetworkId
import com.tangem.data.networks.models.SimpleNetworkStatus
import com.tangem.datasource.local.network.entity.NetworkStatusDM
import com.tangem.domain.models.StatusSource
@ -23,14 +25,15 @@ internal object SimpleNetworkStatusConverter : Converter<NetworkStatusDM, Simple
)
val derivationPath = NetworkDerivationPathConverter.convert(value = value.derivationPath)
val rawNetworkId = value.networkId.value
val amountsConverter = NetworkAmountsConverter(
rawNetworkId = value.networkId.value,
rawNetworkId = rawNetworkId,
derivationPath = derivationPath,
)
val yieldSupplyStatusConverter = NetworkYieldSupplyStatusConverter(
rawNetworkId = value.networkId.value,
rawNetworkId = rawNetworkId,
derivationPath = derivationPath,
)
@ -54,9 +57,11 @@ internal object SimpleNetworkStatusConverter : Converter<NetworkStatusDM, Simple
}
}
val rawId = Blockchain.fromId(rawNetworkId).toNetworkId()
return SimpleNetworkStatus(
id = Network.ID(
value = value.networkId.value,
value = rawId,
derivationPath = NetworkDerivationPathConverter.convert(value = value.derivationPath),
),
value = status,

View file

@ -2,6 +2,7 @@ package com.tangem.data.networks.store
import android.content.Context
import androidx.datastore.core.DataStore
import com.tangem.blockchainsdk.utils.toBlockchain
import com.tangem.data.networks.converters.NetworkStatusDataModelConverter
import com.tangem.data.networks.converters.SimpleNetworkStatusConverter
import com.tangem.data.networks.models.SimpleNetworkStatus
@ -27,15 +28,15 @@ internal typealias WalletIdWithStatusDM = Map<String, Set<NetworkStatusDM>>
* Default implementation of [NetworksStatusesStore]
*
* @param context context
* @param scope app coroutine scope
* @property runtimeStore runtime store
* @property persistenceDataStore persistence store
* @param dispatchers dispatchers
*/
internal class DefaultNetworksStatusesStore(
context: Context,
scope: AppCoroutineScope,
private val runtimeStore: RuntimeSharedStore<WalletIdWithSimpleStatus>,
private val persistenceDataStore: DataStore<WalletIdWithStatusDM>,
private val scope: AppCoroutineScope,
) : NetworksStatusesStore {
init {
@ -112,7 +113,8 @@ internal class DefaultNetworksStatusesStore(
storedStatuses.toMutableMap().apply {
val updatedValues = this[userWalletId.stringValue].orEmpty().filterNot {
networks.any { network ->
it.networkId.value == network.rawId && it.derivationPath.value == network.derivationPath.value
it.networkId.value == network.toBlockchain().id &&
it.derivationPath.value == network.derivationPath.value
}
}

View file

@ -1,6 +1,7 @@
package com.tangem.data.networks.converters
import com.google.common.truth.Truth
import com.tangem.blockchainsdk.utils.toBlockchain
import com.tangem.common.test.domain.token.MockCryptoCurrencyFactory
import com.tangem.datasource.local.network.entity.NetworkStatusDM
import com.tangem.datasource.local.network.entity.NetworkStatusDM.*
@ -74,7 +75,7 @@ internal class NetworkStatusDataModelConverterTest {
),
),
expected = Verified(
networkId = ID(network.rawId),
networkId = ID(network.toBlockchain().id),
derivationPath = DerivationPath(
value = "",
type = DerivationPath.Type.NONE,
@ -119,7 +120,7 @@ internal class NetworkStatusDataModelConverterTest {
),
),
expected = NoAccount(
networkId = ID(network.rawId),
networkId = ID(network.toBlockchain().id),
derivationPath = DerivationPath(
value = "",
type = DerivationPath.Type.NONE,

View file

@ -1,6 +1,7 @@
package com.tangem.data.networks.converters
import com.google.common.truth.Truth
import com.tangem.blockchainsdk.utils.toBlockchain
import com.tangem.common.test.domain.token.MockCryptoCurrencyFactory
import com.tangem.data.networks.models.SimpleNetworkStatus
import com.tangem.datasource.local.network.entity.NetworkStatusDM
@ -48,7 +49,7 @@ internal class SimpleNetworkStatusConverterTest {
// region Verified
ConvertModel(
value = Verified(
networkId = ID(network.rawId),
networkId = ID(network.toBlockchain().id),
derivationPath = DerivationPath(
value = "card",
type = DerivationPath.Type.CARD,
@ -74,7 +75,7 @@ internal class SimpleNetworkStatusConverterTest {
),
expected = SimpleNetworkStatus(
id = Network.ID(
value = network.rawId,
value = network.backendId,
derivationPath = Network.DerivationPath.Card("card"),
),
value = NetworkStatus.Verified(
@ -116,7 +117,7 @@ internal class SimpleNetworkStatusConverterTest {
// region NoAccount
ConvertModel(
value = NoAccount(
networkId = ID(network.rawId),
networkId = ID(network.toBlockchain().id),
derivationPath = DerivationPath(
value = "card",
type = DerivationPath.Type.CARD,
@ -137,7 +138,7 @@ internal class SimpleNetworkStatusConverterTest {
),
expected = SimpleNetworkStatus(
id = Network.ID(
value = network.rawId,
value = network.backendId,
derivationPath = Network.DerivationPath.Card("card"),
),
value = NetworkStatus.NoAccount(
@ -168,7 +169,7 @@ internal class SimpleNetworkStatusConverterTest {
// region Error
ConvertModel(
value = Verified(
networkId = ID(network.rawId),
networkId = ID(network.toBlockchain().id),
derivationPath = DerivationPath(
value = "card",
type = DerivationPath.Type.CARD,
@ -189,7 +190,7 @@ internal class SimpleNetworkStatusConverterTest {
),
ConvertModel(
value = Verified(
networkId = ID(network.rawId),
networkId = ID(network.toBlockchain().id),
derivationPath = DerivationPath(
value = "card",
type = DerivationPath.Type.CARD,
@ -205,7 +206,7 @@ internal class SimpleNetworkStatusConverterTest {
),
ConvertModel(
value = Verified(
networkId = ID(network.rawId),
networkId = ID(network.toBlockchain().id),
derivationPath = DerivationPath(
value = "card",
type = DerivationPath.Type.CARD,
@ -230,7 +231,7 @@ internal class SimpleNetworkStatusConverterTest {
),
ConvertModel(
value = NoAccount(
networkId = ID(network.rawId),
networkId = ID(network.toBlockchain().id),
derivationPath = DerivationPath(
value = "card",
type = DerivationPath.Type.CARD,
@ -255,7 +256,7 @@ internal class SimpleNetworkStatusConverterTest {
),
ConvertModel(
value = NoAccount(
networkId = ID(network.rawId),
networkId = ID(network.toBlockchain().id),
derivationPath = DerivationPath(
value = "card",
type = DerivationPath.Type.CARD,
@ -276,7 +277,7 @@ internal class SimpleNetworkStatusConverterTest {
),
ConvertModel(
value = NoAccount(
networkId = ID(network.rawId),
networkId = ID(network.toBlockchain().id),
derivationPath = DerivationPath(
value = "card",
type = DerivationPath.Type.CARD,

View file

@ -52,7 +52,7 @@ internal class CommonNetworkStatusFetcherTest {
val userWalletId = UserWalletId("011")
val network = cryptoCurrencyFactory.ethereum.network
val extraTokens = setOf(
cryptoCurrencyFactory.createToken(Blockchain.Ethereum) as CryptoCurrency.Token,
cryptoCurrencyFactory.createToken(Blockchain.Ethereum),
)
val updateException = IllegalStateException()
@ -80,7 +80,7 @@ internal class CommonNetworkStatusFetcherTest {
val userWalletId = UserWalletId("011")
val network = cryptoCurrencyFactory.ethereum.network
val extraTokens = setOf(
cryptoCurrencyFactory.createToken(Blockchain.Ethereum) as CryptoCurrency.Token,
cryptoCurrencyFactory.createToken(Blockchain.Ethereum),
)
val updateResult = model.updateResult
val status = model.status
@ -143,15 +143,15 @@ internal class CommonNetworkStatusFetcherTest {
it.copy(
amounts = mapOf(
CryptoCurrency.ID.fromValue(
value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND",
value = "token⟨ethereum⟩NEVER-MIND⚓NEVER-MIND",
) to NetworkStatus.Amount.NotFound,
),
pendingTransactions = mapOf(
CryptoCurrency.ID.fromValue(value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND") to emptySet(),
CryptoCurrency.ID.fromValue(value = "token⟨ethereum⟩NEVER-MIND⚓NEVER-MIND") to emptySet(),
),
yieldSupplyStatuses = mapOf(
CryptoCurrency.ID.fromValue(
value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND",
value = "token⟨ethereum⟩NEVER-MIND⚓NEVER-MIND",
) to null,
),
)