summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/ReceiveFundsFragment.kt
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/ReceiveFundsFragment.kt')
-rw-r--r--wallet/src/main/java/net/taler/wallet/ReceiveFundsFragment.kt86
1 files changed, 43 insertions, 43 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/ReceiveFundsFragment.kt b/wallet/src/main/java/net/taler/wallet/ReceiveFundsFragment.kt
index cf01e59..2accaaf 100644
--- a/wallet/src/main/java/net/taler/wallet/ReceiveFundsFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/ReceiveFundsFragment.kt
@@ -29,13 +29,11 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
-import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
-import androidx.compose.material.Button
-import androidx.compose.material.MaterialTheme
-import androidx.compose.material.OutlinedTextField
-import androidx.compose.material.Surface
-import androidx.compose.material.Text
+import androidx.compose.material3.Button
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -43,10 +41,8 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.stringResource
-import androidx.compose.ui.text.input.KeyboardType.Companion.Decimal
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.os.bundleOf
@@ -54,34 +50,40 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
-import com.google.android.material.composethemeadapter.MdcTheme
import net.taler.common.Amount
+import net.taler.common.CurrencySpecification
+import net.taler.wallet.compose.AmountInputField
+import net.taler.wallet.compose.DEFAULT_INPUT_DECIMALS
+import net.taler.wallet.compose.TalerSurface
import net.taler.wallet.exchanges.ExchangeItem
class ReceiveFundsFragment : Fragment() {
private val model: MainViewModel by activityViewModels()
private val exchangeManager get() = model.exchangeManager
+ private val withdrawManager get() = model.withdrawManager
+ private val balanceManager get() = model.balanceManager
+ private val peerManager get() = model.peerManager
+ private val scopeInfo get() = model.transactionManager.selectedScope ?: error("No scope selected")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?,
): View = ComposeView(requireContext()).apply {
setContent {
- MdcTheme {
- Surface {
- ReceiveFundsIntro(
- model.transactionManager.selectedCurrency ?: error("No currency selected"),
- this@ReceiveFundsFragment::onManualWithdraw,
- this@ReceiveFundsFragment::onPeerPull,
- )
- }
+ TalerSurface {
+ ReceiveFundsIntro(
+ scopeInfo.currency,
+ balanceManager.getSpecForScopeInfo(scopeInfo),
+ this@ReceiveFundsFragment::onManualWithdraw,
+ this@ReceiveFundsFragment::onPeerPull,
+ )
}
}
}
override fun onStart() {
super.onStart()
- activity?.setTitle(R.string.transactions_receive_funds)
+ activity?.setTitle(getString(R.string.transactions_receive_funds_title, scopeInfo.currency))
}
private fun onManualWithdraw(amount: Amount) {
@@ -99,15 +101,16 @@ class ReceiveFundsFragment : Fragment() {
Toast.makeText(requireContext(), "No exchange available", LENGTH_LONG).show()
return
}
- exchangeManager.withdrawalExchange = exchange
+
// now that we have the exchange, we can navigate
- val bundle = bundleOf("amount" to amount.toJSONString())
- findNavController().navigate(
- R.id.action_receiveFunds_to_nav_exchange_manual_withdrawal, bundle)
+ exchangeManager.withdrawalExchange = exchange
+ withdrawManager.getWithdrawalDetails(exchange.exchangeBaseUrl, amount)
+ findNavController().navigate(R.id.action_receiveFunds_to_nav_prompt_withdraw)
}
private fun onPeerPull(amount: Amount) {
val bundle = bundleOf("amount" to amount.toJSONString())
+ peerManager.checkPeerPullCredit(amount)
findNavController().navigate(R.id.action_receiveFunds_to_nav_peer_pull, bundle)
}
}
@@ -115,6 +118,7 @@ class ReceiveFundsFragment : Fragment() {
@Composable
private fun ReceiveFundsIntro(
currency: String,
+ spec: CurrencySpecification?,
onManualWithdraw: (Amount) -> Unit,
onPeerPull: (Amount) -> Unit,
) {
@@ -124,46 +128,40 @@ private fun ReceiveFundsIntro(
.fillMaxWidth()
.verticalScroll(scrollState),
) {
- var text by rememberSaveable { mutableStateOf("") }
+ var text by rememberSaveable { mutableStateOf("0") }
var isError by rememberSaveable { mutableStateOf(false) }
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.padding(16.dp),
) {
- OutlinedTextField(
+ AmountInputField(
modifier = Modifier
.weight(1f)
.padding(end = 16.dp),
value = text,
- keyboardOptions = KeyboardOptions.Default.copy(keyboardType = Decimal),
onValueChange = { input ->
isError = false
- text = input.filter { it.isDigit() || it == '.' }
+ text = input
+ },
+ label = { Text(stringResource(R.string.receive_amount)) },
+ supportingText = {
+ if (isError) Text(stringResource(R.string.receive_amount_invalid))
},
isError = isError,
- label = {
- if (isError) {
- Text(
- stringResource(R.string.receive_amount_invalid),
- color = Color.Red,
- )
- } else {
- Text(stringResource(R.string.receive_amount))
- }
- }
+ numberOfDecimals = spec?.numFractionalInputDigits ?: DEFAULT_INPUT_DECIMALS,
)
Text(
modifier = Modifier,
- text = currency,
+ text = spec?.symbol ?: currency,
softWrap = false,
- style = MaterialTheme.typography.h6,
+ style = MaterialTheme.typography.titleLarge,
)
}
Text(
modifier = Modifier.padding(horizontal = 16.dp),
text = stringResource(R.string.receive_intro),
- style = MaterialTheme.typography.h6,
+ style = MaterialTheme.typography.titleLarge,
)
Row(modifier = Modifier.padding(16.dp)) {
Button(
@@ -173,16 +171,18 @@ private fun ReceiveFundsIntro(
.weight(1f),
onClick = {
val amount = getAmount(currency, text)
- if (amount == null) isError = true
+ if (amount == null || amount.isZero()) isError = true
else onManualWithdraw(amount)
}) {
Text(text = stringResource(R.string.receive_withdraw))
}
Button(
- modifier = Modifier.weight(1f).height(IntrinsicSize.Max),
+ modifier = Modifier
+ .weight(1f)
+ .height(IntrinsicSize.Max),
onClick = {
val amount = getAmount(currency, text)
- if (amount == null) isError = true
+ if (amount == null || amount.isZero()) isError = true
else onPeerPull(amount)
},
) {
@@ -196,6 +196,6 @@ private fun ReceiveFundsIntro(
@Composable
fun PreviewReceiveFundsIntro() {
Surface {
- ReceiveFundsIntro("TESTKUDOS", {}) {}
+ ReceiveFundsIntro("TESTKUDOS", null, {}) {}
}
}