Skip to content

Commit 8be67a5

Browse files
committed
feat: fee amount on send review screen
1 parent 510ee36 commit 8be67a5

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

app/src/main/java/to/bitkit/ui/screens/wallets/send/SendConfirmScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private fun OnChainDescription(
341341
)
342342
Row {
343343
BodySSB(stringResource(fee.title) + " (")
344-
MoneySSB(sats = 210, accent = Colors.White) // TODO get from state
344+
MoneySSB(sats = uiState.fee, accent = Colors.White)
345345
BodySSB(")")
346346
}
347347
Icon(

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,14 @@ class AppViewModel @Inject constructor(
357357
}
358358

359359
private fun onSpeedChange(speed: TransactionSpeed) {
360-
_sendUiState.update {
361-
it.copy(speed = speed)
360+
if (speed !is TransactionSpeed.Custom) {
361+
_sendUiState.update {
362+
it.copy(speed = speed)
363+
}
364+
} else {
365+
// TODO implement custom fee screen in next PRs
362366
}
367+
refreshFeeIfNeeded()
363368
setSendEffect(SendEffect.PopBack)
364369
}
365370

@@ -393,13 +398,15 @@ class AppViewModel @Inject constructor(
393398
return
394399
}
395400

401+
refreshFeeIfNeeded()
396402
setSendEffect(SendEffect.NavigateToReview)
397403
}
398404

399405
private fun onCoinSelectionContinue(utxos: List<SpendableUtxo>) {
400406
_sendUiState.update {
401407
it.copy(selectedUtxos = utxos)
402408
}
409+
refreshFeeIfNeeded()
403410
setSendEffect(SendEffect.NavigateToReview)
404411
}
405412

@@ -511,6 +518,7 @@ class AppViewModel @Inject constructor(
511518
)
512519
if (quickPayHandled) return
513520

521+
refreshFeeIfNeeded()
514522
if (isMainScanner) {
515523
showSheet(Sheet.Send(SendRoute.Confirm))
516524
} else {
@@ -1053,6 +1061,34 @@ class AppViewModel @Inject constructor(
10531061

10541062
fun resetQuickPayData() = _quickPayData.update { null }
10551063

1064+
private fun refreshFeeIfNeeded() {
1065+
val currentState = _sendUiState.value
1066+
if (currentState.payMethod != SendMethod.ONCHAIN ||
1067+
currentState.amount == 0uL ||
1068+
currentState.address.isEmpty()
1069+
) {
1070+
return
1071+
}
1072+
1073+
viewModelScope.launch(bgDispatcher) {
1074+
lightningRepo.calculateTotalFee(
1075+
amountSats = currentState.amount,
1076+
address = currentState.address,
1077+
speed = currentState.speed,
1078+
utxosToSpend = currentState.selectedUtxos,
1079+
).onSuccess { feeSat ->
1080+
_sendUiState.update {
1081+
it.copy(fee = feeSat.toLong())
1082+
}
1083+
}.onFailure { e ->
1084+
Logger.warn("Failed to calculate send fee", e = e, context = TAG)
1085+
_sendUiState.update {
1086+
it.copy(fee = 0)
1087+
}
1088+
}
1089+
}
1090+
}
1091+
10561092
suspend fun resetSendState() {
10571093
_sendUiState.value = SendUiState(
10581094
speed = settingsStore.data.first().defaultTransactionSpeed,
@@ -1239,6 +1275,10 @@ class AppViewModel @Inject constructor(
12391275
proceedWithPayment()
12401276
}
12411277
}
1278+
1279+
companion object {
1280+
private const val TAG = "AppViewModel"
1281+
}
12421282
}
12431283

12441284
// region send contract
@@ -1261,6 +1301,7 @@ data class SendUiState(
12611301
val isLoading: Boolean = false,
12621302
val speed: TransactionSpeed = TransactionSpeed.default(),
12631303
val comment: String = "",
1304+
val fee: Long = 0,
12641305
)
12651306

12661307
enum class AmountWarning(@StringRes val message: Int) {

0 commit comments

Comments
 (0)