Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrVakhtinTari committed Nov 16, 2023
1 parent 6e95c96 commit 74142f9
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 436 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,13 @@ class TariWalletApplication : Application() {

override fun onStart(owner: LifecycleOwner) {
super.onStart(owner)
securityPrefRepository.isAuthenticated = false
logger.i("App in foreground")
isInForeground = true
walletServiceLauncher.startOnAppForegrounded()
EventBus.post(Event.App.AppForegrounded())
}

override fun onStop(owner: LifecycleOwner) {
securityPrefRepository.isAuthenticated = false
super.onStop(owner)
logger.i("App in background")
isInForeground = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ class DeeplinkFormatter @Inject constructor(private val networkRepository: Netwo

val parsedDeeplink = DeepLink.getByCommand(command, paramentrs)

if (parsedDeeplink is DeepLink.Send && !TariWalletAddress.validate(parsedDeeplink.walletAddressHex)) return null
if (parsedDeeplink is DeepLink.UserProfile && !TariWalletAddress.validate(parsedDeeplink.tariAddressHex)) return null
if (parsedDeeplink is DeepLink.Send) {
if (!TariWalletAddress.validate(parsedDeeplink.walletAddressHex)) return null
}
if (parsedDeeplink is DeepLink.UserProfile) {
if (!TariWalletAddress.validate(parsedDeeplink.tariAddressHex)) return null
}

return parsedDeeplink
}
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/tari/android/wallet/event/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
*/
package com.tari.android.wallet.event

import com.tari.android.wallet.model.*
import com.tari.android.wallet.model.CancelledTx
import com.tari.android.wallet.model.CompletedTx
import com.tari.android.wallet.model.PendingInboundTx
import com.tari.android.wallet.model.PendingOutboundTx
import com.tari.android.wallet.model.TransactionSendStatus
import com.tari.android.wallet.model.TxId
import com.tari.android.wallet.ui.fragment.send.finalize.TxFailureReason

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class TariWalletAddress() : Parcelable, Serializable {
return Array(size) { TariWalletAddress() }
}

fun validate(addressHex: String): Boolean = addressHex.length == 66
fun validate(addressHex: String): Boolean = addressHex.length > 64
}

override fun writeToParcel(parcel: Parcel, flags: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ abstract class CommonActivity<Binding : ViewBinding, VM : CommonViewModel> : App
super.onCreate(savedInstanceState)
dialogManager.context = this

onBackInvokedDispatcher.registerOnBackInvokedCallback(0) {
overridePendingTransition(R.anim.enter_from_left, R.anim.exit_to_right)
}

overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left)
subscribeToCommon(connectionStateViewModel)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ open class ContactSelectionViewModel : CommonViewModel() {
if (hex.isEmpty()) return
val walletAddress = walletService.getWalletAddressFromHexString(hex)
selectedUser.value = ContactDto(FFIContactDto(walletAddress), name)
goNext.postValue(Unit)
}

fun getUserDto(): ContactDto = selectedUser.value ?: contactListSource.value.orEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TransactionHistoryFragment : CommonFragment<FragmentContactTransactionHist
ui.emptyState.setVisible(items.isEmpty())

adapter.update(items)
adapter.notifyDataSetChanged()
}

private fun initUI() = with(ui) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,53 @@ package com.tari.android.wallet.ui.fragment.contact_book.transactionHistory

import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.toLiveData
import com.tari.android.wallet.ui.common.CommonViewModel
import com.tari.android.wallet.ui.common.recyclerView.CommonViewHolderItem
import com.tari.android.wallet.ui.fragment.contact_book.data.ContactsRepository
import com.tari.android.wallet.ui.fragment.contact_book.data.contacts.ContactDto
import com.tari.android.wallet.ui.fragment.tx.TransactionRepository
import com.tari.android.wallet.ui.fragment.tx.adapter.TransactionItem
import io.reactivex.BackpressureStrategy
import javax.inject.Inject

class TransactionHistoryViewModel : CommonViewModel() {

@Inject
lateinit var transactionRepository: TransactionRepository

@Inject
lateinit var contactRepository: ContactsRepository

var selectedContact = MutableLiveData<ContactDto>()

var list = MediatorLiveData<MutableList<CommonViewHolderItem>>()

init {
component.inject(this)

list.addSource(contactRepository.publishSubject.toFlowable(BackpressureStrategy.LATEST).toLiveData()) {
updateList()
}

list.addSource(selectedContact) { updateList() }

list.addSource(transactionRepository.debouncedList) { updateList() }
list.addSource(transactionRepository.list) { updateList() }
}

private fun updateList() {
val filtered = transactionRepository.list.value?.filter {
val contact = selectedContact.value ?: return
val actualContact = contactRepository.getByUuid(contact.uuid)
if (contact != actualContact) selectedContact.postValue(actualContact)

val filtered: MutableList<CommonViewHolderItem> = transactionRepository.list.value?.filter {
if (it is TransactionItem) {
it.tx.tariContact.walletAddress == selectedContact.value?.contact?.extractWalletAddress()
} else {
false
}
}
list.postValue(filtered.orEmpty().toMutableList())
}.orEmpty().map { (it as TransactionItem).copy(contact = actualContact) }.toMutableList()
list.postValue(filtered)
}
}

Loading

0 comments on commit 74142f9

Please sign in to comment.