Skip to content

Commit 5713e3c

Browse files
committed
refactor: remove unnecessary code
1 parent 732d12e commit 5713e3c

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package to.bitkit.repositories
22

3+
import androidx.room.PrimaryKey
34
import com.synonym.bitkitcore.Activity
45
import com.synonym.bitkitcore.Activity.Onchain
56
import com.synonym.bitkitcore.ActivityFilter
@@ -20,12 +21,15 @@ import to.bitkit.data.CacheStore
2021
import to.bitkit.data.dto.InProgressTransfer
2122
import to.bitkit.data.dto.PendingBoostActivity
2223
import to.bitkit.data.dto.TransferType
24+
import to.bitkit.data.entities.TagMetadataEntity
2325
import to.bitkit.di.BgDispatcher
2426
import to.bitkit.ext.matchesPaymentId
27+
import to.bitkit.ext.nowTimestamp
2528
import to.bitkit.ext.rawId
2629
import to.bitkit.services.CoreService
2730
import to.bitkit.utils.AddressChecker
2831
import to.bitkit.utils.Logger
32+
import java.security.InvalidParameterException
2933
import javax.inject.Inject
3034
import javax.inject.Singleton
3135

@@ -562,6 +566,35 @@ class ActivityRepo @Inject constructor(
562566
}
563567
}
564568

569+
suspend fun saveTagsMetadata(
570+
id: String,
571+
paymentHash: String? = null,
572+
txId: String? = null,
573+
address: String,
574+
isReceive: Boolean,
575+
tags: List<String>,
576+
): Result<Unit> = withContext(bgDispatcher) {
577+
return@withContext runCatching {
578+
579+
if (tags.isEmpty()) throw InvalidParameterException("tags must not be empty")
580+
581+
db.tagMetadataDao().saveTagMetadata(
582+
tagMetadata = TagMetadataEntity(
583+
id = id,
584+
paymentHash = paymentHash,
585+
txId = txId,
586+
address = address,
587+
isReceive = isReceive,
588+
tags = tags,
589+
createdAt = nowTimestamp().toEpochMilli()
590+
)
591+
)
592+
}.onFailure { e ->
593+
Logger.error("getAllAvailableTags error", e, context = TAG)
594+
}
595+
}
596+
597+
565598
// MARK: - Development/Testing Methods
566599

567600
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import to.bitkit.data.entities.TagMetadataEntity
2424
import to.bitkit.data.keychain.Keychain
2525
import to.bitkit.di.BgDispatcher
2626
import to.bitkit.env.Env
27+
import to.bitkit.ext.nowTimestamp
2728
import to.bitkit.ext.toHex
2829
import to.bitkit.ext.totalNextOutboundHtlcLimitSats
2930
import to.bitkit.models.AddressModel
@@ -451,7 +452,7 @@ class WalletRepo @Inject constructor(
451452
tags = tags,
452453
address = onChainAddress,
453454
isReceive = true,
454-
createdAt = System.currentTimeMillis()
455+
createdAt = nowTimestamp().toEpochMilli()
455456
)
456457
)
457458
}

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ class AppViewModel @Inject constructor(
193193
try {
194194
when (event) { // TODO Create individual sheet for each type of event
195195
is Event.PaymentReceived -> {
196-
handleTags(event)
197196
showNewTransactionSheet(
198197
NewTransactionSheetDetails(
199198
type = NewTransactionSheetType.LIGHTNING,
@@ -260,16 +259,6 @@ class AppViewModel @Inject constructor(
260259
}
261260
}
262261

263-
private suspend fun handleTags(event: Event.PaymentReceived) {
264-
val tags = walletRepo.searchInvoiceByPaymentHash(paymentHash = event.paymentHash).getOrNull()?.tags.orEmpty()
265-
activityRepo.addTagsToTransaction(
266-
paymentHashOrTxId = event.paymentHash,
267-
type = ActivityFilter.LIGHTNING,
268-
txType = PaymentType.RECEIVED,
269-
tags = tags
270-
)
271-
}
272-
273262
private fun checkGeoStatus() {
274263
viewModelScope.launch {
275264
try {
@@ -927,10 +916,11 @@ class AppViewModel @Inject constructor(
927916
sendOnchain(validatedAddress.address, amount)
928917
.onSuccess { txId ->
929918
val tags = _sendUiState.value.selectedTags
930-
activityRepo.addTagsToTransaction(
931-
paymentHashOrTxId = txId,
932-
type = ActivityFilter.ONCHAIN,
933-
txType = PaymentType.SENT,
919+
activityRepo.saveTagsMetadata(
920+
id = txId,
921+
txId = txId,
922+
address = validatedAddress.address,
923+
isReceive = false,
934924
tags = tags
935925
)
936926
Logger.info("Onchain send result txid: $txId", context = TAG)
@@ -966,10 +956,11 @@ class AppViewModel @Inject constructor(
966956
sendLightning(bolt11, paymentAmount).onSuccess { paymentHash ->
967957
Logger.info("Lightning send result payment hash: $paymentHash", context = TAG)
968958
val tags = _sendUiState.value.selectedTags
969-
activityRepo.addTagsToTransaction(
970-
paymentHashOrTxId = paymentHash,
971-
type = ActivityFilter.LIGHTNING,
972-
txType = PaymentType.SENT,
959+
activityRepo.saveTagsMetadata(
960+
id = paymentHash,
961+
paymentHash = paymentHash,
962+
address = _sendUiState.value.address,
963+
isReceive = false,
973964
tags = tags
974965
)
975966
setSendEffect(SendEffect.PaymentSuccess())

0 commit comments

Comments
 (0)