commit d147b093cd1d0d3dfd3f2daf8f2eb05892fc2769
parent ba6c8259009814beb871033ed912d15b2e7ae0d4
Author: Iván Ávalos <avalos@disroot.org>
Date: Mon, 26 Aug 2024 20:38:28 +0200
[wallet] Also render KYC link on p2p credit transactions
bug 0009107
Diffstat:
7 files changed, 72 insertions(+), 14 deletions(-)
diff --git a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt
@@ -27,8 +27,11 @@ import net.taler.common.Timestamp
import net.taler.wallet.R
import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED
import net.taler.wallet.backend.TalerErrorInfo
+import net.taler.wallet.transactions.ActionButton
+import net.taler.wallet.transactions.ActionListener
import net.taler.wallet.transactions.AmountType
import net.taler.wallet.transactions.PeerInfoShort
+import net.taler.wallet.transactions.Transaction
import net.taler.wallet.transactions.TransactionAction.Abort
import net.taler.wallet.transactions.TransactionAction.Retry
import net.taler.wallet.transactions.TransactionAction.Suspend
@@ -42,7 +45,13 @@ import net.taler.wallet.transactions.TransactionPeerPullCredit
import net.taler.wallet.transactions.TransactionState
@Composable
-fun ColumnScope.TransactionPeerPullCreditComposable(t: TransactionPeerPullCredit, spec: CurrencySpecification?) {
+fun ColumnScope.TransactionPeerPullCreditComposable(
+ t: TransactionPeerPullCredit,
+ spec: CurrencySpecification?,
+ actionListener: ActionListener,
+) {
+ ActionButton(tx = t, listener = actionListener)
+
if (t.error == null) PeerQrCode(
state = t.txState,
talerUri = t.talerUri,
@@ -94,7 +103,9 @@ fun TransactionPeerPullCreditPreview(loading: Boolean = false) {
error = TalerErrorInfo(code = EXCHANGE_GENERIC_KYC_REQUIRED),
)
Surface {
- TransactionPeerComposable(t, true, null) {}
+ TransactionPeerComposable(t, true, null, object: ActionListener {
+ override fun onActionButtonClicked(tx: Transaction, type: ActionListener.Type) {}
+ }) {}
}
}
diff --git a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullDebit.kt b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullDebit.kt
@@ -26,8 +26,10 @@ import net.taler.common.Timestamp
import net.taler.wallet.R
import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED
import net.taler.wallet.backend.TalerErrorInfo
+import net.taler.wallet.transactions.ActionListener
import net.taler.wallet.transactions.AmountType
import net.taler.wallet.transactions.PeerInfoShort
+import net.taler.wallet.transactions.Transaction
import net.taler.wallet.transactions.TransactionAction.Abort
import net.taler.wallet.transactions.TransactionAction.Retry
import net.taler.wallet.transactions.TransactionAction.Suspend
@@ -85,6 +87,8 @@ fun TransactionPeerPullDebitPreview() {
error = TalerErrorInfo(code = EXCHANGE_GENERIC_KYC_REQUIRED),
)
Surface {
- TransactionPeerComposable(t, true, null) {}
+ TransactionPeerComposable(t, true, null, object: ActionListener {
+ override fun onActionButtonClicked(tx: Transaction, type: ActionListener.Type) {}
+ }) {}
}
}
diff --git a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt
@@ -26,8 +26,11 @@ import net.taler.common.Timestamp
import net.taler.wallet.R
import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED
import net.taler.wallet.backend.TalerErrorInfo
+import net.taler.wallet.transactions.ActionButton
+import net.taler.wallet.transactions.ActionListener
import net.taler.wallet.transactions.AmountType
import net.taler.wallet.transactions.PeerInfoShort
+import net.taler.wallet.transactions.Transaction
import net.taler.wallet.transactions.TransactionAction.Abort
import net.taler.wallet.transactions.TransactionAction.Retry
import net.taler.wallet.transactions.TransactionAction.Suspend
@@ -39,7 +42,13 @@ import net.taler.wallet.transactions.TransactionPeerPushCredit
import net.taler.wallet.transactions.TransactionState
@Composable
-fun TransactionPeerPushCreditComposable(t: TransactionPeerPushCredit, spec: CurrencySpecification?) {
+fun TransactionPeerPushCreditComposable(
+ t: TransactionPeerPushCredit,
+ spec: CurrencySpecification?,
+ actionListener: ActionListener,
+) {
+ ActionButton(tx = t, listener = actionListener)
+
TransactionAmountComposable(
label = stringResource(id = R.string.amount_sent),
amount = t.amountRaw.withSpec(spec),
@@ -85,6 +94,8 @@ fun TransactionPeerPushCreditPreview() {
error = TalerErrorInfo(code = EXCHANGE_GENERIC_KYC_REQUIRED),
)
Surface {
- TransactionPeerComposable(t, true, null) {}
+ TransactionPeerComposable(t, true, null, object : ActionListener {
+ override fun onActionButtonClicked(tx: Transaction, type: ActionListener.Type) {}
+ }) {}
}
}
diff --git a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushDebit.kt b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushDebit.kt
@@ -38,8 +38,10 @@ import net.taler.wallet.backend.TalerErrorInfo
import net.taler.wallet.compose.QrCodeUriComposable
import net.taler.wallet.compose.TalerSurface
import net.taler.wallet.compose.getQrCodeSize
+import net.taler.wallet.transactions.ActionListener
import net.taler.wallet.transactions.AmountType
import net.taler.wallet.transactions.PeerInfoShort
+import net.taler.wallet.transactions.Transaction
import net.taler.wallet.transactions.TransactionAction.Abort
import net.taler.wallet.transactions.TransactionAction.Retry
import net.taler.wallet.transactions.TransactionAction.Suspend
@@ -141,7 +143,9 @@ fun TransactionPeerPushDebitPreview(loading: Boolean = false) {
)
TalerSurface {
- TransactionPeerComposable(t, true, null) {}
+ TransactionPeerComposable(t, true, null, object: ActionListener {
+ override fun onActionButtonClicked(tx: Transaction, type: ActionListener.Type) {}
+ }) {}
}
}
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/ActionButtonComposable.kt b/wallet/src/main/java/net/taler/wallet/transactions/ActionButtonComposable.kt
@@ -48,7 +48,7 @@ interface ActionListener {
@Composable
fun ActionButton(
modifier: Modifier = Modifier,
- tx: TransactionWithdrawal,
+ tx: Transaction,
listener: ActionListener,
) {
if (tx.txState.major == Pending) {
@@ -64,21 +64,28 @@ fun ActionButton(
@Composable
private fun KycButton(
modifier: Modifier = Modifier,
- tx: TransactionWithdrawal,
+ tx: Transaction,
listener: ActionListener,
) {
Button(
onClick = { listener.onActionButtonClicked(tx, ActionListener.Type.COMPLETE_KYC) },
modifier = modifier,
) {
- Text(stringResource(R.string.transaction_action_kyc))
+ val label = stringResource(R.string.transaction_action_kyc)
+ Icon(
+ Icons.Default.Link,
+ label,
+ modifier = Modifier.size(ButtonDefaults.IconSize)
+ )
+ Spacer(Modifier.size(ButtonDefaults.IconSpacing))
+ Text(label)
}
}
@Composable
private fun ConfirmBankButton(
modifier: Modifier = Modifier,
- tx: TransactionWithdrawal,
+ tx: Transaction,
listener: ActionListener,
) {
Button(
@@ -99,7 +106,7 @@ private fun ConfirmBankButton(
@Composable
private fun ConfirmManualButton(
modifier: Modifier = Modifier,
- tx: TransactionWithdrawal,
+ tx: Transaction,
listener: ActionListener,
) {
Button(
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt
@@ -44,12 +44,13 @@ import net.taler.common.CurrencySpecification
import net.taler.common.toAbsoluteTime
import net.taler.wallet.R
import net.taler.wallet.compose.TalerSurface
+import net.taler.wallet.launchInAppBrowser
import net.taler.wallet.peer.TransactionPeerPullCreditComposable
import net.taler.wallet.peer.TransactionPeerPullDebitComposable
import net.taler.wallet.peer.TransactionPeerPushCreditComposable
import net.taler.wallet.peer.TransactionPeerPushDebitComposable
-class TransactionPeerFragment : TransactionDetailFragment() {
+class TransactionPeerFragment : TransactionDetailFragment(), ActionListener {
override fun onCreateView(
inflater: LayoutInflater,
@@ -61,12 +62,29 @@ class TransactionPeerFragment : TransactionDetailFragment() {
val t = transactionManager.selectedTransaction.observeAsState(null).value
if (t != null) TransactionPeerComposable(t, devMode,
balanceManager.getSpecForCurrency(t.amountRaw.currency),
+ this@TransactionPeerFragment,
) {
onTransitionButtonClicked(t, it)
}
}
}
}
+
+ override fun onActionButtonClicked(tx: Transaction, type: ActionListener.Type) {
+ when (type) {
+ ActionListener.Type.COMPLETE_KYC -> {
+ val kycUrl = when (tx) {
+ is TransactionPeerPullCredit -> tx.kycUrl
+ is TransactionPeerPushCredit -> tx.kycUrl
+ else -> return
+ } ?: return
+
+ launchInAppBrowser(requireContext(), kycUrl)
+ }
+
+ else -> {} // does not apply
+ }
+ }
}
@Composable
@@ -74,6 +92,7 @@ fun TransactionPeerComposable(
t: Transaction,
devMode: Boolean,
spec: CurrencySpecification?,
+ actionListener: ActionListener,
onTransition: (t: TransactionAction) -> Unit,
) {
val scrollState = rememberScrollState()
@@ -94,8 +113,8 @@ fun TransactionPeerComposable(
)
when (t) {
- is TransactionPeerPullCredit -> TransactionPeerPullCreditComposable(t, spec)
- is TransactionPeerPushCredit -> TransactionPeerPushCreditComposable(t, spec)
+ is TransactionPeerPullCredit -> TransactionPeerPullCreditComposable(t, spec, actionListener)
+ is TransactionPeerPushCredit -> TransactionPeerPushCreditComposable(t, spec, actionListener)
is TransactionPeerPullDebit -> TransactionPeerPullDebitComposable(t, spec)
is TransactionPeerPushDebit -> TransactionPeerPushDebitComposable(t, spec)
else -> error("unexpected transaction: ${t::class.simpleName}")
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt
@@ -456,6 +456,7 @@ class TransactionPeerPullCredit(
override val timestamp: Timestamp,
override val txState: TransactionState,
override val txActions: List<TransactionAction>,
+ val kycUrl: String? = null,
val exchangeBaseUrl: String,
override val error: TalerErrorInfo? = null,
override val amountRaw: Amount,
@@ -515,6 +516,7 @@ class TransactionPeerPushCredit(
override val timestamp: Timestamp,
override val txState: TransactionState,
override val txActions: List<TransactionAction>,
+ val kycUrl: String? = null,
val exchangeBaseUrl: String,
override val error: TalerErrorInfo? = null,
override val amountRaw: Amount,