OutgoingPushScreen.kt (3744B)
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.DisposableEffect 24 import androidx.compose.runtime.LaunchedEffect 25 import androidx.compose.runtime.getValue 26 import androidx.compose.runtime.livedata.observeAsState 27 import androidx.compose.runtime.remember 28 import androidx.compose.ui.Modifier 29 import androidx.compose.ui.res.stringResource 30 import net.taler.wallet.NavigateCallback 31 import net.taler.wallet.R 32 import net.taler.wallet.WalletDestination 33 import net.taler.wallet.backend.TalerErrorInfo 34 import net.taler.wallet.compose.GlobalScaffold 35 import net.taler.wallet.compose.TalerSurface 36 import net.taler.wallet.compose.collectAsStateLifecycleAware 37 import net.taler.wallet.main.MainViewModel 38 import net.taler.wallet.main.ViewMode 39 40 @Composable 41 fun OutgoingPushScreen( 42 model: MainViewModel, 43 onNavigate: NavigateCallback, 44 onNavigateBack: () -> Unit, 45 onShowError: (TalerErrorInfo) -> Unit, 46 ) { 47 val peerManager = model.peerManager 48 val transactionManager = model.transactionManager 49 val balanceManager = model.balanceManager 50 val exchangeManager = model.exchangeManager 51 52 val state by peerManager.pushState.collectAsStateLifecycleAware() 53 val viewMode by model.viewMode.collectAsStateLifecycleAware() 54 val devMode by model.devMode.observeAsState(false) 55 56 DisposableEffect(Unit) { 57 onDispose { 58 peerManager.resetPushPayment() 59 } 60 } 61 62 LaunchedEffect(state) { 63 val s = state 64 if (s is OutgoingResponse) { 65 if (transactionManager.selectTransaction(s.transactionId)) { 66 onNavigate(WalletDestination.TransactionPeer, true) 67 } else { 68 onNavigateBack() 69 } 70 } 71 72 if (s is OutgoingError) { 73 onShowError(s.info) 74 } 75 } 76 77 TalerSurface { 78 GlobalScaffold( 79 model = model, 80 modifier = Modifier.fillMaxSize(), 81 title = { Text(stringResource(R.string.send_peer_title)) }, 82 onNavigateBack = onNavigateBack, 83 ) { paddingValues -> 84 OutgoingPushComposable( 85 modifier = Modifier.padding(paddingValues), 86 state = state, 87 defaultScope = remember { (viewMode as? ViewMode.Transactions)?.selectedScope }, 88 scopes = balanceManager.getScopes(true), 89 devMode = devMode, 90 getCurrencySpec = exchangeManager::getSpecForScopeInfo, 91 getFees = { 92 model.selectScope(it.scope) 93 peerManager.checkPeerPushFees(it.amount, restrictScope = it.scope) 94 }, 95 onSend = { amount, summary, hours -> 96 peerManager.initiatePeerPushDebit(amount.amount, summary, hours, restrictScope = amount.scope) 97 }, 98 ) 99 } 100 } 101 }