IncomingPullPaymentScreen.kt (2784B)
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.peer 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.ui.Modifier 26 import androidx.compose.ui.res.stringResource 27 import net.taler.wallet.NavigateCallback 28 import net.taler.wallet.R 29 import net.taler.wallet.WalletDestination 30 import net.taler.wallet.backend.TalerErrorInfo 31 import net.taler.wallet.compose.GlobalScaffold 32 import net.taler.wallet.compose.TalerSurface 33 import net.taler.wallet.compose.collectAsStateLifecycleAware 34 import net.taler.wallet.main.MainViewModel 35 36 @Composable 37 fun IncomingPullPaymentScreen( 38 model: MainViewModel, 39 onNavigate: NavigateCallback, 40 onNavigateBack: () -> Unit, 41 onShowError: (TalerErrorInfo) -> Unit, 42 ) { 43 val peerManager = model.peerManager 44 val transactionManager = model.transactionManager 45 46 val state by peerManager.incomingPullState.collectAsStateLifecycleAware() 47 48 LaunchedEffect(state) { 49 val s = state 50 if (s is IncomingAccepted) { 51 if (transactionManager.selectTransaction(s.transactionId)) { 52 onNavigate(WalletDestination.TransactionPeer, true) 53 } else { 54 onNavigateBack() 55 } 56 } else if (s is IncomingError) { 57 onShowError(s.info) 58 } 59 } 60 61 TalerSurface { 62 GlobalScaffold( 63 model = model, 64 modifier = Modifier.fillMaxSize(), 65 title = { Text(stringResource(R.string.pay_peer_title)) }, 66 onNavigateBack = onNavigateBack, 67 ) { paddingValues -> 68 IncomingComposable( 69 modifier = Modifier.padding(paddingValues), 70 state = peerManager.incomingPullState.collectAsStateLifecycleAware(), 71 data = incomingPull 72 ) { terms -> 73 peerManager.confirmPeerPullDebit(terms) 74 } 75 } 76 } 77 }