Skip to content

Commit 09fc795

Browse files
authored
testapp: Clear PresentmentModel before using MdocProximityQrPresentment. (#1311)
Also add guidance in the KDoc and log a warning if this isn't done. Fixes #1306. Test: Manually tested. Signed-off-by: David Zeuthen <[email protected]>
1 parent 5322230 commit 09fc795

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

multipaz-compose/src/commonMain/kotlin/org/multipaz/compose/presentment/MdocProximityQrPresentment.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ import org.multipaz.models.presentment.MdocPresentmentMechanism
2828
import org.multipaz.models.presentment.PresentmentModel
2929
import org.multipaz.models.presentment.PresentmentSource
3030
import org.multipaz.prompt.PromptModel
31+
import org.multipaz.util.Logger
3132
import org.multipaz.util.toBase64Url
3233

34+
private const val TAG = "MdocProximityQrPresentment"
35+
3336
/**
3437
* A composable for presentment with QR engagement according to ISO/IEC 18013-5:2021.
3538
*
@@ -45,6 +48,9 @@ import org.multipaz.util.toBase64Url
4548
* includes showing consent and authentication dialogs. When the reader disconnects [presentmentModel]
4649
* goes to state [PresentmentModel.State.IDLE] and [showQrButton] composable is shown.
4750
*
51+
* Applications should call [PresentmentModel.reset] before entering the composition containing this
52+
* composable.
53+
*
4854
* @param modifier a [Modifier].
4955
* @param appName the name of the application.
5056
* @param appIconPainter the icon for the application.
@@ -123,6 +129,10 @@ fun MdocProximityQrPresentment(
123129
}
124130

125131
PresentmentModel.State.CONNECTING -> {
132+
if (qrCodeToShow.value == null) {
133+
Logger.w(TAG, "No QR code. Did you forget to reset the PresentmentModel before " +
134+
"entering the composition containing this MdocProximityQrPresentment?")
135+
}
126136
qrCodeToShow.value?.let {
127137
showQrCode(it)
128138
}

samples/testapp/src/commonMain/kotlin/org/multipaz/testapp/App.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,10 @@ class App private constructor (val promptModel: PromptModel) {
886886
onClickConsentSheetList = { navController.navigate(ConsentPromptDestination.route) },
887887
onClickQrCodes = { navController.navigate(QrCodesDestination.route) },
888888
onClickNfc = { navController.navigate(NfcDestination.route) },
889-
onClickIsoMdocProximitySharing = { navController.navigate(IsoMdocProximitySharingDestination.route) },
889+
onClickIsoMdocProximitySharing = {
890+
presentmentModel.reset()
891+
navController.navigate(IsoMdocProximitySharingDestination.route)
892+
},
890893
onClickIsoMdocProximityReading = { navController.navigate(IsoMdocProximityReadingDestination.route) },
891894
onClickDcRequest = { navController.navigate(DcRequestDestination.route) },
892895
onClickMdocTransportMultiDeviceTesting = { navController.navigate(IsoMdocMultiDeviceTestingDestination.route) },

0 commit comments

Comments
 (0)