display gwei better

This commit is contained in:
ivan grachev 2023-11-02 21:50:00 +03:00
parent 0635215d80
commit 33af59bf09
2 changed files with 13 additions and 4 deletions

View File

@ -16,9 +16,9 @@ struct Transaction {
return gas != nil && gasPrice != nil
}
var gasPriceGwei: UInt? {
var gasPriceGwei: String? {
guard let gasPrice = gasPrice, let value = BigInt(hexString: gasPrice) else { return nil }
return value.gweiUInt
return value.gwei
}
func description(chain: EthereumNetwork, price: Double?) -> String {

View File

@ -20,8 +20,17 @@ extension BigInt {
return decimal.multiplying(byPowerOf10: -18).doubleValue
}
var gweiUInt: UInt {
return decimal.multiplying(byPowerOf10: -9).uintValue
var gwei: String {
let gweiDecimal = decimal.multiplying(byPowerOf10: -9)
let uintValue = gweiDecimal.uintValue
if uintValue > 0 {
return String(uintValue)
} else {
let formatter = NumberFormatter()
formatter.minimumSignificantDigits = 1
formatter.maximumSignificantDigits = 1
return formatter.string(from: gweiDecimal) ?? "0"
}
}
}