update string extension

This commit is contained in:
ivan grachev 2023-10-26 23:53:36 +03:00
parent 163e866cca
commit 030b51a4c7
2 changed files with 4 additions and 3 deletions

View File

@ -35,7 +35,7 @@ enum EthereumNetwork: Int {
}
var hexStringId: String {
return String(id, radix: 16, uppercase: false).withHexPrefix
return String.hex(id, withPrefix: true)
}
static func withChainId(_ chainId: String?) -> EthereumNetwork? {

View File

@ -35,8 +35,9 @@ extension String {
return String.hexPrefix + self
}
static func hex<T>(_ value: T) -> String where T : BinaryInteger {
return String(value, radix: 16)
static func hex<T>(_ value: T, withPrefix: Bool = false) -> String where T : BinaryInteger {
let prefix = withPrefix ? hexPrefix : ""
return prefix + String(value, radix: 16)
}
}