diff options
Diffstat (limited to 'wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/WithdrawalCreationActivity.kt')
-rw-r--r-- | wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/WithdrawalCreationActivity.kt | 65 |
1 files changed, 23 insertions, 42 deletions
diff --git a/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/WithdrawalCreationActivity.kt b/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/WithdrawalCreationActivity.kt index e07e400..229f911 100644 --- a/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/WithdrawalCreationActivity.kt +++ b/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/WithdrawalCreationActivity.kt @@ -1,50 +1,39 @@ package ch.bfh.habej2.wallee_c2ec import android.os.Bundle -import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.appcompat.app.AppCompatActivity import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.Button import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import ch.bfh.habej2.wallee_c2ec.client.c2ec.C2ECClient -import ch.bfh.habej2.wallee_c2ec.config.TERMINAL_CONFIG +import androidx.compose.ui.platform.LocalContext +import ch.bfh.habej2.wallee_c2ec.client.taler.BankIntegrationClient +import ch.bfh.habej2.wallee_c2ec.config.TalerBankIntegrationConfig import ch.bfh.habej2.wallee_c2ec.ui.theme.Walleec2ecTheme -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.launch -import java.security.SecureRandom -import java.util.Base64 +import java.util.concurrent.Executors -class WithdrawalCreationActivity : ComponentActivity() { +class WithdrawalCreationActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val encodedWopid = encodeWopid(createWopid()) - - val client = C2ECClient() + // TODO Initialize model properly and put in location where everyone involved has access + val model = WithdrawalViewModel(BankIntegrationClient(TalerBankIntegrationConfig( + "TestExchange", "http://localhost:8082/c2ec", "Wallee-1", "secret" + ))) + model.initialize() setContent { - LaunchedEffect(key1 = "") { - this.launch { - - val withdrawal = client.retrieveWithdrawalStatus(encodedWopid, 30000) - - // TODO launch payment activity when selected state is returned, - // when response arrives, send intent to start PaymentActivity for the withdrawal - // otherwise show error and leave. - } - } + // start long polling activity for the created wopid and start authorization + model.startAuthorizationWhenReadyOrAbort(LocalContext.current) Walleec2ecTheme { - // A surface container using the 'background' color from the theme Surface( modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background @@ -54,13 +43,17 @@ class WithdrawalCreationActivity : ComponentActivity() { horizontalAlignment = Alignment.CenterHorizontally ) { - Text(text = "Generated Random WOPID=$encodedWopid") + Text(text = "Generated Random WOPID=${model.uiState.encodedWopid}") - Text(text = "QR-Code content: ${formatTalerUri(encodedWopid)}") + Text(text = "QR-Code content: ${formatTalerUri(model.uiState.encodedWopid)}") - Button(onClick = { finish() }) { - // TODO: abort payment here - Text(text = "back") + QRCode(model.uiState.encodedWopid) + + Button(onClick = { + Executors.newSingleThreadExecutor().submit { model.withdrawalOperationFailed(applicationContext) } + finish() + }) { + Text(text = "abort") } } } @@ -68,17 +61,5 @@ class WithdrawalCreationActivity : ComponentActivity() { } } - private fun formatTalerUri(encodedWopid: String) = - "taler://withdraw/$encodedWopid?terminal_id=${TERMINAL_CONFIG.terminalId}" - - private fun encodeWopid(wopid: ByteArray) = - String(Base64.getUrlEncoder().encode(wopid)) - - private fun createWopid(): ByteArray { - - val wopid = ByteArray(32) - val rand = SecureRandom() - rand.nextBytes(wopid) // will seed automatically - return wopid - } + private fun formatTalerUri(encodedWopid: String) = "taler://withdraw/$encodedWopid" } |