@@ -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