Skip to content

Commit

Permalink
Merge pull request #1732 from novasamatech/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
valentunn authored Nov 27, 2024
2 parents ddbf9bf + 8e313d6 commit 69b103e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 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 = '9.0.2'
versionCode = 161
versionName = '9.0.3'
versionCode = 162

applicationId = "io.novafoundation.nova"
releaseApplicationSuffix = "market"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.novafoundation.nova.feature_external_sign_impl.domain.sign.polkadot
import com.google.gson.Gson
import io.novafoundation.nova.common.address.AddressIconGenerator
import io.novafoundation.nova.common.address.AddressModel
import io.novafoundation.nova.common.address.createAddressModel
import io.novafoundation.nova.common.utils.asHexString
import io.novafoundation.nova.common.utils.bigIntegerFromHex
import io.novafoundation.nova.common.utils.intFromHex
Expand All @@ -27,6 +26,7 @@ import io.novafoundation.nova.feature_external_sign_impl.domain.sign.ExternalSig
import io.novafoundation.nova.feature_wallet_api.domain.interfaces.TokenRepository
import io.novafoundation.nova.feature_wallet_api.domain.model.Token
import io.novafoundation.nova.runtime.ext.accountIdOf
import io.novafoundation.nova.runtime.ext.anyAddressToAccountId
import io.novafoundation.nova.runtime.ext.utilityAsset
import io.novafoundation.nova.runtime.extrinsic.CustomSignedExtensions
import io.novafoundation.nova.runtime.extrinsic.metadata.MetadataShortenerService
Expand All @@ -38,6 +38,7 @@ import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain
import io.novafoundation.nova.runtime.multiNetwork.getChainOrNull
import io.novafoundation.nova.runtime.multiNetwork.getRuntime
import io.novasama.substrate_sdk_android.extensions.fromHex
import io.novasama.substrate_sdk_android.runtime.AccountId
import io.novasama.substrate_sdk_android.runtime.RuntimeSnapshot
import io.novasama.substrate_sdk_android.runtime.definitions.types.fromHex
import io.novasama.substrate_sdk_android.runtime.definitions.types.generics.EraType
Expand Down Expand Up @@ -104,12 +105,13 @@ class PolkadotExternalSignInteractor(
override val validationSystem: ConfirmDAppOperationValidationSystem = EmptyValidationSystem()

override suspend fun createAccountAddressModel(): AddressModel {
return addressIconGenerator.createAddressModel(
accountAddress = signPayload.address,
val icon = addressIconGenerator.createAddressIcon(
accountId = signPayload.accountId(),
sizeInDp = AddressIconGenerator.SIZE_MEDIUM,
accountName = null,
background = AddressIconGenerator.BACKGROUND_TRANSPARENT
backgroundColorRes = AddressIconGenerator.BACKGROUND_TRANSPARENT
)

return AddressModel(signPayload.address, icon, name = null)
}

override suspend fun chainUi(): Result<ChainUi?> {
Expand Down Expand Up @@ -293,6 +295,18 @@ class PolkadotExternalSignInteractor(
}
}

private suspend fun PolkadotSignPayload.accountId(): AccountId {
return when (this) {
is PolkadotSignPayload.Json -> {
val chain = chainOrNull()

chain?.accountIdOf(address) ?: address.anyAddressToAccountId()
}

is PolkadotSignPayload.Raw -> address.anyAddressToAccountId()
}
}

private class ActualMetadataHash(val modifiedOriginal: Boolean, val checkMetadataHash: CheckMetadataHash) {

constructor(modifiedOriginal: Boolean, hash: ByteArray?) : this(modifiedOriginal, CheckMetadataHash(hash))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ fun Chain.accountIdOf(address: String): ByteArray {
}
}

fun String.anyAddressToAccountId(): ByteArray {
return runCatching {
// Substrate
toAccountId()
}.recoverCatching {
// Evm
asEthereumAddress().toAccountId().value
}.getOrThrow()
}

fun Chain.accountIdOrNull(address: String): ByteArray? {
return runCatching { accountIdOf(address) }.getOrNull()
}
Expand Down

0 comments on commit 69b103e

Please sign in to comment.