summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-01-16 22:39:18 -0600
committerIván Ávalos <avalos@disroot.org>2023-01-16 22:39:18 -0600
commit3b584c20212c86142689592a24658b3b83464cb4 (patch)
tree0bb9604d5b24519cd43c87c7f95495c3f43197d8
parent46b1b61c1162ce67d155f4637e7709d2b8ec0901 (diff)
downloadtaler-android-dev/ivan-avalos/kyc.tar.gz
taler-android-dev/ivan-avalos/kyc.tar.bz2
taler-android-dev/ivan-avalos/kyc.zip
[wallet] Initial implementation of KYC handlingdev/ivan-avalos/kyc
#0007566
-rw-r--r--wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt3
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionAdapter.kt16
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt16
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt15
-rw-r--r--wallet/src/main/res/layout/fragment_transaction_withdrawal.xml23
-rw-r--r--wallet/src/main/res/layout/list_item_transaction.xml13
-rw-r--r--wallet/src/main/res/values/strings.xml1
7 files changed, 79 insertions, 8 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..e66c338 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt
@@ -57,6 +57,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())
@@ -107,4 +108,19 @@ class TransactionWithdrawalFragment : TransactionDetailFragment() {
} else ui.confirmWithdrawalButton.visibility = View.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) }
+ View.VISIBLE
+ }
+ else -> View.GONE
+ }
+ } ?: View.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..d4de099 100644
--- a/wallet/src/main/res/layout/fragment_transaction_withdrawal.xml
+++ b/wallet/src/main/res/layout/fragment_transaction_withdrawal.xml
@@ -62,12 +62,26 @@
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"
@@ -80,7 +94,6 @@
<TextView
android:id="@+id/chosenAmountView"
style="@style/TransactionContent"
- app:layout_constraintBottom_toTopOf="@+id/feeLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chosenAmountLabel"
@@ -90,7 +103,6 @@
android:id="@+id/feeLabel"
style="@style/TransactionLabel"
android:text="@string/withdraw_fees"
- app:layout_constraintBottom_toTopOf="@+id/feeView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chosenAmountView" />
@@ -99,7 +111,6 @@
android:id="@+id/feeView"
style="@style/TransactionContent"
android:textColor="@color/red"
- app:layout_constraintBottom_toTopOf="@+id/exchangeLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/feeLabel"
@@ -109,7 +120,6 @@
android:id="@+id/exchangeLabel"
style="@style/TransactionLabel"
android:text="@string/withdraw_exchange"
- app:layout_constraintBottom_toTopOf="@+id/exchangeView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/feeView" />
@@ -117,7 +127,6 @@
<TextView
android:id="@+id/exchangeView"
style="@style/TransactionContent"
- app:layout_constraintBottom_toTopOf="@+id/deleteButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/exchangeLabel"
@@ -127,10 +136,10 @@
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"
- app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/exchangeView" />
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>