taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

TransactionActionsComposable.kt (5699B)


      1 /*
      2  * This file is part of GNU Taler
      3  * (C) 2023 Taler Systems S.A.
      4  *
      5  * GNU Taler is free software; you can redistribute it and/or modify it under the
      6  * terms of the GNU General Public License as published by the Free Software
      7  * Foundation; either version 3, or (at your option) any later version.
      8  *
      9  * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11  * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License along with
     14  * GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 
     17 package net.taler.wallet.transactions
     18 
     19 import androidx.compose.foundation.layout.ColumnScope
     20 import androidx.compose.foundation.layout.Spacer
     21 import androidx.compose.foundation.layout.padding
     22 import androidx.compose.foundation.layout.size
     23 import androidx.compose.material.icons.Icons
     24 import androidx.compose.material.icons.filled.AccountBalance
     25 import androidx.compose.material.icons.filled.Link
     26 import androidx.compose.material.icons.filled.QrCode
     27 import androidx.compose.material3.Button
     28 import androidx.compose.material3.ButtonDefaults
     29 import androidx.compose.material3.Icon
     30 import androidx.compose.material3.MaterialTheme
     31 import androidx.compose.material3.Text
     32 import androidx.compose.runtime.Composable
     33 import androidx.compose.ui.Modifier
     34 import androidx.compose.ui.res.stringResource
     35 import androidx.compose.ui.text.style.TextAlign
     36 import androidx.compose.ui.unit.dp
     37 import net.taler.wallet.R
     38 import net.taler.wallet.transactions.TransactionMinorState.BankConfirmTransfer
     39 import net.taler.wallet.transactions.TransactionMinorState.ExchangeWaitReserve
     40 import net.taler.wallet.transactions.TransactionMinorState.KycAuthRequired
     41 import net.taler.wallet.transactions.TransactionMinorState.KycRequired
     42 import net.taler.wallet.transfer.PaytoQrCode
     43 import net.taler.wallet.withdraw.QrCodeSpec
     44 
     45 @Composable
     46 fun ColumnScope.WithdrawalActions(
     47     tx: TransactionWithdrawal,
     48     mainQrCode: QrCodeSpec? = null,
     49     onConfirmBank: () -> Unit,
     50     onConfirmKyc: (url: String) -> Unit,
     51     onConfirmManual: () -> Unit,
     52     onShowQrCodes: () -> Unit,
     53 ) {
     54     when (tx.txState.minor) {
     55         BankConfirmTransfer -> {
     56             ConfirmBankButton(onConfirmBank)
     57         }
     58 
     59         KycRequired -> if (tx.kycUrl != null) {
     60             ConfirmKycButton {
     61                 onConfirmKyc(tx.kycUrl)
     62             }
     63         }
     64 
     65         ExchangeWaitReserve -> {
     66             Text(
     67                 text = stringResource(R.string.withdraw_manual_instruction_manual),
     68                 modifier = Modifier.padding(16.dp),
     69                 textAlign = TextAlign.Center,
     70                 style = MaterialTheme.typography.bodyLarge,
     71             )
     72 
     73             WireTransferStepsButton(onConfirmManual)
     74 
     75             if (mainQrCode != null) {
     76                 Text(
     77                     text = stringResource(R.string.withdraw_manual_instruction_qr),
     78                     modifier = Modifier.padding(16.dp),
     79                     textAlign = TextAlign.Center,
     80                     style = MaterialTheme.typography.bodyLarge,
     81                 )
     82 
     83                 PaytoQrCode(
     84                     modifier = Modifier.padding(horizontal = 16.dp),
     85                     qrCode = mainQrCode,
     86                 )
     87             } else {
     88                 ShowQrCodesButton(onShowQrCodes)
     89             }
     90         }
     91 
     92         else -> {}
     93     }
     94 }
     95 
     96 @Composable
     97 fun ColumnScope.DepositActions(
     98     tx: TransactionDeposit,
     99     onWireTransfer: () -> Unit,
    100     onShowQrCodes: () -> Unit,
    101 ) {
    102     if (tx.txState.minor == KycAuthRequired) {
    103         WireTransferStepsButton(onWireTransfer)
    104         ShowQrCodesButton(onShowQrCodes)
    105     }
    106 }
    107 
    108 @Composable
    109 fun ColumnScope.PeerActions(
    110     tx: Transaction,
    111     onConfirmKyc: (url: String) -> Unit,
    112 ) {
    113     val kycUrl = when(tx) {
    114         is TransactionPeerPushCredit -> tx.kycUrl
    115         is TransactionPeerPullCredit -> tx.kycUrl
    116         else -> null
    117     } ?: return
    118 
    119     if (tx.txState.minor == KycRequired) {
    120         ConfirmKycButton { onConfirmKyc(kycUrl) }
    121     }
    122 }
    123 
    124 @Composable
    125 private fun ConfirmBankButton(onClick: () -> Unit) {
    126     Button(onClick) {
    127         val label = stringResource(R.string.withdraw_button_confirm_bank)
    128         Icon(
    129             Icons.Default.Link,
    130             label,
    131             modifier = Modifier.size(ButtonDefaults.IconSize)
    132         )
    133         Spacer(Modifier.size(ButtonDefaults.IconSpacing))
    134         Text(label)
    135     }
    136 }
    137 
    138 @Composable
    139 private fun WireTransferStepsButton(onClick: () -> Unit) {
    140     Button(onClick) {
    141         Icon(
    142             Icons.Default.AccountBalance,
    143             contentDescription = null,
    144             modifier = Modifier.size(ButtonDefaults.IconSize)
    145         )
    146         Spacer(Modifier.size(ButtonDefaults.IconSpacing))
    147         Text(stringResource(R.string.withdraw_manual_ready_details_intro))
    148     }
    149 }
    150 
    151 @Composable
    152 private fun ShowQrCodesButton(onClick: () -> Unit) {
    153     Button(onClick) {
    154         Icon(
    155             Icons.Default.QrCode,
    156             contentDescription = null,
    157             modifier = Modifier.size(ButtonDefaults.IconSize)
    158         )
    159         Spacer(Modifier.size(ButtonDefaults.IconSpacing))
    160         Text(stringResource(R.string.withdraw_manual_ready_details_qr))
    161     }
    162 }
    163 
    164 @Composable
    165 private fun ConfirmKycButton(onClick: () -> Unit) {
    166     Button(onClick) {
    167         Icon(
    168             Icons.Default.Link,
    169             contentDescription = null,
    170             modifier = Modifier.size(ButtonDefaults.IconSize)
    171         )
    172         Spacer(Modifier.size(ButtonDefaults.IconSpacing))
    173         Text(stringResource(R.string.transaction_action_kyc))
    174     }
    175 }