Updated on 2026-08-14
This commit is contained in:
parent
90d157ff37
commit
ac25a445c6
4 changed files with 23 additions and 11 deletions
|
|
@ -43,6 +43,14 @@ fun List<PendingTransaction>.removeUnknownTransactions(): List<PendingTransactio
|
|||
return this.filter { it.type != PendingTransactionType.Unknown }
|
||||
}
|
||||
|
||||
fun List<PendingTransaction>.filterByCoin(): List<PendingTransaction> {
|
||||
return this.filter { it.transactionData.amount.type == AmountType.Coin }
|
||||
}
|
||||
|
||||
fun List<PendingTransaction>.filterByToken(token: Token): List<PendingTransaction> {
|
||||
return this.filter { it.currency == token.symbol }
|
||||
}
|
||||
|
||||
fun TransactionData.toPendingTransactionForToken(token: Token, walletAddress: String): PendingTransaction? {
|
||||
if (this.amount.currencySymbol != token.symbol) return null
|
||||
return this.toPendingTransaction(walletAddress)
|
||||
|
|
|
|||
|
|
@ -357,7 +357,11 @@ data class WalletData(
|
|||
return listOfAddresses.size > 1
|
||||
}
|
||||
|
||||
fun shouldEnableTokenSendButton(): Boolean = !blockchainAmountIsEmpty() || !tokenAmountIsEmpty()
|
||||
fun shouldEnableTokenSendButton(): Boolean = if (blockchainAmountIsEmpty()) {
|
||||
false
|
||||
} else {
|
||||
!tokenAmountIsEmpty()
|
||||
}
|
||||
|
||||
fun assembleWarnings(): List<WalletWarning> {
|
||||
val blockchain = currency.blockchain
|
||||
|
|
@ -380,10 +384,11 @@ data class WalletData(
|
|||
val fullName = currency.blockchain.fullName
|
||||
walletWarnings.add(WalletWarning.BalanceNotEnoughForFee(fullName))
|
||||
}
|
||||
|
||||
return walletWarnings.sortedBy { it.showingPosition }
|
||||
}
|
||||
|
||||
private fun blockchainAmountIsEmpty(): Boolean = currencyData.blockchainAmount?.isZero() ?: false
|
||||
private fun blockchainAmountIsEmpty(): Boolean = currencyData.blockchainAmount?.isZero() == true
|
||||
|
||||
private fun tokenAmountIsEmpty(): Boolean = currencyData.amount?.isZero() == true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@ import com.tangem.tap.common.extensions.toFiatString
|
|||
import com.tangem.tap.common.extensions.toFormattedCurrencyString
|
||||
import com.tangem.tap.domain.getFirstToken
|
||||
import com.tangem.tap.domain.tokens.BlockchainNetwork
|
||||
import com.tangem.tap.features.wallet.models.filterByToken
|
||||
import com.tangem.tap.features.wallet.models.getPendingTransactions
|
||||
import com.tangem.tap.features.wallet.models.removeUnknownTransactions
|
||||
import com.tangem.tap.features.wallet.models.toPendingTransactions
|
||||
import com.tangem.tap.features.wallet.redux.*
|
||||
import com.tangem.tap.features.wallet.ui.BalanceStatus
|
||||
import com.tangem.tap.features.wallet.ui.BalanceWidgetData
|
||||
|
|
@ -106,10 +107,9 @@ class MultiWalletReducer {
|
|||
throw NullPointerException("MultiWallet.TokenLoaded: WalletManager must be no NULL")
|
||||
}
|
||||
|
||||
val pendingTransactions = wallet.recentTransactions.toPendingTransactions(wallet.address)
|
||||
val pendingTransactions = wallet.getPendingTransactions()
|
||||
val tokenSendButton = action.amount.value?.isZero() == false && pendingTransactions.isEmpty()
|
||||
val tokenPendingTransactions = pendingTransactions
|
||||
.filter { it.currency == action.amount.currencySymbol }
|
||||
val tokenPendingTransactions = pendingTransactions.filterByToken(action.token)
|
||||
val tokenBalanceStatus = when {
|
||||
tokenPendingTransactions.isNotEmpty() -> BalanceStatus.TransactionInProgress
|
||||
pendingTransactions.isNotEmpty() -> BalanceStatus.SameCurrencyTransactionInProgress
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ import com.tangem.tap.common.extensions.toFormattedCurrencyString
|
|||
import com.tangem.tap.common.extensions.toFormattedFiatValue
|
||||
import com.tangem.tap.domain.getFirstToken
|
||||
import com.tangem.tap.domain.tokens.BlockchainNetwork
|
||||
import com.tangem.tap.features.wallet.models.filterByToken
|
||||
import com.tangem.tap.features.wallet.models.getPendingTransactions
|
||||
import com.tangem.tap.features.wallet.models.removeUnknownTransactions
|
||||
import com.tangem.tap.features.wallet.models.toPendingTransactions
|
||||
import com.tangem.tap.features.wallet.redux.*
|
||||
import com.tangem.tap.features.wallet.ui.BalanceStatus
|
||||
import com.tangem.tap.features.wallet.ui.BalanceWidgetData
|
||||
|
|
@ -73,8 +73,7 @@ class OnWalletLoadedReducer {
|
|||
val tokens = wallet.getTokens().mapNotNull { token ->
|
||||
val currency = Currency.fromBlockchainNetwork(blockchainNetwork, token)
|
||||
val tokenWalletData = walletState.getWalletData(currency)
|
||||
val tokenPendingTransactions =
|
||||
pendingTransactions.filter { it.currency == token.symbol }
|
||||
val tokenPendingTransactions = pendingTransactions.filterByToken(token)
|
||||
val tokenBalanceStatus = when {
|
||||
tokenPendingTransactions.isNotEmpty() -> BalanceStatus.TransactionInProgress
|
||||
pendingTransactions.isNotEmpty() -> BalanceStatus.SameCurrencyTransactionInProgress
|
||||
|
|
@ -85,7 +84,7 @@ class OnWalletLoadedReducer {
|
|||
tokenWalletData?.fiatRate?.let { rate -> tokenAmountValue?.toFiatValue(rate) }
|
||||
|
||||
val tokenSendButton = newWalletData.shouldEnableTokenSendButton()
|
||||
&& tokenPendingTransactions.isEmpty()
|
||||
&& tokenPendingTransactions.isEmpty()
|
||||
tokenWalletData?.copy(
|
||||
currencyData = tokenWalletData.currencyData.copy(
|
||||
status = tokenBalanceStatus,
|
||||
|
|
@ -156,7 +155,7 @@ class OnWalletLoadedReducer {
|
|||
val fiatAmountRaw = fiatRate?.multiply(amount)?.setScale(2, RoundingMode.DOWN)
|
||||
val fiatAmount = fiatRate?.let { amount?.toFiatString(it, fiatCurrencyName) }
|
||||
|
||||
val pendingTransactions = wallet.recentTransactions.toPendingTransactions(wallet.address)
|
||||
val pendingTransactions = wallet.getPendingTransactions()
|
||||
val sendButtonEnabled = amount?.isZero() == false && pendingTransactions.isEmpty()
|
||||
val balanceStatus = if (pendingTransactions.isNotEmpty()) {
|
||||
BalanceStatus.TransactionInProgress
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue