aboutsummaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src/main/java/net')
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawFragment.kt10
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawSuccessFragment.kt197
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt51
3 files changed, 244 insertions, 14 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawFragment.kt
index 0cb39d2..660fec2 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawFragment.kt
@@ -66,8 +66,14 @@ class ManualWithdrawFragment : Fragment() {
return
}
ui.amountLayout.error = null
- val value = ui.amountView.text.toString().toLong()
- val amount = Amount(exchangeItem.currency, value, 0)
+ var value = 0.0
+ try {
+ value = ui.amountView.text.toString().replace(',', '.').toDouble()
+ } catch (e: NumberFormatException) {
+ ui.amountLayout.error = getString(R.string.withdraw_amount_error)
+ return
+ }
+ val amount = Amount.fromDouble(exchangeItem.currency, value)
ui.amountView.hideKeyboard()
withdrawManager.getWithdrawalDetails(exchangeItem.exchangeBaseUrl, amount)
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawSuccessFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawSuccessFragment.kt
index cdacde6..b638627 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawSuccessFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawSuccessFragment.kt
@@ -31,6 +31,7 @@ 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.size
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
@@ -44,6 +45,7 @@ import androidx.compose.material.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.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Alignment.Companion.End
import androidx.compose.ui.Modifier
@@ -53,8 +55,13 @@ 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.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.unit.TextUnit
+import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.em
+import androidx.compose.ui.unit.sp
import androidx.core.content.getSystemService
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
@@ -82,17 +89,26 @@ class ManualWithdrawSuccessFragment : Fragment() {
val onBankAppClick = if (componentName == null) null else {
{ startActivitySafe(intent) }
}
- val onCancelClick = if (status.transactionId == null) null else {
+ val tid = status.transactionId
+ val onCancelClick = if (tid == null) null else {
{
- transactionManager.deleteTransaction(status.transactionId)
+ transactionManager.deleteTransaction(tid)
findNavController().navigate(R.id.action_nav_exchange_manual_withdrawal_success_to_nav_main)
}
}
setContent {
MdcTheme {
Surface {
- Screen(status, onBankAppClick, onCancelClick)
+ when (status) {
+ is WithdrawStatus.ManualTransferRequiredBitcoin -> {
+ ScreenBitcoin(status, onBankAppClick, onCancelClick)
+ }
+ is WithdrawStatus.ManualTransferRequiredIBAN -> {
+ ScreenIBAN(status, onBankAppClick, onCancelClick)
+ }
+ }
}
+
}
}
}
@@ -104,8 +120,8 @@ class ManualWithdrawSuccessFragment : Fragment() {
}
@Composable
-private fun Screen(
- status: WithdrawStatus.ManualTransferRequired,
+private fun ScreenIBAN(
+ status: WithdrawStatus.ManualTransferRequiredIBAN,
bankAppClick: (() -> Unit)?,
onCancelClick: (() -> Unit)?,
) {
@@ -172,6 +188,154 @@ private fun Screen(
}
@Composable
+private fun ScreenBitcoin(
+ status: WithdrawStatus.ManualTransferRequiredBitcoin,
+ bankAppClick: (() -> Unit)?,
+ onCancelClick: (() -> Unit)?,
+) {
+ val scrollState = rememberScrollState()
+ Column(modifier = Modifier
+ .padding(all = 16.dp)
+ .wrapContentWidth(CenterHorizontally)
+ .verticalScroll(scrollState)
+ ) {
+ Text(
+ text = stringResource(R.string.withdraw_manual_ready_title),
+ style = MaterialTheme.typography.h5,
+ )
+ Text(
+ text = stringResource(R.string.withdraw_manual_ready_intro,
+ status.amountRaw.toString()),
+ style = MaterialTheme.typography.body1,
+ modifier = Modifier
+ .padding(vertical = 8.dp)
+ )
+ Text(
+ text = stringResource(R.string.withdraw_manual_bitcoin_ready_details_intro),
+ style = MaterialTheme.typography.body1,
+ modifier = Modifier
+ .padding(vertical = 8.dp)
+ )
+ Text(
+ text = stringResource(R.string.withdraw_manual_bitcoin_ready_details_segwit),
+ style = MaterialTheme.typography.body1,
+ modifier = Modifier
+ .padding(vertical = 8.dp)
+ )
+ DetailRow(stringResource(R.string.withdraw_manual_ready_subject), status.subject)
+ Text(
+ text = stringResource(R.string.withdraw_manual_bitcoin_ready_details_bitcoincore),
+ style = MaterialTheme.typography.body1,
+ modifier = Modifier
+ .padding(vertical = 8.dp)
+ )
+ BitcoinSegwitAddrs(
+ status.amountRaw,
+ status.account,
+ status.segwitAddrs
+ )
+ Text(
+ text = stringResource(R.string.withdraw_manual_bitcoin_ready_details_confirm,
+ status.amountRaw.withCurrency(Amount.SEGWIT_MIN.currency) + Amount.SEGWIT_MIN + Amount.SEGWIT_MIN),
+ style = MaterialTheme.typography.body1,
+ modifier = Modifier
+ .padding(vertical = 8.dp)
+ )
+ Text(
+ text = stringResource(R.string.withdraw_manual_ready_warning),
+ style = MaterialTheme.typography.body2,
+ color = colorResource(R.color.notice_text),
+ modifier = Modifier
+ .align(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(CenterHorizontally),
+ ) {
+ Text(text = stringResource(R.string.withdraw_manual_ready_bank_button))
+ }
+ }
+ if (onCancelClick != null) {
+ Button(
+ onClick = onCancelClick,
+ colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(R.color.red)),
+ modifier = Modifier
+ .padding(vertical = 16.dp)
+ .align(End),
+ ) {
+ Text(text = stringResource(R.string.withdraw_manual_ready_cancel))
+ }
+ }
+ }
+}
+
+@Composable
+fun BitcoinSegwitAddrs(amount: Amount, addr: String, segwitAddrs: List<String>) {
+ val context = LocalContext.current
+
+ val sr = segwitAddrs.map { s -> """
+${s} ${Amount.SEGWIT_MIN}
+ """.trimIndent()}.joinToString(separator = "\n")
+ val copyText = """
+${addr} ${amount.withCurrency("BTC")}
+${sr}
+ """.trimIndent()
+
+ Column {
+
+ Row (modifier = Modifier.padding(vertical = 8.dp)){
+ Column (modifier = Modifier.weight(0.3f)) {
+ Text(
+ text = addr,
+ style = MaterialTheme.typography.body1,
+ fontWeight = FontWeight.Normal,
+ fontSize = 3.em
+ )
+ Text(
+ text = amount.withCurrency("BTC").toString(),
+ style = MaterialTheme.typography.body1,
+ fontWeight = FontWeight.Bold,
+ )
+ }
+ }
+ for(sAddr in segwitAddrs) {
+ Row (modifier = Modifier.padding(vertical = 8.dp)){
+ Column (modifier = Modifier.weight(0.3f)) {
+ Text(
+ text = sAddr,
+ style = MaterialTheme.typography.body1,
+ fontWeight = FontWeight.Normal,
+ fontSize = 3.em
+ )
+ Text(
+ text = Amount.SEGWIT_MIN.toString(),
+ style = MaterialTheme.typography.body1,
+ fontWeight = FontWeight.Bold,
+ )
+ }
+ }
+ }
+
+ Row (verticalAlignment = Alignment.CenterVertically) {
+ IconButton(
+ onClick = { copyToClipBoard(context, "this", copyText) },
+ ) { Icon(Icons.Default.ContentCopy, stringResource(R.string.copy)) }
+ Text (
+ text = stringResource(R.string.copy),
+ style = MaterialTheme.typography.body1,
+ )
+ }
+ }
+
+}
+@Composable
fun DetailRow(label: String, content: String, copy: Boolean = true) {
val context = LocalContext.current
Row {
@@ -202,9 +366,9 @@ fun DetailRow(label: String, content: String, copy: Boolean = true) {
@Preview
@Composable
-fun PreviewScreen() {
+fun PreviewScreen2() {
Surface {
- Screen(WithdrawStatus.ManualTransferRequired(
+ ScreenIBAN(WithdrawStatus.ManualTransferRequiredIBAN(
exchangeBaseUrl = "test.exchange.taler.net",
uri = Uri.parse("https://taler.net"),
iban = "ASDQWEASDZXCASDQWE",
@@ -215,6 +379,25 @@ fun PreviewScreen() {
}
}
+@Preview
+@Composable
+fun PreviewScreenBitcoin() {
+ Surface {
+ ScreenBitcoin(WithdrawStatus.ManualTransferRequiredBitcoin(
+ exchangeBaseUrl = "bitcoin.ice.bfh.ch",
+ uri = Uri.parse("https://taler.net"),
+ account = "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
+ segwitAddrs = listOf<String>(
+ "bc1qqleages8702xvg9qcyu02yclst24xurdrynvxq",
+ "bc1qsleagehks96u7jmqrzcf0fw80ea5g57qm3m84c"
+ ),
+ subject = "0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00",
+ amountRaw = Amount("BITCOINBTC", 0, 14000000),
+ transactionId = "",
+ ), {}) {}
+ }
+}
+
private fun copyToClipBoard(context: Context, label: String, str: String) {
val clipboard = context.getSystemService<ClipboardManager>()
val clip = ClipData.newPlainText(label, str)
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
index d96f421..ca6ba17 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
@@ -16,6 +16,7 @@
package net.taler.wallet.withdraw
+import Bech32Data
import android.net.Uri
import android.util.Log
import androidx.annotation.UiThread
@@ -25,6 +26,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
import net.taler.common.Amount
+import net.taler.common.CyptoUtils
import net.taler.common.Event
import net.taler.common.toEvent
import net.taler.wallet.TAG
@@ -33,6 +35,11 @@ import net.taler.wallet.backend.WalletBackendApi
import net.taler.wallet.exchanges.ExchangeFees
import net.taler.wallet.exchanges.ExchangeItem
import net.taler.wallet.withdraw.WithdrawStatus.ReceivedDetails
+import toBech32Data
+import kotlin.experimental.and
+import kotlin.experimental.or
+import kotlin.math.floor
+import kotlin.reflect.KProperty
sealed class WithdrawStatus {
data class Loading(val talerWithdrawUri: String? = null) : WithdrawStatus()
@@ -57,14 +64,30 @@ sealed class WithdrawStatus {
object Withdrawing : WithdrawStatus()
data class Success(val currency: String) : WithdrawStatus()
- data class ManualTransferRequired(
+ sealed class ManualTransferRequired: WithdrawStatus() {
+ abstract val uri: Uri
+ abstract val transactionId: String?
+ }
+
+ data class ManualTransferRequiredIBAN(
val exchangeBaseUrl: String,
- val uri: Uri,
+ override val uri: Uri,
val iban: String,
val subject: String,
val amountRaw: Amount,
- val transactionId: String?,
- ) : WithdrawStatus()
+ override val transactionId: String?,
+ ) : ManualTransferRequired() {
+ }
+
+ data class ManualTransferRequiredBitcoin(
+ val exchangeBaseUrl: String,
+ override val uri: Uri,
+ val account: String,
+ val segwitAddrs: List<String>,
+ val subject: String,
+ val amountRaw: Amount,
+ override val transactionId: String?,
+ ) : ManualTransferRequired()
data class Error(val message: String?) : WithdrawStatus()
}
@@ -264,6 +287,7 @@ class WithdrawManager(
}
+
fun createManualTransferRequired(
amount: Amount,
exchangeBaseUrl: String,
@@ -271,7 +295,22 @@ fun createManualTransferRequired(
transactionId: String? = null,
): WithdrawStatus.ManualTransferRequired {
val uri = Uri.parse(uriStr)
- return WithdrawStatus.ManualTransferRequired(
+ if ("bitcoin".equals(uri.authority, true)) {
+ val msg = uri.getQueryParameter("message")
+ val reg = "\\b([A-Z0-9]{52})\\b".toRegex().find(msg.orEmpty())
+ val reserve = reg?.value ?: uri.getQueryParameter("subject")!!
+ val segwitAddrs = Bech32.generateFakeSegwitAddress(reserve, uri.pathSegments.first())
+ return WithdrawStatus.ManualTransferRequiredBitcoin(
+ exchangeBaseUrl = exchangeBaseUrl,
+ uri = uri,
+ account = uri.lastPathSegment!!,
+ segwitAddrs = segwitAddrs,
+ subject = reserve,
+ amountRaw = amount,
+ transactionId = transactionId,
+ )
+ }
+ return WithdrawStatus.ManualTransferRequiredIBAN(
exchangeBaseUrl = exchangeBaseUrl,
uri = uri,
iban = uri.lastPathSegment!!,
@@ -280,3 +319,5 @@ fun createManualTransferRequired(
transactionId = transactionId,
)
}
+
+