-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFeeRate.kt
More file actions
98 lines (92 loc) · 3.2 KB
/
FeeRate.kt
File metadata and controls
98 lines (92 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package to.bitkit.models
import android.content.Context
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.ui.graphics.Color
import com.synonym.bitkitcore.FeeRates
import to.bitkit.R
import to.bitkit.ui.theme.Colors
enum class FeeRate(
@StringRes val title: Int,
@StringRes val description: Int,
@StringRes val shortDescription: Int,
@DrawableRes val icon: Int,
val color: Color,
) {
INSTANT(
title = R.string.fee__instant__title,
description = R.string.fee__instant__description,
shortDescription = R.string.fee__instant__shortDescription,
color = Colors.Purple,
icon = R.drawable.ic_lightning,
),
FAST(
title = R.string.fee__fast__title,
description = R.string.fee__fast__description,
shortDescription = R.string.fee__fast__shortDescription,
color = Colors.Brand,
icon = R.drawable.ic_speed_fast,
),
NORMAL(
title = R.string.fee__normal__title,
description = R.string.fee__normal__description,
shortDescription = R.string.fee__normal__shortDescription,
color = Colors.Brand,
icon = R.drawable.ic_speed_normal,
),
SLOW(
title = R.string.fee__slow__title,
description = R.string.fee__slow__description,
shortDescription = R.string.fee__slow__shortDescription,
color = Colors.Brand,
icon = R.drawable.ic_speed_slow,
),
MINIMUM(
title = R.string.fee__minimum__title,
description = R.string.fee__minimum__description,
shortDescription = R.string.fee__minimum__shortDescription,
color = Colors.Brand,
icon = R.drawable.ic_speed_slow,
),
CUSTOM(
title = R.string.fee__custom__title,
description = R.string.fee__custom__description,
shortDescription = R.string.fee__custom__shortDescription,
color = Colors.White64,
icon = R.drawable.ic_settings,
);
fun toSpeed(): TransactionSpeed {
return when (this) {
INSTANT, FAST -> TransactionSpeed.Fast
NORMAL -> TransactionSpeed.Medium
MINIMUM, SLOW -> TransactionSpeed.Slow
CUSTOM -> TransactionSpeed.Custom(0u)
}
}
companion object {
fun fromSpeed(speed: TransactionSpeed): FeeRate {
return when (speed) {
is TransactionSpeed.Fast -> FAST
is TransactionSpeed.Medium -> NORMAL
is TransactionSpeed.Slow -> SLOW
is TransactionSpeed.Custom -> CUSTOM
}
}
fun fromSatsPerVByte(satsPerVByte: ULong, feeRates: FeeRates): FeeRate {
val value = satsPerVByte.toUInt()
return when {
value >= feeRates.fast -> FAST
value >= feeRates.mid -> NORMAL
value >= feeRates.slow -> SLOW
else -> MINIMUM
}
}
fun Context.getFeeShortDescription(
feeRate: ULong,
feeRates: FeeRates?,
): String {
val feeRateEnum = feeRates?.let { fromSatsPerVByte(feeRate, it) } ?: NORMAL
return getString(feeRateEnum.shortDescription)
}
}
}