Updated on 2026-08-14
This commit is contained in:
parent
69deadf5fe
commit
23264bc7f0
29 changed files with 667 additions and 271 deletions
|
|
@ -9,7 +9,7 @@ import java.math.BigDecimal
|
|||
/**
|
||||
* Network status for storage in the local cache. Supports two types - the [Verified] and [NoAccount].
|
||||
*
|
||||
* @see [com.tangem.domain.tokens.model.NetworkStatus]
|
||||
* @see [com.tangem.domain.models.network.NetworkStatus]
|
||||
*/
|
||||
@JsonClass(generateAdapter = true, generator = PolymorphicAdapterType.NAME_POLYMORPHIC_ADAPTER)
|
||||
sealed interface NetworkStatusDM {
|
||||
|
|
@ -41,8 +41,8 @@ sealed interface NetworkStatusDM {
|
|||
@Json(name = "derivation_path") override val derivationPath: DerivationPath,
|
||||
@Json(name = "selected_address") override val selectedAddress: String,
|
||||
@Json(name = "available_addresses") override val availableAddresses: Set<Address>,
|
||||
@Json(name = "amounts") val amounts: Map<String, BigDecimal>,
|
||||
@Json(name = "yield_supply_statuses") val yieldSupplyStatuses: Map<String, YieldSupplyStatus?> = emptyMap(),
|
||||
@Json(name = "amounts") val amounts: List<CurrencyAmount>,
|
||||
@Json(name = "yield_supply_statuses") val yieldSupplyStatuses: List<YieldSupplyStatus>,
|
||||
) : NetworkStatusDM
|
||||
|
||||
/**
|
||||
|
|
@ -107,10 +107,44 @@ sealed interface NetworkStatusDM {
|
|||
}
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class CurrencyAmount(
|
||||
@Json(name = "id") val id: CurrencyId,
|
||||
@Json(name = "amount") val amount: BigDecimal,
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class YieldSupplyStatus(
|
||||
@Json(name = "id") val id: CurrencyId,
|
||||
@Json(name = "is_active") val isActive: Boolean,
|
||||
@Json(name = "is_initialized") val isInitialized: Boolean,
|
||||
@Json(name = "is_allowed_to_spend") val isAllowedToSpend: Boolean,
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class CurrencyId(
|
||||
@Json(name = "value") val value: String,
|
||||
) {
|
||||
|
||||
companion object Companion {
|
||||
|
||||
const val CONTRACT_ADDRESS_DELIMITER = '\u2693' // ⚓
|
||||
|
||||
fun createCoinId(coinId: String): CurrencyId {
|
||||
return CurrencyId(value = coinId)
|
||||
}
|
||||
|
||||
fun createTokenId(rawTokenId: String?, contractAddress: String): CurrencyId {
|
||||
return CurrencyId(
|
||||
value = buildString {
|
||||
if (rawTokenId != null) {
|
||||
append(rawTokenId)
|
||||
}
|
||||
append(CONTRACT_ADDRESS_DELIMITER)
|
||||
append(contractAddress)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -64,9 +64,15 @@ class NetworkStatusDMSerializationTest {
|
|||
NetworkStatusDM.Address("0x123456", NetworkStatusDM.Address.Type.Primary),
|
||||
NetworkStatusDM.Address("0xabcdef", NetworkStatusDM.Address.Type.Secondary),
|
||||
),
|
||||
amounts = mapOf("ETH" to BigDecimal("1.2345")),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
"ETH" to NetworkStatusDM.YieldSupplyStatus(
|
||||
amounts = listOf(
|
||||
NetworkStatusDM.CurrencyAmount(
|
||||
id = NetworkStatusDM.CurrencyId.createCoinId("ethereum"),
|
||||
amount = BigDecimal("1.2345"),
|
||||
),
|
||||
),
|
||||
yieldSupplyStatuses = listOf(
|
||||
NetworkStatusDM.YieldSupplyStatus(
|
||||
id = NetworkStatusDM.CurrencyId.createCoinId("ethereum"),
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
|
|
@ -91,9 +97,15 @@ class NetworkStatusDMSerializationTest {
|
|||
NetworkStatusDM.Address("0x123456", NetworkStatusDM.Address.Type.Primary),
|
||||
NetworkStatusDM.Address("0xabcdef", NetworkStatusDM.Address.Type.Secondary),
|
||||
),
|
||||
amounts = mapOf("ETH" to BigDecimal("1.2345")),
|
||||
yieldSupplyStatuses = mapOf(
|
||||
"ETH" to NetworkStatusDM.YieldSupplyStatus(
|
||||
amounts = listOf(
|
||||
NetworkStatusDM.CurrencyAmount(
|
||||
id = NetworkStatusDM.CurrencyId.createCoinId("ethereum"),
|
||||
amount = BigDecimal("1.2345"),
|
||||
),
|
||||
),
|
||||
yieldSupplyStatuses = listOf(
|
||||
NetworkStatusDM.YieldSupplyStatus(
|
||||
id = NetworkStatusDM.CurrencyId.createCoinId("ethereum"),
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue