diff options
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt')
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt b/wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt index 2e2ed8a..609629e 100644 --- a/wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt +++ b/wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt @@ -48,6 +48,8 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import net.taler.common.Amount import net.taler.wallet.R +import net.taler.wallet.backend.TalerErrorCode.WALLET_PEER_PULL_PAYMENT_INSUFFICIENT_BALANCE +import net.taler.wallet.backend.TalerErrorCode.WALLET_PEER_PUSH_PAYMENT_INSUFFICIENT_BALANCE import net.taler.wallet.backend.TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED import net.taler.wallet.backend.TalerErrorInfo @@ -132,7 +134,7 @@ fun ColumnScope.PeerPullTermsComposable( modifier = Modifier.align(End), ) { Text( - text = stringResource(id = R.string.payment_label_amount_total), + text = stringResource(id = R.string.amount_total_label), style = MaterialTheme.typography.bodyLarge, ) Text( @@ -143,22 +145,26 @@ fun ColumnScope.PeerPullTermsComposable( ) } // this gets used for credit and debit, so fee calculation differs - val fee = if (data.isCredit) { + val fee = if (data.isCredit && terms.amountRaw > terms.amountEffective) { terms.amountRaw - terms.amountEffective - } else { + } else if (terms.amountEffective > terms.amountRaw) { terms.amountEffective - terms.amountRaw + } else null + + if (fee != null) { + val feeStr = if (data.isCredit) { + stringResource(R.string.amount_negative, fee) + } else { + stringResource(R.string.amount_positive, fee) + } + Text( + modifier = Modifier.align(End), + text = feeStr, + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.error, + ) } - val feeStr = if (data.isCredit) { - stringResource(R.string.amount_negative, fee) - } else { - stringResource(R.string.amount_positive, fee) - } - if (!fee.isZero()) Text( - modifier = Modifier.align(End), - text = feeStr, - style = MaterialTheme.typography.bodyLarge, - color = MaterialTheme.colorScheme.error, - ) + if (terms is IncomingAccepting) { CircularProgressIndicator( modifier = Modifier @@ -187,11 +193,17 @@ fun ColumnScope.PeerPullTermsComposable( @Composable fun ColumnScope.PeerPullErrorComposable(s: IncomingError) { + val message = when (s.info.code) { + WALLET_PEER_PULL_PAYMENT_INSUFFICIENT_BALANCE -> stringResource(R.string.payment_balance_insufficient) + WALLET_PEER_PUSH_PAYMENT_INSUFFICIENT_BALANCE -> stringResource(R.string.payment_balance_insufficient) + else -> s.info.userFacingMsg + } + Text( modifier = Modifier .align(CenterHorizontally) .padding(horizontal = 32.dp), - text = s.info.userFacingMsg, + text = message, style = MaterialTheme.typography.headlineSmall, color = MaterialTheme.colorScheme.error, ) @@ -212,11 +224,11 @@ fun PeerPullCheckingPreview() { fun PeerPullTermsPreview() { Surface { val terms = IncomingTerms( - amountRaw = Amount.fromDouble("TESTKUDOS", 42.23), - amountEffective = Amount.fromDouble("TESTKUDOS", 42.423), + amountRaw = Amount.fromString("TESTKUDOS", "42.23"), + amountEffective = Amount.fromString("TESTKUDOS", "42.423"), contractTerms = PeerContractTerms( summary = "This is a long test summary that can be more than one line long for sure", - amount = Amount.fromDouble("TESTKUDOS", 23.42), + amount = Amount.fromString("TESTKUDOS", "23.42"), ), id = "ID123", ) @@ -232,11 +244,11 @@ fun PeerPullTermsPreview() { fun PeerPullAcceptingPreview() { Surface { val terms = IncomingTerms( - amountRaw = Amount.fromDouble("TESTKUDOS", 42.23), - amountEffective = Amount.fromDouble("TESTKUDOS", 42.123), + amountRaw = Amount.fromString("TESTKUDOS", "42.23"), + amountEffective = Amount.fromString("TESTKUDOS", "42.123"), contractTerms = PeerContractTerms( summary = "This is a long test summary that can be more than one line long for sure", - amount = Amount.fromDouble("TESTKUDOS", 23.42), + amount = Amount.fromString("TESTKUDOS", "23.42"), ), id = "ID123", ) |