Skip to content

Commit d50e308

Browse files
authored
Merge pull request #331 from synonymdev/feat/send-success-screen
Display the success screen in the send sheet
2 parents af536da + 2a787d2 commit d50e308

File tree

3 files changed

+65
-21
lines changed

3 files changed

+65
-21
lines changed

app/src/main/java/to/bitkit/ui/ContentView.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,6 @@ fun ContentView(
325325
appViewModel = appViewModel,
326326
walletViewModel = walletViewModel,
327327
startDestination = sheet.route,
328-
onComplete = { txSheet ->
329-
appViewModel.hideSheet()
330-
appViewModel.clearClipboardForAutoRead()
331-
txSheet?.let { appViewModel.showNewTransactionSheet(details = it, event = null) }
332-
}
333328
)
334329
}
335330

app/src/main/java/to/bitkit/ui/sheets/SendSheet.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import androidx.navigation.compose.NavHost
1515
import androidx.navigation.compose.rememberNavController
1616
import androidx.navigation.toRoute
1717
import kotlinx.serialization.Serializable
18-
import to.bitkit.models.NewTransactionSheetDetails
1918
import to.bitkit.ui.screens.scanner.QrScanningScreen
2019
import to.bitkit.ui.screens.wallets.send.AddTagScreen
2120
import to.bitkit.ui.screens.wallets.send.PIN_CHECK_RESULT_KEY
@@ -46,7 +45,6 @@ fun SendSheet(
4645
appViewModel: AppViewModel,
4746
walletViewModel: WalletViewModel,
4847
startDestination: SendRoute = SendRoute.Recipient,
49-
onComplete: (NewTransactionSheetDetails?) -> Unit,
5048
) {
5149
LaunchedEffect(startDestination) {
5250
// always reset state on new user-initiated send
@@ -72,7 +70,10 @@ fun SendSheet(
7270
is SendEffect.NavigateToCoinSelection -> navController.navigate(SendRoute.CoinSelection)
7371
is SendEffect.NavigateToConfirm -> navController.navigate(SendRoute.Confirm)
7472
is SendEffect.PopBack -> navController.popBackStack(it.route, inclusive = false)
75-
is SendEffect.PaymentSuccess -> onComplete(it.sheet)
73+
is SendEffect.PaymentSuccess -> {
74+
appViewModel.clearClipboardForAutoRead()
75+
navController.navigate(SendRoute.Success)
76+
}
7677
is SendEffect.NavigateToQuickPay -> navController.navigate(SendRoute.QuickPay)
7778
is SendEffect.NavigateToWithdrawConfirm -> navController.navigate(SendRoute.WithdrawConfirm)
7879
is SendEffect.NavigateToWithdrawError -> navController.navigate(SendRoute.WithdrawError)
@@ -162,6 +163,14 @@ fun SendSheet(
162163
onNavigateToPin = { navController.navigate(SendRoute.PinCheck) },
163164
)
164165
}
166+
composableWithDefaultTransitions<SendRoute.Success> {
167+
val sendDetail by appViewModel.successSendUiState.collectAsStateWithLifecycle()
168+
NewTransactionSheetView(
169+
details = sendDetail,
170+
onCloseClick = { appViewModel.hideSheet() },
171+
onDetailClick = { appViewModel.onClickSendDetail() }
172+
)
173+
}
165174
composableWithDefaultTransitions<SendRoute.WithdrawConfirm> {
166175
val uiState by appViewModel.sendUiState.collectAsStateWithLifecycle()
167176
WithdrawConfirmScreen(
@@ -210,7 +219,7 @@ fun SendSheet(
210219
SendQuickPayScreen(
211220
quickPayData = requireNotNull(quickPayData),
212221
onPaymentComplete = {
213-
onComplete(null)
222+
navController.navigate(SendRoute.Success)
214223
},
215224
onShowError = { errorMessage ->
216225
navController.navigate(SendRoute.Error(errorMessage))
@@ -227,11 +236,11 @@ fun SendSheet(
227236
popUpTo<SendRoute.Recipient> { inclusive = true }
228237
}
229238
} else {
230-
onComplete(null)
239+
navController.navigate(SendRoute.Success)
231240
}
232241
},
233242
onClose = {
234-
onComplete(null)
243+
appViewModel.hideSheet()
235244
}
236245
)
237246
}
@@ -285,6 +294,9 @@ sealed interface SendRoute {
285294
@Serializable
286295
data object Confirm : SendRoute
287296

297+
@Serializable
298+
data object Success : SendRoute
299+
288300
@Serializable
289301
data class Error(val errorMessage: String) : SendRoute
290302
}

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

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,13 @@ class AppViewModel @Inject constructor(
237237

238238
is Event.PaymentSuccessful -> {
239239
// TODO: fee is not the sats sent. Need to get this amount from elsewhere like send flow or something.
240-
showNewTransactionSheet(
240+
handlePaymentSuccess(
241241
NewTransactionSheetDetails(
242242
type = NewTransactionSheetType.LIGHTNING,
243243
direction = NewTransactionSheetDirection.SENT,
244244
paymentHashOrTxId = event.paymentHash,
245245
sats = ((event.feePaidMsat ?: 0u) / 1000u).toLong(),
246246
),
247-
event = event
248247
)
249248
}
250249

@@ -937,14 +936,12 @@ class AppViewModel @Inject constructor(
937936
tags = tags
938937
)
939938
Logger.info("Onchain send result txid: $txId", context = TAG)
940-
setSendEffect(
941-
SendEffect.PaymentSuccess(
942-
NewTransactionSheetDetails(
943-
type = NewTransactionSheetType.ONCHAIN,
944-
direction = NewTransactionSheetDirection.SENT,
945-
paymentHashOrTxId = txId,
946-
sats = amount.toLong(),
947-
)
939+
handlePaymentSuccess(
940+
NewTransactionSheetDetails(
941+
type = NewTransactionSheetType.ONCHAIN,
942+
direction = NewTransactionSheetDirection.SENT,
943+
paymentHashOrTxId = txId,
944+
sats = amount.toLong(),
948945
)
949946
)
950947
lightningRepo.sync()
@@ -1059,6 +1056,30 @@ class AppViewModel @Inject constructor(
10591056
}
10601057
}
10611058

1059+
fun onClickSendDetail() {
1060+
val activityType = _successSendUiState.value.type.toActivityFilter()
1061+
val txType = _successSendUiState.value.direction.toTxType()
1062+
val paymentHashOrTxId = _successSendUiState.value.paymentHashOrTxId ?: return
1063+
_successSendUiState.update { it.copy(isLoadingDetails = true) }
1064+
viewModelScope.launch(bgDispatcher) {
1065+
activityRepo.findActivityByPaymentId(
1066+
paymentHashOrTxId = paymentHashOrTxId,
1067+
type = activityType,
1068+
txType = txType,
1069+
retry = true
1070+
).onSuccess { activity ->
1071+
hideSheet()
1072+
_successSendUiState.update { it.copy(isLoadingDetails = false) }
1073+
val nextRoute = Routes.ActivityDetail(activity.rawId())
1074+
mainScreenEffect(MainScreenEffect.Navigate(nextRoute))
1075+
}.onFailure { e ->
1076+
Logger.error(msg = "Activity not found", context = TAG)
1077+
toast(e)
1078+
_successSendUiState.update { it.copy(isLoadingDetails = false) }
1079+
}
1080+
}
1081+
}
1082+
10621083
private suspend fun sendOnchain(address: String, amount: ULong): Result<Txid> {
10631084
return lightningRepo.sendOnChain(
10641085
address = address,
@@ -1225,6 +1246,17 @@ class AppViewModel @Inject constructor(
12251246

12261247
val newTransaction = _newTransaction.asStateFlow()
12271248

1249+
private val _successSendUiState = MutableStateFlow(
1250+
NewTransactionSheetDetails(
1251+
type = NewTransactionSheetType.LIGHTNING,
1252+
direction = NewTransactionSheetDirection.SENT,
1253+
paymentHashOrTxId = null,
1254+
sats = 0
1255+
)
1256+
)
1257+
1258+
val successSendUiState = _successSendUiState.asStateFlow()
1259+
12281260
fun setNewTransactionSheetEnabled(enabled: Boolean) {
12291261
isNewTransactionSheetEnabled = enabled
12301262
}
@@ -1408,6 +1440,11 @@ class AppViewModel @Inject constructor(
14081440
}
14091441
}
14101442

1443+
private fun handlePaymentSuccess(details: NewTransactionSheetDetails) {
1444+
_successSendUiState.update { details }
1445+
setSendEffect(SendEffect.PaymentSuccess(details))
1446+
}
1447+
14111448
companion object {
14121449
private const val TAG = "AppViewModel"
14131450
private const val SEND_AMOUNT_WARNING_THRESHOLD = 100.0

0 commit comments

Comments
 (0)