@@ -925,7 +925,7 @@ class AppViewModel @Inject constructor(
925925 sendOnchain(validatedAddress.address, amount)
926926 .onSuccess { txId ->
927927 val tags = _sendUiState .value.selectedTags
928- // TODO Tags are not added if the activity is not already created
928+ // TODO Tags are not added if the activity is not already created
929929 activityRepo.addTagsToTransaction(
930930 paymentHashOrTxId = txId,
931931 type = ActivityFilter .ONCHAIN ,
@@ -939,6 +939,7 @@ class AppViewModel @Inject constructor(
939939 type = NewTransactionSheetType .ONCHAIN ,
940940 direction = NewTransactionSheetDirection .SENT ,
941941 sats = amount.toLong(),
942+ paymentHashOrTxId = txId
942943 )
943944 )
944945 )
@@ -1032,17 +1033,35 @@ class AppViewModel @Inject constructor(
10321033 // TODO This method is being called before the activity is added
10331034 val filter = newTransaction.type.toActivityFilter()
10341035 val paymentType = newTransaction.direction.toTxType()
1036+ val paymentHashOrTxId = newTransaction.paymentHashOrTxId
10351037
10361038 viewModelScope.launch(bgDispatcher) {
1037- val activity = coreService.activity.get(filter = filter, txType = paymentType, limit = 1u ).firstOrNull()
10381039
1039- if (activity == null ) {
1040- Logger .error(msg = " Activity not found" , context = TAG )
1041- return @launch
1042- }
1040+ if (paymentHashOrTxId != null ) {
1041+ activityRepo.findActivityByPaymentId(
1042+ paymentHashOrTxId = paymentHashOrTxId,
1043+ type = newTransaction.type.toActivityFilter(),
1044+ txType = newTransaction.direction.toTxType(),
1045+ retry = false
1046+ ).onSuccess { activity ->
1047+ val nextRoute = Routes .ActivityDetail (activity.rawId())
1048+ mainScreenEffect(MainScreenEffect .Navigate (nextRoute))
1049+ }.onFailure {
1050+ // Navigate to activity detail preview if activity doesn't exists yet
1051+ // TODO CREATE A PREVIEW SCREEN
1052+ }
10431053
1044- val nextRoute = Routes .ActivityDetail (activity.rawId())
1045- mainScreenEffect(MainScreenEffect .Navigate (nextRoute))
1054+ } else {
1055+ val activity = coreService.activity.get(filter = filter, txType = paymentType, limit = 1u ).firstOrNull()
1056+ if (activity == null ) {
1057+ Logger .error(msg = " Activity not found" , context = TAG )
1058+ return @launch
1059+ }
1060+
1061+ // Navigate to activity detail preview if activity doesn't exists yet
1062+ val nextRoute = Routes .ActivityDetail (activity.rawId())
1063+ mainScreenEffect(MainScreenEffect .Navigate (nextRoute))
1064+ }
10461065 }
10471066 }
10481067
0 commit comments