From a2efabb3b8b2ed9e38763c8d28b731c86f30d936 Mon Sep 17 00:00:00 2001 From: StanislavDevIOS Date: Tue, 28 Nov 2023 13:57:27 +0200 Subject: [PATCH 1/3] [trello.com/c/QSPhhLjV] fix: wallets balance freezes when pull refresh --- .../Wallets/Adamant/AdmWalletService.swift | 4 +++- .../Wallets/Bitcoin/BtcWalletService.swift | 18 +++++++++-------- .../Wallets/Dash/DashWalletService.swift | 18 +++++++++-------- .../Wallets/Doge/DogeWalletService.swift | 18 +++++++++-------- .../Wallets/ERC20/ERC20WalletService.swift | 18 +++++++++-------- .../Wallets/Ethereum/EthWalletService.swift | 19 +++++++++--------- .../Wallets/Lisk/LskWalletService.swift | 20 ++++++++++--------- 7 files changed, 64 insertions(+), 51 deletions(-) diff --git a/Adamant/Modules/Wallets/Adamant/AdmWalletService.swift b/Adamant/Modules/Wallets/Adamant/AdmWalletService.swift index cd59d988f..8fddcbcb8 100644 --- a/Adamant/Modules/Wallets/Adamant/AdmWalletService.swift +++ b/Adamant/Modules/Wallets/Adamant/AdmWalletService.swift @@ -142,14 +142,16 @@ final class AdmWalletService: NSObject, WalletService { let isRaised: Bool if let wallet = wallet as? AdmWallet { - wallet.isBalanceInitialized = true isRaised = (wallet.balance < account.balance) && wallet.isBalanceInitialized if wallet.balance != account.balance { wallet.balance = account.balance notify = true + } else if wallet.isBalanceInitialized { + notify = true } else { notify = false } + wallet.isBalanceInitialized = true } else { let wallet = AdmWallet(address: account.address) wallet.isBalanceInitialized = true diff --git a/Adamant/Modules/Wallets/Bitcoin/BtcWalletService.swift b/Adamant/Modules/Wallets/Bitcoin/BtcWalletService.swift index 68e8fc78e..0613545a3 100644 --- a/Adamant/Modules/Wallets/Bitcoin/BtcWalletService.swift +++ b/Adamant/Modules/Wallets/Bitcoin/BtcWalletService.swift @@ -139,7 +139,6 @@ final class BtcWalletService: WalletService { @Atomic private(set) var btcWallet: BtcWallet? @Atomic private(set) var enabled = true @Atomic public var network: Network - @Atomic private var initialBalanceCheck = false static let jsonDecoder = JSONDecoder() @@ -215,7 +214,6 @@ final class BtcWalletService: WalletService { .receive(on: OperationQueue.main) .sink { [weak self] _ in self?.btcWallet = nil - self?.initialBalanceCheck = false if let balanceObserver = self?.balanceObserver { NotificationCenter.default.removeObserver(balanceObserver) self?.balanceObserver = nil @@ -255,22 +253,21 @@ final class BtcWalletService: WalletService { setState(.updating) if let balance = try? await getBalance() { - wallet.isBalanceInitialized = true let notification: Notification.Name? - let isRaised = (wallet.balance < balance) && !initialBalanceCheck + let isRaised = (wallet.balance < balance) && wallet.isBalanceInitialized if wallet.balance != balance { wallet.balance = balance notification = walletUpdatedNotification - initialBalanceCheck = false - } else if initialBalanceCheck { - initialBalanceCheck = false + } else if !wallet.isBalanceInitialized { notification = walletUpdatedNotification } else { notification = nil } + wallet.isBalanceInitialized = true + if isRaised { vibroService.applyVibration(.success) } @@ -413,6 +410,12 @@ extension BtcWalletService: InitiatedWithPassphraseService { let eWallet = try BtcWallet(privateKey: privateKey, addressConverter: addressConverter) self.btcWallet = eWallet + NotificationCenter.default.post( + name: walletUpdatedNotification, + object: self, + userInfo: [AdamantUserInfoKey.WalletService.wallet: eWallet] + ) + if !self.enabled { self.enabled = true NotificationCenter.default.post(name: self.serviceEnabledChanged, object: self) @@ -429,7 +432,6 @@ extension BtcWalletService: InitiatedWithPassphraseService { throw WalletServiceError.accountNotFound } - service.initialBalanceCheck = true service.setState(.upToDate, silent: true) Task { service.update() diff --git a/Adamant/Modules/Wallets/Dash/DashWalletService.swift b/Adamant/Modules/Wallets/Dash/DashWalletService.swift index f1376e784..d31b42cfa 100644 --- a/Adamant/Modules/Wallets/Dash/DashWalletService.swift +++ b/Adamant/Modules/Wallets/Dash/DashWalletService.swift @@ -117,7 +117,6 @@ final class DashWalletService: WalletService { @Atomic private (set) var dashWallet: DashWallet? @Atomic private (set) var enabled = true @Atomic public var network: Network - @Atomic private var initialBalanceCheck = false let defaultDispatchQueue = DispatchQueue(label: "im.adamant.dashWalletService", qos: .userInteractive, attributes: [.concurrent]) @@ -191,7 +190,6 @@ final class DashWalletService: WalletService { .receive(on: OperationQueue.main) .sink { [weak self] _ in self?.dashWallet = nil - self?.initialBalanceCheck = false if let balanceObserver = self?.balanceObserver { NotificationCenter.default.removeObserver(balanceObserver) self?.balanceObserver = nil @@ -231,21 +229,20 @@ final class DashWalletService: WalletService { setState(.updating) if let balance = try? await getBalance() { - wallet.isBalanceInitialized = true let notification: Notification.Name? - let isRaised = (wallet.balance < balance) && !initialBalanceCheck + let isRaised = (wallet.balance < balance) && wallet.isBalanceInitialized if wallet.balance != balance { wallet.balance = balance notification = walletUpdatedNotification - initialBalanceCheck = false - } else if initialBalanceCheck { - initialBalanceCheck = false + } else if !wallet.isBalanceInitialized { notification = walletUpdatedNotification } else { notification = nil } + wallet.isBalanceInitialized = true + if isRaised { vibroService.applyVibration(.success) } @@ -304,6 +301,12 @@ extension DashWalletService: InitiatedWithPassphraseService { self.dashWallet = eWallet + NotificationCenter.default.post( + name: walletUpdatedNotification, + object: self, + userInfo: [AdamantUserInfoKey.WalletService.wallet: eWallet] + ) + if !self.enabled { self.enabled = true NotificationCenter.default.post(name: self.serviceEnabledChanged, object: self) @@ -319,7 +322,6 @@ extension DashWalletService: InitiatedWithPassphraseService { } } - service.initialBalanceCheck = true service.setState(.upToDate, silent: true) Task { service.update() diff --git a/Adamant/Modules/Wallets/Doge/DogeWalletService.swift b/Adamant/Modules/Wallets/Doge/DogeWalletService.swift index d98c95f6e..04234b135 100644 --- a/Adamant/Modules/Wallets/Doge/DogeWalletService.swift +++ b/Adamant/Modules/Wallets/Doge/DogeWalletService.swift @@ -112,7 +112,6 @@ final class DogeWalletService: WalletService { @Atomic private(set) var dogeWallet: DogeWallet? @Atomic private(set) var enabled = true @Atomic public var network: Network - @Atomic private var initialBalanceCheck = false let defaultDispatchQueue = DispatchQueue( label: "im.adamant.dogeWalletService", @@ -189,7 +188,6 @@ final class DogeWalletService: WalletService { .receive(on: OperationQueue.main) .sink { [weak self] _ in self?.dogeWallet = nil - self?.initialBalanceCheck = false if let balanceObserver = self?.balanceObserver { NotificationCenter.default.removeObserver(balanceObserver) self?.balanceObserver = nil @@ -229,21 +227,20 @@ final class DogeWalletService: WalletService { setState(.updating) if let balance = try? await getBalance() { - wallet.isBalanceInitialized = true let notification: Notification.Name? - let isRaised = (wallet.balance < balance) && !initialBalanceCheck + let isRaised = (wallet.balance < balance) && wallet.isBalanceInitialized if wallet.balance != balance { wallet.balance = balance notification = walletUpdatedNotification - initialBalanceCheck = false - } else if initialBalanceCheck { - initialBalanceCheck = false + } else if !wallet.isBalanceInitialized { notification = walletUpdatedNotification } else { notification = nil } + wallet.isBalanceInitialized = true + if isRaised { vibroService.applyVibration(.success) } @@ -293,6 +290,12 @@ extension DogeWalletService: InitiatedWithPassphraseService { let eWallet = try DogeWallet(privateKey: privateKey, addressConverter: addressConverter) self.dogeWallet = eWallet + NotificationCenter.default.post( + name: walletUpdatedNotification, + object: self, + userInfo: [AdamantUserInfoKey.WalletService.wallet: eWallet] + ) + if !self.enabled { self.enabled = true NotificationCenter.default.post(name: self.serviceEnabledChanged, object: self) @@ -308,7 +311,6 @@ extension DogeWalletService: InitiatedWithPassphraseService { } } - service.initialBalanceCheck = true service.setState(.upToDate, silent: true) Task { diff --git a/Adamant/Modules/Wallets/ERC20/ERC20WalletService.swift b/Adamant/Modules/Wallets/ERC20/ERC20WalletService.swift index aee990a69..1c8508abc 100644 --- a/Adamant/Modules/Wallets/ERC20/ERC20WalletService.swift +++ b/Adamant/Modules/Wallets/ERC20/ERC20WalletService.swift @@ -122,7 +122,6 @@ final class ERC20WalletService: WalletService { let token: ERC20Token @Atomic private(set) var enabled = true @Atomic private var subscriptions = Set() - @Atomic private var initialBalanceCheck = false // MARK: - State @Atomic private (set) var state: WalletServiceState = .notInitiated @@ -199,7 +198,6 @@ final class ERC20WalletService: WalletService { .receive(on: OperationQueue.main) .sink { [weak self] _ in self?.ethWallet = nil - self?.initialBalanceCheck = false if let balanceObserver = self?.balanceObserver { NotificationCenter.default.removeObserver(balanceObserver) self?.balanceObserver = nil @@ -239,21 +237,20 @@ final class ERC20WalletService: WalletService { setState(.updating) if let balance = try? await getBalance(forAddress: wallet.ethAddress) { - wallet.isBalanceInitialized = true let notification: Notification.Name? - let isRaised = (wallet.balance < balance) && !initialBalanceCheck + let isRaised = (wallet.balance < balance) && wallet.isBalanceInitialized if wallet.balance != balance { wallet.balance = balance notification = walletUpdatedNotification - initialBalanceCheck = false - } else if initialBalanceCheck { - initialBalanceCheck = false + } else if !wallet.isBalanceInitialized { notification = walletUpdatedNotification } else { notification = nil } + wallet.isBalanceInitialized = true + if isRaised { vibroService.applyVibration(.success) } @@ -375,7 +372,12 @@ extension ERC20WalletService: InitiatedWithPassphraseService { NotificationCenter.default.post(name: serviceEnabledChanged, object: self) } - self.initialBalanceCheck = true + NotificationCenter.default.post( + name: walletUpdatedNotification, + object: self, + userInfo: [AdamantUserInfoKey.WalletService.wallet: eWallet] + ) + self.setState(.upToDate, silent: true) Task { await update() diff --git a/Adamant/Modules/Wallets/Ethereum/EthWalletService.swift b/Adamant/Modules/Wallets/Ethereum/EthWalletService.swift index 6b25c1858..7b75a03ed 100644 --- a/Adamant/Modules/Wallets/Ethereum/EthWalletService.swift +++ b/Adamant/Modules/Wallets/Ethereum/EthWalletService.swift @@ -139,7 +139,6 @@ final class EthWalletService: WalletService { public static let transactionsListApiSubpath = "ethtxs" @Atomic private(set) var enabled = true - @Atomic private var initialBalanceCheck = false @Atomic private var subscriptions = Set() @ObservableValue private(set) var historyTransactions: [TransactionDetails] = [] @@ -214,7 +213,6 @@ final class EthWalletService: WalletService { .receive(on: OperationQueue.main) .sink { [weak self] _ in self?.ethWallet = nil - self?.initialBalanceCheck = false if let balanceObserver = self?.balanceObserver { NotificationCenter.default.removeObserver(balanceObserver) self?.balanceObserver = nil @@ -264,23 +262,21 @@ final class EthWalletService: WalletService { setState(.updating) if let balance = try? await getBalance(forAddress: wallet.ethAddress) { - wallet.isBalanceInitialized = true - let notification: Notification.Name? - let isRaised = (wallet.balance < balance) && !initialBalanceCheck + let isRaised = (wallet.balance < balance) && wallet.isBalanceInitialized if wallet.balance != balance { wallet.balance = balance notification = walletUpdatedNotification - initialBalanceCheck = false - } else if initialBalanceCheck { - initialBalanceCheck = false + } else if !wallet.isBalanceInitialized { notification = walletUpdatedNotification } else { notification = nil } + wallet.isBalanceInitialized = true + if isRaised { vibroService.applyVibration(.success) } @@ -399,6 +395,12 @@ extension EthWalletService: InitiatedWithPassphraseService { // MARK: 3. Update ethWallet = eWallet + NotificationCenter.default.post( + name: walletUpdatedNotification, + object: self, + userInfo: [AdamantUserInfoKey.WalletService.wallet: eWallet] + ) + if !enabled { enabled = true NotificationCenter.default.post(name: serviceEnabledChanged, object: self) @@ -414,7 +416,6 @@ extension EthWalletService: InitiatedWithPassphraseService { } } - service.initialBalanceCheck = true service.setState(.upToDate, silent: true) Task { diff --git a/Adamant/Modules/Wallets/Lisk/LskWalletService.swift b/Adamant/Modules/Wallets/Lisk/LskWalletService.swift index a5b5136da..987116b73 100644 --- a/Adamant/Modules/Wallets/Lisk/LskWalletService.swift +++ b/Adamant/Modules/Wallets/Lisk/LskWalletService.swift @@ -85,7 +85,6 @@ final class LskWalletService: WalletService { let transferAvailable: Bool = true let netHash = Constants.Nethash.main - @Atomic private var initialBalanceCheck = false @Atomic private(set) var lskWallet: LskWallet? let defaultDispatchQueue = DispatchQueue( @@ -161,7 +160,6 @@ final class LskWalletService: WalletService { .receive(on: OperationQueue.main) .sink { [weak self] _ in self?.lskWallet = nil - self?.initialBalanceCheck = false if let balanceObserver = self?.balanceObserver { NotificationCenter.default.removeObserver(balanceObserver) self?.balanceObserver = nil @@ -208,22 +206,21 @@ final class LskWalletService: WalletService { } if let balance = try? await getBalance() { - let isRaised = (wallet.balance < balance) && !initialBalanceCheck - - wallet.isBalanceInitialized = true let notification: Notification.Name? + let isRaised = (wallet.balance < balance) && wallet.isBalanceInitialized + if wallet.balance != balance { wallet.balance = balance notification = walletUpdatedNotification - initialBalanceCheck = false - } else if initialBalanceCheck { - initialBalanceCheck = false + } else if !wallet.isBalanceInitialized { notification = walletUpdatedNotification } else { notification = nil } + wallet.isBalanceInitialized = true + if isRaised { vibroService.applyVibration(.success) } @@ -312,6 +309,12 @@ extension LskWalletService: InitiatedWithPassphraseService { // MARK: 3. Update let wallet = LskWallet(address: address, keyPair: keyPair, nounce: "", isNewApi: true) self.lskWallet = wallet + + NotificationCenter.default.post( + name: walletUpdatedNotification, + object: self, + userInfo: [AdamantUserInfoKey.WalletService.wallet: wallet] + ) } catch { print("\(error)") throw WalletServiceError.accountNotFound @@ -337,7 +340,6 @@ extension LskWalletService: InitiatedWithPassphraseService { } } - service.initialBalanceCheck = true service.setState(.upToDate, silent: true) Task { From 1f2d56287e8d20e2c9ff8728edcb0fbd63d48c55 Mon Sep 17 00:00:00 2001 From: StanislavDevIOS Date: Tue, 28 Nov 2023 14:00:36 +0200 Subject: [PATCH 2/3] [trello.com/c/3uD9Q0eY] update libraries --- .../xcshareddata/swiftpm/Package.resolved | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Adamant.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Adamant.xcworkspace/xcshareddata/swiftpm/Package.resolved index 233c8657b..88a2fda6f 100644 --- a/Adamant.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Adamant.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -105,8 +105,8 @@ "repositoryURL": "https://github.com/google/GoogleDataTransport.git", "state": { "branch": null, - "revision": "98a00258d4518b7521253a70b7f70bb76d2120fe", - "version": "9.2.4" + "revision": "aae45a320fd0d11811820335b1eabc8753902a40", + "version": "9.2.5" } }, { @@ -114,8 +114,8 @@ "repositoryURL": "https://github.com/google/GoogleUtilities.git", "state": { "branch": null, - "revision": "4446686bc3714d49ce043d0f68318f42ed718cb6", - "version": "7.11.4" + "revision": "bc27fad73504f3d4af235de451f02ee22586ebd3", + "version": "7.12.1" } }, { @@ -159,8 +159,8 @@ "repositoryURL": "https://github.com/firebase/leveldb.git", "state": { "branch": null, - "revision": "0706abcc6b0bd9cedfbb015ba840e4a780b5159b", - "version": "1.22.2" + "revision": "9d108e9112aa1d65ce508facf804674546116d9c", + "version": "1.22.3" } }, { @@ -177,8 +177,8 @@ "repositoryURL": "https://github.com/MessageKit/MessageKit.git", "state": { "branch": null, - "revision": "14bfa7eb9f93267c3d7b8cdf58615bba27be672a", - "version": "4.1.1" + "revision": "1993e8e90d4e9a61b8d9bc8ceb733964ce943376", + "version": "4.2.0" } }, { @@ -276,7 +276,7 @@ "repositoryURL": "https://github.com/socketio/socket.io-client-swift", "state": { "branch": "master", - "revision": "a1ed825835a2d8c2555938e96557ccc05e4bebf3", + "revision": "175da8b5156f6b132436f0676cc84c2f6a766b6e", "version": null } }, @@ -285,8 +285,8 @@ "repositoryURL": "https://github.com/daltoniam/Starscream", "state": { "branch": null, - "revision": "df8d82047f6654d8e4b655d1b1525c64e1059d21", - "version": "4.0.4" + "revision": "ac6c0fc9da221873e01bd1a0d4818498a71eef33", + "version": "4.0.6" } }, { @@ -294,8 +294,8 @@ "repositoryURL": "https://github.com/apple/swift-protobuf.git", "state": { "branch": null, - "revision": "ce20dc083ee485524b802669890291c0d8090170", - "version": "1.22.1" + "revision": "07f7f26ded8df9645c072f220378879c4642e063", + "version": "1.25.1" } }, { From dce0b44320cab02c91617e0486f2d9fbb33a1517 Mon Sep 17 00:00:00 2001 From: StanislavDevIOS Date: Tue, 28 Nov 2023 14:03:25 +0200 Subject: [PATCH 3/3] [trello.com/c/3uD9Q0eY] removed our implementation of velocity --- .../Helpers/SwiftUI/DragGesture+Extension.swift | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 CommonKit/Sources/CommonKit/Helpers/SwiftUI/DragGesture+Extension.swift diff --git a/CommonKit/Sources/CommonKit/Helpers/SwiftUI/DragGesture+Extension.swift b/CommonKit/Sources/CommonKit/Helpers/SwiftUI/DragGesture+Extension.swift deleted file mode 100644 index e92ff8006..000000000 --- a/CommonKit/Sources/CommonKit/Helpers/SwiftUI/DragGesture+Extension.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// File.swift -// -// -// Created by Andrey Golubenko on 24.07.2023. -// - -import SwiftUI - -public extension DragGesture.Value { - var velocity: CGSize { - .init( - width: predictedEndLocation.x - location.x, - height: predictedEndLocation.y - location.y - ) - } -}