Skip to content

Commit 43e080c

Browse files
committed
chore: review #604
1 parent fe0015f commit 43e080c

6 files changed

Lines changed: 23 additions & 16 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ suspend fun getData(): Result<Data> = withContext(Dispatchers.IO) {
209209
- ALWAYS wrap `ULong` numbers with `USat` in arithmetic operations, to guard against overflows
210210
- PREFER to use one-liners with `run {}` when applicable, e.g. `override fun someCall(value: String) = run { this.value = value }`
211211
- ALWAYS add imports instead of inline fully-qualified names
212-
- ALWAYS place `@Suppress(...)` annotations at the narrowest possible scope (statement, property, or function level); NEVER use `@file:Suppress(...)` when a more targeted suppression is possible, EXCEPT for `MatchingDeclarationName` where file-level is acceptable when reordering declarations is impractical
212+
- ALWAYS place `@Suppress()` annotations at the narrowest possible scope; ONLY use `@file:Suppress()` for `MatchingDeclarationName` when reordering declarations is impractical
213213

214214
### Architecture Guidelines
215215

app/src/main/java/to/bitkit/data/widgets/WeatherService.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import to.bitkit.data.dto.FeeEstimates
1111
import to.bitkit.data.dto.WeatherDTO
1212
import to.bitkit.env.Env
1313
import to.bitkit.ext.nowMs
14+
import to.bitkit.models.USD
1415
import to.bitkit.models.WidgetType
1516
import to.bitkit.repositories.CurrencyRepo
1617
import to.bitkit.utils.AppError
@@ -35,20 +36,25 @@ class WeatherService @Inject constructor(
3536
override val widgetType = WidgetType.WEATHER
3637
override val refreshInterval = 8.minutes
3738

39+
@Volatile
3840
private var cachedFeeEstimates: FeeEstimates? = null
41+
42+
@Volatile
3943
private var feeEstimatesTimestamp: Long = 0L
44+
45+
@Volatile
4046
private var cachedHistoricalData: List<BlockFeeRates>? = null
47+
48+
@Volatile
4149
private var historicalDataTimestamp: Long = 0L
4250

4351
companion object {
4452
private const val TAG = "WeatherService"
4553

46-
@Suppress("SpellCheckingInspection")
47-
private const val AVERAGE_SEGWIT_VBYTES_SIZE = 140
54+
private const val AVERAGE_SEGWIT_VB_SIZE = 140
4855
private const val USD_GOOD_THRESHOLD = 1.0 // $1 USD threshold for good condition
4956
private const val PERCENTILE_LOW = 0.33
5057
private const val PERCENTILE_HIGH = 0.66
51-
private const val USD_CURRENCY = "USD"
5258
private val TTL_FEE_ESTIMATES = 2.minutes
5359
private val TTL_HISTORICAL_DATA = 30.minutes
5460
}
@@ -64,16 +70,16 @@ class WeatherService @Inject constructor(
6470
val condition = calculateCondition(feeEstimates.normal, history)
6571

6672
// Calculate average fee for display
67-
val avgFeeSats = (feeEstimates.normal * AVERAGE_SEGWIT_VBYTES_SIZE).toInt()
73+
val avgFeeSats = (feeEstimates.normal * AVERAGE_SEGWIT_VB_SIZE).toLong()
6874
val currentFee = formatFeeForDisplay(avgFeeSats)
6975

7076
WeatherDTO(
7177
condition = condition,
7278
currentFee = currentFee,
73-
nextBlockFee = feeEstimates.fast
79+
nextBlockFee = feeEstimates.fast,
7480
)
7581
}.onFailure {
76-
Logger.warn("Failed to fetch weather data", e = it, context = TAG)
82+
Logger.warn("Failed to fetch weather data", it, context = TAG)
7783
}
7884

7985
private suspend fun getFeeEstimates(): FeeEstimates {
@@ -118,8 +124,8 @@ class WeatherService @Inject constructor(
118124
val highThreshold = historicalFees[floor(historicalFees.size * PERCENTILE_HIGH).toInt()]
119125

120126
// Check USD threshold first
121-
val avgFeeSats = currentFeeRate * AVERAGE_SEGWIT_VBYTES_SIZE
122-
val avgFeeUsd = currencyRepo.convertSatsToFiat(avgFeeSats.toLong(), currency = USD_CURRENCY).getOrNull()
127+
val avgFeeSats = currentFeeRate * AVERAGE_SEGWIT_VB_SIZE
128+
val avgFeeUsd = currencyRepo.convertSatsToFiat(avgFeeSats.toLong(), USD).getOrNull()
123129
?: return FeeCondition.AVERAGE
124130

125131
if (avgFeeUsd.value <= BigDecimal(USD_GOOD_THRESHOLD)) return FeeCondition.GOOD
@@ -132,8 +138,8 @@ class WeatherService @Inject constructor(
132138
}
133139
}
134140

135-
private fun formatFeeForDisplay(satoshis: Int): String {
136-
val usdValue = currencyRepo.convertSatsToFiat(satoshis.toLong(), currency = USD_CURRENCY).getOrNull()
141+
private fun formatFeeForDisplay(sats: Long): String {
142+
val usdValue = currencyRepo.convertSatsToFiat(sats, USD).getOrNull()
137143
return usdValue?.formatted.orEmpty()
138144
}
139145
}

app/src/main/java/to/bitkit/models/Currency.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const val FIAT_GROUPING_SEPARATOR = ','
1919
const val DECIMAL_SEPARATOR = '.'
2020
const val CLASSIC_DECIMALS = 8
2121
const val FIAT_DECIMALS = 2
22-
const val EUR_CURRENCY = "EUR"
22+
const val EUR = "EUR"
23+
const val USD = "USD"
2324

2425
@Serializable
2526
data class FxRateResponse(

app/src/main/java/to/bitkit/repositories/BlocktankRepo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import to.bitkit.env.Env
4141
import to.bitkit.ext.calculateRemoteBalance
4242
import to.bitkit.ext.nowTimestamp
4343
import to.bitkit.models.BlocktankBackupV1
44-
import to.bitkit.models.EUR_CURRENCY
44+
import to.bitkit.models.EUR
4545
import to.bitkit.services.CoreService
4646
import to.bitkit.services.LightningService
4747
import to.bitkit.utils.Logger
@@ -378,7 +378,7 @@ class BlocktankRepo @Inject constructor(
378378
}
379379

380380
private fun getSatsPerEur(): ULong? {
381-
return currencyRepo.convertFiatToSats(BigDecimal(1), EUR_CURRENCY).getOrNull()
381+
return currencyRepo.convertFiatToSats(BigDecimal(1), EUR).getOrNull()
382382
}
383383

384384
private fun totalBtChannelsValueSats(info: IBtInfo?): ULong {

app/src/main/java/to/bitkit/ui/screens/transfer/SpendingConfirmScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ import to.bitkit.ui.components.PrimaryButton
5353
import to.bitkit.ui.components.SwipeToConfirm
5454
import to.bitkit.ui.components.VerticalSpacer
5555
import to.bitkit.ui.components.settings.SettingsSwitchRow
56+
import to.bitkit.ui.openNotificationSettings
5657
import to.bitkit.ui.scaffold.AppTopBar
5758
import to.bitkit.ui.scaffold.DrawerNavIcon
5859
import to.bitkit.ui.scaffold.ScreenColumn
59-
import to.bitkit.ui.openNotificationSettings
6060
import to.bitkit.ui.theme.AppSwitchDefaults
6161
import to.bitkit.ui.theme.AppThemeSurface
6262
import to.bitkit.ui.theme.Colors

app/src/main/java/to/bitkit/ui/screens/wallets/receive/ReceiveConfirmScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ import to.bitkit.ui.components.Title
3636
import to.bitkit.ui.components.VerticalSpacer
3737
import to.bitkit.ui.components.settings.SettingsSwitchRow
3838
import to.bitkit.ui.currencyViewModel
39+
import to.bitkit.ui.openNotificationSettings
3940
import to.bitkit.ui.scaffold.SheetTopBar
4041
import to.bitkit.ui.shared.modifiers.sheetHeight
4142
import to.bitkit.ui.shared.util.gradientBackground
42-
import to.bitkit.ui.openNotificationSettings
4343
import to.bitkit.ui.theme.AppSwitchDefaults
4444
import to.bitkit.ui.theme.AppThemeSurface
4545
import to.bitkit.ui.theme.Colors

0 commit comments

Comments
 (0)