Updated on 2026-08-14

This commit is contained in:
Tangem 2020-09-11 12:14:58 +00:00
commit 1627ad1a71
16 changed files with 265 additions and 61 deletions

View file

@ -64,7 +64,7 @@ dependencies {
implementation 'com.google.android.material:material:1.2.1'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
implementation 'com.tangem:blockchain:1.28.0'
implementation 'com.tangem:blockchain:1.31.0'
//lifecycle
implementation "androidx.lifecycle:lifecycle-runtime:2.2.0"

View file

@ -1,5 +1,6 @@
package com.tangem.tap.features.send.redux
import com.tangem.blockchain.common.Amount
import org.rekotlin.Action
/**
@ -10,6 +11,10 @@ interface SendScreenActionUi : SendScreenAction
object ReleaseSendState : Action
data class PrepareSendScreen(
val amount: Amount
) : SendScreenAction
// Address or PayId
sealed class AddressPayIdActionUi : SendScreenActionUi {
data class ChangeAddressOrPayId(val data: String) : AddressPayIdActionUi()

View file

@ -1,6 +1,7 @@
package com.tangem.tap.features.wallet.redux
import android.content.Context
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.Wallet
import com.tangem.commands.Card
import com.tangem.tap.common.redux.ErrorAction
@ -39,7 +40,10 @@ sealed class WalletAction : Action {
}
object Scan : WalletAction()
object Send : WalletAction()
data class Send(val amount: Amount? = null) : WalletAction() {
object ChooseCurrency : WalletAction()
object Cancel : WalletAction()
}
object CreatePayId : WalletAction() {
data class CompleteCreatingPayId(val payId: String) : WalletAction()
data class Success(val payId: String) : WalletAction()

View file

@ -8,8 +8,11 @@ import com.tangem.common.CompletionResult
import com.tangem.common.extensions.toHexString
import com.tangem.tap.common.extensions.copyToClipboard
import com.tangem.tap.common.redux.AppState
import com.tangem.tap.common.redux.navigation.AppScreen
import com.tangem.tap.common.redux.navigation.NavigationAction
import com.tangem.tap.domain.PayIdManager
import com.tangem.tap.domain.TapError
import com.tangem.tap.features.send.redux.PrepareSendScreen
import com.tangem.tap.network.NetworkStateChanged
import com.tangem.tap.scope
import com.tangem.tap.store
@ -60,7 +63,7 @@ val walletMiddleware: Middleware<AppState> = { dispatch, state ->
is WalletAction.CreatePayId.CompleteCreatingPayId -> {
scope.launch {
val cardId = store.state.globalState.scanNoteResponse?.card?.cardId
val wallet = store.state.walletState.wallet
val wallet = store.state.globalState.scanNoteResponse?.walletManager?.wallet
val publicKey = store.state.globalState.scanNoteResponse?.card?.cardPublicKey
if (cardId != null && wallet != null && publicKey != null) {
val result = PayIdManager().setPayId(
@ -109,7 +112,23 @@ val walletMiddleware: Middleware<AppState> = { dispatch, state ->
val intent = Intent(Intent.ACTION_VIEW, uri)
ContextCompat.startActivity(action.context, intent, null)
}
is WalletAction.Send -> {
if (action.amount != null) {
store.dispatch(PrepareSendScreen(action.amount))
store.dispatch(NavigationAction.NavigateTo(AppScreen.Send))
} else {
if (store.state.walletState.wallet?.amounts?.size ?: 0 > 1) {
store.dispatch(WalletAction.Send.ChooseCurrency)
} else {
val amount = store.state.walletState.wallet?.amounts?.toList()
?.get(0)?.second
if (amount != null) {
store.dispatch(PrepareSendScreen(amount))
store.dispatch(NavigationAction.NavigateTo(AppScreen.Send))
}
}
}
}
}
next(action)
}

View file

@ -153,17 +153,19 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
token = newState.currencyData.token?.copy(fiatAmount = tokenFiatAmount)
))
}
// is WalletAction.LoadArtwork -> {
// newState = newState.copy(cardImage = null)
// }
is WalletAction.LoadArtwork.Success -> {
newState = newState.copy(cardImage = Artwork(action.artworkId, action.artwork.toBitmap()))
}
is WalletAction.ShowQrCode -> {
newState = newState.copy(qrCode = newState.addressData?.shareUrl?.toQrCode())
newState = newState.copy(
walletDialog = WalletDialog.QrDialog(
newState.addressData?.shareUrl?.toQrCode(),
newState.addressData?.shareUrl
)
)
}
is WalletAction.HideQrCode -> {
newState = newState.copy(qrCode = null)
newState = newState.copy(walletDialog = null)
}
is WalletAction.LoadPayId.Success -> newState = newState.copy(
payIdData = PayIdData(PayIdState.Created, action.payId)
@ -172,17 +174,25 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
payIdData = PayIdData(PayIdState.NotCreated, null)
)
is WalletAction.CreatePayId, is WalletAction.CreatePayId.Failure ->
newState = newState.copy(creatingPayIdState = CreatingPayIdState.EnterPayId)
newState = newState.copy(
walletDialog = WalletDialog.CreatePayIdDialog(CreatingPayIdState.EnterPayId)
)
is WalletAction.CreatePayId.CompleteCreatingPayId -> newState = newState.copy(
creatingPayIdState = CreatingPayIdState.Waiting
walletDialog = WalletDialog.CreatePayIdDialog(CreatingPayIdState.Waiting)
)
is WalletAction.CreatePayId.Success -> newState = newState.copy(
payIdData = PayIdData(PayIdState.Created, action.payId),
creatingPayIdState = null
)
is WalletAction.CreatePayId.Cancel -> newState = newState.copy(
creatingPayIdState = null
walletDialog = null
)
is WalletAction.CreatePayId.Cancel -> newState = newState.copy(walletDialog = null)
is WalletAction.Send.ChooseCurrency -> {
val amounts = newState.wallet?.amounts?.toList()?.unzip()?.second
newState = newState.copy(
walletDialog = WalletDialog.SelectAmountToSendDialog(amounts)
)
}
is WalletAction.Send.Cancel -> newState = newState.copy(walletDialog = null)
}
return newState
}

View file

@ -1,6 +1,7 @@
package com.tangem.tap.features.wallet.redux
import android.graphics.Bitmap
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.Wallet
import com.tangem.tap.common.entities.Button
import com.tangem.tap.features.wallet.models.PendingTransaction
@ -16,11 +17,16 @@ data class WalletState(
val addressData: AddressData? = null,
val currencyData: BalanceWidgetData = BalanceWidgetData(),
val payIdData: PayIdData = PayIdData(),
val qrCode: Bitmap? = null,
val creatingPayIdState: CreatingPayIdState? = null,
val walletDialog: WalletDialog? = null,
val mainButton: WalletMainButton = WalletMainButton.SendButton(false)
) : StateType
sealed class WalletDialog {
data class QrDialog(val qrCode: Bitmap?, val shareUrl: String?) : WalletDialog()
data class CreatePayIdDialog(val creatingPayIdState: CreatingPayIdState?) : WalletDialog()
data class SelectAmountToSendDialog(val amounts: List<Amount>?) : WalletDialog()
}
enum class ProgressState { Loading, Done, Error }

View file

@ -10,14 +10,14 @@ 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.*
import kotlinx.android.synthetic.main.item_pending_transaction.view.*
class PendingTransactionsAdapter
: ListAdapter<PendingTransaction, PendingTransactionsAdapter.TransactionsViewHolder>(DiffUtilCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TransactionsViewHolder {
val layout = LayoutInflater.from(parent.context)
.inflate(R.layout.layout_pending_transaction, parent, false)
.inflate(R.layout.item_pending_transaction, parent, false)
return TransactionsViewHolder(layout)
}
@ -26,8 +26,6 @@ class PendingTransactionsAdapter
}
object DiffUtilCallback : DiffUtil.ItemCallback<PendingTransaction>() {
override fun areContentsTheSame(
oldItem: PendingTransaction, newItem: PendingTransaction
) = oldItem == newItem
@ -35,7 +33,6 @@ class PendingTransactionsAdapter
override fun areItemsTheSame(
oldItem: PendingTransaction, newItem: PendingTransaction
) = oldItem == newItem
}
@ -58,5 +55,4 @@ class PendingTransactionsAdapter
view.iv_pending_transaction.setImageDrawable(view.context.getDrawableCompat(image))
}
}
}

View file

@ -1,5 +1,6 @@
package com.tangem.tap.features.wallet.ui
import android.app.Dialog
import android.graphics.Bitmap
import android.os.Bundle
import android.view.View
@ -11,9 +12,11 @@ import com.google.android.material.snackbar.Snackbar
import com.tangem.tap.common.extensions.getDrawable
import com.tangem.tap.common.extensions.hide
import com.tangem.tap.common.extensions.show
import com.tangem.tap.common.redux.navigation.AppScreen
import com.tangem.tap.common.redux.navigation.NavigationAction
import com.tangem.tap.features.wallet.redux.*
import com.tangem.tap.features.wallet.ui.dialogs.AmountToSendDialog
import com.tangem.tap.features.wallet.ui.dialogs.PayIdDialog
import com.tangem.tap.features.wallet.ui.dialogs.QrDialog
import com.tangem.tap.store
import com.tangem.wallet.R
import kotlinx.android.synthetic.main.card_balance.*
@ -24,8 +27,7 @@ import org.rekotlin.StoreSubscriber
class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<WalletState> {
private var qrDialog: QrDialog? = null
private var payIdDialog: PayIdDialog? = null
private var dialog: Dialog? = null
private var snackbar: Snackbar? = null
private lateinit var viewAdapter: PendingTransactionsAdapter
@ -93,12 +95,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
viewAdapter.submitList(state.pendingTransactions)
if (state.qrCode != null && state.addressData?.shareUrl != null) {
if (qrDialog == null) qrDialog = QrDialog(requireContext())
qrDialog?.showQr(state.qrCode, state.addressData.shareUrl)
} else {
qrDialog?.dismiss()
}
handleDialogs(state.walletDialog)
l_balance.show()
BalanceWidget(this, state.currencyData).setup()
@ -125,19 +122,6 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
PayIdState.ErrorLoading -> {
}
}
when (state.creatingPayIdState) {
CreatingPayIdState.EnterPayId -> {
if (payIdDialog == null) payIdDialog = PayIdDialog(requireContext())
payIdDialog?.show()
payIdDialog?.stopProgress()
}
CreatingPayIdState.Waiting -> payIdDialog?.showProgress()
null -> {
payIdDialog?.dismiss()
payIdDialog = null
}
}
}
private fun setupNoInternetHandling(state: WalletState) {
@ -169,7 +153,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
btn_main.setOnClickListener {
when (state.mainButton) {
is WalletMainButton.SendButton -> store.dispatch(NavigationAction.NavigateTo(AppScreen.Send))
is WalletMainButton.SendButton -> store.dispatch(WalletAction.Send())
is WalletMainButton.CreateWalletButton -> store.dispatch(WalletAction.CreateWallet)
}
}
@ -195,4 +179,36 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
}
}
private fun handleDialogs(walletDialog: WalletDialog?) {
when (walletDialog) {
is WalletDialog.QrDialog -> {
if (walletDialog.qrCode != null && walletDialog.shareUrl != null) {
if (dialog == null) dialog = QrDialog(requireContext()).apply {
this.showQr(walletDialog.qrCode, walletDialog.shareUrl)
}
}
}
is WalletDialog.CreatePayIdDialog -> {
when (walletDialog.creatingPayIdState) {
CreatingPayIdState.EnterPayId -> {
if (dialog == null) dialog = PayIdDialog(requireContext()).apply {
this.show()
this.stopProgress()
}
}
CreatingPayIdState.Waiting -> (dialog as? PayIdDialog)?.showProgress()
}
}
is WalletDialog.SelectAmountToSendDialog -> {
if (dialog == null) dialog = AmountToSendDialog(requireContext()).apply {
this.show(walletDialog.amounts)
}
}
null -> {
dialog?.dismiss()
dialog = null
}
}
}
}

View file

@ -0,0 +1,82 @@
package com.tangem.tap.features.wallet.ui.dialogs
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.view.ContextThemeWrapper
import androidx.recyclerview.widget.*
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.tangem.blockchain.common.Amount
import com.tangem.tap.common.extensions.toFormattedString
import com.tangem.tap.features.wallet.redux.WalletAction
import com.tangem.tap.store
import com.tangem.wallet.R
import kotlinx.android.synthetic.main.dialog_wallet_send.*
import kotlinx.android.synthetic.main.item_wallet_amount_to_send.view.*
class AmountToSendDialog(context: Context) : BottomSheetDialog(context) {
init {
this.setContentView(R.layout.dialog_wallet_send)
}
fun show(amounts: List<Amount>?) {
this.setOnDismissListener {
store.dispatch(WalletAction.Send.Cancel)
}
rv_amounts_to_send.layoutManager = LinearLayoutManager(context)
val dividerItemDecoration = DividerItemDecoration(
ContextThemeWrapper(rv_amounts_to_send.context, R.style.AppTheme),
DividerItemDecoration.VERTICAL
)
rv_amounts_to_send.addItemDecoration(dividerItemDecoration)
val viewAdapter = ChooseAmountAdapter()
rv_amounts_to_send.adapter = viewAdapter
viewAdapter.submitList(amounts)
show()
}
}
class ChooseAmountAdapter
: ListAdapter<Amount, ChooseAmountAdapter.AmountViewHolder>(DiffUtilCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AmountViewHolder {
val layout = LayoutInflater.from(parent.context)
.inflate(R.layout.item_wallet_amount_to_send, parent, false)
return AmountViewHolder(layout)
}
override fun onBindViewHolder(holder: AmountViewHolder, position: Int) {
holder.bind(currentList[position])
}
object DiffUtilCallback : DiffUtil.ItemCallback<Amount>() {
override fun areContentsTheSame(
oldItem: Amount, newItem: Amount
) = oldItem.currencySymbol == newItem.currencySymbol
override fun areItemsTheSame(
oldItem: Amount, newItem: Amount
) = oldItem == newItem
}
class AmountViewHolder(val view: View) :
RecyclerView.ViewHolder(view) {
fun bind(amount: Amount) {
view.tv_currency_symbol.text = amount.currencySymbol
view.tv_amount.text = amount.value?.toFormattedString(amount.decimals)
view.setOnClickListener {
store.dispatch(WalletAction.Send.Cancel)
store.dispatch(WalletAction.Send(amount))
}
}
}
}

View file

@ -1,4 +1,4 @@
package com.tangem.tap.features.wallet.ui
package com.tangem.tap.features.wallet.ui.dialogs
import android.app.Dialog
import android.content.Context

View file

@ -1,4 +1,4 @@
package com.tangem.tap.features.wallet.ui
package com.tangem.tap.features.wallet.ui.dialogs
import android.app.Dialog
import android.content.Context

View file

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="30dp"
android:height="30dp"
android:tint="@color/warning"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/warning"
android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z" />
</vector>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:layout_marginBottom="60dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:text="Select"
android:textSize="14sp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_amounts_to_send"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center">
<TextView
android:id="@+id/tv_currency_symbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:textColor="@color/darkGray6"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tv_amount"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="BTC" />
<TextView
android:id="@+id/tv_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/darkGray6"
android:textSize="20sp"
app:layout_constraintBaseline_toBaselineOf="@+id/tv_currency_symbol"
app:layout_constraintEnd_toStartOf="@+id/imageView"
app:layout_constraintStart_toEndOf="@+id/tv_currency_symbol"
tools:text="0.43" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_angle_bracket_right"
app:layout_constraintBottom_toBottomOf="@+id/tv_currency_symbol"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/tv_currency_symbol" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -68,9 +68,9 @@
<androidx.constraintlayout.widget.Group
android:id="@+id/group_error"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="tv_status_error, tv_status_error_message" />
<TextView
@ -91,19 +91,24 @@
<TextView
android:id="@+id/tv_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_marginEnd="4dp"
android:ellipsize="end"
android:gravity="end|bottom"
android:maxLines="1"
android:paddingTop="16dp"
android:textColor="@color/darkGray6"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="end"
app:autoSizeMaxTextSize="20sp"
app:autoSizeMinTextSize="12sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform"
app:layout_constraintEnd_toStartOf="@id/tv_currency_symbol"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@id/tv_currency"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@id/tv_currency_symbol"
tools:text="0.43" />
<TextView