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