From 12d6c5a430201116821fc80abeec3f2875acfe31 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 8 Oct 2020 00:41:01 +0200 Subject: [PATCH] Fixed that if persisting newly added account fails callback never gets called and AddAccountDialog therefore is stuck forever --- .../banking/ui/presenter/BankingPresenter.kt | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index d7fdea20..932414c1 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -174,28 +174,35 @@ open class BankingPresenter( newClient.addAccountAsync { response -> if (response.successful) { - val bank = response.bank - bank.displayIndex = allBanks.size - - addClientForBank(bank, newClient) - - selectedBank(bank) - - callBanksChangedListeners() - - persistBankOffUiThread(bank) - - response.retrievedData.forEach { retrievedData -> - retrievedAccountTransactions(GetTransactionsResponse(retrievedData), startDate, false) + try { + handleSuccessfullyAddedBank(response.bank, newClient, response, startDate) + } catch (e: Exception) { + log.error(e) { "Could not save successfully added bank" } } - - findIconForBankAsync(bank) } callback(response) } } + protected open fun handleSuccessfullyAddedBank(bank: TypedBankData, newClient: IBankingClient, response: AddAccountResponse, startDate: Date) { + bank.displayIndex = allBanks.size + + addClientForBank(bank, newClient) + + selectedBank(bank) + + callBanksChangedListeners() + + findIconForBankAsync(bank) + + persistBankOffUiThread(bank) + + response.retrievedData.forEach { retrievedData -> + retrievedAccountTransactions(GetTransactionsResponse(retrievedData), startDate, false) + } + } + protected open fun findIconForBankAsync(bank: TypedBankData) { bankIconFinder.findIconForBankAsync(bank.bankName) { bankIconUrl -> bankIconUrl?.let {