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 | 88 |
1 files changed, 60 insertions, 28 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 0095bc4..609629e 100644 --- a/wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt +++ b/wallet/src/main/java/net/taler/wallet/peer/IncomingComposable.kt @@ -27,13 +27,13 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material.Button -import androidx.compose.material.ButtonDefaults -import androidx.compose.material.Card -import androidx.compose.material.CircularProgressIndicator -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Surface -import androidx.compose.material.Text +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Card +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.State import androidx.compose.runtime.mutableStateOf @@ -48,19 +48,25 @@ 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 data class IncomingData( + val isCredit: Boolean, @StringRes val intro: Int, @StringRes val button: Int, ) val incomingPush = IncomingData( + isCredit = true, intro = R.string.receive_peer_payment_intro, button = R.string.receive_peer_payment_title, ) val incomingPull = IncomingData( + isCredit = false, intro = R.string.pay_peer_intro, button = R.string.payment_button_confirm, ) @@ -85,12 +91,12 @@ fun IncomingComposable( ) when (val s = state.value) { IncomingChecking -> PeerPullCheckingComposable() - is IncomingTerms -> PeerPullTermsComposable(s, onAccept, data) is IncomingAccepting -> PeerPullTermsComposable(s, onAccept, data) + is IncomingTerms -> PeerPullTermsComposable(s, onAccept, data) + is IncomingError -> PeerPullErrorComposable(s) IncomingAccepted -> { // we navigate away, don't show anything } - is IncomingError -> PeerPullErrorComposable(s) } } } @@ -115,36 +121,50 @@ fun ColumnScope.PeerPullTermsComposable( .padding(16.dp) .align(CenterHorizontally), text = terms.contractTerms.summary, - style = MaterialTheme.typography.h5, + style = MaterialTheme.typography.headlineSmall, ) Spacer(modifier = Modifier.weight(1f)) Card(modifier = Modifier.fillMaxWidth()) { Column( - modifier = Modifier.padding(8.dp) + modifier = Modifier + .padding(8.dp) + .fillMaxWidth() ) { Row( modifier = Modifier.align(End), ) { Text( - text = stringResource(id = R.string.payment_label_amount_total), - style = MaterialTheme.typography.body1, + text = stringResource(id = R.string.amount_total_label), + style = MaterialTheme.typography.bodyLarge, ) Text( modifier = Modifier.padding(start = 8.dp), text = terms.contractTerms.amount.toString(), - style = MaterialTheme.typography.body1, + style = MaterialTheme.typography.bodyLarge, fontWeight = FontWeight.Bold, ) } - val fee = - Amount.zero(terms.amount.currency) // terms.amount - terms.contractTerms.amount - if (!fee.isZero()) { + // this gets used for credit and debit, so fee calculation differs + val fee = if (data.isCredit && terms.amountRaw > terms.amountEffective) { + terms.amountRaw - terms.amountEffective + } 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 = stringResource(id = R.string.payment_fee, fee), - style = MaterialTheme.typography.body1, + text = feeStr, + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.error, ) } + if (terms is IncomingAccepting) { CircularProgressIndicator( modifier = Modifier @@ -157,7 +177,7 @@ fun ColumnScope.PeerPullTermsComposable( .align(End) .padding(top = 8.dp), colors = ButtonDefaults.buttonColors( - backgroundColor = colorResource(R.color.green), + containerColor = colorResource(R.color.green), contentColor = Color.White, ), onClick = { onAccept(terms) }, @@ -173,13 +193,19 @@ 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, - style = MaterialTheme.typography.h5, - color = colorResource(id = R.color.red), + text = message, + style = MaterialTheme.typography.headlineSmall, + color = MaterialTheme.colorScheme.error, ) } @@ -198,10 +224,11 @@ fun PeerPullCheckingPreview() { fun PeerPullTermsPreview() { Surface { val terms = IncomingTerms( - amount = Amount.fromDouble("TESTKUDOS", 42.23), + 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", ) @@ -217,10 +244,11 @@ fun PeerPullTermsPreview() { fun PeerPullAcceptingPreview() { Surface { val terms = IncomingTerms( - amount = Amount.fromDouble("TESTKUDOS", 42.23), + 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", ) @@ -236,7 +264,11 @@ fun PeerPullAcceptingPreview() { fun PeerPullPayErrorPreview() { Surface { @SuppressLint("UnrememberedMutableState") - val s = mutableStateOf(IncomingError(TalerErrorInfo(42, "hint", "msg"))) + val s = mutableStateOf( + IncomingError( + info = TalerErrorInfo(WALLET_WITHDRAWAL_KYC_REQUIRED, "hint", "msg"), + ) + ) IncomingComposable(s, incomingPush) {} } } |