Skip to content

Commit

Permalink
Merge pull request #144 from niscy-eudiw/main
Browse files Browse the repository at this point in the history
Issuance pre-auth flow implementation
  • Loading branch information
stzouvaras authored Jul 8, 2024
2 parents af259d7 + 08384af commit 96e1fd6
Show file tree
Hide file tree
Showing 14 changed files with 637 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2023 European Commission
*
* Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European
* Commission - subsequent versions of the EUPL (the "Licence"); You may not use this work
* except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the Licence for the specific language
* governing permissions and limitations under the Licence.
*/

package eu.europa.ec.commonfeature.config

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import eu.europa.ec.uilogic.config.ConfigNavigation
import eu.europa.ec.uilogic.config.NavigationType
import eu.europa.ec.uilogic.serializer.UiSerializable
import eu.europa.ec.uilogic.serializer.UiSerializableParser
import eu.europa.ec.uilogic.serializer.adapter.SerializableTypeAdapter

data class OfferCodeUiConfig(
val offerURI: String,
val txCodeLength: Int,
val issuerName: String,
val onSuccessNavigation: ConfigNavigation
) : UiSerializable {

companion object Parser : UiSerializableParser {
override val serializedKeyName = "offerCodeUiConfig"
override fun provideParser(): Gson {
return GsonBuilder().registerTypeAdapter(
NavigationType::class.java,
SerializableTypeAdapter<NavigationType>()
).create()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ sealed class IssueDocumentPartialState {
val crypto: BiometricCrypto,
val resultHandler: DeviceAuthenticationResult
) : IssueDocumentPartialState()

data object Start : IssueDocumentPartialState()
}

sealed class IssueDocumentsPartialState {
Expand All @@ -69,8 +67,6 @@ sealed class IssueDocumentsPartialState {
val crypto: BiometricCrypto,
val resultHandler: DeviceAuthenticationResult
) : IssueDocumentsPartialState()

data object Start : IssueDocumentsPartialState()
}

sealed class AddSampleDataPartialState {
Expand Down Expand Up @@ -125,6 +121,7 @@ interface WalletCoreDocumentsController {

fun issueDocumentsByOfferUri(
offerUri: String,
txCode: String? = null
): Flow<IssueDocumentsPartialState>

fun deleteDocument(
Expand All @@ -144,6 +141,9 @@ class WalletCoreDocumentsControllerImpl(
private val genericErrorMessage
get() = resourceProvider.genericErrorMessage()

private val documentErrorMessage
get() = resourceProvider.getString(R.string.issuance_generic_error)

override fun loadSampleData(sampleDataByteArray: ByteArray): Flow<LoadSampleDataPartialState> =
flow {
when (val result = eudiWallet.loadSampleData(sampleDataByteArray)) {
Expand Down Expand Up @@ -198,7 +198,7 @@ class WalletCoreDocumentsControllerImpl(
when (response) {
is IssueDocumentsPartialState.Failure -> emit(
IssueDocumentPartialState.Failure(
errorMessage = response.errorMessage
errorMessage = documentErrorMessage
)
)

Expand All @@ -220,29 +220,28 @@ class WalletCoreDocumentsControllerImpl(
response.documentIds.first()
)
)

is IssueDocumentsPartialState.Start -> emit(
IssueDocumentPartialState.Start
)
}
}
}
}
}.safeAsync {
IssueDocumentPartialState.Failure(errorMessage = it.localizedMessage ?: genericErrorMessage)
IssueDocumentPartialState.Failure(errorMessage = documentErrorMessage)
}

override fun issueDocumentsByOfferUri(offerUri: String): Flow<IssueDocumentsPartialState> =
override fun issueDocumentsByOfferUri(
offerUri: String,
txCode: String?
): Flow<IssueDocumentsPartialState> =
callbackFlow {
eudiWallet.issueDocumentByOfferUri(
offerUri = offerUri,
onEvent = issuanceCallback()
onEvent = issuanceCallback(),
txCode = txCode
)

awaitClose()
}.safeAsync {
IssueDocumentsPartialState.Failure(
errorMessage = it.localizedMessage ?: genericErrorMessage
errorMessage = documentErrorMessage
)
}

Expand Down Expand Up @@ -334,8 +333,7 @@ class WalletCoreDocumentsControllerImpl(
is OfferResult.Failure -> {
trySendBlocking(
ResolveDocumentOfferPartialState.Failure(
errorMessage = offerResult.cause.localizedMessage
?: genericErrorMessage
errorMessage = offerResult.cause.message ?: genericErrorMessage
)
)
}
Expand Down Expand Up @@ -370,7 +368,7 @@ class WalletCoreDocumentsControllerImpl(

}.safeAsync {
IssueDocumentsPartialState.Failure(
errorMessage = it.localizedMessage ?: genericErrorMessage
errorMessage = documentErrorMessage
)
}

Expand Down Expand Up @@ -400,10 +398,9 @@ class WalletCoreDocumentsControllerImpl(
}

is IssueEvent.Failure -> {
val errorMessage = event.cause.localizedMessage ?: genericErrorMessage
trySendBlocking(
IssueDocumentsPartialState.Failure(
errorMessage = errorMessage
errorMessage = documentErrorMessage
)
)
}
Expand All @@ -413,7 +410,7 @@ class WalletCoreDocumentsControllerImpl(
if (event.issuedDocuments.isEmpty()) {
trySendBlocking(
IssueDocumentsPartialState.Failure(
errorMessage = genericErrorMessage
errorMessage = documentErrorMessage
)
)
return@OnIssueEvent
Expand Down Expand Up @@ -442,9 +439,6 @@ class WalletCoreDocumentsControllerImpl(

is IssueEvent.Started -> {
totalDocumentsToBeIssued = event.total
trySendBlocking(
IssueDocumentsPartialState.Start
)
}

is IssueEvent.DocumentDeferred -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import eu.europa.ec.issuancefeature.interactor.document.DocumentDetailsInteracto
import eu.europa.ec.issuancefeature.interactor.document.DocumentOfferInteractor
import eu.europa.ec.issuancefeature.interactor.document.DocumentOfferInteractorImpl
import eu.europa.ec.resourceslogic.provider.ResourceProvider
import eu.europa.ec.uilogic.serializer.UiSerializer
import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Factory
import org.koin.core.annotation.Module
Expand Down Expand Up @@ -65,10 +66,12 @@ fun provideSuccessInteractor(
fun provideDocumentOfferInteractor(
walletCoreDocumentsController: WalletCoreDocumentsController,
resourceProvider: ResourceProvider,
deviceAuthenticationInteractor: DeviceAuthenticationInteractor
deviceAuthenticationInteractor: DeviceAuthenticationInteractor,
uiSerializer: UiSerializer
): DocumentOfferInteractor =
DocumentOfferInteractorImpl(
walletCoreDocumentsController,
deviceAuthenticationInteractor,
resourceProvider
resourceProvider,
uiSerializer
)
Loading

0 comments on commit 96e1fd6

Please sign in to comment.