Skip to content

Commit 06df849

Browse files
chore: added 'custom' case to Units and removed Int as raw value type
1 parent 927a0a9 commit 06df849

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

Sources/Core/Utility/Utilities.swift

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public struct Utilities {
286286

287287
extension Utilities {
288288
/// Various units used in Ethereum ecosystem
289-
public enum Units: Int {
289+
public enum Units {
290290
case wei
291291
case kwei
292292
case babbage
@@ -310,31 +310,34 @@ extension Utilities {
310310
case mether
311311
case gether
312312
case tether
313+
case custom(Int)
313314

314315
public var decimals: Int {
315316
switch self {
316-
case .wei:
317-
return 0
318-
case .kwei, .babbage, .femtoether:
319-
return 3
320-
case .mwei, .lovelace, .picoether:
321-
return 6
322-
case .gwei, .shannon, .nanoether, .nano:
323-
return 9
324-
case .microether, .szabo, .micro:
325-
return 12
326-
case .finney, .milliether, .milli:
327-
return 15
328-
case .ether:
329-
return 18
330-
case .kether, .grand:
331-
return 21
332-
case .mether:
333-
return 24
334-
case .gether:
335-
return 27
336-
case .tether:
337-
return 30
317+
case .wei:
318+
return 0
319+
case .kwei, .babbage, .femtoether:
320+
return 3
321+
case .mwei, .lovelace, .picoether:
322+
return 6
323+
case .gwei, .shannon, .nanoether, .nano:
324+
return 9
325+
case .microether, .szabo, .micro:
326+
return 12
327+
case .finney, .milliether, .milli:
328+
return 15
329+
case .ether:
330+
return 18
331+
case .kether, .grand:
332+
return 21
333+
case .mether:
334+
return 24
335+
case .gether:
336+
return 27
337+
case .tether:
338+
return 30
339+
case .custom(let decimals):
340+
return max(0, decimals)
338341
}
339342
}
340343
}

0 commit comments

Comments
 (0)