Skip to content

Commit

Permalink
Fixes a memory leak solved by @hectorchu
Browse files Browse the repository at this point in the history
- We had strong reference to the observer(s) and this was causing lingering issues causing the app to crash at rutime
- Updated the key file references

Signed-off-by: kcw-grunt <[email protected]>
  • Loading branch information
kcw-grunt committed Jan 7, 2024
1 parent f6ca735 commit 16a58d8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
13 changes: 0 additions & 13 deletions litewallet/PartnerData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation
import UIKit

enum PartnerName {
case unstop
case infura
case litewalletOps
case litewalletStart
Expand Down Expand Up @@ -53,18 +52,6 @@ struct Partner {
return errorDescription
}

case .unstop:

if let dictionary = NSDictionary(contentsOfFile: filePath) as? [String: AnyObject],
let key = dictionary["change-now-api"] as? String
{
return key
} else {
let errorDescription = "ERROR-CHANGENOW_KEY"
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, properties: ["error": errorDescription])
return errorDescription
}

case .litewalletOps:

if let dictionary = NSDictionary(contentsOfFile: filePath) as? [String: AnyObject],
Expand Down
2 changes: 1 addition & 1 deletion litewallet/StartViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class StartViewModel: ObservableObject {
/// Test seed count
guard seedWords.count == 12 else { return }

/// Set for default
/// Set for default. This model needs a initial value
walletManager.forceSetPin(newPin: Partner.partnerKeyPath(name: .litewalletStart))

guard walletManager.setRandomSeedPhrase() != nil else {
Expand Down
8 changes: 5 additions & 3 deletions litewallet/src/ModalPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,14 @@ class ModalPresenter: Subscriber, Trackable {
sendVC.presentScan = presentScan(parent: root)
sendVC.presentVerifyPin = { [weak self, weak root] bodyText, callback in
guard let myself = self else { return }
guard let myroot = root else { return }

let vc = VerifyPinViewController(bodyText: bodyText, pinLength: myself.store.state.pinLength, callback: callback)
vc.transitioningDelegate = self?.verifyPinTransitionDelegate
vc.transitioningDelegate = myself.verifyPinTransitionDelegate
vc.modalPresentationStyle = .overFullScreen
vc.modalPresentationCapturesStatusBarAppearance = true
root?.view.isFrameChangeBlocked = true
root?.present(vc, animated: true, completion: nil)
myroot.view.isFrameChangeBlocked = true
myroot.present(vc, animated: true, completion: nil)
}
sendVC.onPublishSuccess = { [weak self] in
self?.presentAlert(.sendSuccess, completion: {})
Expand Down
20 changes: 11 additions & 9 deletions litewallet/src/WalletCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,33 +147,35 @@ class WalletCoordinator: Subscriber, Trackable {
}

private func addWalletObservers() {
NotificationCenter.default.addObserver(forName: .walletBalanceChangedNotification, object: nil, queue: nil, using: { _ in
self.updateBalance()
self.requestTxUpdate()
weak var myself = self
NotificationCenter.default.addObserver(forName: .walletBalanceChangedNotification, object: nil, queue: nil, using: {
_ in
myself?.updateBalance()
myself?.requestTxUpdate()
})

NotificationCenter.default.addObserver(forName: .walletTxStatusUpdateNotification, object: nil, queue: nil, using: { _ in
self.requestTxUpdate()
myself?.requestTxUpdate()
})

NotificationCenter.default.addObserver(forName: .walletTxRejectedNotification, object: nil, queue: nil, using: { note in
guard let recommendRescan = note.userInfo?["recommendRescan"] as? Bool else { return }
self.requestTxUpdate()
myself?.requestTxUpdate()
if recommendRescan {
self.store.perform(action: RecommendRescan.set(recommendRescan))
myself?.store.perform(action: RecommendRescan.set(recommendRescan))
}
})

NotificationCenter.default.addObserver(forName: .walletSyncStartedNotification, object: nil, queue: nil, using: { _ in
self.onSyncStart()
myself?.onSyncStart()
})

NotificationCenter.default.addObserver(forName: .walletSyncStoppedNotification, object: nil, queue: nil, using: { note in
self.onSyncStop(notification: note)
myself?.onSyncStop(notification: note)
})

NotificationCenter.default.addObserver(forName: .languageChangedNotification, object: nil, queue: nil, using: { _ in
self.updateTransactions()
myself?.updateTransactions()
})
}

Expand Down

0 comments on commit 16a58d8

Please sign in to comment.