diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt
index 12efe010c8..1b7eff8f23 100644
--- a/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt
+++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt
@@ -12,9 +12,10 @@ internal class WalletDetailsButtonsRow @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : LinearLayout(context, attrs, defStyleAttr) {
+
private val binding = ViewWalletDetailsButtonsRowBinding.inflate(
LayoutInflater.from(context),
- this
+ this,
)
var onBuyClick: (() -> Unit)? = null
@@ -36,7 +37,7 @@ internal class WalletDetailsButtonsRow @JvmOverloads constructor(
fun updateButtonsVisibility(
buyAllowed: Boolean,
sellAllowed: Boolean,
- sendAllowed: Boolean
+ sendAllowed: Boolean,
) = with(binding) {
btnBuy.isVisible = (buyAllowed && !sellAllowed) || (!buyAllowed && !sellAllowed)
btnBuy.isEnabled = buyAllowed
diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/MultiWalletView.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/MultiWalletView.kt
index 4267ad7ebd..73504ddbfc 100644
--- a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/MultiWalletView.kt
+++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/MultiWalletView.kt
@@ -1,5 +1,6 @@
package com.tangem.tap.features.wallet.ui.wallet
+import android.widget.Button
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import com.tangem.common.card.Card
@@ -20,11 +21,11 @@ import com.tangem.tap.features.wallet.redux.WalletState
import com.tangem.tap.features.wallet.ui.BalanceStatus
import com.tangem.tap.features.wallet.ui.WalletFragment
import com.tangem.tap.features.wallet.ui.adapters.WalletAdapter
+import com.tangem.tap.features.wallet.ui.view.WalletDetailsButtonsRow
import com.tangem.tap.store
import com.tangem.wallet.R
import com.tangem.wallet.databinding.FragmentWalletBinding
-
class MultiWalletView : WalletView() {
private lateinit var walletsAdapter: WalletAdapter
override fun changeWalletView(fragment: WalletFragment, binding: FragmentWalletBinding) {
@@ -33,14 +34,12 @@ class MultiWalletView : WalletView() {
showMultiWalletView(binding)
}
-
private fun showMultiWalletView(binding: FragmentWalletBinding) = with(binding) {
tvTwinCardNumber.hide()
rvPendingTransaction.hide()
lCardBalance.root.hide()
lAddress.root.hide()
- lButtonsShort.root.hide()
- lButtonsLong.root.hide()
+ rowButtons.hide()
lSingleWalletBalance.root.hide()
rvMultiwallet.show()
btnAddToken.show()
@@ -59,7 +58,6 @@ class MultiWalletView : WalletView() {
}
}
-
override fun onViewCreated() {
setupWalletsRecyclerView()
}
@@ -86,17 +84,17 @@ class MultiWalletView : WalletView() {
TokensAction.LoadCurrencies(
supportedBlockchains = currenciesRepository.getBlockchains(
card.firmwareVersion,
- card.isTestCard
+ card.isTestCard,
),
- scanResponse = store.state.globalState.scanResponse
- )
+ scanResponse = store.state.globalState.scanResponse,
+ ),
)
store.dispatch(TokensAction.AllowToAddTokens(true))
store.dispatch(
TokensAction.SetAddedCurrencies(
wallets = state.walletsData,
- derivationStyle = card.derivationStyle
- )
+ derivationStyle = card.derivationStyle,
+ ),
)
store.dispatch(NavigationAction.NavigateTo(AppScreen.AddTokens))
}
@@ -105,7 +103,7 @@ class MultiWalletView : WalletView() {
private fun handleBackupWarning(
binding: FragmentWalletBinding,
- showBackupWarning: Boolean
+ showBackupWarning: Boolean,
) = with(binding.lWalletBackupWarning) {
root.isVisible = showBackupWarning
root.setOnClickListener {
@@ -128,11 +126,11 @@ class MultiWalletView : WalletView() {
veilBalance.unVeil()
}
tvProcessing.animateVisibility(
- show = totalBalance.state == ProgressState.Error
+ show = totalBalance.state == ProgressState.Error,
)
tvBalance.text = totalBalance.fiatAmount.formatAmountAsSpannedString(
- currencySymbol = totalBalance.fiatCurrency.symbol
+ currencySymbol = totalBalance.fiatCurrency.symbol,
)
tvCurrencyName.text = totalBalance.fiatCurrency.code
@@ -145,14 +143,14 @@ class MultiWalletView : WalletView() {
private fun handleErrorStates(
state: WalletState,
binding: FragmentWalletBinding,
- fragment: WalletFragment
+ fragment: WalletFragment,
) {
when (state.primaryWallet?.currencyData?.status) {
BalanceStatus.EmptyCard -> {
showErrorState(
binding,
fragment.getText(R.string.wallet_error_empty_card),
- fragment.getString(R.string.wallet_error_empty_card_subtitle)
+ fragment.getString(R.string.wallet_error_empty_card_subtitle),
)
configureButtonsForEmptyWalletState(binding)
}
@@ -160,7 +158,7 @@ class MultiWalletView : WalletView() {
showErrorState(
binding,
fragment.getText(R.string.wallet_error_unsupported_blockchain),
- fragment.getString(R.string.wallet_error_unsupported_blockchain_subtitle)
+ fragment.getString(R.string.wallet_error_unsupported_blockchain_subtitle),
)
}
else -> { /* no-op */
@@ -184,9 +182,21 @@ class MultiWalletView : WalletView() {
private fun configureButtonsForEmptyWalletState(binding: FragmentWalletBinding) =
with(binding) {
- lButtonsLong.root.show()
- lButtonsLong.btnConfirmLong.setOnClickListener { store.dispatch(WalletAction.CreateWallet) }
- lButtonsLong.btnConfirmLong.text =
- fragment?.getText(R.string.wallet_button_create_wallet)
+ rowButtons.btnBuy.hide()
+ rowButtons.btnSell.hide()
+ rowButtons.btnTrade.hide()
+ rowButtons.show()
+
+ rowButtons.btnSend.text = fragment?.getText(R.string.wallet_button_create_wallet)
+ rowButtons.onSendClick = { store.dispatch(WalletAction.CreateWallet) }
}
-}
\ No newline at end of file
+}
+
+private val WalletDetailsButtonsRow.btnBuy: Button
+ get() = this.findViewById(R.id.btn_buy)
+private val WalletDetailsButtonsRow.btnSell: Button
+ get() = this.findViewById(R.id.btn_sell)
+private val WalletDetailsButtonsRow.btnTrade: Button
+ get() = this.findViewById(R.id.btn_trade)
+private val WalletDetailsButtonsRow.btnSend: Button
+ get() = this.findViewById(R.id.btn_send)
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt
index bcbb6a06ff..fa046cc3f0 100644
--- a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt
+++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt
@@ -2,7 +2,6 @@ package com.tangem.tap.features.wallet.ui.wallet
import android.view.View
import android.view.ViewGroup
-import android.widget.Button
import androidx.recyclerview.widget.LinearLayoutManager
import com.tangem.domain.common.TwinCardNumber
import com.tangem.tap.common.extensions.beginDelayedTransition
@@ -12,11 +11,15 @@ import com.tangem.tap.common.extensions.show
import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsState
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.models.PendingTransaction
-import com.tangem.tap.features.wallet.redux.*
+import com.tangem.tap.features.wallet.redux.WalletAction
+import com.tangem.tap.features.wallet.redux.WalletData
+import com.tangem.tap.features.wallet.redux.WalletMainButton
+import com.tangem.tap.features.wallet.redux.WalletState
import com.tangem.tap.features.wallet.ui.BalanceWidget
import com.tangem.tap.features.wallet.ui.MultipleAddressUiHelper
import com.tangem.tap.features.wallet.ui.WalletFragment
import com.tangem.tap.features.wallet.ui.adapters.PendingTransactionsAdapter
+import com.tangem.tap.features.wallet.ui.view.WalletDetailsButtonsRow
import com.tangem.tap.store
import com.tangem.wallet.R
import com.tangem.wallet.databinding.FragmentWalletBinding
@@ -55,7 +58,7 @@ class SingleWalletView : WalletView() {
state.primaryWallet ?: return
setupTwinCards(state.twinCardsState, binding)
- setupButtons(state.primaryWallet, state.isTangemTwins, binding)
+ setupButtons(state.primaryWallet, binding)
setupAddressCard(state.primaryWallet, binding)
showPendingTransactionsIfPresent(state.primaryWallet.pendingTransactions)
setupBalance(state, state.primaryWallet)
@@ -79,9 +82,7 @@ class SingleWalletView : WalletView() {
}
}
- private fun setupTwinCards(
- twinCardsState: TwinCardsState?, binding: FragmentWalletBinding,
- ) = with(binding) {
+ private fun setupTwinCards(twinCardsState: TwinCardsState?, binding: FragmentWalletBinding) = with(binding) {
twinCardsState?.cardNumber?.let { cardNumber ->
tvTwinCardNumber.show()
val number = when (cardNumber) {
@@ -96,19 +97,8 @@ class SingleWalletView : WalletView() {
}
}
- private fun setupButtons(
- state: WalletData, isTwinsWallet: Boolean, binding: FragmentWalletBinding,
- ) = with(binding) {
- setupButtonsType(state, binding)
- val tradeState = state.tradeCryptoState
- val btnConfirm = if (tradeState.isAvailableToSell() || tradeState.isAvailableToBuy()) {
- lButtonsShort.btnConfirm
- } else {
- lButtonsLong.btnConfirmLong
- }
-
- setupConfirmButton(state, btnConfirm, isTwinsWallet)
-
+ private fun setupButtons(state: WalletData, binding: FragmentWalletBinding) = with(binding) {
+ setupRowButtons(state, rowButtons)
lAddress.btnCopy.setOnClickListener {
state.walletAddresses?.selectedAddress?.address?.let { addressString ->
store.dispatch(WalletAction.CopyAddress(addressString, fragment!!.requireContext()))
@@ -124,64 +114,22 @@ class SingleWalletView : WalletView() {
)
}
}
-
- setupTradeButton(binding, state.tradeCryptoState)
}
- private fun setupTradeButton(binding: FragmentWalletBinding, tradeCryptoState: TradeCryptoState) {
- val allowedToBuy = tradeCryptoState.isAvailableToBuy()
- val allowedToSell = tradeCryptoState.isAvailableToSell()
- val action = when {
- allowedToBuy && !allowedToSell -> WalletAction.TradeCryptoAction.Buy()
- !allowedToBuy && allowedToSell -> WalletAction.TradeCryptoAction.Sell
- allowedToBuy && allowedToSell -> WalletAction.DialogAction.ChooseTradeActionDialog
- else -> null
- }
- val text = when {
- allowedToBuy && !allowedToSell -> R.string.wallet_button_buy
- !allowedToBuy && allowedToSell -> R.string.wallet_button_sell
- allowedToBuy && allowedToSell -> R.string.wallet_button_trade
- else -> R.string.wallet_button_trade
- }
- val icon = when {
- allowedToBuy && !allowedToSell -> R.drawable.ic_arrow_up
- !allowedToBuy && allowedToSell -> R.drawable.ic_arrow_down
- allowedToBuy && allowedToSell -> R.drawable.ic_arrows_up_down
- else -> null
- }
- with(binding) {
- lButtonsShort.btnTrade.text = fragment?.getText(text)
- icon?.let { lButtonsShort.btnTrade.setIconResource(it) }
- lButtonsShort.btnTrade.setOnClickListener { if (action != null) store.dispatch(action) }
- }
- }
+ private fun setupRowButtons(state: WalletData, rowButtons: WalletDetailsButtonsRow) {
+ val allowedToBuy = state.tradeCryptoState.isAvailableToBuy()
+ val allowedToSell = state.tradeCryptoState.isAvailableToSell()
+ rowButtons.updateButtonsVisibility(
+ buyAllowed = allowedToBuy,
+ sellAllowed = allowedToSell,
+ sendAllowed = state.mainButton.enabled,
+ )
- private fun setupButtonsType(state: WalletData, binding: FragmentWalletBinding) = with(binding) {
- if (state.tradeCryptoState.isAvailableToSell() || state.tradeCryptoState.isAvailableToBuy()) {
- lButtonsLong.root.hide()
- lButtonsShort.root.show()
- } else {
- lButtonsLong.root.show()
- lButtonsShort.root.hide()
- }
- }
+ rowButtons.onBuyClick = { store.dispatch(WalletAction.TradeCryptoAction.Buy()) }
+ rowButtons.onSendClick = { store.dispatch(WalletAction.TradeCryptoAction.Sell) }
+ rowButtons.onTradeClick = { store.dispatch(WalletAction.DialogAction.ChooseTradeActionDialog) }
- private fun setupConfirmButton(
- state: WalletData, btnConfirm: Button, isTwinsWallet: Boolean,
- ) {
- val buttonTitle = when (state.mainButton) {
- is WalletMainButton.SendButton -> R.string.wallet_button_send
- is WalletMainButton.CreateWalletButton -> {
- if (!isTwinsWallet) {
- R.string.wallet_button_create_wallet
- } else {
- R.string.wallet_button_create_twin_wallet
- }
- }
- }
- btnConfirm.text = fragment?.getString(buttonTitle)
- btnConfirm.isEnabled = state.mainButton.enabled
- btnConfirm.setOnClickListener {
+ rowButtons.onSendClick = {
when (state.mainButton) {
is WalletMainButton.SendButton -> store.dispatch(WalletAction.Send())
is WalletMainButton.CreateWalletButton -> store.dispatch(WalletAction.CreateWallet)
diff --git a/app/src/main/res/layout/fragment_wallet.xml b/app/src/main/res/layout/fragment_wallet.xml
index b2118902ec..fa0eaf1398 100644
--- a/app/src/main/res/layout/fragment_wallet.xml
+++ b/app/src/main/res/layout/fragment_wallet.xml
@@ -47,7 +47,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
- android:paddingBottom="74dp">
+ android:paddingBottom="32dp">
-
-
-
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent" />
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ tools:orientation="horizontal"
+ tools:parentTag="android.widget.LinearLayout">
-
+
+
-
-
+
+
+
+ android:id="@+id/btn_send"
+ style="@style/TapButtonWithIcon"
+ android:layout_width="0dp"
+ android:layout_marginStart="6dp"
+ android:layout_weight="1"
+ android:text="@string/wallet_button_send"
+ app:icon="@drawable/ic_send" />