Updated on 2026-08-14
This commit is contained in:
parent
eaa1215307
commit
7b026e8447
12 changed files with 249 additions and 186 deletions
|
|
@ -108,24 +108,22 @@ fun BigDecimal.isLessThanOrEqual(value: BigDecimal): Boolean {
|
|||
|
||||
fun BigDecimal.formatAmountAsSpannedString(
|
||||
currencySymbol: String,
|
||||
integerPartSizeProportion: Float = 1.4f
|
||||
reminderPartSizeProportion: Float = 0.7f
|
||||
): SpannedString {
|
||||
val amount = this
|
||||
.setScale(2, RoundingMode.HALF_UP)
|
||||
.toString()
|
||||
.formatWithSpaces()
|
||||
val integer = amount.substringBefore('.')
|
||||
val reminder = amount.substringAfter('.')
|
||||
|
||||
return buildSpannedString {
|
||||
append(integer)
|
||||
append('.')
|
||||
append(
|
||||
integer,
|
||||
RelativeSizeSpan(integerPartSizeProportion),
|
||||
"$reminder $currencySymbol",
|
||||
RelativeSizeSpan(reminderPartSizeProportion),
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
append('.')
|
||||
append(reminder)
|
||||
append(' ')
|
||||
append(currencySymbol)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.tangem.tap.features.wallet.ui.adapters
|
|||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
|
@ -10,6 +11,7 @@ import com.tangem.blockchain.common.Blockchain
|
|||
import com.tangem.blockchain.common.Token
|
||||
import com.tangem.domain.common.TapWorkarounds.derivationStyle
|
||||
import com.tangem.tap.common.extensions.getString
|
||||
import com.tangem.tap.common.extensions.hide
|
||||
import com.tangem.tap.common.extensions.loadCurrenciesIcon
|
||||
import com.tangem.tap.common.extensions.show
|
||||
import com.tangem.tap.features.wallet.redux.Currency
|
||||
|
|
@ -61,57 +63,63 @@ class WalletAdapter
|
|||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(wallet: WalletData) = with(binding) {
|
||||
tvCurrency.text = wallet.currencyData.currency
|
||||
tvAmount.text = wallet.currencyData.amountFormatted.orEmpty()
|
||||
tvAmountFiat.text = wallet.currencyData.fiatAmountFormatted
|
||||
tvExchangeRate.text = wallet.fiatRateString
|
||||
cardWallet.setOnClickListener {
|
||||
store.dispatch(WalletAction.MultiWallet.SelectWallet(wallet))
|
||||
val status = wallet.currencyData.status
|
||||
val isCustomCurrency = wallet.currency.isCustomCurrency(
|
||||
derivationStyle = store.state.globalState
|
||||
.scanResponse
|
||||
?.card
|
||||
?.derivationStyle
|
||||
)
|
||||
val statusMessage = when (status) {
|
||||
BalanceStatus.TransactionInProgress -> {
|
||||
root.getString(R.string.wallet_balance_tx_in_progress)
|
||||
}
|
||||
BalanceStatus.Unreachable -> {
|
||||
root.getString(R.string.wallet_balance_blockchain_unreachable)
|
||||
}
|
||||
BalanceStatus.NoAccount -> {
|
||||
root.getString(R.string.wallet_error_no_account)
|
||||
}
|
||||
BalanceStatus.VerifiedOnline,
|
||||
BalanceStatus.SameCurrencyTransactionInProgress,
|
||||
BalanceStatus.EmptyCard,
|
||||
BalanceStatus.UnknownBlockchain,
|
||||
BalanceStatus.Loading,
|
||||
null -> null
|
||||
}
|
||||
val blockchain = wallet.currency.blockchain
|
||||
val token = (wallet.currency as? Currency.Token)?.token
|
||||
|
||||
val isCustom = wallet.currency
|
||||
.isCustomCurrency(store.state.globalState.scanResponse?.card?.derivationStyle)
|
||||
tvExchangeRate.show(!isCustom)
|
||||
tvCustomCurrency.show(isCustom)
|
||||
if (status == null || status == BalanceStatus.Loading) {
|
||||
lContent.root.hide()
|
||||
lShimmer.root.veil()
|
||||
} else {
|
||||
lShimmer.root.unVeil()
|
||||
lContent.root.show()
|
||||
}
|
||||
|
||||
Picasso.get().loadCurrenciesIcon(
|
||||
imageView = ivCurrency,
|
||||
textView = tvTokenLetter,
|
||||
token = token, blockchain = blockchain,
|
||||
token = (wallet.currency as? Currency.Token)?.token,
|
||||
blockchain = wallet.currency.blockchain,
|
||||
)
|
||||
|
||||
when (wallet.currencyData.status) {
|
||||
BalanceStatus.VerifiedOnline,
|
||||
BalanceStatus.SameCurrencyTransactionInProgress -> hideMessage()
|
||||
BalanceStatus.Loading -> if (wallet.currencyData.amountFormatted == null) {
|
||||
showMessage(root.getString(R.string.wallet_balance_loading))
|
||||
}
|
||||
BalanceStatus.TransactionInProgress ->
|
||||
showMessage(root.getString(R.string.wallet_balance_tx_in_progress))
|
||||
BalanceStatus.Unreachable ->
|
||||
showMessage(root.getString(R.string.wallet_balance_blockchain_unreachable))
|
||||
lContent.tvCurrency.text = wallet.currencyData.currency
|
||||
lContent.tvAmountFiat.text = wallet.currencyData.fiatAmountFormatted ?: "—"
|
||||
lContent.tvAmount.text = wallet.currencyData.amountFormatted ?: "—"
|
||||
|
||||
BalanceStatus.NoAccount ->
|
||||
showMessage(root.getString(R.string.wallet_error_no_account))
|
||||
else -> {
|
||||
}
|
||||
lContent.tvStatus.isVisible = statusMessage != null
|
||||
lContent.tvStatus.text = statusMessage
|
||||
|
||||
lContent.tvExchangeRate.isVisible = statusMessage == null
|
||||
lContent.tvExchangeRate.text = if (isCustomCurrency) {
|
||||
root.getString(id = R.string.token_item_no_rate)
|
||||
} else {
|
||||
wallet.fiatRateString
|
||||
}
|
||||
}
|
||||
|
||||
private fun showMessage(message: String) {
|
||||
toggleMessage(true)
|
||||
binding.tvStatus.text = message
|
||||
}
|
||||
|
||||
private fun hideMessage() {
|
||||
toggleMessage(false)
|
||||
}
|
||||
|
||||
private fun toggleMessage(show: Boolean) {
|
||||
binding.tvAmount.show(!show)
|
||||
binding.tvStatus.show(show)
|
||||
cardWallet.setOnClickListener {
|
||||
store.dispatch(WalletAction.MultiWallet.SelectWallet(wallet))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package com.tangem.tap.features.wallet.ui.wallet
|
||||
|
||||
import android.app.Dialog
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.tangem.common.card.Card
|
||||
|
|
@ -132,13 +131,11 @@ class MultiWalletView : WalletView {
|
|||
) = with(binding.lCardTotalBalance) {
|
||||
root.isVisible = totalBalance != null
|
||||
if (totalBalance != null) {
|
||||
tvBalance.animateVisibility(
|
||||
show = totalBalance.state != TotalBalance.State.Loading,
|
||||
hiddenVisibility = View.INVISIBLE
|
||||
)
|
||||
pbLoading.animateVisibility(
|
||||
show = totalBalance.state == TotalBalance.State.Loading
|
||||
)
|
||||
if (totalBalance.state == TotalBalance.State.Loading) {
|
||||
veilBalance.veil()
|
||||
} else {
|
||||
veilBalance.unVeil()
|
||||
}
|
||||
tvProcessing.animateVisibility(
|
||||
show = totalBalance.state == TotalBalance.State.SomeTokensFailed
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue