-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show all metadata and mark the locked ones with lock icon #1010
Changes from all commits
d35af95
301a188
9e51481
d50a0e9
514a257
3cc5e0e
ab62f3e
d932cc2
13d1a6f
480ebd4
72be154
76a8dee
2a350f2
0195e7f
9f49a92
8454eaa
696baae
11bb869
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,7 @@ import com.radixdlt.sargon.extensions.init | |
import com.radixdlt.sargon.extensions.string | ||
import com.radixdlt.sargon.extensions.toDecimal192 | ||
import rdx.works.core.domain.resources.Divisibility | ||
import rdx.works.core.domain.resources.ExplicitMetadataKey | ||
import rdx.works.core.domain.resources.Resource | ||
import rdx.works.core.domain.resources.metadata.Metadata | ||
import rdx.works.core.domain.resources.metadata.MetadataType | ||
import rdx.works.core.domain.resources.metadata.poolAddress | ||
import rdx.works.core.domain.resources.metadata.validatorAddress | ||
import java.time.Instant | ||
|
@@ -50,17 +47,14 @@ data class ResourceEntity( | |
val synced: Instant | ||
) { | ||
|
||
val isDetailsAvailable: Boolean | ||
get() = when (type) { | ||
ResourceEntityType.FUNGIBLE -> supply != null && divisibility != null && behaviours != null | ||
ResourceEntityType.NON_FUNGIBLE -> supply != null && behaviours != null | ||
} | ||
|
||
@Suppress("CyclomaticComplexMethod") | ||
fun toResource(amount: Decimal192?): Resource { | ||
val validatorAndPoolMetadata = listOf( | ||
validatorAddress?.let { | ||
Metadata.Primitive(ExplicitMetadataKey.VALIDATOR.key, it.string, MetadataType.Address) | ||
}, | ||
poolAddress?.let { | ||
Metadata.Primitive(ExplicitMetadataKey.POOL.key, it.string, MetadataType.Address) | ||
} | ||
).mapNotNull { it } | ||
|
||
return when (type) { | ||
ResourceEntityType.FUNGIBLE -> { | ||
Resource.FungibleResource( | ||
|
@@ -69,7 +63,7 @@ data class ResourceEntity( | |
assetBehaviours = behaviours?.behaviours?.toSet(), | ||
currentSupply = supply, | ||
divisibility = divisibility, | ||
metadata = metadata?.metadata.orEmpty() + validatorAndPoolMetadata | ||
metadata = metadata?.metadata.orEmpty() | ||
) | ||
} | ||
|
||
|
@@ -80,7 +74,7 @@ data class ResourceEntity( | |
assetBehaviours = behaviours?.behaviours?.toSet(), | ||
items = emptyList(), | ||
currentSupply = supply?.string?.toIntOrNull(), | ||
metadata = metadata?.metadata.orEmpty() + validatorAndPoolMetadata | ||
metadata = metadata?.metadata.orEmpty() | ||
) | ||
} | ||
} | ||
|
@@ -97,9 +91,8 @@ data class ResourceEntity( | |
validatorAddress = metadata.validatorAddress(), | ||
poolAddress = metadata.poolAddress(), | ||
metadata = metadata | ||
.filterNot { it.key in setOf(ExplicitMetadataKey.POOL.key, ExplicitMetadataKey.VALIDATOR.key) } | ||
.takeIf { it.isNotEmpty() } | ||
?.let { MetadataColumn(it) }, | ||
?.let { MetadataColumn(it, MetadataColumn.ImplicitMetadataState.Unknown) }, | ||
synced = synced | ||
) | ||
|
||
|
@@ -112,9 +105,8 @@ data class ResourceEntity( | |
validatorAddress = metadata.validatorAddress(), | ||
poolAddress = metadata.poolAddress(), | ||
metadata = metadata | ||
.filterNot { it.key in setOf(ExplicitMetadataKey.POOL.key, ExplicitMetadataKey.VALIDATOR.key) } | ||
.takeIf { it.isNotEmpty() } | ||
?.let { MetadataColumn(it) }, | ||
?.let { MetadataColumn(it, MetadataColumn.ImplicitMetadataState.Unknown) }, | ||
synced = synced | ||
) | ||
} | ||
|
@@ -126,7 +118,8 @@ data class ResourceEntity( | |
details: StateEntityDetailsResponseItemDetails? = null | ||
): ResourceEntity = from( | ||
address = ResourceAddress.init(resourceAddress), | ||
metadataCollection = explicitMetadata, | ||
explicitMetadata = explicitMetadata, | ||
implicitMetadata = null, | ||
details = details, | ||
type = ResourceEntityType.FUNGIBLE, | ||
synced = synced | ||
|
@@ -139,7 +132,8 @@ data class ResourceEntity( | |
details: StateEntityDetailsResponseItemDetails? = null | ||
): ResourceEntity = from( | ||
address = ResourceAddress.init(resourceAddress), | ||
metadataCollection = explicitMetadata, | ||
explicitMetadata = explicitMetadata, | ||
implicitMetadata = null, | ||
details = details, | ||
type = ResourceEntityType.NON_FUNGIBLE, | ||
synced = synced | ||
|
@@ -156,33 +150,44 @@ data class ResourceEntity( | |
} | ||
return from( | ||
address = ResourceAddress.init(address), | ||
metadataCollection = metadata, | ||
explicitMetadata = explicitMetadata, | ||
implicitMetadata = metadata, | ||
details = details, | ||
type = type, | ||
synced = synced | ||
) | ||
} | ||
|
||
@Suppress("LongParameterList") | ||
private fun from( | ||
address: ResourceAddress, | ||
metadataCollection: EntityMetadataCollection?, | ||
explicitMetadata: EntityMetadataCollection?, | ||
implicitMetadata: EntityMetadataCollection?, | ||
details: StateEntityDetailsResponseItemDetails?, | ||
type: ResourceEntityType, | ||
synced: Instant | ||
): ResourceEntity { | ||
val metadata = metadataCollection?.toMetadata().orEmpty() | ||
val metadataColumn = if (implicitMetadata != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the difference between explicit/implicit metadata? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicit metadata are the ones we request when we communicate with GW and GW ensures that we will receive them. Also known as standard metadata. For example a resource may have defined 150 metadata. If you do a simple entity details request, on the first response we will only receive the first page of them (100) and we need to paginate them in order to get the other 50. Although we need to somehow make sure that some metadata will be received since are crucial to rendering the UI without the need of pagination, like name, symbol, description, icon_url.... So for these requests you will see that we put When the user navigates to asset details, we can also display the rest of the metadata (besides the explicit ones). Decided to call them implicit. If we know that there is a page to be paginated, this is the time we do it. |
||
MetadataColumn.from( | ||
explicitMetadata = explicitMetadata, | ||
implicitMetadata = implicitMetadata | ||
) | ||
} else { | ||
MetadataColumn( | ||
metadata = explicitMetadata?.toMetadata().orEmpty(), | ||
implicitState = MetadataColumn.ImplicitMetadataState.Unknown | ||
) | ||
}.takeIf { it.metadata.isNotEmpty() } | ||
|
||
return ResourceEntity( | ||
address = address, | ||
type = type, | ||
divisibility = details?.divisibility(), | ||
behaviours = details?.let { BehavioursColumn(it.extractBehaviours()) }, | ||
supply = details?.totalSupply(), | ||
validatorAddress = metadata.validatorAddress(), | ||
poolAddress = metadata.poolAddress(), | ||
metadata = metadata | ||
.filterNot { it.key in setOf(ExplicitMetadataKey.VALIDATOR.key, ExplicitMetadataKey.POOL.key) } | ||
.takeIf { it.isNotEmpty() } | ||
?.let { MetadataColumn(it) }, | ||
validatorAddress = metadataColumn?.metadata?.validatorAddress(), | ||
poolAddress = metadataColumn?.metadata?.poolAddress(), | ||
metadata = metadataColumn, | ||
synced = synced | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should use same
json
as we use for gateway models serialization?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it is different, this is how the column is serialized into a json string. Room stores metadata in a custom type called
MetadataColumn
which uses this serialisation logic inside. Also theMetadata
type we have defined is a domain model and not a GW one.