diff options
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/withdraw/manual')
8 files changed, 672 insertions, 358 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawFragment.kt index aae8c95..c499c3b 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawFragment.kt @@ -25,6 +25,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController import net.taler.common.Amount +import net.taler.common.AmountParserException import net.taler.common.hideKeyboard import net.taler.wallet.MainViewModel import net.taler.wallet.R @@ -73,14 +74,13 @@ class ManualWithdrawFragment : Fragment() { return } ui.amountLayout.error = null - val value: Double + val amount: Amount try { - value = ui.amountView.text.toString().replace(',', '.').toDouble() - } catch (e: NumberFormatException) { + amount = Amount.fromString(currency, ui.amountView.text.toString()) + } catch (e: AmountParserException) { ui.amountLayout.error = getString(R.string.withdraw_amount_error) return } - val amount = Amount.fromDouble(currency, value) ui.amountView.hideKeyboard() withdrawManager.getWithdrawalDetails(exchangeItem.exchangeBaseUrl, amount) diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawSuccessFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawSuccessFragment.kt index 3102123..63413c2 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawSuccessFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawSuccessFragment.kt @@ -16,59 +16,78 @@ package net.taler.wallet.withdraw.manual -import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.appcompat.app.AppCompatActivity import androidx.compose.ui.platform.ComposeView import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController -import net.taler.common.startActivitySafe +import net.taler.common.openUri +import net.taler.common.shareText import net.taler.wallet.MainViewModel import net.taler.wallet.R import net.taler.wallet.compose.TalerSurface +import net.taler.wallet.withdraw.TransferData import net.taler.wallet.withdraw.WithdrawStatus class ManualWithdrawSuccessFragment : Fragment() { private val model: MainViewModel by activityViewModels() - private val transactionManager by lazy { model.transactionManager } private val withdrawManager by lazy { model.withdrawManager } + private val balanceManager by lazy { model.balanceManager } + + private lateinit var status: WithdrawStatus.ManualTransferRequired + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, ): View = ComposeView(requireContext()).apply { - val status = withdrawManager.withdrawStatus.value as WithdrawStatus.ManualTransferRequired - val intent = Intent().apply { - data = status.uri - } - // TODO test if this works with an actual payto:// handling app - val componentName = intent.resolveActivity(requireContext().packageManager) - val onBankAppClick = if (componentName == null) null else { - { requireContext().startActivitySafe(intent) } - } - val tid = status.transactionId - val onCancelClick = if (tid == null) null else { - { - transactionManager.deleteTransaction(tid) - findNavController().navigate(R.id.action_nav_exchange_manual_withdrawal_success_to_nav_main) + status = withdrawManager.withdrawStatus.value as WithdrawStatus.ManualTransferRequired + + // Set action bar subtitle and unset on exit + if (status.withdrawalTransfers.size > 1) { + val activity = requireActivity() as AppCompatActivity + + activity.apply { + supportActionBar?.subtitle = getString(R.string.withdraw_subtitle) + } + + findNavController().addOnDestinationChangedListener { controller, destination, args -> + if (destination.id != R.id.nav_exchange_manual_withdrawal_success) { + activity.apply { + supportActionBar?.subtitle = null + } + } } } + setContent { TalerSurface { - when (status) { - is WithdrawStatus.ManualTransferRequiredBitcoin -> { - ScreenBitcoin(status, onBankAppClick, onCancelClick) - } - is WithdrawStatus.ManualTransferRequiredIBAN -> { - ScreenIBAN(status, onBankAppClick, onCancelClick) - } - } + ScreenTransfer( + status = status, + spec = balanceManager.getSpecForCurrency(status.transactionAmountRaw.currency), + bankAppClick = { onBankAppClick(it) }, + shareClick = { onShareClick(it) }, + ) } } } + private fun onBankAppClick(transfer: TransferData) { + requireContext().openUri( + uri = transfer.withdrawalAccount.paytoUri, + title = requireContext().getString(R.string.share_payment) + ) + } + + private fun onShareClick(transfer: TransferData) { + requireContext().shareText( + text = transfer.withdrawalAccount.paytoUri, + ) + } + override fun onStart() { super.onStart() activity?.setTitle(R.string.withdraw_title) diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ScreenBitcoin.kt b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ScreenBitcoin.kt deleted file mode 100644 index fa20072..0000000 --- a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ScreenBitcoin.kt +++ /dev/null @@ -1,169 +0,0 @@ -/* - * This file is part of GNU Taler - * (C) 2022 Taler Systems S.A. - * - * GNU Taler is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 3, or (at your option) any later version. - * - * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - -package net.taler.wallet.withdraw.manual - -import android.net.Uri -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.wrapContentWidth -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.Button -import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Surface -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Alignment.Companion.End -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.em -import net.taler.common.Amount -import net.taler.wallet.CURRENCY_BTC -import net.taler.wallet.R -import net.taler.wallet.compose.CopyToClipboardButton -import net.taler.wallet.withdraw.WithdrawStatus - -@Composable -fun ScreenBitcoin( - status: WithdrawStatus.ManualTransferRequiredBitcoin, - bankAppClick: (() -> Unit)?, - onCancelClick: (() -> Unit)?, -) { - val scrollState = rememberScrollState() - Column(modifier = Modifier - .wrapContentWidth(Alignment.CenterHorizontally) - .verticalScroll(scrollState) - .padding(all = 16.dp) - ) { - Text( - text = stringResource(R.string.withdraw_manual_bitcoin_title), - style = MaterialTheme.typography.headlineSmall, - ) - Text( - text = stringResource(R.string.withdraw_manual_bitcoin_intro), - style = MaterialTheme.typography.bodyLarge, - modifier = Modifier - .padding(vertical = 8.dp) - ) - BitcoinSegwitAddrs( - amount = status.amountRaw, - addr = status.account, - segwitAddresses = status.segwitAddrs - ) - if (bankAppClick != null) { - Button( - onClick = bankAppClick, - modifier = Modifier - .padding(vertical = 16.dp) - .align(Alignment.CenterHorizontally), - ) { - Text(text = stringResource(R.string.withdraw_manual_ready_bank_button)) - } - } - if (onCancelClick != null) { - Button( - onClick = onCancelClick, - colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.error), - modifier = Modifier - .padding(vertical = 16.dp) - .align(End), - ) { - Text( - text = stringResource(R.string.withdraw_manual_ready_cancel), - color = MaterialTheme.colorScheme.onError, - ) - } - } - } -} - -@Composable -fun BitcoinSegwitAddrs(amount: Amount, addr: String, segwitAddresses: List<String>) { - Column { - CopyToClipboardButton( - modifier = Modifier.align(End), - label = "Bitcoin", - content = getCopyText(amount, addr, segwitAddresses), - ) - Row(modifier = Modifier.padding(vertical = 8.dp)) { - Column(modifier = Modifier.weight(0.3f)) { - Text( - text = addr, - style = MaterialTheme.typography.bodyLarge, - fontWeight = FontWeight.Normal, - fontSize = 3.em - ) - Text( - text = amount.withCurrency("BTC").toString(), - style = MaterialTheme.typography.bodyLarge, - fontWeight = FontWeight.Bold, - ) - } - } - for (segwitAddress in segwitAddresses) { - Row(modifier = Modifier.padding(vertical = 8.dp)) { - Column(modifier = Modifier.weight(0.3f)) { - Text( - text = segwitAddress, - style = MaterialTheme.typography.bodyLarge, - fontWeight = FontWeight.Normal, - fontSize = 3.em, - ) - Text( - text = SEGWIT_MIN.toString(), - style = MaterialTheme.typography.bodyLarge, - fontWeight = FontWeight.Bold, - ) - } - } - } - } -} - -private val SEGWIT_MIN = Amount("BTC", 0, 294) - -private fun getCopyText(amount: Amount, addr: String, segwitAddresses: List<String>): String { - val sr = segwitAddresses.joinToString(separator = "\n") { s -> - "\n$s ${SEGWIT_MIN}\n" - } - return "$addr ${amount.withCurrency("BTC")}\n$sr" -} - -@Preview -@Composable -fun PreviewScreenBitcoin() { - Surface { - ScreenBitcoin(WithdrawStatus.ManualTransferRequiredBitcoin( - exchangeBaseUrl = "bitcoin.ice.bfh.ch", - uri = Uri.parse("https://taler.net"), - account = "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4", - segwitAddrs = listOf( - "bc1qqleages8702xvg9qcyu02yclst24xurdrynvxq", - "bc1qsleagehks96u7jmqrzcf0fw80ea5g57qm3m84c" - ), - subject = "0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00", - amountRaw = Amount(CURRENCY_BTC, 0, 14000000), - transactionId = "", - ), {}) {} - } -} diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ScreenIBAN.kt b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ScreenIBAN.kt deleted file mode 100644 index 537f3ad..0000000 --- a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ScreenIBAN.kt +++ /dev/null @@ -1,160 +0,0 @@ -/* - * This file is part of GNU Taler - * (C) 2022 Taler Systems S.A. - * - * GNU Taler is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 3, or (at your option) any later version. - * - * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - -package net.taler.wallet.withdraw.manual - -import android.net.Uri -import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.background -import androidx.compose.foundation.border -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.wrapContentWidth -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.Button -import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Surface -import androidx.compose.material3.Text -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ContentCopy -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.alpha -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.colorResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight -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.compose.copyToClipBoard -import net.taler.wallet.withdraw.WithdrawStatus - -@Composable -fun ScreenIBAN( - status: WithdrawStatus.ManualTransferRequiredIBAN, - bankAppClick: (() -> Unit)?, - onCancelClick: (() -> Unit)?, -) { - val scrollState = rememberScrollState() - Column(modifier = Modifier - .wrapContentWidth(Alignment.CenterHorizontally) - .verticalScroll(scrollState) - .padding(all = 16.dp) - ) { - Text( - text = stringResource(R.string.withdraw_manual_ready_title), - style = MaterialTheme.typography.headlineSmall, - ) - Text( - text = stringResource(R.string.withdraw_manual_ready_intro, - status.amountRaw.toString()), - style = MaterialTheme.typography.bodyLarge, - modifier = Modifier - .padding(vertical = 8.dp) - ) - DetailRow(stringResource(R.string.withdraw_manual_ready_iban), status.iban) - DetailRow(stringResource(R.string.withdraw_manual_ready_subject), status.subject) - DetailRow(stringResource(R.string.amount_chosen), status.amountRaw.toString()) - DetailRow(stringResource(R.string.withdraw_exchange), status.exchangeBaseUrl, false) - Text( - text = stringResource(R.string.withdraw_manual_ready_warning), - style = MaterialTheme.typography.bodyMedium, - color = colorResource(R.color.notice_text), - modifier = Modifier - .align(Alignment.CenterHorizontally) - .padding(all = 8.dp) - .background(colorResource(R.color.notice_background)) - .border(BorderStroke(2.dp, colorResource(R.color.notice_border))) - .padding(all = 16.dp) - ) - if (bankAppClick != null) { - Button( - onClick = bankAppClick, - modifier = Modifier - .padding(vertical = 16.dp) - .align(Alignment.CenterHorizontally), - ) { - Text(text = stringResource(R.string.withdraw_manual_ready_bank_button)) - } - } - if (onCancelClick != null) { - Button( - onClick = onCancelClick, - colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.error), - modifier = Modifier - .padding(vertical = 16.dp) - .align(Alignment.End), - ) { - Text( - text = stringResource(R.string.withdraw_manual_ready_cancel), - color = MaterialTheme.colorScheme.onError, - ) - } - } - } -} - -@Composable -fun DetailRow(label: String, content: String, copy: Boolean = true) { - val context = LocalContext.current - Row { - Column( - modifier = Modifier - .weight(0.3f)) { - Text( - text = label, - style = MaterialTheme.typography.bodyLarge, - fontWeight = if (copy) FontWeight.Bold else FontWeight.Normal, - ) - if (copy) { - IconButton( - onClick = { copyToClipBoard(context, label, content) }, - ) { Icon(Icons.Default.ContentCopy, stringResource(R.string.copy)) } - } - } - Text( - text = content, - style = MaterialTheme.typography.bodyLarge, - modifier = Modifier - .padding(bottom = 8.dp) - .weight(0.7f) - .then(if (copy) Modifier else Modifier.alpha(0.7f)) - ) - } -} - -@Preview -@Composable -fun PreviewScreenIBAN() { - Surface { - ScreenIBAN(WithdrawStatus.ManualTransferRequiredIBAN( - exchangeBaseUrl = "test.exchange.taler.net", - uri = Uri.parse("https://taler.net"), - iban = "ASDQWEASDZXCASDQWE", - subject = "Taler Withdrawal P2T19EXRBY4B145JRNZ8CQTD7TCS03JE9VZRCEVKVWCP930P56WG", - amountRaw = Amount("KUDOS", 10, 0), - transactionId = "", - ), {}) {} - } -} diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ScreenTransfer.kt b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ScreenTransfer.kt new file mode 100644 index 0000000..00495fb --- /dev/null +++ b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ScreenTransfer.kt @@ -0,0 +1,326 @@ +/* + * This file is part of GNU Taler + * (C) 2023 Taler Systems S.A. + * + * GNU Taler is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3, or (at your option) any later version. + * + * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +package net.taler.wallet.withdraw.manual + +import androidx.compose.foundation.layout.Column +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.icons.Icons +import androidx.compose.material.icons.filled.ContentCopy +import androidx.compose.material3.Button +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.ScrollableTabRow +import androidx.compose.material3.Surface +import androidx.compose.material3.Tab +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import net.taler.common.Amount +import net.taler.wallet.CURRENCY_BTC +import net.taler.wallet.R +import net.taler.common.CurrencySpecification +import net.taler.wallet.compose.ShareButton +import net.taler.wallet.compose.copyToClipBoard +import net.taler.wallet.transactions.AmountType +import net.taler.wallet.transactions.TransactionAmountComposable +import net.taler.wallet.transactions.WithdrawalExchangeAccountDetails +import net.taler.wallet.transactions.WithdrawalExchangeAccountDetails.Status.* +import net.taler.wallet.withdraw.TransferData +import net.taler.wallet.withdraw.WithdrawStatus + +@Composable +fun ScreenTransfer( + status: WithdrawStatus.ManualTransferRequired, + spec: CurrencySpecification?, + bankAppClick: ((transfer: TransferData) -> Unit)?, + shareClick: ((transfer: TransferData) -> Unit)?, +) { + // TODO: show some placeholder + if (status.withdrawalTransfers.isEmpty()) return + + val transfers = status.withdrawalTransfers.filter { + // TODO: in dev mode, show debug info when status is `Error' + it.withdrawalAccount.status == Ok + }.sortedByDescending { + it.withdrawalAccount.priority + } + + val defaultTransfer = transfers[0] + var selectedTransfer by remember { mutableStateOf(defaultTransfer) } + + Column { + if (status.withdrawalTransfers.size > 1) { + TransferAccountChooser( + accounts = transfers.map { it.withdrawalAccount }, + selectedAccount = selectedTransfer.withdrawalAccount, + onSelectAccount = { account -> + status.withdrawalTransfers.find { + it.withdrawalAccount.paytoUri == account.paytoUri + }?.let { selectedTransfer = it } + } + ) + } + + val scrollState = rememberScrollState() + Column( + modifier = Modifier + .verticalScroll(scrollState), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + when (val transfer = selectedTransfer) { + is TransferData.Taler -> TransferTaler( + transfer = transfer, + exchangeBaseUrl = status.exchangeBaseUrl, + transactionAmountRaw = status.transactionAmountRaw.withSpec(spec), + transactionAmountEffective = status.transactionAmountEffective.withSpec(spec), + ) + + is TransferData.IBAN -> TransferIBAN( + transfer = transfer, + exchangeBaseUrl = status.exchangeBaseUrl, + transactionAmountRaw = status.transactionAmountRaw.withSpec(spec), + transactionAmountEffective = status.transactionAmountEffective.withSpec(spec), + ) + + is TransferData.Bitcoin -> TransferBitcoin( + transfer = transfer, + transactionAmountRaw = status.transactionAmountRaw.withSpec(spec), + transactionAmountEffective = status.transactionAmountEffective.withSpec(spec), + ) + } + + if (bankAppClick != null) { + Button( + onClick = { bankAppClick(selectedTransfer) }, + modifier = Modifier + .padding(bottom = 16.dp), + ) { + Text(text = stringResource(R.string.withdraw_manual_ready_bank_button)) + } + } + + if (shareClick != null) { + ShareButton( + content = selectedTransfer.withdrawalAccount.paytoUri, + modifier = Modifier + .padding(bottom = 16.dp), + ) + } + } + } +} + +@Composable +fun DetailRow( + label: String, + content: String, + copy: Boolean = true, +) { + val context = LocalContext.current + + Column( + modifier = Modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + modifier = Modifier.padding(top = 16.dp, start = 6.dp, end = 6.dp), + text = label, + style = MaterialTheme.typography.bodyMedium, + ) + + Text( + modifier = Modifier.padding( + top = 8.dp, + start = 6.dp, + end = 6.dp, + ), + text = content, + style = MaterialTheme.typography.bodyLarge, + fontFamily = if (copy) FontFamily.Monospace else FontFamily.Default, + textAlign = TextAlign.Center, + ) + + if (copy) { + IconButton( + onClick = { copyToClipBoard(context, label, content) }, + ) { + Icon( + imageVector = Icons.Default.ContentCopy, + contentDescription = stringResource(R.string.copy), + ) + } + } + } +} + +@Composable +fun WithdrawalAmountTransfer( + amountRaw: Amount, + amountEffective: Amount, + conversionAmountRaw: Amount, +) { + Column( + modifier = Modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + TransactionAmountComposable( + label = stringResource(R.string.amount_transfer), + amount = conversionAmountRaw, + amountType = AmountType.Neutral, + ) + + if (amountRaw.currency != conversionAmountRaw.currency) { + TransactionAmountComposable( + label = stringResource(R.string.amount_conversion), + amount = amountRaw, + amountType = AmountType.Neutral, + ) + } + + if (amountRaw > amountEffective) { + val fee = amountRaw - amountEffective + TransactionAmountComposable( + label = stringResource(id = R.string.amount_fee), + amount = fee, + amountType = AmountType.Negative, + ) + + TransactionAmountComposable( + label = stringResource(id = R.string.amount_total), + amount = amountEffective, + amountType = AmountType.Positive, + ) + } + } +} + +@Composable +fun TransferAccountChooser( + modifier: Modifier = Modifier, + accounts: List<WithdrawalExchangeAccountDetails>, + selectedAccount: WithdrawalExchangeAccountDetails, + onSelectAccount: (account: WithdrawalExchangeAccountDetails) -> Unit, +) { + val selectedIndex = accounts.indexOfFirst { + it.paytoUri == selectedAccount.paytoUri + } + + ScrollableTabRow( + selectedTabIndex = selectedIndex, + modifier = modifier, + edgePadding = 8.dp, + ) { + accounts.forEachIndexed { index, account -> + Tab( + selected = selectedAccount.paytoUri == account.paytoUri, + onClick = { onSelectAccount(account) }, + text = { + if (!account.bankLabel.isNullOrEmpty()) { + Text(account.bankLabel) + } else if (account.currencySpecification?.name != null) { + Text(stringResource( + R.string.withdraw_account_currency, + index + 1, + account.currencySpecification.name, + )) + } else if (account.transferAmount?.currency != null) { + Text(stringResource( + R.string.withdraw_account_currency, + index + 1, + account.transferAmount.currency, + )) + } else Text(stringResource(R.string.withdraw_account, index + 1)) + }, + ) + } + } +} + +@Preview +@Composable +fun ScreenTransferPreview() { + Surface { + ScreenTransfer( + status = WithdrawStatus.ManualTransferRequired( + transactionId = "", + transactionAmountRaw = Amount.fromJSONString("KUDOS:10"), + transactionAmountEffective = Amount.fromJSONString("KUDOS:9.5"), + exchangeBaseUrl = "test.exchange.taler.net", + withdrawalTransfers = listOf( + TransferData.IBAN( + iban = "ASDQWEASDZXCASDQWE", + subject = "Taler Withdrawal P2T19EXRBY4B145JRNZ8CQTD7TCS03JE9VZRCEVKVWCP930P56WG", + amountRaw = Amount("KUDOS", 10, 0), + amountEffective = Amount("KUDOS", 9, 5), + withdrawalAccount = WithdrawalExchangeAccountDetails( + paytoUri = "https://taler.net/kudos", + transferAmount = Amount("KUDOS", 10, 0), + status = Ok, + currencySpecification = CurrencySpecification( + "KUDOS", + numFractionalInputDigits = 2, + numFractionalNormalDigits = 2, + numFractionalTrailingZeroDigits = 2, + altUnitNames = emptyMap(), + ), + ), + ), + TransferData.Bitcoin( + account = "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4", + segwitAddresses = listOf( + "bc1qqleages8702xvg9qcyu02yclst24xurdrynvxq", + "bc1qsleagehks96u7jmqrzcf0fw80ea5g57qm3m84c" + ), + subject = "0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00", + amountRaw = Amount(CURRENCY_BTC, 0, 14000000), + amountEffective = Amount(CURRENCY_BTC, 0, 14000000), + withdrawalAccount = WithdrawalExchangeAccountDetails( + paytoUri = "https://taler.net/btc", + transferAmount = Amount("BTC", 0, 14000000), + status = Ok, + currencySpecification = CurrencySpecification( + "Bitcoin", + numFractionalInputDigits = 2, + numFractionalNormalDigits = 2, + numFractionalTrailingZeroDigits = 2, + altUnitNames = emptyMap(), + ), + ), + ) + ), + ), + spec = null, + bankAppClick = {}, + shareClick = {}, + ) + } +}
\ No newline at end of file diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/manual/TransferBitcoin.kt b/wallet/src/main/java/net/taler/wallet/withdraw/manual/TransferBitcoin.kt new file mode 100644 index 0000000..c21ca7e --- /dev/null +++ b/wallet/src/main/java/net/taler/wallet/withdraw/manual/TransferBitcoin.kt @@ -0,0 +1,112 @@ +/* + * This file is part of GNU Taler + * (C) 2023 Taler Systems S.A. + * + * GNU Taler is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3, or (at your option) any later version. + * + * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +package net.taler.wallet.withdraw.manual + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment.Companion.CenterHorizontally +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import net.taler.common.Amount +import net.taler.wallet.R +import net.taler.wallet.compose.CopyToClipboardButton +import net.taler.wallet.withdraw.TransferData + +@Composable +fun TransferBitcoin( + transfer: TransferData.Bitcoin, + transactionAmountRaw: Amount, + transactionAmountEffective: Amount, +) { + Column( + modifier = Modifier.padding(all = 16.dp), + horizontalAlignment = CenterHorizontally, + ) { + Text( + text = stringResource(R.string.withdraw_manual_bitcoin_intro), + style = MaterialTheme.typography.bodyLarge, + modifier = Modifier + .padding(vertical = 8.dp) + ) + + BitcoinSegwitAddresses( + amount = transfer.amountRaw, + address = transfer.account, + segwitAddresses = transfer.segwitAddresses, + ) + + transfer.withdrawalAccount.transferAmount?.let { amount -> + WithdrawalAmountTransfer( + amountRaw = transactionAmountRaw, + amountEffective = transactionAmountEffective, + conversionAmountRaw = amount.withSpec( + transfer.withdrawalAccount.currencySpecification, + ), + ) + } + } +} + +@Composable +fun BitcoinSegwitAddresses(amount: Amount, address: String, segwitAddresses: List<String>) { + Column { + val allSegwitAddresses = listOf(address) + segwitAddresses + for (segwitAddress in allSegwitAddresses) { + Row(modifier = Modifier.padding(vertical = 8.dp)) { + Column(modifier = Modifier.weight(0.3f)) { + Text( + text = segwitAddress, + fontWeight = FontWeight.Normal, + fontFamily = FontFamily.Monospace, + style = MaterialTheme.typography.bodySmall, + ) + Text( + text = if (segwitAddress == address) + amount.withCurrency("BTC").toString() + else SEGWIT_MIN.toString(), + style = MaterialTheme.typography.bodyLarge, + fontWeight = FontWeight.Bold, + ) + } + } + } + + CopyToClipboardButton( + modifier = Modifier + .padding(top = 16.dp, start = 6.dp, end = 6.dp) + .align(CenterHorizontally), + label = "Bitcoin", + content = getCopyText(amount, address, segwitAddresses), + ) + } +} + +private val SEGWIT_MIN = Amount("BTC", 0, 294) + +private fun getCopyText(amount: Amount, addr: String, segwitAddresses: List<String>): String { + val sr = segwitAddresses.joinToString(separator = "\n") { s -> + "\n$s ${SEGWIT_MIN}\n" + } + return "$addr ${amount.withCurrency("BTC")}\n$sr" +}
\ No newline at end of file diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/manual/TransferIBAN.kt b/wallet/src/main/java/net/taler/wallet/withdraw/manual/TransferIBAN.kt new file mode 100644 index 0000000..1698530 --- /dev/null +++ b/wallet/src/main/java/net/taler/wallet/withdraw/manual/TransferIBAN.kt @@ -0,0 +1,93 @@ +/* + * This file is part of GNU Taler + * (C) 2023 Taler Systems S.A. + * + * GNU Taler is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3, or (at your option) any later version. + * + * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +package net.taler.wallet.withdraw.manual + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.colorResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import net.taler.common.Amount +import net.taler.wallet.R +import net.taler.wallet.cleanExchange +import net.taler.wallet.transactions.TransactionInfoComposable +import net.taler.wallet.withdraw.TransferData + +@Composable +fun TransferIBAN( + transfer: TransferData.IBAN, + exchangeBaseUrl: String, + transactionAmountRaw: Amount, + transactionAmountEffective: Amount, +) { + val transferAmount = transfer + .withdrawalAccount + .transferAmount + ?.withSpec(transfer.withdrawalAccount.currencySpecification) + ?: transfer.amountRaw + + Column( + modifier = Modifier.padding(all = 16.dp), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + text = stringResource( + R.string.withdraw_manual_ready_intro, + transferAmount), + style = MaterialTheme.typography.bodyLarge, + modifier = Modifier + .padding(vertical = 8.dp) + ) + + Text( + text = stringResource(R.string.withdraw_manual_ready_warning), + style = MaterialTheme.typography.bodyMedium, + color = colorResource(R.color.notice_text), + modifier = Modifier + .align(Alignment.CenterHorizontally) + .padding(all = 8.dp) + .background(colorResource(R.color.notice_background)) + .border(BorderStroke(2.dp, colorResource(R.color.notice_border))) + .padding(all = 16.dp) + ) + + DetailRow(stringResource(R.string.withdraw_manual_ready_subject), transfer.subject) + transfer.receiverName?.let { + DetailRow(stringResource(R.string.withdraw_manual_ready_receiver), it) + } + DetailRow(stringResource(R.string.withdraw_manual_ready_iban), transfer.iban) + + TransactionInfoComposable( + label = stringResource(R.string.withdraw_exchange), + info = cleanExchange(exchangeBaseUrl), + ) + + WithdrawalAmountTransfer( + amountRaw = transactionAmountRaw, + amountEffective = transactionAmountEffective, + conversionAmountRaw = transferAmount, + ) + } +}
\ No newline at end of file diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/manual/TransferTaler.kt b/wallet/src/main/java/net/taler/wallet/withdraw/manual/TransferTaler.kt new file mode 100644 index 0000000..089d0de --- /dev/null +++ b/wallet/src/main/java/net/taler/wallet/withdraw/manual/TransferTaler.kt @@ -0,0 +1,93 @@ +/* + * This file is part of GNU Taler + * (C) 2024 Taler Systems S.A. + * + * GNU Taler is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3, or (at your option) any later version. + * + * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +package net.taler.wallet.withdraw.manual + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.colorResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import net.taler.common.Amount +import net.taler.wallet.R +import net.taler.wallet.cleanExchange +import net.taler.wallet.transactions.TransactionInfoComposable +import net.taler.wallet.withdraw.TransferData + +@Composable +fun TransferTaler( + transfer: TransferData.Taler, + exchangeBaseUrl: String, + transactionAmountRaw: Amount, + transactionAmountEffective: Amount, +) { + val transferAmount = transfer + .withdrawalAccount + .transferAmount + ?.withSpec(transfer.withdrawalAccount.currencySpecification) + ?: transfer.amountRaw + + Column( + modifier = Modifier.padding(all = 16.dp), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + text = stringResource( + R.string.withdraw_manual_ready_intro, + transferAmount), + style = MaterialTheme.typography.bodyLarge, + modifier = Modifier + .padding(vertical = 8.dp) + ) + + Text( + text = stringResource(R.string.withdraw_manual_ready_warning), + style = MaterialTheme.typography.bodyMedium, + color = colorResource(R.color.notice_text), + modifier = Modifier + .align(Alignment.CenterHorizontally) + .padding(all = 8.dp) + .background(colorResource(R.color.notice_background)) + .border(BorderStroke(2.dp, colorResource(R.color.notice_border))) + .padding(all = 16.dp) + ) + + DetailRow(stringResource(R.string.withdraw_manual_ready_subject), transfer.subject) + transfer.receiverName?.let { + DetailRow(stringResource(R.string.withdraw_manual_ready_receiver), it) + } + DetailRow(stringResource(R.string.withdraw_manual_ready_account), transfer.account) + + TransactionInfoComposable( + label = stringResource(R.string.withdraw_exchange), + info = cleanExchange(exchangeBaseUrl), + ) + + WithdrawalAmountTransfer( + amountRaw = transactionAmountRaw, + amountEffective = transactionAmountEffective, + conversionAmountRaw = transferAmount, + ) + } +}
\ No newline at end of file |