diff options
7 files changed, 84 insertions, 5 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt index e52fd4f..c87c28c 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt @@ -68,6 +68,9 @@ data class TalerErrorInfo( // Error details @Serializable(JSONObjectDeserializer::class) val details: JSONObject? = null, + + // KYC URL (in case KYC is required) + val kycUrl: String? = null, ) { val userFacingMsg: String get() { diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionAdapter.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionAdapter.kt index b11f438..c4ec060 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionAdapter.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionAdapter.kt @@ -32,6 +32,7 @@ import androidx.recyclerview.selection.SelectionTracker import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.Adapter import androidx.recyclerview.widget.RecyclerView.ViewHolder +import com.google.android.material.button.MaterialButton import net.taler.common.exhaustive import net.taler.common.toRelativeTime import net.taler.wallet.R @@ -78,6 +79,7 @@ internal class TransactionAdapter( private val icon: ImageView = v.findViewById(R.id.icon) private val title: TextView = v.findViewById(R.id.title) private val extraInfoView: TextView = v.findViewById(R.id.extraInfoView) + private val actionButton: MaterialButton = v.findViewById(R.id.actionButton) private val time: TextView = v.findViewById(R.id.time) private val amount: TextView = v.findViewById(R.id.amount) private val pendingView: TextView = v.findViewById(R.id.pendingView) @@ -95,6 +97,7 @@ internal class TransactionAdapter( } title.text = transaction.getTitle(context) bindExtraInfo(transaction) + bindActionButton(transaction) time.text = transaction.timestamp.ms.toRelativeTime(context) bindAmount(transaction) pendingView.visibility = if (transaction.pending) VISIBLE else GONE @@ -123,6 +126,19 @@ internal class TransactionAdapter( } } + private fun bindActionButton(transaction: Transaction) { + actionButton.setOnClickListener { listener.onActionButtonClicked(transaction) } + actionButton.visibility = transaction.error?.let { error -> + when (error.code) { + 7025 -> { // KYC + actionButton.setText(R.string.transaction_action_kyc) + VISIBLE + } + else -> GONE + } + } ?: GONE + } + private fun bindAmount(transaction: Transaction) { val amountStr = transaction.amountEffective.amountStr when (transaction.amountType) { diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt index ff8d272..feea5ba 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt @@ -22,6 +22,8 @@ import android.net.Uri import android.os.Bundle import android.view.LayoutInflater import android.view.View +import android.view.View.GONE +import android.view.View.VISIBLE import android.view.ViewGroup import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController @@ -57,6 +59,7 @@ class TransactionWithdrawalFragment : TransactionDetailFragment() { ui.effectiveAmountLabel.text = getString(R.string.withdraw_total) ui.effectiveAmountView.text = t.amountEffective.toString() setupConfirmWithdrawalButton(t) + setupActionButton(t) ui.chosenAmountLabel.text = getString(R.string.amount_chosen) ui.chosenAmountView.text = getString(R.string.amount_positive, t.amountRaw.toString()) @@ -103,8 +106,23 @@ class TransactionWithdrawalFragment : TransactionDetailFragment() { findNavController().navigate( R.id.action_nav_transactions_detail_withdrawal_to_nav_exchange_manual_withdrawal_success) } - } else ui.confirmWithdrawalButton.visibility = View.GONE - } else ui.confirmWithdrawalButton.visibility = View.GONE + } else ui.confirmWithdrawalButton.visibility = GONE + } else ui.confirmWithdrawalButton.visibility = GONE } + private fun setupActionButton(t: TransactionWithdrawal) { + ui.actionButton.visibility = t.error?.let { error -> + when (error.code) { + 7025 -> { // KYC + ui.actionButton.setText(R.string.transaction_action_kyc) + val i = Intent(ACTION_VIEW).apply { + data = Uri.parse(error.kycUrl) + } + ui.actionButton.setOnClickListener { startActivitySafe(i) } + VISIBLE + } + else -> GONE + } + } ?: GONE + } } diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt index 969b0de..f8c1047 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt @@ -16,6 +16,8 @@ package net.taler.wallet.transactions +import android.content.Intent +import android.net.Uri import android.os.Bundle import android.view.ActionMode import android.view.LayoutInflater @@ -39,12 +41,14 @@ import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL import net.taler.common.Amount import net.taler.common.fadeIn import net.taler.common.fadeOut +import net.taler.common.startActivitySafe import net.taler.wallet.MainViewModel import net.taler.wallet.R import net.taler.wallet.databinding.FragmentTransactionsBinding interface OnTransactionClickListener { fun onTransactionClicked(transaction: Transaction) + fun onActionButtonClicked(transaction: Transaction) } class TransactionsFragment : Fragment(), OnTransactionClickListener, ActionMode.Callback { @@ -177,6 +181,17 @@ class TransactionsFragment : Fragment(), OnTransactionClickListener, ActionMode. } } + override fun onActionButtonClicked(transaction: Transaction) { + transaction.error?.let {error -> + when (error.code) { + 7025 -> { // KYC + val i = Intent(Intent.ACTION_VIEW, Uri.parse(error.kycUrl)) + startActivitySafe(i) + } + } + } + } + private fun onTransactionsResult(result: TransactionsResult) = when (result) { is TransactionsResult.Error -> { ui.list.fadeOut() diff --git a/wallet/src/main/res/layout/fragment_transaction_withdrawal.xml b/wallet/src/main/res/layout/fragment_transaction_withdrawal.xml index 78d1667..783b2d9 100644 --- a/wallet/src/main/res/layout/fragment_transaction_withdrawal.xml +++ b/wallet/src/main/res/layout/fragment_transaction_withdrawal.xml @@ -62,19 +62,33 @@ android:drawableLeft="@drawable/ic_account_balance" android:text="@string/withdraw_button_confirm_bank" app:drawableTint="?attr/colorOnPrimarySurface" - app:layout_constraintBottom_toTopOf="@+id/chosenAmountLabel" + app:layout_constraintBottom_toTopOf="@+id/actionButton" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/effectiveAmountView" tools:ignore="RtlHardcoded" /> + <Button + android:id="@+id/actionButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginVertical="10dp" + android:backgroundTint="@color/colorAccent" + android:visibility="gone" + app:layout_constraintBottom_toTopOf="@id/chosenAmountLabel" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/confirmWithdrawalButton" + tools:text="@string/transaction_action_kyc" + tools:visibility="visible" /> + <TextView android:id="@+id/chosenAmountLabel" style="@style/TransactionLabel" app:layout_constraintBottom_toTopOf="@+id/chosenAmountView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/confirmWithdrawalButton" + app:layout_constraintTop_toBottomOf="@+id/actionButton" tools:text="@string/amount_chosen" /> <TextView @@ -127,6 +141,7 @@ android:id="@+id/deleteButton" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginVertical="10dp" android:text="@string/transactions_delete" app:backgroundTint="@color/red" app:icon="@drawable/ic_delete" diff --git a/wallet/src/main/res/layout/list_item_transaction.xml b/wallet/src/main/res/layout/list_item_transaction.xml index 64d9045..232afb8 100644 --- a/wallet/src/main/res/layout/list_item_transaction.xml +++ b/wallet/src/main/res/layout/list_item_transaction.xml @@ -62,6 +62,17 @@ tools:text="@string/withdraw_waiting_confirm" tools:visibility="visible" /> + <com.google.android.material.button.MaterialButton + android:id="@+id/actionButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:visibility="gone" + app:backgroundTint="@color/colorAccent" + app:layout_constraintStart_toStartOf="@id/title" + app:layout_constraintTop_toBottomOf="@id/extraInfoView" + tools:text="Complete KYC" + tools:visibility="visible"/> + <TextView android:id="@+id/time" android:layout_width="0dp" @@ -72,7 +83,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/barrier" app:layout_constraintStart_toStartOf="@+id/title" - app:layout_constraintTop_toBottomOf="@+id/extraInfoView" + app:layout_constraintTop_toBottomOf="@+id/actionButton" tools:text="23 min ago" /> <androidx.constraintlayout.widget.Barrier diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml index 51c2ff3..52dacfe 100644 --- a/wallet/src/main/res/values/strings.xml +++ b/wallet/src/main/res/values/strings.xml @@ -105,6 +105,7 @@ GNU Taler is immune against many types of fraud, such as phishing of credit card <string name="transaction_peer_pull_credit">Invoice</string> <string name="transaction_peer_pull_debit">Invoice paid</string> <string name="transaction_peer_push_credit">Push payment</string> + <string name="transaction_action_kyc">Complete KYC</string> <string name="payment_title">Payment</string> <string name="payment_fee">+%s payment fee</string> |