Skip to content

Commit

Permalink
Merge pull request #1738 from novasamatech/hotfix/fee_issues
Browse files Browse the repository at this point in the history
Hotfix/fee issues
  • Loading branch information
antonijzelinskij authored Dec 4, 2024
2 parents 7f8cd35 + a0f8c5b commit 5170f66
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
2 changes: 0 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ android {
versionNameSuffix '-github'
applicationIdSuffix '.github'

buildConfigField "String", "APP_UPDATE_SOURCE_LINK", "\"https://github.com/novasamatech/nova-wallet-android/releases\""

buildConfigField "String", "BuildType", "\"releaseGithub\""
}
develop {
Expand Down
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.1.0'
versionCode = 163
versionName = '9.1.1'
versionCode = 166

applicationId = "io.novafoundation.nova"
releaseApplicationSuffix = "market"
Expand Down
6 changes: 6 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

releaseGithub {
initWith buildTypes.release
matchingFallbacks = ['release']
buildConfigField "String", "APP_UPDATE_SOURCE_LINK", "\"https://github.com/novasamatech/nova-wallet-android/releases\""
}
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ fun RuntimeMetadata.firstExistingModuleName(vararg options: String): String {
return options.first(::hasModule)
}

fun RuntimeMetadata.firstExistingCall(vararg options: Pair<String, String>): MetadataFunction {
val result = options.tryFindNonNull { (moduleName, functionName) ->
moduleOrNull(moduleName)?.callOrNull(functionName)
}

return requireNotNull(result)
}

fun RuntimeMetadata.firstExistingModuleOrNull(vararg options: String): Module? {
return options.tryFindNonNull { moduleOrNull(it) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.novafoundation.nova.feature_wallet_impl.data.network.blockchain.assets.transfers.orml

import io.novafoundation.nova.common.utils.Modules
import io.novafoundation.nova.common.utils.firstExistingModuleName
import io.novafoundation.nova.common.utils.firstExistingCall
import io.novafoundation.nova.feature_account_api.data.extrinsic.ExtrinsicService
import io.novafoundation.nova.feature_wallet_api.data.network.blockhain.assets.AssetSourceRegistry
import io.novafoundation.nova.feature_wallet_api.data.network.blockhain.assets.tranfers.AssetTransfer
Expand Down Expand Up @@ -50,10 +50,15 @@ class OrmlAssetTransfers(
target: AccountId,
amount: BigInteger
) {
val (moduleIndex, callIndex) = runtime.metadata.firstExistingCall(
Modules.TOKENS to "transfer",
Modules.CURRENCIES to "transfer"
).index

call(
moduleName = runtime.metadata.firstExistingModuleName(Modules.CURRENCIES, Modules.TOKENS),
callName = "transfer",
arguments = mapOf(
moduleIndex = moduleIndex,
callIndex = callIndex,
args = mapOf(
"dest" to AddressInstanceConstructor.constructInstance(runtime.typeRegistry, target),
"currency_id" to chainAsset.ormlCurrencyId(runtime),
"amount" to amount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import io.novafoundation.nova.runtime.multiNetwork.getRuntime
import io.novafoundation.nova.runtime.multiNetwork.getSocket
import io.novasama.substrate_sdk_android.runtime.RuntimeSnapshot
import io.novasama.substrate_sdk_android.runtime.extrinsic.signer.SendableExtrinsic
import io.novasama.substrate_sdk_android.runtime.metadata.RuntimeMetadata
import io.novasama.substrate_sdk_android.runtime.metadata.methodOrNull
import io.novasama.substrate_sdk_android.runtime.metadata.runtimeApiOrNull
import io.novasama.substrate_sdk_android.scale.dataType.DataType
import io.novasama.substrate_sdk_android.wsrpc.SocketService
import io.novasama.substrate_sdk_android.wsrpc.executeAsync
Expand Down Expand Up @@ -64,7 +67,7 @@ class RpcCalls(
val runtime = chainRegistry.getRuntime(chainId)

return when {
chain.additional.feeViaRuntimeCall() && runtime.metadata.hasRuntimeApisMetadata() -> queryFeeViaRuntimeApiV15(chainId, extrinsic)
chain.additional.feeViaRuntimeCall() && runtime.metadata.hasDetectedPaymentApi() -> queryFeeViaRuntimeApiV15(chainId, extrinsic)

chain.additional.feeViaRuntimeCall() && runtime.hasFeeDecodeType() -> queryFeeViaRuntimeApiPreV15(chainId, extrinsic)

Expand Down Expand Up @@ -146,6 +149,10 @@ class RpcCalls(
return socketFor(chainId).executeAsync(GetStorageSize(storageKey)).result?.asGsonParsedNumber().orZero()
}

private fun RuntimeMetadata.hasDetectedPaymentApi(): Boolean {
return hasRuntimeApisMetadata() && runtimeApiOrNull("TransactionPaymentApi")?.methodOrNull("query_info") != null
}

private suspend fun socketFor(chainId: ChainId) = chainRegistry.getSocket(chainId)

private suspend fun queryFeeViaRpcCall(chainId: ChainId, extrinsic: SendableExtrinsic): FeeResponse {
Expand Down

0 comments on commit 5170f66

Please sign in to comment.