WireTransferDetailsScreen.kt (5188B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2026 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.transfer 18 19 import androidx.compose.foundation.layout.fillMaxSize 20 import androidx.compose.foundation.layout.padding 21 import androidx.compose.material3.Text 22 import androidx.compose.runtime.Composable 23 import androidx.compose.runtime.LaunchedEffect 24 import androidx.compose.runtime.getValue 25 import androidx.compose.runtime.livedata.observeAsState 26 import androidx.compose.runtime.remember 27 import androidx.compose.ui.Modifier 28 import androidx.compose.ui.platform.LocalContext 29 import androidx.compose.ui.res.stringResource 30 import net.taler.lib.android.openUri 31 import net.taler.lib.android.shareText 32 import net.taler.wallet.R 33 import net.taler.wallet.compose.GlobalScaffold 34 import net.taler.wallet.compose.collectAsStateLifecycleAware 35 import net.taler.wallet.main.MainViewModel 36 import net.taler.wallet.transactions.TransactionDeposit 37 import net.taler.wallet.transactions.TransactionMajorState.Done 38 import net.taler.wallet.transactions.TransactionWithdrawal 39 import net.taler.wallet.transactions.WithdrawalDetails 40 import net.taler.wallet.transactions.WithdrawalExchangeAccountDetails 41 42 @Composable 43 fun WireTransferDetailsScreen( 44 model: MainViewModel, 45 showQrCodes: Boolean, 46 onNavigateBack: () -> Unit, 47 ) { 48 val context = LocalContext.current 49 val sharePaymentTitle = stringResource(R.string.share_payment) 50 val transactionManager = model.transactionManager 51 val withdrawManager = model.withdrawManager 52 val exchangeManager = model.exchangeManager 53 54 val selectedTx by transactionManager.selectedTransaction.collectAsStateLifecycleAware() 55 val devMode by model.devMode.observeAsState(false) 56 57 LaunchedEffect(selectedTx) { 58 if (selectedTx?.txState?.major == Done) { 59 onNavigateBack() 60 } 61 } 62 63 GlobalScaffold( 64 model = model, 65 modifier = Modifier.fillMaxSize(), 66 title = { Text(stringResource(R.string.wire_transfer)) }, 67 onNavigateBack = onNavigateBack, 68 ) { paddingValues -> 69 val transfers = remember(selectedTx) { 70 selectedTx?.let { tx -> 71 when (tx) { 72 is TransactionWithdrawal -> when (tx.withdrawalDetails) { 73 is WithdrawalDetails.ManualTransfer -> { 74 tx.withdrawalDetails.exchangeCreditAccountDetails 75 } 76 else -> null 77 } 78 is TransactionDeposit -> tx.kycAuthTransferInfo?.let { 79 it.creditPaytoUris.map { paytoUri -> 80 WithdrawalExchangeAccountDetails( 81 paytoUri = paytoUri, 82 status = WithdrawalExchangeAccountDetails.Status.Ok, 83 ) 84 } 85 } 86 else -> null 87 }?.map { 88 it.getTransferDetails( 89 amountRaw = tx.amountRaw, 90 amountEffective = tx.amountEffective 91 ) 92 } 93 } 94 }?.filterNotNull() 95 96 if (transfers != null) ScreenTransfer( 97 modifier = Modifier.padding(paddingValues), 98 transfers = transfers, 99 getQrCodes = { withdrawManager.getQrCodesForPayto(it.withdrawalAccount.paytoUri) }, 100 spec = selectedTx?.amountRaw?.currency?.let { 101 selectedTx?.scopes?.let { selectedScopes -> 102 exchangeManager.getSpecForCurrency(it, selectedScopes) 103 } ?: run { 104 exchangeManager.getSpecForCurrency(it) 105 } 106 }, 107 bankAppClick = { transfer -> 108 context.openUri( 109 uri = transfer.withdrawalAccount.paytoUri, 110 title = sharePaymentTitle 111 ) 112 }, 113 shareClick = { transfer -> 114 context.shareText( 115 text = transfer.withdrawalAccount.paytoUri, 116 ) 117 }, 118 showQrCodes = showQrCodes, 119 devMode = devMode, 120 transferContext = when (val tx = selectedTx) { 121 is TransactionWithdrawal -> TransferContext.ManualWithdrawal 122 is TransactionDeposit -> TransferContext.DepositKycAuth( 123 tx.kycAuthTransferInfo?.debitPaytoUri ?: "" 124 ) 125 else -> return@GlobalScaffold 126 } 127 ) 128 } 129 }