From 59b821316387c52b86acaa6c90553a68c1898c7c Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 8 Sep 2024 18:14:35 +0200 Subject: [PATCH] Extracted clearUserApprovedDecoupledTanCallbacks() and clearing callbacks also when user did not enter TAN or requested to change TAN method or medium to avoid memory leaks --- .../net/codinux/banking/fints/model/TanChallenge.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt index 56425241..bda1b202 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt @@ -32,18 +32,24 @@ open class TanChallenge( this.enterTanResult = EnterTanResult(null, true, responseAfterApprovingDecoupledTan) userApprovedDecoupledTanCallbacks.forEach { it.invoke() } - userApprovedDecoupledTanCallbacks.clear() + clearUserApprovedDecoupledTanCallbacks() } fun userDidNotEnterTan() { + clearUserApprovedDecoupledTanCallbacks() + this.enterTanResult = EnterTanResult(null) } fun userAsksToChangeTanMethod(changeTanMethodTo: TanMethod) { + clearUserApprovedDecoupledTanCallbacks() + this.enterTanResult = EnterTanResult(null, changeTanMethodTo = changeTanMethodTo) } fun userAsksToChangeTanMedium(changeTanMediumTo: TanMedium, changeTanMediumResultCallback: ((FinTsClientResponse) -> Unit)?) { + clearUserApprovedDecoupledTanCallbacks() + this.enterTanResult = EnterTanResult(null, changeTanMediumTo = changeTanMediumTo, changeTanMediumResultCallback = changeTanMediumResultCallback) } @@ -56,6 +62,10 @@ open class TanChallenge( } } + protected open fun clearUserApprovedDecoupledTanCallbacks() { + userApprovedDecoupledTanCallbacks.clear() + } + override fun toString(): String { return "$tanMethod (medium: $tanMediaIdentifier): $messageToShowToUser"