cashless2ecash

cashless2ecash: pay with cards for digital cash (experimental)
Log | Files | Refs | README

RegisterParametersScreen.kt (3485B)


      1 // This file is part of taler-cashless2ecash.
      2 // Copyright (C) 2024 Joel Häberli
      3 //
      4 // taler-cashless2ecash is free software: you can redistribute it and/or modify it
      5 // under the terms of the GNU Affero General Public License as published
      6 // by the Free Software Foundation, either version 3 of the License,
      7 // or (at your option) any later version.
      8 //
      9 // taler-cashless2ecash is distributed in the hope that it will be useful, but
     10 // WITHOUT ANY WARRANTY; without even the implied warranty of
     11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12 // Affero General Public License for more details.
     13 //
     14 // You should have received a copy of the GNU Affero General Public License
     15 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16 //
     17 // SPDX-License-Identifier: AGPL3.0-or-later
     18 
     19 package ch.bfh.habej2.wallee_c2ec.withdrawal
     20 
     21 import android.annotation.SuppressLint
     22 import android.app.Activity
     23 import android.os.Handler
     24 import android.os.Looper
     25 import android.util.Log
     26 import android.widget.Toast
     27 import androidx.compose.foundation.layout.Arrangement
     28 import androidx.compose.foundation.layout.Box
     29 import androidx.compose.foundation.layout.Column
     30 import androidx.compose.foundation.layout.padding
     31 import androidx.compose.foundation.layout.width
     32 import androidx.compose.material3.Text
     33 import androidx.compose.runtime.Composable
     34 import androidx.compose.runtime.LaunchedEffect
     35 import androidx.compose.runtime.SideEffect
     36 import androidx.compose.runtime.collectAsState
     37 import androidx.compose.runtime.getValue
     38 import androidx.compose.runtime.rememberUpdatedState
     39 import androidx.compose.ui.Alignment
     40 import androidx.compose.ui.Modifier
     41 import androidx.compose.ui.platform.LocalConfiguration
     42 import androidx.compose.ui.unit.dp
     43 import ch.bfh.habej2.wallee_c2ec.R
     44 import kotlinx.coroutines.flow.distinctUntilChanged
     45 
     46 
     47 @Composable
     48 fun RegisterParametersScreen(
     49     model: WithdrawalViewModel,
     50     activity: Activity,
     51     navigateToWhenRegistered: () -> Unit
     52 ) {
     53 
     54     val uiState by model.uiState.collectAsState()
     55     val configuration = LocalConfiguration.current
     56 
     57     // Check if the Taler Wallet is ready to authorize the withdrawal
     58     model.setAuthorizationReadyOrRetry()
     59 
     60     when (uiState.withdrawalState) {
     61         WithdrawalState.READY_FOR_AUTHORIZATION -> {
     62             navigateToWhenRegistered()
     63         }
     64         WithdrawalState.E2EC_TIMEOUT -> {
     65             Toast.makeText(
     66                 activity,
     67                 activity.getString(R.string.timeout),
     68                 Toast.LENGTH_LONG
     69             ).show()
     70             model.withdrawalOperationFailed(activity)
     71         }
     72         else -> {
     73             Column(
     74                 Modifier.width(configuration.screenWidthDp.dp),
     75                 verticalArrangement = Arrangement.Center,
     76                 horizontalAlignment = Alignment.CenterHorizontally
     77             ) {
     78                 Text(
     79                     text = "Scan the QR Code with your Taler Wallet to",
     80                     modifier = Modifier.padding(top = 15.dp)
     81                 )
     82                 Text(text = "register the withdrawal parameters")
     83 
     84 
     85                 QRCode(
     86                     TalerConstants.formatTalerUri(
     87                         uiState.terminalsApiBasePath,
     88                         uiState.encodedWopid
     89                     )
     90                 )
     91 
     92 
     93                 TalerButton(
     94                     text = "Stop",
     95                     onClick = { model.withdrawalOperationFailed(activity) })
     96             }
     97         }
     98     }
     99 }