Updated on 2026-08-14

This commit is contained in:
Tangem 2025-02-18 20:43:38 +04:00
parent 42f0e3f0fe
commit 0bf2decb83
13 changed files with 244 additions and 109 deletions

View file

@ -8,12 +8,10 @@ import java.math.BigDecimal
*
* @property network The network for which the status is provided.
* @property value The specific status value, represented as a sealed class to encapsulate the various possible states of the network.
* @property isCached flag that determines whether the status is a cache
*/
data class NetworkStatus(
val network: Network,
val value: Value,
val isCached: Boolean,
) {
/**
@ -21,24 +19,33 @@ data class NetworkStatus(
*
* This sealed class includes different states like unreachable, missed derivation, verified, and no account.
*/
sealed class Value
sealed class Value {
abstract val isCached: Boolean
}
/**
* Represents the state where the network is refreshing.
*/
data object Refreshing : Value()
data object Refreshing : Value() {
override val isCached: Boolean = false
}
/**
* Represents the state where the network is unreachable.
*
* @property address Network addresses.
*/
data class Unreachable(val address: NetworkAddress?) : Value()
data class Unreachable(val address: NetworkAddress?) : Value() {
override val isCached: Boolean = false
}
/**
* Represents the state where a derivation has been missed.
*/
data object MissedDerivation : Value()
data object MissedDerivation : Value() {
override val isCached: Boolean = false
}
/**
* Represents the verified state of the network, including the amounts associated with different cryptocurrencies
@ -47,12 +54,14 @@ data class NetworkStatus(
* @property address Network addresses.
* @property amounts A map containing the amounts associated with different cryptocurrencies within the network.
* @property pendingTransactions A map containing pending transactions associated with different cryptocurrencies
* @property isCached flag that determines whether the status is a cache
* within the network.
*/
data class Verified(
val address: NetworkAddress,
val amounts: Map<CryptoCurrency.ID, CryptoCurrencyAmountStatus>,
val pendingTransactions: Map<CryptoCurrency.ID, Set<TxHistoryItem>>,
override val isCached: Boolean,
) : Value()
/**
@ -61,10 +70,12 @@ data class NetworkStatus(
* @property address Network addresses.
* @property amountToCreateAccount The amount required to create an account within the network.
* @property errorMessage error message
* @property isCached flag that determines whether the status is a cache
*/
data class NoAccount(
val address: NetworkAddress,
val amountToCreateAccount: BigDecimal,
val errorMessage: String,
override val isCached: Boolean,
) : Value()
}

View file

@ -61,13 +61,11 @@ internal object MockNetworks {
private val networkStatus1 = NetworkStatus(
network = network1,
value = NetworkStatus.Unreachable(address = null),
isCached = false,
)
private val networkStatus2 = NetworkStatus(
network = network2,
value = NetworkStatus.MissedDerivation,
isCached = false,
)
private val networkStatus3 = NetworkStatus(
@ -78,8 +76,8 @@ internal object MockNetworks {
defaultAddress = NetworkAddress.Address(value = "mock", NetworkAddress.Address.Type.Primary),
),
errorMessage = "",
isCached = false,
),
isCached = false,
)
private val verifiedNetworkStatus1: NetworkStatus
@ -94,6 +92,7 @@ internal object MockNetworks {
address = NetworkAddress.Single(
defaultAddress = NetworkAddress.Address(value = "mock", NetworkAddress.Address.Type.Primary),
),
isCached = false,
),
)
@ -109,6 +108,7 @@ internal object MockNetworks {
address = NetworkAddress.Single(
defaultAddress = NetworkAddress.Address(value = "mock", NetworkAddress.Address.Type.Primary),
),
isCached = false,
),
)
@ -125,6 +125,7 @@ internal object MockNetworks {
address = NetworkAddress.Single(
defaultAddress = NetworkAddress.Address(value = "mock", NetworkAddress.Address.Type.Primary),
),
isCached = false,
),
)
}