TransactionWithdrawalFragment.kt (3874B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2020 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 android.os.Bundle 20 import android.view.LayoutInflater 21 import android.view.View 22 import android.view.ViewGroup 23 import androidx.compose.runtime.getValue 24 import androidx.compose.runtime.remember 25 import androidx.compose.ui.platform.ComposeView 26 import androidx.core.os.bundleOf 27 import androidx.navigation.fragment.findNavController 28 import net.taler.wallet.R 29 import net.taler.wallet.compose.TalerSurface 30 import net.taler.wallet.compose.collectAsStateLifecycleAware 31 import net.taler.wallet.launchInAppBrowser 32 import net.taler.wallet.transactions.WithdrawalDetails.TalerBankIntegrationApi 33 import net.taler.wallet.withdraw.TransactionWithdrawalComposable 34 35 class TransactionWithdrawalFragment : TransactionDetailFragment() { 36 37 override fun onCreateView( 38 inflater: LayoutInflater, 39 container: ViewGroup?, 40 savedInstanceState: Bundle?, 41 ): View = ComposeView(requireContext()).apply { 42 setContent { 43 TalerSurface { 44 val t by transactionManager.selectedTransaction.collectAsStateLifecycleAware() 45 (t as? TransactionWithdrawal)?.let { tx -> 46 // show QR code only if withdrawal only contains one 47 val qrCode = remember(tx) { 48 (tx.withdrawalDetails as? WithdrawalDetails.ManualTransfer)?.let { details -> 49 if (details.exchangeCreditAccountDetails?.size == 1) { 50 val account0 = details.exchangeCreditAccountDetails[0] 51 val qrCodes = withdrawManager.getQrCodesForPayto(account0.paytoUri) 52 if (qrCodes.size == 1) qrCodes[0] 53 else null 54 } else null 55 } 56 } 57 58 TransactionWithdrawalComposable( 59 t = tx, 60 devMode = devMode, 61 spec = exchangeManager.getSpecForCurrency(tx.amountRaw.currency, tx.scopes), 62 qrCode = qrCode, 63 onConfirmKyc = { onConfirmKyc(it) }, 64 onConfirmBank = { onConfirmBank(tx) }, 65 onConfirmManual = { onWireTransferSteps() }, 66 onShowQrCodes = { onShowQrCodes() }, 67 ) { 68 onTransitionButtonClicked(tx, it) 69 } 70 } 71 } 72 } 73 } 74 75 fun onConfirmKyc(url: String) { 76 launchInAppBrowser(requireContext(), url) 77 } 78 79 fun onConfirmBank(tx: TransactionWithdrawal) { 80 if (tx.withdrawalDetails !is TalerBankIntegrationApi) return 81 tx.withdrawalDetails.bankConfirmationUrl?.let { url -> 82 launchInAppBrowser(requireContext(), url) 83 } 84 } 85 86 fun onWireTransferSteps(showQrCodes: Boolean = false) { 87 findNavController().navigate( 88 R.id.action_global_wireTransferDetails, 89 bundleOf("showQrCodes" to showQrCodes) 90 ) 91 } 92 93 fun onShowQrCodes() { 94 onWireTransferSteps(showQrCodes = true) 95 } 96 }