From 7c7ab85690b7bc1ecbf36433fcac0b57132eb232 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 27 Nov 2023 13:15:26 -0500 Subject: [PATCH] fix(delete): fix closing the app before login would make it crash Fixes #12880 --- src/app/boot/app_controller.nim | 2 +- src/app/modules/main/wallet_section/send/account_item.nim | 2 +- src/app/modules/main/wallet_section/send/view.nim | 6 ++++-- src/app/modules/startup/io_interface.nim | 3 +++ src/app/modules/startup/module.nim | 7 +++++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index bd805af08e..ac772c29bb 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -477,7 +477,7 @@ proc finishAppLoading*(self: AppController) = self.privacyService.removeMnemonic() if not self.startupModule.isNil: - self.startupModule.delete + self.startupModule.onAppLoaded() self.startupModule = nil self.mainModule.checkAndPerformProfileMigrationIfNeeded() diff --git a/src/app/modules/main/wallet_section/send/account_item.nim b/src/app/modules/main/wallet_section/send/account_item.nim index 2862653e41..dfe410a8e6 100644 --- a/src/app/modules/main/wallet_section/send/account_item.nim +++ b/src/app/modules/main/wallet_section/send/account_item.nim @@ -44,7 +44,7 @@ QtObject: self.canSend = canSend proc delete*(self: AccountItem) = - self.QObject.delete + self.QObject.delete proc newAccountItem*( name: string = "", diff --git a/src/app/modules/main/wallet_section/send/view.nim b/src/app/modules/main/wallet_section/send/view.nim index 570ac23137..b534f1ef39 100644 --- a/src/app/modules/main/wallet_section/send/view.nim +++ b/src/app/modules/main/wallet_section/send/view.nim @@ -35,11 +35,13 @@ QtObject: proc delete*(self: View) = self.accounts.delete self.senderAccounts.delete - self.selectedSenderAccount.delete + if self.selectedSenderAccount != nil: + self.selectedSenderAccount.delete self.fromNetworksModel.delete self.toNetworksModel.delete self.transactionRoutes.delete - self.selectedReceiveAccount.delete + if self.selectedSenderAccount != nil: + self.selectedReceiveAccount.delete self.QObject.delete proc newView*(delegate: io_interface.AccessInterface): View = diff --git a/src/app/modules/startup/io_interface.nim b/src/app/modules/startup/io_interface.nim index 8cbf2ebc1d..261e8ebcf8 100644 --- a/src/app/modules/startup/io_interface.nim +++ b/src/app/modules/startup/io_interface.nim @@ -19,6 +19,9 @@ type method delete*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method onAppLoaded*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + method load*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/startup/module.nim b/src/app/modules/startup/module.nim index 464c388972..03be358c3c 100644 --- a/src/app/modules/startup/module.nim +++ b/src/app/modules/startup/module.nim @@ -84,6 +84,13 @@ proc newModule*[T](delegate: T, {.push warning[Deprecated]: off.} method delete*[T](self: Module[T]) = + self.view.delete + self.viewVariant.delete + self.controller.delete + if not self.keycardSharedModule.isNil: + self.keycardSharedModule.delete + +method onAppLoaded*[T](self: Module[T]) = singletonInstance.engine.setRootContextProperty("startupModule", newQVariant()) self.view.delete self.view = nil