Skip to content

Commit

Permalink
Fix/tx history updates (#1119)
Browse files Browse the repository at this point in the history
* Fix - tx status doesn't update realtime

* Code style
  • Loading branch information
valentunn authored Sep 14, 2023
1 parent 1b1c7c0 commit e08445c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TransactionHistoryAdapter(

interface Handler {

fun transactionClicked(transactionModel: OperationModel)
fun transactionClicked(transactionId: String)
}

override fun createGroupViewHolder(parent: ViewGroup): GroupedListHolder {
Expand All @@ -51,9 +51,15 @@ class TransactionHistoryAdapter(
}

override fun bindChild(holder: GroupedListHolder, position: Int, child: OperationModel, payloads: List<Any>) {
require(holder is TransactionHolder)

resolvePayload(holder, position, payloads) {
when (it) {
OperationModel::amountDetails -> (holder as TransactionHolder).bindFiatWithTime(child)
OperationModel::statusAppearance -> holder.bindStatus(child)
OperationModel::header -> holder.bindHeader(child)
OperationModel::subHeader -> holder.bindSubHeader(child)
OperationModel::amount -> holder.bindAmount(child)
OperationModel::amountDetails -> holder.bindAmountDetails(child)
}
}
}
Expand All @@ -70,32 +76,49 @@ class TransactionHolder(

fun bind(item: OperationModel, handler: TransactionHistoryAdapter.Handler) {
with(containerView) {
header.text = item.header
bindHeader(item)

bindAmount(item)

valuePrimary.setTextColorRes(item.amountColorRes)
valuePrimary.text = item.amount
bindAmountDetails(item)
bindSubHeader(item)

bindFiatWithTime(item)
subHeader.text = item.subHeader
subHeader.ellipsize = item.subHeaderEllipsize
icon.setIcon(item.operationIcon, imageLoader)

if (item.statusAppearance != OperationStatusAppearance.COMPLETED) {
status.makeVisible()
status.setImageResource(item.statusAppearance.icon)
status.setImageTintRes(item.statusAppearance.statusIconTint)
} else {
status.makeGone()
}
bindStatus(item)

setOnClickListener { handler.transactionClicked(item) }
setOnClickListener { handler.transactionClicked(item.id) }
}
}

fun bindFiatWithTime(item: OperationModel) {
fun bindAmount(item: OperationModel) = with(containerView) {
valuePrimary.setTextColorRes(item.amountColorRes)
valuePrimary.text = item.amount
}

fun bindHeader(item: OperationModel) {
containerView.header.text = item.header
}

fun bindAmountDetails(item: OperationModel) {
containerView.valueSecondary.setTextOrHide(item.amountDetails)
}

fun bindSubHeader(item: OperationModel) = with(containerView) {
subHeader.text = item.subHeader
subHeader.ellipsize = item.subHeaderEllipsize
}

fun bindStatus(item: OperationModel) = with(containerView) {
if (item.statusAppearance != OperationStatusAppearance.COMPLETED) {
status.makeVisible()
status.setImageResource(item.statusAppearance.icon)
status.setImageTintRes(item.statusAppearance.statusIconTint)
} else {
status.makeGone()
}
}

override fun unbind() {
containerView.icon.clear()
}
Expand All @@ -109,7 +132,13 @@ class DayHolder(view: View) : GroupedListHolder(view) {
}
}

private object TransactionPayloadGenerator : PayloadGenerator<OperationModel>(OperationModel::amountDetails)
private object TransactionPayloadGenerator : PayloadGenerator<OperationModel>(
OperationModel::statusAppearance,
OperationModel::header,
OperationModel::subHeader,
OperationModel::amount,
OperationModel::amountDetails,
)

object TransactionHistoryDiffCallback : BaseGroupedDiffCallback<DayHeader, OperationModel>(DayHeader::class.java) {
override fun areGroupItemsTheSame(oldItem: DayHeader, newItem: DayHeader): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import io.novafoundation.nova.common.utils.updateTopMargin
import io.novafoundation.nova.common.view.bottomSheet.LockBottomSheetBehavior
import io.novafoundation.nova.common.view.shape.getTopRoundedCornerDrawable
import io.novafoundation.nova.feature_assets.R
import io.novafoundation.nova.feature_assets.presentation.model.OperationModel
import kotlinx.android.synthetic.main.view_transfer_history.view.placeholder
import kotlinx.android.synthetic.main.view_transfer_history.view.transactionHistoryFilter
import kotlinx.android.synthetic.main.view_transfer_history.view.transactionHistoryList
Expand All @@ -32,7 +31,7 @@ import kotlinx.android.synthetic.main.view_transfer_history.view.transactionHist

typealias ScrollingListener = (position: Int) -> Unit
typealias SlidingStateListener = (Int) -> Unit
typealias TransactionClickListener = (OperationModel) -> Unit
typealias TransactionClickListener = (transactionId: String) -> Unit

private const val MIN_MARGIN = 20 // dp
private const val MAX_MARGIN = 32 // dp
Expand Down Expand Up @@ -202,8 +201,8 @@ class TransferHistorySheet @JvmOverloads constructor(
super.onDetachedFromWindow()
}

override fun transactionClicked(transactionModel: OperationModel) {
transactionClickListener?.invoke(transactionModel)
override fun transactionClicked(transactionId: String) {
transactionClickListener?.invoke(transactionId)
}

private fun addScrollListener() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.novafoundation.nova.feature_assets.presentation.transaction.history.mixin

import io.novafoundation.nova.feature_assets.presentation.model.OperationModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow

Expand All @@ -23,7 +22,7 @@ interface TransactionHistoryUi {

val state: Flow<State>

fun transactionClicked(transactionModel: OperationModel)
fun transactionClicked(transactionId: String)
}

interface TransactionHistoryMixin : TransactionHistoryUi, CoroutineScope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import io.novafoundation.nova.common.utils.singleReplaySharedFlow
import io.novafoundation.nova.feature_account_api.presenatation.account.AddressDisplayUseCase
import io.novafoundation.nova.feature_assets.domain.WalletInteractor
import io.novafoundation.nova.feature_assets.presentation.AssetsRouter
import io.novafoundation.nova.feature_assets.presentation.model.OperationModel
import io.novafoundation.nova.feature_assets.presentation.model.OperationParcelizeModel
import io.novafoundation.nova.feature_assets.presentation.transaction.filter.HistoryFiltersProviderFactory
import io.novafoundation.nova.feature_assets.presentation.transaction.history.mixin.TransactionHistoryUi.State.ListState
Expand Down Expand Up @@ -111,11 +110,11 @@ class TransactionHistoryProvider(
}
}

override fun transactionClicked(transactionModel: OperationModel) {
override fun transactionClicked(transactionId: String) {
launch {
val operations = (domainState.first() as? State.WithData)?.data ?: return@launch

val clickedOperation = operations.first { it.id == transactionModel.id }
val clickedOperation = operations.first { it.id == transactionId }

val currency = currencyRepository.getSelectedCurrency()

Expand Down

0 comments on commit e08445c

Please sign in to comment.