TransactionPeerPullDebit.kt (3853B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2022 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.material3.Surface 20 import androidx.compose.runtime.Composable 21 import androidx.compose.ui.Modifier 22 import androidx.compose.ui.res.stringResource 23 import androidx.compose.ui.tooling.preview.Preview 24 import net.taler.common.Amount 25 import net.taler.common.CurrencySpecification 26 import net.taler.common.Timestamp 27 import net.taler.wallet.R 28 import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED 29 import net.taler.wallet.backend.TalerErrorInfo 30 import net.taler.wallet.balances.ScopeInfo 31 import net.taler.wallet.transactions.AmountType 32 import net.taler.wallet.transactions.PeerInfoShort 33 import net.taler.wallet.transactions.TransactionAction.Abort 34 import net.taler.wallet.transactions.TransactionAction.Retry 35 import net.taler.wallet.transactions.TransactionAction.Suspend 36 import net.taler.wallet.transactions.TransactionAmountComposable 37 import net.taler.wallet.transactions.TransactionInfoComposable 38 import net.taler.wallet.transactions.TransactionMajorState.Pending 39 import net.taler.wallet.transactions.TransactionPeerComposable 40 import net.taler.wallet.transactions.TransactionPeerPullDebit 41 import net.taler.wallet.transactions.TransactionState 42 43 @Composable 44 fun TransactionPeerPullDebitComposable(t: TransactionPeerPullDebit, spec: CurrencySpecification?) { 45 TransactionAmountComposable( 46 label = stringResource(id = R.string.transaction_order_total), 47 amount = t.amountRaw.withSpec(spec), 48 amountType = AmountType.Neutral, 49 ) 50 51 if (t.amountEffective > t.amountRaw) { 52 val fee = t.amountEffective - t.amountRaw 53 TransactionAmountComposable( 54 label = stringResource(id = R.string.amount_fee), 55 amount = fee.withSpec(spec), 56 amountType = AmountType.Negative, 57 ) 58 } 59 60 TransactionAmountComposable( 61 label = stringResource(id = R.string.transaction_paid), 62 amount = t.amountEffective.withSpec(spec), 63 amountType = AmountType.Negative, 64 ) 65 66 TransactionInfoComposable( 67 label = stringResource(id = R.string.send_peer_purpose), 68 info = t.info.summary ?: "", 69 ) 70 } 71 72 @Preview 73 @Composable 74 fun TransactionPeerPullDebitPreview() { 75 val t = TransactionPeerPullDebit( 76 transactionId = "transactionId", 77 timestamp = Timestamp.fromMillis(System.currentTimeMillis() - 360 * 60 * 1000), 78 txState = TransactionState(Pending), 79 txActions = listOf(Retry, Suspend, Abort), 80 exchangeBaseUrl = "https://exchange.example.org/", 81 amountRaw = Amount.fromString("TESTKUDOS", "42.1337"), 82 amountEffective = Amount.fromString("TESTKUDOS", "42.23"), 83 info = PeerInfoShort( 84 expiration = Timestamp.fromMillis(System.currentTimeMillis() + 60 * 60 * 1000), 85 summary = "test invoice", 86 ), 87 error = TalerErrorInfo(code = EXCHANGE_GENERIC_KYC_REQUIRED), 88 scopes = listOf(ScopeInfo.Exchange( 89 currency = "TESTKUDOS", 90 url = "exchange.test.taler.net", 91 )) 92 ) 93 Surface { 94 TransactionPeerComposable(t, true, null, Modifier, {}) {} 95 } 96 }