diff --git a/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt b/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt index 31e4627793..8ecd269976 100644 --- a/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt +++ b/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt @@ -6,7 +6,6 @@ import com.google.zxing.BarcodeFormat import com.google.zxing.EncodeHintType import com.google.zxing.qrcode.QRCodeWriter import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel -import com.tangem.blockchain.common.Blockchain import java.math.BigDecimal import java.math.RoundingMode import java.text.DecimalFormat @@ -34,16 +33,16 @@ fun String.toQrCode(): Bitmap { return bmp } -fun BigDecimal.toFormattedString(blockchain: Blockchain): String { +fun BigDecimal.toFormattedString(decimals: Int): String { val symbols = DecimalFormatSymbols(Locale.US) symbols.decimalSeparator = '.' val df = DecimalFormat() df.decimalFormatSymbols = symbols - df.maximumFractionDigits = blockchain.decimals() + df.maximumFractionDigits = decimals df.minimumFractionDigits = 0 df.isGroupingUsed = false val bd = BigDecimal(unscaledValue(), scale()) - bd.setScale(blockchain.decimals(), BigDecimal.ROUND_DOWN) + bd.setScale(decimals, BigDecimal.ROUND_DOWN) return df.format(bd) } diff --git a/app/src/main/java/com/tangem/tap/common/extensions/UI.kt b/app/src/main/java/com/tangem/tap/common/extensions/UI.kt index e08ffeb499..255ce6949e 100644 --- a/app/src/main/java/com/tangem/tap/common/extensions/UI.kt +++ b/app/src/main/java/com/tangem/tap/common/extensions/UI.kt @@ -24,6 +24,10 @@ fun Fragment.getDrawable(@DrawableRes drawableResId: Int): Drawable? { return ContextCompat.getDrawable(requireContext(), drawableResId) } +fun Context.getDrawableCompat(@DrawableRes drawableResId: Int): Drawable? { + return ContextCompat.getDrawable(this, drawableResId) +} + fun View.show(show: Boolean) { if (show) this.visibility = View.VISIBLE else this.visibility = View.GONE } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt b/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt new file mode 100644 index 0000000000..4f1d7293d4 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt @@ -0,0 +1,36 @@ +package com.tangem.tap.features.wallet.models + +import com.tangem.blockchain.common.TransactionData +import com.tangem.tap.common.extensions.toFormattedString + +data class PendingTransaction( + val address: String, + val amount: String, + val currency: String, + val type: PendingTransactionType +) + +enum class PendingTransactionType { Incoming, Outcoming } + +fun TransactionData.toPendingTransaction(walletAddress: String): PendingTransaction { + val type: PendingTransactionType = if (this.sourceAddress == walletAddress) { + PendingTransactionType.Outcoming + } else { + PendingTransactionType.Incoming + } + val address = if (this.sourceAddress == walletAddress) { + this.destinationAddress + } else { + this.sourceAddress + } + return PendingTransaction( + address, + this.amount.value?.toFormattedString(amount.decimals) ?: "?", + this.amount.currencySymbol, + type + ) +} + +fun List.toPendingTransactions(walletAddress: String): List{ + return this.map { it.toPendingTransaction(walletAddress) } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt index 30c87d7ea9..8690115296 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletReducer.kt @@ -7,6 +7,7 @@ import com.tangem.tap.common.extensions.toFiatString import com.tangem.tap.common.extensions.toFormattedString import com.tangem.tap.common.extensions.toQrCode import com.tangem.tap.common.redux.AppState +import com.tangem.tap.features.wallet.models.toPendingTransactions import com.tangem.tap.features.wallet.ui.BalanceStatus import com.tangem.tap.features.wallet.ui.BalanceWidgetData import com.tangem.tap.features.wallet.ui.TokenData @@ -37,7 +38,7 @@ private fun internalReduce(action: Action, state: AppState): WalletState { } else { AddressData(wallet.address, wallet.shareUrl, wallet.exploreUrl) } - val currentArtworkId = state.globalState.scanNoteResponse?.verifyResponse?.artworkInfo?.id + val currentArtworkId = state.globalState.scanNoteResponse?.verifyResponse?.artworkInfo?.id val cardImage = if (newState.cardImage?.artworkId == currentArtworkId) { newState.cardImage } else { @@ -61,7 +62,7 @@ private fun internalReduce(action: Action, state: AppState): WalletState { val tokenFiatRate = state.globalState.fiatRates.getRateForCryptoCurrency(token.currencySymbol) val tokenFiatAmount = tokenFiatRate?.let { token.value?.toFiatString(it) } TokenData( - token.value?.toFormattedString(action.wallet.blockchain) ?: "", + token.value?.toFormattedString(token.decimals) ?: "", token.currencySymbol, tokenFiatAmount) } else { null @@ -70,16 +71,20 @@ private fun internalReduce(action: Action, state: AppState): WalletState { val fiatRate = state.globalState.fiatRates.getRateForCryptoCurrency(action.wallet.blockchain.currency) val fiatAmount = fiatRate?.let { amount?.toFiatString(it) } + val pendingTransactions = action.wallet.transactions + .toPendingTransactions(action.wallet.address) + val sendButtonEnabled = amount?.isZero() == false || token?.value?.isZero() == false newState = newState.copy( state = ProgressState.Done, wallet = action.wallet, currencyData = BalanceWidgetData( BalanceStatus.VerifiedOnline, action.wallet.blockchain.fullName, currencySymbol = action.wallet.blockchain.currency, - amount?.toFormattedString(action.wallet.blockchain), + amount?.toFormattedString(action.wallet.blockchain.decimals()), token = tokenData, fiatAmount = fiatAmount ), + pendingTransactions = pendingTransactions, mainButton = WalletMainButton.SendButton(sendButtonEnabled) ) } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt index 171670bdca..4144388fef 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt @@ -3,6 +3,7 @@ package com.tangem.tap.features.wallet.redux import android.graphics.Bitmap import com.tangem.blockchain.common.Wallet import com.tangem.tap.common.entities.Button +import com.tangem.tap.features.wallet.models.PendingTransaction import com.tangem.tap.features.wallet.ui.BalanceWidgetData import org.rekotlin.StateType @@ -10,6 +11,7 @@ data class WalletState( val state: ProgressState = ProgressState.Done, val cardImage: Artwork? = null, val wallet: Wallet? = null, + val pendingTransactions: List = emptyList(), val addressData: AddressData? = null, val currencyData: BalanceWidgetData = BalanceWidgetData(), val payIdData: PayIdData = PayIdData(), diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/PendingTransactionsAdapter.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/PendingTransactionsAdapter.kt new file mode 100644 index 0000000000..d6b3f66f7f --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/PendingTransactionsAdapter.kt @@ -0,0 +1,62 @@ +package com.tangem.tap.features.wallet.ui + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView +import com.tangem.tap.common.extensions.getDrawableCompat +import com.tangem.tap.features.wallet.models.PendingTransaction +import com.tangem.tap.features.wallet.models.PendingTransactionType +import com.tangem.wallet.R +import kotlinx.android.synthetic.main.layout_pending_transaction.view.* + +class PendingTransactionsAdapter + : ListAdapter(DiffUtilCallback) { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TransactionsViewHolder { + val layout = LayoutInflater.from(parent.context) + .inflate(R.layout.layout_pending_transaction, parent, false) + return TransactionsViewHolder(layout) + } + + override fun onBindViewHolder(holder: TransactionsViewHolder, position: Int) { + holder.bind(currentList[position]) + } + + object DiffUtilCallback : DiffUtil.ItemCallback() { + + + override fun areContentsTheSame( + oldItem: PendingTransaction, newItem: PendingTransaction + ) = oldItem == newItem + + override fun areItemsTheSame( + oldItem: PendingTransaction, newItem: PendingTransaction + ) = oldItem == newItem + + } + + + class TransactionsViewHolder(val view: View) : + RecyclerView.ViewHolder(view) { + + fun bind(transaction: PendingTransaction) { + val transactionDescriptionRes = when (transaction.type) { + PendingTransactionType.Incoming -> R.string.wallet_pending_transaction_incoming + PendingTransactionType.Outcoming -> R.string.wallet_pending_transaction_outcoming + } + val image = when (transaction.type) { + PendingTransactionType.Incoming -> R.drawable.ic_arrow_down + PendingTransactionType.Outcoming -> R.drawable.ic_arrow_right + } + view.tv_pending_transaction.text = view.context.getString( + transactionDescriptionRes, transaction.amount, transaction.currency + ) + view.tv_pending_transaction_address.text = transaction.address + view.iv_pending_transaction.setImageDrawable(view.context.getDrawableCompat(image)) + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt index e38da8854f..887f9c2ee3 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.View import androidx.activity.OnBackPressedCallback import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.LinearLayoutManager import androidx.transition.TransitionInflater import com.tangem.tap.common.extensions.getDrawable import com.tangem.tap.common.extensions.hide @@ -26,6 +27,9 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber + + + + diff --git a/app/src/main/res/drawable/ic_arrow_right.xml b/app/src/main/res/drawable/ic_arrow_right.xml index f45f66f818..ef1cbb3777 100644 --- a/app/src/main/res/drawable/ic_arrow_right.xml +++ b/app/src/main/res/drawable/ic_arrow_right.xml @@ -1,9 +1,16 @@ - + android:height="14dp" + android:viewportWidth="12" + android:viewportHeight="10"> + + + + diff --git a/app/src/main/res/layout/fragment_wallet.xml b/app/src/main/res/layout/fragment_wallet.xml index 390f561132..eadd74b5e1 100644 --- a/app/src/main/res/layout/fragment_wallet.xml +++ b/app/src/main/res/layout/fragment_wallet.xml @@ -34,9 +34,12 @@ android:id="@+id/sv_wallet" android:layout_width="match_parent" android:layout_height="match_parent" - android:fillViewport="true"> + android:fillViewport="true" + android:overScrollMode="never" + > @@ -54,12 +57,21 @@ android:src="@drawable/card_default" app:layout_constraintTop_toTopOf="parent" /> + + + app:layout_constraintTop_toBottomOf="@id/rv_pending_transaction" /> + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d7bf881470..3cd7b67af8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,6 +25,8 @@ Account is not created Load %1s+ %2s to create account Tokens + Receiving %1s %2s from + Sending %1s %2s to Create PayID Enter desired PayID first