Added callback to get notified when user approved Decoupled TAN (e.g. to close a dialog)

This commit is contained in:
dankito 2024-09-02 19:35:36 +02:00
parent 3f9921a62e
commit 6865f64880
1 changed files with 14 additions and 0 deletions

View File

@ -21,6 +21,8 @@ open class TanChallenge(
open val isEnteringTanDone: Boolean
get() = enterTanResult != null
private val userApprovedDecoupledTanCallbacks = mutableListOf<() -> Unit>()
fun userEnteredTan(enteredTan: String) {
this.enterTanResult = EnterTanResult(enteredTan.replace(" ", ""))
@ -28,6 +30,9 @@ open class TanChallenge(
internal fun userApprovedDecoupledTan(responseAfterApprovingDecoupledTan: BankResponse) {
this.enterTanResult = EnterTanResult(null, true, responseAfterApprovingDecoupledTan)
userApprovedDecoupledTanCallbacks.forEach { it.invoke() }
userApprovedDecoupledTanCallbacks.clear()
}
fun userDidNotEnterTan() {
@ -43,6 +48,15 @@ open class TanChallenge(
}
fun addUserApprovedDecoupledTanCallback(callback: () -> Unit) {
if (isEnteringTanDone == false) {
this.userApprovedDecoupledTanCallbacks.add(callback)
} else if (enterTanResult != null && enterTanResult!!.userApprovedDecoupledTan == true) {
callback()
}
}
override fun toString(): String {
return "$tanMethod (medium: $tanMediaIdentifier): $messageToShowToUser"
}