Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = '2.0.12'
versionCode = 73
versionName = '2.0.13'
versionCode = 74

// SDK and tools
compileSdkVersion = 31
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package jp.co.soramitsu.common.data.network.runtime.calls
import jp.co.soramitsu.fearless_utils.wsrpc.request.runtime.RuntimeRequest

class FeeCalculationRequest(extrinsicInHex: String) : RuntimeRequest(
method = "payment_queryInfo",
method = "payment_queryFeeDetails",
params = listOf(extrinsicInHex)
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package jp.co.soramitsu.common.data.network.runtime.model

import java.math.BigInteger
import jp.co.soramitsu.fearless_utils.extensions.fromHex
import jp.co.soramitsu.fearless_utils.extensions.fromUnsignedBytes
import jp.co.soramitsu.fearless_utils.extensions.requireHexPrefix

// todo there were a field which caused an errors:
// val weight: Long
Expand All @@ -11,6 +14,33 @@ import java.math.BigInteger
// "class":"normal",
// "partialFee":"15407544760"
// }

class FeeResponse(
val partialFee: BigInteger
val inclusionFee: InclusionFee
)

class InclusionFee(
private val baseFee: String?,
private val lenFee: String?,
private val adjustedWeightFee: String?,
) {
val sum: BigInteger
get() = baseFee.decodeBigInt() + lenFee.decodeBigInt() + adjustedWeightFee.decodeBigInt()

private fun String?.decodeBigInt(): BigInteger {
// because substrate returns hexes with different length:
// 0x3b9aca00
// 0x3486ced00
// 0xb320334
if (this == null) return BigInteger.ZERO
return if (this.length.isEven.not()) {
val withoutPrefix = removePrefix("0x")
"0$withoutPrefix".requireHexPrefix()
} else {
this
}.fromHex().fromUnsignedBytes()
}

private val Int.isEven: Boolean
get() = this % 2 == 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package jp.co.soramitsu.common.utils

import android.content.Context
import android.text.format.DateUtils
import android.util.Log
import java.math.BigDecimal
import java.math.RoundingMode
import java.text.DecimalFormat
Expand Down Expand Up @@ -83,7 +84,13 @@ fun Long.formatDaysSinceEpoch(context: Context): String? {
val currentDays = System.currentTimeMillis().daysFromMillis()
val diff = currentDays - this

if (diff < 0) throw IllegalArgumentException("Past date should be less than current")
if (diff < 0) {
Log.e(
"jp.co.soramitsu.common.utils.NumberFormattersKt.formatDaysSinceEpoch",
"Error: diff < 0: ",
IllegalArgumentException("Past date should be less than current")
)
}

return when (diff) {
0L -> context.getString(R.string.today)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class RpcCalls(

val feeResponse = socketFor(chainId).executeAsync(request, mapper = pojo<FeeResponse>().nonNull())

return feeResponse.partialFee
return feeResponse.inclusionFee.sum
}

suspend fun submitExtrinsic(chainId: ChainId, extrinsic: String): String {
Expand Down