IncomingPushPaymentScreen.kt (3243B)
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.runtime.livedata.observeAsState 26 import androidx.compose.ui.Modifier 27 import androidx.compose.ui.res.stringResource 28 import net.taler.wallet.NavigateCallback 29 import net.taler.wallet.R 30 import net.taler.wallet.WalletDestination 31 import net.taler.wallet.backend.TalerErrorInfo 32 import net.taler.wallet.compose.GlobalScaffold 33 import net.taler.wallet.compose.TalerSurface 34 import net.taler.wallet.compose.collectAsStateLifecycleAware 35 import net.taler.wallet.main.MainViewModel 36 37 @Composable 38 fun IncomingPushPaymentScreen( 39 model: MainViewModel, 40 onNavigate: NavigateCallback, 41 onNavigateBack: () -> Unit, 42 onShowError: (TalerErrorInfo) -> Unit, 43 ) { 44 val peerManager = model.peerManager 45 val transactionManager = model.transactionManager 46 val exchangeManager = model.exchangeManager 47 48 val state = peerManager.incomingPushState.collectAsStateLifecycleAware() 49 val exchanges by exchangeManager.exchanges.observeAsState() 50 51 LaunchedEffect(exchanges) { 52 exchanges?.let { 53 peerManager.refreshPeerPushCreditTos(it) 54 } 55 } 56 57 LaunchedEffect(state.value) { 58 val s = state.value 59 if (s is IncomingAccepted) { 60 if (transactionManager.selectTransaction(s.transactionId)) { 61 onNavigate(WalletDestination.TransactionPeer, true) 62 } else { 63 onNavigateBack() 64 } 65 } else if (s is IncomingError) { 66 onShowError(s.info) 67 } 68 } 69 70 TalerSurface { 71 GlobalScaffold( 72 model = model, 73 modifier = Modifier.fillMaxSize(), 74 title = { Text(stringResource(R.string.receive_peer_payment_title)) }, 75 onNavigateBack = onNavigateBack, 76 ) { paddingValues -> 77 IncomingComposable( 78 modifier = Modifier.padding(paddingValues), 79 state = state, 80 data = incomingPush 81 ) { terms -> 82 if (terms is IncomingTosReview) { 83 onNavigate(WalletDestination.ReviewExchangeTOS(terms.exchangeBaseUrl), false) 84 } else { 85 peerManager.confirmPeerPushCredit(terms) 86 } 87 } 88 } 89 } 90 }