diff --git a/Kukai Mobile/Modules/Account/AccountViewController.swift b/Kukai Mobile/Modules/Account/AccountViewController.swift index 11f78eb4..e6edac97 100644 --- a/Kukai Mobile/Modules/Account/AccountViewController.swift +++ b/Kukai Mobile/Modules/Account/AccountViewController.swift @@ -54,6 +54,11 @@ class AccountViewController: UIViewController, UITableViewDelegate, EstimatedTot }.store(in: &bag) } + deinit { + bag.forEach({ $0.cancel() }) + viewModel.cleanup() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) viewModel.isPresentedForSelectingToken = (self.parent != nil && self.tabBarController == nil) diff --git a/Kukai Mobile/Modules/Account/AccountViewModel.swift b/Kukai Mobile/Modules/Account/AccountViewModel.swift index be78d62f..b8338849 100644 --- a/Kukai Mobile/Modules/Account/AccountViewModel.swift +++ b/Kukai Mobile/Modules/Account/AccountViewModel.swift @@ -125,6 +125,10 @@ class AccountViewModel: ViewModel, UITableViewDiffableDataSourceHandler { } deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Account/TokenDetailsViewController.swift b/Kukai Mobile/Modules/Account/TokenDetailsViewController.swift index e01b53df..c274f07d 100644 --- a/Kukai Mobile/Modules/Account/TokenDetailsViewController.swift +++ b/Kukai Mobile/Modules/Account/TokenDetailsViewController.swift @@ -62,6 +62,11 @@ class TokenDetailsViewController: UIViewController, UITableViewDelegate { } } + deinit { + cancellable = nil + viewModel.cleanup() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) diff --git a/Kukai Mobile/Modules/Account/TokenDetailsViewModel.swift b/Kukai Mobile/Modules/Account/TokenDetailsViewModel.swift index 95cc5dfe..1c7127fb 100644 --- a/Kukai Mobile/Modules/Account/TokenDetailsViewModel.swift +++ b/Kukai Mobile/Modules/Account/TokenDetailsViewModel.swift @@ -170,7 +170,13 @@ public class TokenDetailsViewModel: ViewModel, TokenDetailsChartCellDelegate { }.store(in: &bag) } + // deinit doesn't reliably call, even when the parent VC does call deinit. + // add backup for now until more testing can be done deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Activity/ActivityViewController.swift b/Kukai Mobile/Modules/Activity/ActivityViewController.swift index e5026906..946e5208 100644 --- a/Kukai Mobile/Modules/Activity/ActivityViewController.swift +++ b/Kukai Mobile/Modules/Activity/ActivityViewController.swift @@ -49,6 +49,11 @@ class ActivityViewController: UIViewController, UITableViewDelegate { }.store(in: &bag) } + deinit { + bag.forEach({ $0.cancel() }) + viewModel.cleanup() + } + override func viewWillAppear(_ animated: Bool) { viewModel.isVisible = true diff --git a/Kukai Mobile/Modules/Activity/ActivityViewModel.swift b/Kukai Mobile/Modules/Activity/ActivityViewModel.swift index b775df30..bd340b54 100644 --- a/Kukai Mobile/Modules/Activity/ActivityViewModel.swift +++ b/Kukai Mobile/Modules/Activity/ActivityViewModel.swift @@ -57,6 +57,10 @@ class ActivityViewModel: ViewModel, UITableViewDiffableDataSourceHandler { } deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewController.swift b/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewController.swift index 3b5e46fe..c4dcfea9 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewController.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewController.swift @@ -68,6 +68,11 @@ class CollectiblesCollectionsViewController: UIViewController, UICollectionViewD }.store(in: &bag) } + deinit { + bag.forEach({ $0.cancel() }) + viewModel.cleanup() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) viewModel.isVisible = true diff --git a/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewModel.swift b/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewModel.swift index 4e6e4ea1..9b382d35 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewModel.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewModel.swift @@ -83,6 +83,10 @@ class CollectiblesCollectionsViewModel: ViewModel, UICollectionViewDiffableDataS } deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Collectibles/CollectiblesFavouritesViewController.swift b/Kukai Mobile/Modules/Collectibles/CollectiblesFavouritesViewController.swift index 658351bb..4f1f5e95 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectiblesFavouritesViewController.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectiblesFavouritesViewController.swift @@ -52,6 +52,11 @@ class CollectiblesFavouritesViewController: UIViewController, UICollectionViewDe }.store(in: &bag) } + deinit { + bag.forEach({ $0.cancel() }) + viewModel.cleanup() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) viewModel.isVisible = true diff --git a/Kukai Mobile/Modules/Collectibles/CollectiblesFavouritesViewModel.swift b/Kukai Mobile/Modules/Collectibles/CollectiblesFavouritesViewModel.swift index cf9700dc..fc1e07ff 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectiblesFavouritesViewModel.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectiblesFavouritesViewModel.swift @@ -57,6 +57,10 @@ class CollectiblesFavouritesViewModel: ViewModel, UICollectionViewDiffableDataSo } deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Collectibles/CollectiblesRecentsViewController.swift b/Kukai Mobile/Modules/Collectibles/CollectiblesRecentsViewController.swift index 802c2391..ccd60ddd 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectiblesRecentsViewController.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectiblesRecentsViewController.swift @@ -52,6 +52,11 @@ class CollectiblesRecentsViewController: UIViewController, UICollectionViewDeleg }.store(in: &bag) } + deinit { + bag.forEach({ $0.cancel() }) + viewModel.cleanup() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) viewModel.isVisible = true diff --git a/Kukai Mobile/Modules/Collectibles/CollectiblesRecentsViewModel.swift b/Kukai Mobile/Modules/Collectibles/CollectiblesRecentsViewModel.swift index 215ae7e7..c2e28182 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectiblesRecentsViewModel.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectiblesRecentsViewModel.swift @@ -57,6 +57,10 @@ class CollectiblesRecentsViewModel: ViewModel, UICollectionViewDiffableDataSourc } deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Collectibles/CollectionDetailsViewController.swift b/Kukai Mobile/Modules/Collectibles/CollectionDetailsViewController.swift index 46d67f9a..108d4f11 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectionDetailsViewController.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectionDetailsViewController.swift @@ -70,6 +70,11 @@ class CollectionDetailsViewController: UIViewController, UICollectionViewDelegat } } + deinit { + cancellable?.cancel() + viewModel.cleanup() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) viewModel.isVisible = true diff --git a/Kukai Mobile/Modules/Collectibles/CollectionDetailsViewModel.swift b/Kukai Mobile/Modules/Collectibles/CollectionDetailsViewModel.swift index 4d4a560d..cba08d9e 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectionDetailsViewModel.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectionDetailsViewModel.swift @@ -47,6 +47,10 @@ class CollectionDetailsViewModel: ViewModel, UICollectionViewDiffableDataSourceH } deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Discover/DiscoverViewController.swift b/Kukai Mobile/Modules/Discover/DiscoverViewController.swift index 4a893f40..ff949185 100644 --- a/Kukai Mobile/Modules/Discover/DiscoverViewController.swift +++ b/Kukai Mobile/Modules/Discover/DiscoverViewController.swift @@ -53,6 +53,11 @@ class DiscoverViewController: UIViewController, UITableViewDelegate, DiscoverFea }.store(in: &bag) } + deinit { + bag.forEach({ $0.cancel() }) + viewModel.cleanup() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) viewModel.isVisible = true diff --git a/Kukai Mobile/Modules/Discover/DiscoverViewModel.swift b/Kukai Mobile/Modules/Discover/DiscoverViewModel.swift index 4ee83a48..1ef0906a 100644 --- a/Kukai Mobile/Modules/Discover/DiscoverViewModel.swift +++ b/Kukai Mobile/Modules/Discover/DiscoverViewModel.swift @@ -49,6 +49,10 @@ class DiscoverViewModel: ViewModel, UITableViewDiffableDataSourceHandler { } deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Home/AccountsViewController.swift b/Kukai Mobile/Modules/Home/AccountsViewController.swift index 1814bd5b..7698b124 100644 --- a/Kukai Mobile/Modules/Home/AccountsViewController.swift +++ b/Kukai Mobile/Modules/Home/AccountsViewController.swift @@ -102,6 +102,11 @@ class AccountsViewController: UIViewController, BottomSheetContainerDelegate { } } + deinit { + cancellable = nil + viewModel.cleanup() + } + func bottomSheetDataChanged() { viewModel.isPresentingForConnectedApps = (bottomSheetContainer != nil) viewModel.addressToMarkAsSelected = addressToMarkAsSelected diff --git a/Kukai Mobile/Modules/Home/AccountsViewModel.swift b/Kukai Mobile/Modules/Home/AccountsViewModel.swift index 80c03ea7..a46e030d 100644 --- a/Kukai Mobile/Modules/Home/AccountsViewModel.swift +++ b/Kukai Mobile/Modules/Home/AccountsViewModel.swift @@ -74,6 +74,10 @@ class AccountsViewModel: ViewModel, UITableViewDiffableDataSourceHandler { } deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Stake/BakerDetailsViewController.swift b/Kukai Mobile/Modules/Stake/BakerDetailsViewController.swift index bf49a14c..4a1ce284 100644 --- a/Kukai Mobile/Modules/Stake/BakerDetailsViewController.swift +++ b/Kukai Mobile/Modules/Stake/BakerDetailsViewController.swift @@ -45,6 +45,11 @@ class BakerDetailsViewController: UIViewController { } } + deinit { + cancellable?.cancel() + viewModel.cleanup() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) diff --git a/Kukai Mobile/Modules/Stake/BakerDetailsViewModel.swift b/Kukai Mobile/Modules/Stake/BakerDetailsViewModel.swift index dc87c469..6e2d7964 100644 --- a/Kukai Mobile/Modules/Stake/BakerDetailsViewModel.swift +++ b/Kukai Mobile/Modules/Stake/BakerDetailsViewModel.swift @@ -36,6 +36,10 @@ class BakerDetailsViewModel: ViewModel, UITableViewDiffableDataSourceHandler { } deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Stake/ChooseBakerViewController.swift b/Kukai Mobile/Modules/Stake/ChooseBakerViewController.swift index a667d15a..d66cff21 100644 --- a/Kukai Mobile/Modules/Stake/ChooseBakerViewController.swift +++ b/Kukai Mobile/Modules/Stake/ChooseBakerViewController.swift @@ -47,6 +47,11 @@ class ChooseBakerViewController: UIViewController { } } + deinit { + cancellable?.cancel() + viewModel.cleanup() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) diff --git a/Kukai Mobile/Modules/Stake/ChooseBakerViewModel.swift b/Kukai Mobile/Modules/Stake/ChooseBakerViewModel.swift index cabb4299..8e63a307 100644 --- a/Kukai Mobile/Modules/Stake/ChooseBakerViewModel.swift +++ b/Kukai Mobile/Modules/Stake/ChooseBakerViewModel.swift @@ -35,6 +35,10 @@ class ChooseBakerViewModel: ViewModel, UITableViewDiffableDataSourceHandler { } deinit { + cleanup() + } + + func cleanup() { bag.forEach({ $0.cancel() }) } diff --git a/Kukai Mobile/Modules/Stake/StakeOnboardingContainerViewController.swift b/Kukai Mobile/Modules/Stake/StakeOnboardingContainerViewController.swift index 0210c7f2..b0de8522 100644 --- a/Kukai Mobile/Modules/Stake/StakeOnboardingContainerViewController.swift +++ b/Kukai Mobile/Modules/Stake/StakeOnboardingContainerViewController.swift @@ -67,7 +67,10 @@ class StakeOnboardingContainerViewController: UIViewController { indicatorStackviewTrailingConstraint.constant = 24 * 5 } + // triple make sure activity listener is up and running before we start + AccountViewModel.setupAccountActivityListener() + // Listen for requests to add pending operations DependencyManager.shared.activityService.$addressesWithPendingOperation .dropFirst() .sink { [weak self] addresses in