From 425c83734e660c64537f6b7d89fe45caaef771df Mon Sep 17 00:00:00 2001 From: Stefan Mitterrutzner Date: Thu, 13 Oct 2022 15:40:13 +0200 Subject: [PATCH 1/2] fixes race condition --- ...HomescreenCertificatesViewController.swift | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/Wallet/Screens/Homescreen/HomescreenCertificatesViewController.swift b/Wallet/Screens/Homescreen/HomescreenCertificatesViewController.swift index b1dc0b4c..1e7a0d32 100644 --- a/Wallet/Screens/Homescreen/HomescreenCertificatesViewController.swift +++ b/Wallet/Screens/Homescreen/HomescreenCertificatesViewController.swift @@ -145,26 +145,29 @@ class HomescreenCertificatesViewController: ViewController { private func startChecks() { DispatchQueue.global(qos: .userInitiated).async { - for i in self.certificateViews { - if let lightQrCode = i.certificate?.lightCertificate?.certificate { - VerifierManager.shared.addObserver(self, for: lightQrCode, modes: Verifier.currentModes()) { [weak i] state in - i?.verificationState = state - } - } else if let qrCode = i.certificate?.qrCode { - VerifierManager.shared.addObserver(self, for: qrCode, modes: Verifier.currentModes()) { [weak i] state in - i?.verificationState = state - } - } else if let transferCode = i.certificate?.transferCode, - transferCode.state != .failed // only start when not already failed - { - TransferManager.shared.addObserver(self, for: transferCode.transferCode) { [weak i] result in - guard let strongI = i else { return } - switch result { - case .success: - // TransferManager adds all the certificates - strongI.transferError = nil - case let .failure(error): - strongI.transferError = error + let modes = Verifier.currentModes() + DispatchQueue.main.async { + for i in self.certificateViews { + if let lightQrCode = i.certificate?.lightCertificate?.certificate { + VerifierManager.shared.addObserver(self, for: lightQrCode, modes: modes) { [weak i] state in + i?.verificationState = state + } + } else if let qrCode = i.certificate?.qrCode { + VerifierManager.shared.addObserver(self, for: qrCode, modes: modes) { [weak i] state in + i?.verificationState = state + } + } else if let transferCode = i.certificate?.transferCode, + transferCode.state != .failed // only start when not already failed + { + TransferManager.shared.addObserver(self, for: transferCode.transferCode) { [weak i] result in + guard let strongI = i else { return } + switch result { + case .success: + // TransferManager adds all the certificates + strongI.transferError = nil + case let .failure(error): + strongI.transferError = error + } } } } From 4cde1487393c2a1e7f23364ba3f1dbff484d4e01 Mon Sep 17 00:00:00 2001 From: Stefan Mitterrutzner Date: Thu, 13 Oct 2022 15:44:46 +0200 Subject: [PATCH 2/2] only fetch currentModes one time --- ...HomescreenCertificatesViewController.swift | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/Wallet/Screens/Homescreen/HomescreenCertificatesViewController.swift b/Wallet/Screens/Homescreen/HomescreenCertificatesViewController.swift index 1e7a0d32..59eefc5a 100644 --- a/Wallet/Screens/Homescreen/HomescreenCertificatesViewController.swift +++ b/Wallet/Screens/Homescreen/HomescreenCertificatesViewController.swift @@ -144,31 +144,27 @@ class HomescreenCertificatesViewController: ViewController { } private func startChecks() { - DispatchQueue.global(qos: .userInitiated).async { - let modes = Verifier.currentModes() - DispatchQueue.main.async { - for i in self.certificateViews { - if let lightQrCode = i.certificate?.lightCertificate?.certificate { - VerifierManager.shared.addObserver(self, for: lightQrCode, modes: modes) { [weak i] state in - i?.verificationState = state - } - } else if let qrCode = i.certificate?.qrCode { - VerifierManager.shared.addObserver(self, for: qrCode, modes: modes) { [weak i] state in - i?.verificationState = state - } - } else if let transferCode = i.certificate?.transferCode, - transferCode.state != .failed // only start when not already failed - { - TransferManager.shared.addObserver(self, for: transferCode.transferCode) { [weak i] result in - guard let strongI = i else { return } - switch result { - case .success: - // TransferManager adds all the certificates - strongI.transferError = nil - case let .failure(error): - strongI.transferError = error - } - } + let modes = Verifier.currentModes() + for i in certificateViews { + if let lightQrCode = i.certificate?.lightCertificate?.certificate { + VerifierManager.shared.addObserver(self, for: lightQrCode, modes: modes) { [weak i] state in + i?.verificationState = state + } + } else if let qrCode = i.certificate?.qrCode { + VerifierManager.shared.addObserver(self, for: qrCode, modes: modes) { [weak i] state in + i?.verificationState = state + } + } else if let transferCode = i.certificate?.transferCode, + transferCode.state != .failed // only start when not already failed + { + TransferManager.shared.addObserver(self, for: transferCode.transferCode) { [weak i] result in + guard let strongI = i else { return } + switch result { + case .success: + // TransferManager adds all the certificates + strongI.transferError = nil + case let .failure(error): + strongI.transferError = error } } }