Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-05 14:20:53 +04:00
commit 4ffe7e8c07
3 changed files with 19 additions and 16 deletions

View file

@ -15,8 +15,7 @@ import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onEmpty
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
private const val TAG = "PaymentAccountStatusProducer"
@ -38,10 +37,20 @@ internal class DefaultPaymentAccountStatusProducer @AssistedInject constructor(
logger.i("[${params.userWalletId}] produce() called")
return paymentAccountStatusesStore.get(userWalletId = params.userWalletId)
.onStart { logger.i("[${params.userWalletId}] flow subscribed to store") }
.onEach { logger.i("[${params.userWalletId}] flow emits statusType=${it.value::class.simpleName}") }
.onEmpty {
logger.i("[${params.userWalletId}] onEmpty triggered: emitting NotCreated fallback")
emit(value = AccountStatus.Payment(account, PaymentAccountStatusValue.NotCreated))
.map { status ->
if (status != null) {
logger.i("[${params.userWalletId}] flow emits statusType=${status.value::class.simpleName}")
AccountStatus.Payment(
account = account,
value = status.value,
)
} else {
logger.i("[${params.userWalletId}] status is null: emitting Empty fallback")
AccountStatus.Payment(
account = account,
value = PaymentAccountStatusValue.Empty,
)
}
}
.flowOn(dispatchers.default)
}

View file

@ -13,11 +13,7 @@ import com.tangem.utils.coroutines.AppCoroutineScope
import com.tangem.utils.coroutines.runSuspendCatching
import com.tangem.utils.logging.TangemLogger
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
internal typealias WalletIdWithPaymentStatus = Map<String, AccountStatus.Payment>
@ -65,7 +61,7 @@ internal class PaymentAccountStatusesStore(
}
}
fun get(userWalletId: UserWalletId): Flow<AccountStatus.Payment> {
fun get(userWalletId: UserWalletId): Flow<AccountStatus.Payment?> {
return runtimeStore.get()
.onStart { logger.i("get($userWalletId): subscribed to runtimeStore") }
.onEach { map ->
@ -74,10 +70,7 @@ internal class PaymentAccountStatusesStore(
"hasEntry=${map.containsKey(userWalletId.stringValue)}",
)
}
.mapNotNull { it[userWalletId.stringValue] }
.onEach { status ->
logger.i("get($userWalletId): emitting statusType=${status.value::class.simpleName}")
}
.map { it[userWalletId.stringValue] }
}
suspend fun getSyncOrNull(userWalletId: UserWalletId): AccountStatus.Payment? {

View file

@ -66,6 +66,7 @@ object BlockchainFeeUtils {
private fun Fee.increaseGasLimitBy(percentage: Int): Fee {
if (this !is Fee.Ethereum) return this
val gasLimit = this.gasLimit
if (gasLimit == BigInteger.ZERO) return this
val increasedGasPrice = this.amount.value?.movePointRight(this.amount.decimals)
?.divide(gasLimit.toBigDecimal(), RoundingMode.HALF_UP)
val increasedGasLimit = gasLimit