taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

TransferBitcoin.kt (3964B)


      1 /*
      2  * This file is part of GNU Taler
      3  * (C) 2025 Taler Systems S.A.
      4  *
      5  * GNU Taler is free software; you can redistribute it and/or modify it under the
      6  * terms of the GNU General Public License as published by the Free Software
      7  * Foundation; either version 3, or (at your option) any later version.
      8  *
      9  * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11  * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License along with
     14  * GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 
     17 package net.taler.wallet.transfer
     18 
     19 import androidx.compose.foundation.layout.Column
     20 import androidx.compose.foundation.layout.Row
     21 import androidx.compose.foundation.layout.padding
     22 import androidx.compose.material3.MaterialTheme
     23 import androidx.compose.material3.Text
     24 import androidx.compose.runtime.Composable
     25 import androidx.compose.ui.Alignment.Companion.CenterHorizontally
     26 import androidx.compose.ui.Modifier
     27 import androidx.compose.ui.res.stringResource
     28 import androidx.compose.ui.text.font.FontFamily
     29 import androidx.compose.ui.text.font.FontWeight
     30 import androidx.compose.ui.unit.dp
     31 import net.taler.common.Amount
     32 import net.taler.wallet.R
     33 import net.taler.wallet.compose.CopyToClipboardButton
     34 import net.taler.wallet.withdraw.TransferData
     35 
     36 @Composable
     37 fun TransferBitcoin(
     38     transfer: TransferData.Bitcoin,
     39 ) {
     40     Column(
     41         modifier = Modifier.padding(all = 16.dp),
     42         horizontalAlignment = CenterHorizontally,
     43     ) {
     44         Text(
     45             text = stringResource(R.string.withdraw_manual_bitcoin_intro),
     46             style = MaterialTheme.typography.bodyLarge,
     47             modifier = Modifier
     48                 .padding(vertical = 8.dp)
     49         )
     50 
     51         BitcoinSegwitAddresses(
     52             amount = transfer.amountRaw,
     53             address = transfer.account,
     54             segwitAddresses = transfer.segwitAddresses,
     55         )
     56 
     57         transfer.withdrawalAccount.transferAmount?.let { amount ->
     58             WithdrawalAmountTransfer(
     59                 conversionAmountRaw = amount.withSpec(
     60                     transfer.withdrawalAccount.currencySpecification,
     61                 ),
     62             )
     63         }
     64     }
     65 }
     66 
     67 @Composable
     68 fun BitcoinSegwitAddresses(amount: Amount, address: String, segwitAddresses: List<String>) {
     69     Column {
     70         val allSegwitAddresses = listOf(address) + segwitAddresses
     71         for (segwitAddress in allSegwitAddresses) {
     72             Row(modifier = Modifier.padding(vertical = 8.dp)) {
     73                 Column(modifier = Modifier.weight(0.3f)) {
     74                     Text(
     75                         text = segwitAddress,
     76                         fontWeight = FontWeight.Normal,
     77                         fontFamily = FontFamily.Monospace,
     78                         style = MaterialTheme.typography.bodySmall,
     79                     )
     80                     Text(
     81                         text = if (segwitAddress == address)
     82                             amount.withCurrency("BTC").toString()
     83                         else SEGWIT_MIN.toString(),
     84                         style = MaterialTheme.typography.bodyLarge,
     85                         fontWeight = FontWeight.Bold,
     86                     )
     87                 }
     88             }
     89         }
     90 
     91         CopyToClipboardButton(
     92             modifier = Modifier
     93                 .padding(top = 16.dp, start = 6.dp, end = 6.dp)
     94                 .align(CenterHorizontally),
     95             label = "Bitcoin",
     96             content = getCopyText(amount, address, segwitAddresses),
     97         )
     98     }
     99 }
    100 
    101 private val SEGWIT_MIN = Amount("BTC", 0, 294)
    102 
    103 private fun getCopyText(amount: Amount, addr: String, segwitAddresses: List<String>): String {
    104     val sr = segwitAddresses.joinToString(separator = "\n") { s ->
    105         "\n$s $SEGWIT_MIN\n"
    106     }
    107     return "$addr ${amount.withCurrency("BTC")}\n$sr"
    108 }