Skip to content

Commit

Permalink
Merge pull request #1342 from novasamatech/rc/7.7.3
Browse files Browse the repository at this point in the history
Rc/7.7.3
  • Loading branch information
antonijzelinskij committed Jan 22, 2024
2 parents 0d1cb08 + 13016ef commit 8e24e18
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
buildscript {
ext {
// App version
versionName = '7.7.2'
versionCode = 110
versionName = '7.7.3'
versionCode = 111

applicationId = "io.novafoundation.nova"
releaseApplicationSuffix = "market"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface OnChainIdentity {
val display: String?
val legal: String?
val web: String?
val riot: String?
val matrix: String?
val email: String?
val pgpFingerprint: String?
val image: String?
Expand All @@ -17,7 +17,7 @@ class RootIdentity(
override val display: String?,
override val legal: String?,
override val web: String?,
override val riot: String?,
override val matrix: String?,
override val email: String?,
override val pgpFingerprint: String?,
override val image: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class IdentityModel(
val display: String?,
val legal: String?,
val web: String?,
val riot: String?,
val matrix: String?,
val email: String?,
val image: String?,
val twitter: String?
Expand All @@ -21,7 +21,7 @@ fun IdentityModel.Companion.from(identity: OnChainIdentity): IdentityModel {
display = display,
legal = legal,
web = web,
riot = riot,
matrix = matrix,
email = email,
image = image,
twitter = twitter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class IdentityView @JvmOverloads constructor(
viewIdentityLegalName.showValueOrHide(legal)
viewIdentityEmail.showValueOrHide(email)
viewIdentityTwitter.showValueOrHide(twitter)
viewIdentityElementName.showValueOrHide(riot)
viewIdentityElementName.showValueOrHide(matrix)
viewIdentityWeb.showValueOrHide(web)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.novafoundation.nova.common.data.network.runtime.binding.bindData
import io.novafoundation.nova.common.data.network.runtime.binding.cast
import io.novafoundation.nova.common.data.network.runtime.binding.castToList
import io.novafoundation.nova.common.data.network.runtime.binding.castToStruct
import io.novafoundation.nova.common.data.network.runtime.binding.castToStructOrNull
import io.novafoundation.nova.common.data.network.runtime.binding.incompatible
import io.novafoundation.nova.common.utils.second
import io.novafoundation.nova.feature_account_api.data.model.OnChainIdentity
Expand All @@ -15,27 +16,40 @@ import jp.co.soramitsu.fearless_utils.extensions.toHexString
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.composite.Struct

@UseCaseBinding
fun bindIdentity(dynamic: Any?,): OnChainIdentity? {
fun bindIdentity(dynamic: Any?): OnChainIdentity? {
if (dynamic == null) return null

val decoded = dynamic.castToStruct()
val decoded = dynamic.castIdentityLegacy() ?: dynamic.castToIdentity()

val identityInfo = decoded.get<Struct.Instance>("info") ?: incompatible()

val pgpFingerprint = identityInfo.get<ByteArray?>("pgpFingerprint")

val matrix = bindIdentityData(identityInfo, "riot", onIncompatibleField = null)
?: bindIdentityData(identityInfo, "matrix", onIncompatibleField = null)

return RootIdentity(
display = bindIdentityData(identityInfo, "display"),
legal = bindIdentityData(identityInfo, "legal"),
web = bindIdentityData(identityInfo, "web"),
riot = bindIdentityData(identityInfo, "riot"),
matrix = matrix,
email = bindIdentityData(identityInfo, "email"),
pgpFingerprint = pgpFingerprint?.toHexString(withPrefix = true),
image = bindIdentityData(identityInfo, "image"),
twitter = bindIdentityData(identityInfo, "twitter")
)
}

private fun Any?.castIdentityLegacy(): Struct.Instance? {
return this.castToStructOrNull()
}

private fun Any?.castToIdentity(): Struct.Instance {
return this.castToList()
.first()
.castToStruct()
}

@UseCaseBinding
fun bindSuperOf(decoded: Any?): SuperOf? {
if (decoded == null) return null
Expand All @@ -51,8 +65,14 @@ fun bindSuperOf(decoded: Any?): SuperOf? {
}

@HelperBinding
fun bindIdentityData(identityInfo: Struct.Instance, field: String): String? {
val value = identityInfo.get<Any?>(field) ?: incompatible()
fun bindIdentityData(
identityInfo: Struct.Instance,
field: String,
onIncompatibleField: (() -> Unit)? = { incompatible() }
): String? {
val value = identityInfo.get<Any?>(field)
?: onIncompatibleField?.invoke()
?: return null

return bindData(value).asString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ fun mapIdentityToIdentityParcelModel(identity: OnChainIdentity): IdentityParcelM
)
}

IdentityParcelModel(display, legal, web, riot, email, pgpFingerprint, image, twitter, childInfo)
IdentityParcelModel(display, legal, web, matrix, email, pgpFingerprint, image, twitter, childInfo)
}
}

fun mapIdentityParcelModelToIdentity(identity: IdentityParcelModel): OnChainIdentity {
return with(identity) {
if (childInfo != null) {
val parent = RootIdentity(childInfo.parentSeparateDisplay, legal, web, riot, email, pgpFingerprint, image, twitter)
val parent = RootIdentity(childInfo.parentSeparateDisplay, legal, web, matrix, email, pgpFingerprint, image, twitter)

ChildIdentity(childInfo.childName, parent)
} else {
RootIdentity(display, legal, web, riot, email, pgpFingerprint, image, twitter)
RootIdentity(display, legal, web, matrix, email, pgpFingerprint, image, twitter)
}
}
}

fun mapIdentityParcelModelToIdentityModel(identity: IdentityParcelModel): IdentityModel {
return with(identity) {
IdentityModel(display, legal, web, riot, email, image, twitter)
IdentityModel(display, legal, web, matrix, email, image, twitter)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class IdentityParcelModel(
val display: String?,
val legal: String?,
val web: String?,
val riot: String?,
val matrix: String?,
val email: String?,
val pgpFingerprint: String?,
val image: String?,
Expand Down

0 comments on commit 8e24e18

Please sign in to comment.