Skip to content

Commit 3cadddd

Browse files
fix: isHex string extension function refactoring
1 parent 62addff commit 3cadddd

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Sources/Web3Core/Utility/String+Extension.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,17 @@ extension String {
137137
}
138138

139139
public var isHex: Bool {
140-
stripHexPrefix().reduce(true, { $0 && $1.isHexDigit } )
140+
var _str = self.trim()
141+
if _str.isEmpty {
142+
return false
143+
}
144+
_str = _str.stripHexPrefix()
145+
for char in _str {
146+
if !char.isHexDigit {
147+
return false
148+
}
149+
}
150+
return true
141151
}
142152
}
143153

Tests/web3swiftTests/localTests/ABIDecoderSliceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ final class ABIDecoderSliceTests: XCTestCase {
8080
var resultArray = [BigUInt]()
8181
for i in 0..<2 {
8282
guard let data = returnData[i][1] as? Data,
83-
let balance = try? erc20_balanceof.decodeReturnData(data)["0"] as? BigUInt else {
83+
let balance = try erc20_balanceof.decodeReturnData(data)["0"] as? BigUInt else {
8484
resultArray.append(0)
8585
continue
8686
}

0 commit comments

Comments
 (0)