diff --git a/data/visa/src/main/kotlin/com/tangem/data/pay/flow/DefaultPaymentAccountStatusProducer.kt b/data/visa/src/main/kotlin/com/tangem/data/pay/flow/DefaultPaymentAccountStatusProducer.kt index 153f0d327d..b8530171db 100644 --- a/data/visa/src/main/kotlin/com/tangem/data/pay/flow/DefaultPaymentAccountStatusProducer.kt +++ b/data/visa/src/main/kotlin/com/tangem/data/pay/flow/DefaultPaymentAccountStatusProducer.kt @@ -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) } diff --git a/data/visa/src/main/kotlin/com/tangem/data/pay/store/PaymentAccountStatusesStore.kt b/data/visa/src/main/kotlin/com/tangem/data/pay/store/PaymentAccountStatusesStore.kt index fd60f231b4..c9ff2fd990 100644 --- a/data/visa/src/main/kotlin/com/tangem/data/pay/store/PaymentAccountStatusesStore.kt +++ b/data/visa/src/main/kotlin/com/tangem/data/pay/store/PaymentAccountStatusesStore.kt @@ -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 @@ -65,7 +61,7 @@ internal class PaymentAccountStatusesStore( } } - fun get(userWalletId: UserWalletId): Flow { + fun get(userWalletId: UserWalletId): Flow { 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? { diff --git a/libs/crypto/src/main/java/com/tangem/lib/crypto/BlockchainFeeUtils.kt b/libs/crypto/src/main/java/com/tangem/lib/crypto/BlockchainFeeUtils.kt index 74d6248b75..5c08e72030 100644 --- a/libs/crypto/src/main/java/com/tangem/lib/crypto/BlockchainFeeUtils.kt +++ b/libs/crypto/src/main/java/com/tangem/lib/crypto/BlockchainFeeUtils.kt @@ -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