From 918eb9bfbb1e4ab475bfb1136a86fdcc824b0638 Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov <80246944+fedorov-d@users.noreply.github.com> Date: Fri, 25 Oct 2024 09:47:05 +0400 Subject: [PATCH 1/9] IOS-8282 Use different parameter keys --- .../Analytics/Analytics+ParameterKey.swift | 1 + .../CommonStakingAnalyticsLogger.swift | 21 ++++++++++++++----- .../StakingTransactionDispatcher.swift | 9 +++----- .../StakingAPIService/DTOs/StakeKitDTO.swift | 15 ++++++------- .../StakeKitStakingAPIService.swift | 2 +- .../StakingAnalyticsLogger.swift | 2 +- .../StakingManager/CommonStakingManager.swift | 8 +++---- 7 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Tangem/App/Services/Analytics/Analytics+ParameterKey.swift b/Tangem/App/Services/Analytics/Analytics+ParameterKey.swift index 161b7fdc27..eecf9a5989 100644 --- a/Tangem/App/Services/Analytics/Analytics+ParameterKey.swift +++ b/Tangem/App/Services/Analytics/Analytics+ParameterKey.swift @@ -15,6 +15,7 @@ extension Analytics { case action = "Action" case errorDescription = "Error Description" case errorCode = "Error Code" + case errorMessage = "Error Message" case newSecOption = "new_security_option" case errorKey = "Tangem SDK error key" case walletConnectAction = "wallet_connect_action" diff --git a/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift b/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift index fdeb3302ba..e930ede820 100644 --- a/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift +++ b/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift @@ -10,11 +10,22 @@ import Foundation import TangemStaking struct CommonStakingAnalyticsLogger: StakingAnalyticsLogger { - func logAPIError(errorDescription: String, currencySymbol: String?) { - var params: [Analytics.ParameterKey: String] = [.errorDescription: errorDescription] - if let currencySymbol { - params[.token] = currencySymbol + func logError(_ error: any Error, currencySymbol: String) { + var parameters: [Analytics.ParameterKey: String] = [.token: currencySymbol] + switch error as? StakeKitAPIError { + case .some(let error): + if let code = error.code { + parameters[.errorCode] = code + } + if let message = error.message { + parameters[.errorMessage] = message + } + case .none: + parameters[.errorDescription] = error.localizedDescription } - Analytics.log(event: .stakingErrors, params: params) + Analytics.log( + event: .stakingErrors, + params: parameters + ) } } diff --git a/Tangem/Modules/Send/SendTransactionDispatcher/StakingTransactionDispatcher.swift b/Tangem/Modules/Send/SendTransactionDispatcher/StakingTransactionDispatcher.swift index 233ef398cb..aeb222ea97 100644 --- a/Tangem/Modules/Send/SendTransactionDispatcher/StakingTransactionDispatcher.swift +++ b/Tangem/Modules/Send/SendTransactionDispatcher/StakingTransactionDispatcher.swift @@ -106,12 +106,9 @@ private extension StakingTransactionDispatcher { do { try await pendingHashesSender.sendHash(hash) } catch { - Analytics.log( - event: .stakingErrors, - params: [ - .token: walletModel.tokenItem.currencySymbol, - .errorDescription: error.localizedDescription, - ] + CommonStakingAnalyticsLogger().logError( + error, + currencySymbol: walletModel.tokenItem.currencySymbol ) } diff --git a/TangemStaking/Services/StakingAPIService/DTOs/StakeKitDTO.swift b/TangemStaking/Services/StakingAPIService/DTOs/StakeKitDTO.swift index 1fa58440c7..bb2cfe8fee 100644 --- a/TangemStaking/Services/StakingAPIService/DTOs/StakeKitDTO.swift +++ b/TangemStaking/Services/StakingAPIService/DTOs/StakeKitDTO.swift @@ -8,15 +8,16 @@ import Foundation -enum StakeKitDTO { - // MARK: - Common +public struct StakeKitAPIError: Decodable, LocalizedError { + public let code: String? + public let message: String? + let level: String? - struct APIError: Decodable, LocalizedError { - let message: String? - let level: String? + public var errorDescription: String? { message } +} - var errorDescription: String? { message } - } +enum StakeKitDTO { + // MARK: - Common struct Token: Codable { let network: String diff --git a/TangemStaking/Services/StakingAPIService/StakeKitStakingAPIService.swift b/TangemStaking/Services/StakingAPIService/StakeKitStakingAPIService.swift index 564bfc8a61..5898e905f8 100644 --- a/TangemStaking/Services/StakingAPIService/StakeKitStakingAPIService.swift +++ b/TangemStaking/Services/StakingAPIService/StakeKitStakingAPIService.swift @@ -109,7 +109,7 @@ private extension StakeKitStakingAPIService { func tryMapError(target: StakeKitTarget, response: Moya.Response) -> Error? { do { - let error = try JSONDecoder().decode(StakeKitDTO.APIError.self, from: response.data) + let error = try JSONDecoder().decode(StakeKitAPIError.self, from: response.data) return error } catch { return nil diff --git a/TangemStaking/Services/StakingAnalytics/StakingAnalyticsLogger.swift b/TangemStaking/Services/StakingAnalytics/StakingAnalyticsLogger.swift index e2717b1984..d6a85c100f 100644 --- a/TangemStaking/Services/StakingAnalytics/StakingAnalyticsLogger.swift +++ b/TangemStaking/Services/StakingAnalytics/StakingAnalyticsLogger.swift @@ -9,5 +9,5 @@ import Foundation public protocol StakingAnalyticsLogger { - func logAPIError(errorDescription: String, currencySymbol: String?) + func logError(_ error: any Error, currencySymbol: String) } diff --git a/TangemStaking/Services/StakingManager/CommonStakingManager.swift b/TangemStaking/Services/StakingManager/CommonStakingManager.swift index f751a43c67..250b53ba2a 100644 --- a/TangemStaking/Services/StakingManager/CommonStakingManager.swift +++ b/TangemStaking/Services/StakingManager/CommonStakingManager.swift @@ -74,8 +74,8 @@ extension CommonStakingManager: StakingManager { try await repository.checkIfConfirmed(balances: balances) try await updateState(state(balances: balances, yield: yield)) } catch { - analyticsLogger.logAPIError( - errorDescription: error.localizedDescription, + analyticsLogger.logError( + error, currencySymbol: wallet.item.symbol ) logger.error(error) @@ -276,8 +276,8 @@ private extension CommonStakingManager { do { return try await request() } catch { - analyticsLogger.logAPIError( - errorDescription: error.localizedDescription, + analyticsLogger.logError( + error, currencySymbol: wallet.item.symbol ) throw error From 3d2526d2398e63eb038b051f6ce9f8e0fa055156 Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov <80246944+fedorov-d@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:08:42 +0400 Subject: [PATCH 2/9] IOS-8282 Remove unused errors --- .../StakingManager/CommonStakingManager.swift | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/TangemStaking/Services/StakingManager/CommonStakingManager.swift b/TangemStaking/Services/StakingManager/CommonStakingManager.swift index 250b53ba2a..f0785248a2 100644 --- a/TangemStaking/Services/StakingManager/CommonStakingManager.swift +++ b/TangemStaking/Services/StakingManager/CommonStakingManager.swift @@ -437,27 +437,12 @@ private extension CommonStakingManager { public enum StakingManagerError: LocalizedError { case stakingManagerStateNotSupportTransactionAction(action: StakingAction) - case stakedBalanceNotFound(validator: String) - case pendingActionNotFound(validator: String) - case transactionNotFound - case notImplemented - case notFound case stakingManagerIsLoading public var errorDescription: String? { switch self { case .stakingManagerStateNotSupportTransactionAction(let action): "StakingManagerNotSupportTransactionAction \(action)" - case .stakedBalanceNotFound(let validator): - "stakedBalanceNotFound \(validator)" - case .pendingActionNotFound(let validator): - "pendingActionNotFound \(validator)" - case .transactionNotFound: - "transactionNotFound" - case .notImplemented: - "notImplemented" - case .notFound: - "notFound" case .stakingManagerIsLoading: "StakingManagerIsLoading" } From d155f7e838c5c6fa1dd3eb590d0e44c0827c75ff Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov <80246944+fedorov-d@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:14:48 +0400 Subject: [PATCH 3/9] IOS-8282 Tweak code style, add StakeKitHTTPError handler --- .../Analytics/CommonStakingAnalyticsLogger.swift | 15 +++++++++------ .../StakeKitStakingAPIService.swift | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift b/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift index e930ede820..b71bb1ce01 100644 --- a/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift +++ b/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift @@ -12,16 +12,19 @@ import TangemStaking struct CommonStakingAnalyticsLogger: StakingAnalyticsLogger { func logError(_ error: any Error, currencySymbol: String) { var parameters: [Analytics.ParameterKey: String] = [.token: currencySymbol] - switch error as? StakeKitAPIError { - case .some(let error): - if let code = error.code { + switch error { + case let apiError as StakeKitAPIError: + if let code = apiError.code { parameters[.errorCode] = code } - if let message = error.message { + if let message = apiError.message { parameters[.errorMessage] = message } - case .none: - parameters[.errorDescription] = error.localizedDescription + case let httpError as StakeKitHTTPError: + parameters[.errorDescription] = httpError.errorDescription + // TODO: handle other errors separately + default: + break } Analytics.log( event: .stakingErrors, diff --git a/TangemStaking/Services/StakingAPIService/StakeKitStakingAPIService.swift b/TangemStaking/Services/StakingAPIService/StakeKitStakingAPIService.swift index 5898e905f8..69cb059d54 100644 --- a/TangemStaking/Services/StakingAPIService/StakeKitStakingAPIService.swift +++ b/TangemStaking/Services/StakingAPIService/StakeKitStakingAPIService.swift @@ -117,12 +117,12 @@ private extension StakeKitStakingAPIService { } } -private enum StakeKitHTTPError: Error { +public enum StakeKitHTTPError: Error { case badStatusCode(response: String?, code: Int) } extension StakeKitHTTPError: LocalizedError { - var errorDescription: String? { + public var errorDescription: String? { switch self { case .badStatusCode(let response, let code): response ?? "HTTP error \(code)" } From 4364db56b323f3cd2175aaf3e565cddbcc5061ce Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov <80246944+fedorov-d@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:17:14 +0400 Subject: [PATCH 4/9] IOS-8282 Add new error case for staking manager --- .../StakingManager/CommonStakingManager.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/TangemStaking/Services/StakingManager/CommonStakingManager.swift b/TangemStaking/Services/StakingManager/CommonStakingManager.swift index f0785248a2..44e9a71261 100644 --- a/TangemStaking/Services/StakingManager/CommonStakingManager.swift +++ b/TangemStaking/Services/StakingManager/CommonStakingManager.swift @@ -107,7 +107,7 @@ extension CommonStakingManager: StakingManager { ) default: log("Invalid staking manager state: \(state), for action: \(action)") - throw StakingManagerError.stakingManagerStateNotSupportTransactionAction(action: action) + throw StakingManagerError.stakingManagerStateNotSupportEstimateFeeAction(action: action) } } @@ -436,13 +436,16 @@ private extension CommonStakingManager { } public enum StakingManagerError: LocalizedError { - case stakingManagerStateNotSupportTransactionAction(action: StakingAction) + case stakingManagerStateNotSupportTransactionAction(action: StakingAction, state: StakingManagerState) + case stakingManagerStateNotSupportEstimateFeeAction(action: StakingAction, state: StakingManagerState) case stakingManagerIsLoading public var errorDescription: String? { switch self { - case .stakingManagerStateNotSupportTransactionAction(let action): - "StakingManagerNotSupportTransactionAction \(action)" + case .stakingManagerStateNotSupportTransactionAction(let action, let state): + "StakingManagerNotSupportTransactionAction \(action) state \(state)" + case .stakingManagerStateNotSupportEstimateFeeAction(let action, let state): + "StakingManagerNotSupportTransactionAction \(action) state \(state)" case .stakingManagerIsLoading: "StakingManagerIsLoading" } From 0dc0c0537d23253009d096081e6df2e0c83cec6b Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov <80246944+fedorov-d@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:59:07 +0400 Subject: [PATCH 5/9] IOS-8282 Add tracking for staking manager errors --- Tangem/App/Services/Analytics/Analytics+Event.swift | 1 + .../Analytics/CommonStakingAnalyticsLogger.swift | 12 ++++++++---- .../StakingManager/CommonStakingManager.swift | 8 ++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Tangem/App/Services/Analytics/Analytics+Event.swift b/Tangem/App/Services/Analytics/Analytics+Event.swift index 1205ed748d..ad76bc711d 100644 --- a/Tangem/App/Services/Analytics/Analytics+Event.swift +++ b/Tangem/App/Services/Analytics/Analytics+Event.swift @@ -288,6 +288,7 @@ extension Analytics { case stakingConfirmationScreenOpened = "[Staking] Confirmation Screen Opened" case stakingErrors = "[Staking] Errors" case stakingErrorTransactionRejected = "[Staking] Error - Transaction Rejected" + case stakingAppErrors = "[Staking] App Errors" case stakingSelectedCurrency = "[Staking] Selected Currency" case stakingButtonShare = "[Staking] Button - Share" case stakingButtonExplore = "[Staking] Button - Explore" diff --git a/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift b/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift index b71bb1ce01..ee29b9d431 100644 --- a/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift +++ b/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift @@ -11,6 +11,7 @@ import TangemStaking struct CommonStakingAnalyticsLogger: StakingAnalyticsLogger { func logError(_ error: any Error, currencySymbol: String) { + let event: Analytics.Event var parameters: [Analytics.ParameterKey: String] = [.token: currencySymbol] switch error { case let apiError as StakeKitAPIError: @@ -20,14 +21,17 @@ struct CommonStakingAnalyticsLogger: StakingAnalyticsLogger { if let message = apiError.message { parameters[.errorMessage] = message } + event = .stakingErrors case let httpError as StakeKitHTTPError: parameters[.errorDescription] = httpError.errorDescription - // TODO: handle other errors separately - default: - break + event = .stakingErrors + case let stakingManagerError as StakingManagerError: + parameters[.errorDescription] = stakingManagerError.errorDescription + event = .stakingAppErrors + default: return } Analytics.log( - event: .stakingErrors, + event: event, params: parameters ) } diff --git a/TangemStaking/Services/StakingManager/CommonStakingManager.swift b/TangemStaking/Services/StakingManager/CommonStakingManager.swift index 44e9a71261..2e21d7fd25 100644 --- a/TangemStaking/Services/StakingManager/CommonStakingManager.swift +++ b/TangemStaking/Services/StakingManager/CommonStakingManager.swift @@ -107,7 +107,7 @@ extension CommonStakingManager: StakingManager { ) default: log("Invalid staking manager state: \(state), for action: \(action)") - throw StakingManagerError.stakingManagerStateNotSupportEstimateFeeAction(action: action) + throw StakingManagerError.stakingManagerStateNotSupportEstimateFeeAction(action: action, state: state) } } @@ -130,7 +130,7 @@ extension CommonStakingManager: StakingManager { type: type ) default: - throw StakingManagerError.stakingManagerStateNotSupportTransactionAction(action: action) + throw StakingManagerError.stakingManagerStateNotSupportTransactionAction(action: action, state: state) } } @@ -443,9 +443,9 @@ public enum StakingManagerError: LocalizedError { public var errorDescription: String? { switch self { case .stakingManagerStateNotSupportTransactionAction(let action, let state): - "StakingManagerNotSupportTransactionAction \(action) state \(state)" + "StakingManagerNotSupportTransactionAction \(action.type) state \(state.description)" case .stakingManagerStateNotSupportEstimateFeeAction(let action, let state): - "StakingManagerNotSupportTransactionAction \(action) state \(state)" + "StakingManagerNotSupportTransactionAction \(action.type) state \(state.description)" case .stakingManagerIsLoading: "StakingManagerIsLoading" } From 6a05302bb007544eb5390c2651d4cff2b3c23387 Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov <80246944+fedorov-d@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:13:41 +0400 Subject: [PATCH 6/9] IOS-8282 Add tracking for stakekitmapper errors --- .../Analytics/CommonStakingAnalyticsLogger.swift | 4 ++-- .../Services/StakeKitMapper/StakeKitMapper.swift | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift b/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift index ee29b9d431..0f8843d099 100644 --- a/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift +++ b/Tangem/App/Services/Analytics/CommonStakingAnalyticsLogger.swift @@ -25,8 +25,8 @@ struct CommonStakingAnalyticsLogger: StakingAnalyticsLogger { case let httpError as StakeKitHTTPError: parameters[.errorDescription] = httpError.errorDescription event = .stakingErrors - case let stakingManagerError as StakingManagerError: - parameters[.errorDescription] = stakingManagerError.errorDescription + case let error as LocalizedError where error is StakingManagerError || error is StakeKitMapperError: + parameters[.errorDescription] = error.errorDescription event = .stakingAppErrors default: return } diff --git a/TangemStaking/Services/StakeKitMapper/StakeKitMapper.swift b/TangemStaking/Services/StakeKitMapper/StakeKitMapper.swift index 3cf2dbbe6a..d134dc587c 100644 --- a/TangemStaking/Services/StakeKitMapper/StakeKitMapper.swift +++ b/TangemStaking/Services/StakeKitMapper/StakeKitMapper.swift @@ -371,8 +371,18 @@ struct StakeKitMapper { } } -enum StakeKitMapperError: Error { +public enum StakeKitMapperError: Error { case notImplement case noData(String) case tronTransactionMappingFailed } + +extension StakeKitMapperError: LocalizedError { + public var errorDescription: String? { + switch self { + case .notImplement: "Not implemented" + case .noData(let string): string + case .tronTransactionMappingFailed: "TronTransactionMappingFailed" + } + } +} From d8e076eb1e7326dffdbc051f1ee35fe46c9961c3 Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov <80246944+fedorov-d@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:15:05 +0400 Subject: [PATCH 7/9] IOS-8282 remove redundant events, add missing parameters in some events --- .../App/Services/Analytics/Analytics+Event.swift | 7 +------ .../TokenNotificationEvent.swift | 7 ++++--- .../MultiWalletNotificationManager.swift | 15 +++++++++------ .../TotalBalanceProvider.swift | 4 ++++ Tangem/Modules/Main/MainCoordinator.swift | 2 -- Tangem/Modules/Main/MainViewModel.swift | 5 ----- .../MultiWalletMainContentViewModel.swift | 1 - .../SingleTokenBaseViewModel.swift | 2 -- .../StakingDetails/StakingDetailsViewModel.swift | 5 ++++- .../ReceiveBottomSheetViewModel.swift | 2 +- 10 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Tangem/App/Services/Analytics/Analytics+Event.swift b/Tangem/App/Services/Analytics/Analytics+Event.swift index ad76bc711d..3e35037127 100644 --- a/Tangem/App/Services/Analytics/Analytics+Event.swift +++ b/Tangem/App/Services/Analytics/Analytics+Event.swift @@ -12,7 +12,6 @@ extension Analytics { enum Event: String { case signedIn = "[Basic] Signed in" case toppedUp = "[Basic] Topped up" - case walletOpened = "[Basic] Wallet Opened" case balanceLoaded = "[Basic] Balance Loaded" case tokenBalanceLoaded = "[Basic] Token Balance" case cardWasScanned = "[Basic] Card Was Scanned" @@ -54,12 +53,9 @@ extension Analytics { case twinSetupFinished = "[Onboarding / Twins] Twin Setup Finished" case onboardingButtonChat = "[Onboarding] Button - Chat" case mainScreenOpened = "[Main Screen] Screen opened" - case mainScreenWalletChangedBySwipe = "[Main Screen] Wallet Swipe" case noticeRateTheAppButtonTapped = "[Main Screen] Notice - Rate The App Button Tapped" case buttonManageTokens = "[Portfolio] Button - Manage Tokens" - case tokenIsTapped = "[Portfolio] Token is Tapped" - case mainRefreshed = "[Portfolio] Refreshed" - case buttonOrganizeTokens = "[Portfolio] Button - Organize Tokens" + case organizeTokensScreenOpened = "[Portfolio / Organize Tokens] Organize Tokens Screen Opened" case organizeTokensButtonSortByBalance = "[Portfolio / Organize Tokens] Button - By Balance" case organizeTokensButtonGroup = "[Portfolio / Organize Tokens] Button - Group" @@ -69,7 +65,6 @@ extension Analytics { case buttonRemoveToken = "[Token] Button - Remove Token" case buttonExplore = "[Token] Button - Explore" case buttonReload = "[Token] Button - Reload" - case refreshed = "[Token] Refreshed" case buttonBuy = "[Token] Button - Buy" case buttonSell = "[Token] Button - Sell" case buttonExchange = "[Token] Button - Exchange" diff --git a/Tangem/App/Services/NotificationManagers/SingleTokenNotifications/TokenNotificationEvent.swift b/Tangem/App/Services/NotificationManagers/SingleTokenNotifications/TokenNotificationEvent.swift index ae7336b93e..21d8ca7c2b 100644 --- a/Tangem/App/Services/NotificationManagers/SingleTokenNotifications/TokenNotificationEvent.swift +++ b/Tangem/App/Services/NotificationManagers/SingleTokenNotifications/TokenNotificationEvent.swift @@ -11,7 +11,7 @@ import SwiftUI enum TokenNotificationEvent: Hashable { case networkUnreachable(currencySymbol: String) - case someNetworksUnreachable + case someNetworksUnreachable(networks: [WalletModel]) case rentFee(rentMessage: String) case noAccount(message: String) case existentialDepositWarning(message: String) @@ -255,8 +255,9 @@ extension TokenNotificationEvent { return [.token: currencySymbol] case .notEnoughFeeForTransaction(let configuration): return [.token: configuration.eventConfiguration.feeAmountTypeCurrencySymbol] - case .someNetworksUnreachable, - .rentFee, + case .someNetworksUnreachable(let networks): + return [.token: networks.map(\.tokenItem.currencySymbol).joined(separator: ",")] + case .rentFee, .noAccount, .existentialDepositWarning, .bnbBeaconChainRetirement, diff --git a/Tangem/App/Services/NotificationManagers/UserWalletNotifications/MultiWalletNotificationManager.swift b/Tangem/App/Services/NotificationManagers/UserWalletNotifications/MultiWalletNotificationManager.swift index 0630151979..fddc819821 100644 --- a/Tangem/App/Services/NotificationManagers/UserWalletNotifications/MultiWalletNotificationManager.swift +++ b/Tangem/App/Services/NotificationManagers/UserWalletNotifications/MultiWalletNotificationManager.swift @@ -35,12 +35,13 @@ final class MultiWalletNotificationManager { } } .sink { [weak self] walletModels in - guard walletModels.contains(where: { $0.state.isBlockchainUnreachable }) else { + let unreachableNetworks = walletModels.filter { $0.state.isBlockchainUnreachable } + guard !unreachableNetworks.isEmpty else { self?.removeSomeNetworksUnreachable() return } - self?.setupSomeNetworksUnreachable() + self?.setupSomeNetworksUnreachable(unreachableNetworks) } } @@ -49,14 +50,16 @@ final class MultiWalletNotificationManager { guard let event = $0.settings.event as? TokenNotificationEvent else { return false } - - return event == .someNetworksUnreachable + switch event { + case .someNetworksUnreachable: return true + default: return false + } } } - private func setupSomeNetworksUnreachable() { + private func setupSomeNetworksUnreachable(_ unreachableNetworks: [WalletModel]) { let factory = NotificationsFactory() - notificationInputsSubject.send([factory.buildNotificationInput(for: TokenNotificationEvent.someNetworksUnreachable)]) + notificationInputsSubject.send([factory.buildNotificationInput(for: TokenNotificationEvent.someNetworksUnreachable(networks: unreachableNetworks))]) } } diff --git a/Tangem/App/Services/TotalBalanceProvider/TotalBalanceProvider.swift b/Tangem/App/Services/TotalBalanceProvider/TotalBalanceProvider.swift index ca14907e5b..878e74cad5 100644 --- a/Tangem/App/Services/TotalBalanceProvider/TotalBalanceProvider.swift +++ b/Tangem/App/Services/TotalBalanceProvider/TotalBalanceProvider.swift @@ -227,6 +227,10 @@ private extension TotalBalanceProvider { return .customToken } + if balance?.isZero == true { + print("aaaaaaaaa") + } + if let balance { return balance > .zero ? .full : .empty } diff --git a/Tangem/Modules/Main/MainCoordinator.swift b/Tangem/Modules/Main/MainCoordinator.swift index db8730e0c6..4cdb50de0b 100644 --- a/Tangem/Modules/Main/MainCoordinator.swift +++ b/Tangem/Modules/Main/MainCoordinator.swift @@ -192,8 +192,6 @@ extension MainCoordinator: MultiWalletMainContentRoutable { func openTokenDetails(for model: WalletModel, userWalletModel: UserWalletModel) { mainBottomSheetUIManager.hide() - Analytics.log(.tokenIsTapped) - let dismissAction: Action = { [weak self] _ in self?.tokenDetailsCoordinator = nil } diff --git a/Tangem/Modules/Main/MainViewModel.swift b/Tangem/Modules/Main/MainViewModel.swift index 9b39093869..e6cfcf73e2 100644 --- a/Tangem/Modules/Main/MainViewModel.swift +++ b/Tangem/Modules/Main/MainViewModel.swift @@ -142,8 +142,6 @@ final class MainViewModel: ObservableObject { } func onPullToRefresh(completionHandler: @escaping RefreshCompletionHandler) { - Analytics.log(.mainRefreshed) - isHorizontalScrollDisabled = true let completion = { [weak self] in self?.isHorizontalScrollDisabled = false @@ -166,8 +164,6 @@ final class MainViewModel: ObservableObject { func onPageChange(dueTo reason: CardsInfoPageChangeReason) { guard reason == .byGesture else { return } - Analytics.log(.mainScreenWalletChangedBySwipe) - if !AppSettings.shared.userDidSwipeWalletsOnMainScreen { AppSettings.shared.userDidSwipeWalletsOnMainScreen = true } @@ -326,7 +322,6 @@ final class MainViewModel: ObservableObject { guard let userWalletId = viewModel.pages[safe: newIndex]?.id else { return } - Analytics.log(.walletOpened) viewModel.userWalletRepository.setSelectedUserWalletId( userWalletId, reason: .userSelected diff --git a/Tangem/Modules/Main/MultiWalletMainContent/MultiWalletMainContentViewModel.swift b/Tangem/Modules/Main/MultiWalletMainContent/MultiWalletMainContentViewModel.swift index 1e1032b530..a5277dcbd7 100644 --- a/Tangem/Modules/Main/MultiWalletMainContent/MultiWalletMainContentViewModel.swift +++ b/Tangem/Modules/Main/MultiWalletMainContent/MultiWalletMainContentViewModel.swift @@ -130,7 +130,6 @@ final class MultiWalletMainContentViewModel: ObservableObject { } func onOpenOrganizeTokensButtonTap() { - Analytics.log(.buttonOrganizeTokens) openOrganizeTokens() } diff --git a/Tangem/Modules/SingleTokenBase/SingleTokenBaseViewModel.swift b/Tangem/Modules/SingleTokenBase/SingleTokenBaseViewModel.swift index 8e55d73350..a464ab1e25 100644 --- a/Tangem/Modules/SingleTokenBase/SingleTokenBaseViewModel.swift +++ b/Tangem/Modules/SingleTokenBase/SingleTokenBaseViewModel.swift @@ -127,8 +127,6 @@ class SingleTokenBaseViewModel: NotificationTapDelegate { return } - Analytics.log(.refreshed) - if let id = walletModel.tokenItem.currencyId, miniChartsProvider.items.isEmpty { miniChartsProvider.fetch(for: [id], with: miniChartPriceIntervalType) } diff --git a/Tangem/Modules/StakingDetails/StakingDetailsViewModel.swift b/Tangem/Modules/StakingDetails/StakingDetailsViewModel.swift index 4837cb14a6..a32ddb8f3d 100644 --- a/Tangem/Modules/StakingDetails/StakingDetailsViewModel.swift +++ b/Tangem/Modules/StakingDetails/StakingDetailsViewModel.swift @@ -78,7 +78,10 @@ final class StakingDetailsViewModel: ObservableObject { let balances = stakingManager.state.balances.flatMap { String($0.count) } ?? String(0) Analytics.log( event: .stakingInfoScreenOpened, - params: [.validatorsCount: balances] + params: [ + .validatorsCount: balances, + .token: walletModel.tokenItem.currencySymbol, + ] ) } } diff --git a/Tangem/UIComponents/ReceiveBottomSheetView/ReceiveBottomSheetViewModel.swift b/Tangem/UIComponents/ReceiveBottomSheetView/ReceiveBottomSheetViewModel.swift index f826baa21e..9eb6d89f45 100644 --- a/Tangem/UIComponents/ReceiveBottomSheetView/ReceiveBottomSheetViewModel.swift +++ b/Tangem/UIComponents/ReceiveBottomSheetView/ReceiveBottomSheetViewModel.swift @@ -49,7 +49,7 @@ class ReceiveBottomSheetViewModel: ObservableObject, Identifiable { } func onViewAppear() { - Analytics.log(.receiveScreenOpened) + Analytics.log(event: .receiveScreenOpened, params: [.token: tokenItem.currencySymbol]) } func headerForAddress(with info: ReceiveAddressInfo) -> String { From 1b6ff729174b95133a616f36b67f477db317df92 Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov <80246944+fedorov-d@users.noreply.github.com> Date: Wed, 30 Oct 2024 16:10:37 +0400 Subject: [PATCH 8/9] IOS-8282 Remove redundant code, add Exchanges Screen Opened analytics event --- Tangem/App/Services/Analytics/Analytics+Event.swift | 1 + .../Services/TotalBalanceProvider/TotalBalanceProvider.swift | 4 ---- .../MarketsTokenDetails/MarketsTokenDetailsViewModel.swift | 2 ++ 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Tangem/App/Services/Analytics/Analytics+Event.swift b/Tangem/App/Services/Analytics/Analytics+Event.swift index 3e35037127..40b0802f7a 100644 --- a/Tangem/App/Services/Analytics/Analytics+Event.swift +++ b/Tangem/App/Services/Analytics/Analytics+Event.swift @@ -307,6 +307,7 @@ extension Analytics { case marketsChartButtonReceive = "[Markets / Chart] Button - Receive" case marketsChartButtonSwap = "[Markets / Chart] Button - Swap" case marketsChartDataError = "[Markets / Chart] Data Error" + case marketsChartExchangesScreenOpened = "[Markets / Chart] Exchanges Screen Opened" // MARK: - Manage Tokens diff --git a/Tangem/App/Services/TotalBalanceProvider/TotalBalanceProvider.swift b/Tangem/App/Services/TotalBalanceProvider/TotalBalanceProvider.swift index 878e74cad5..ca14907e5b 100644 --- a/Tangem/App/Services/TotalBalanceProvider/TotalBalanceProvider.swift +++ b/Tangem/App/Services/TotalBalanceProvider/TotalBalanceProvider.swift @@ -227,10 +227,6 @@ private extension TotalBalanceProvider { return .customToken } - if balance?.isZero == true { - print("aaaaaaaaa") - } - if let balance { return balance > .zero ? .full : .empty } diff --git a/Tangem/Modules/Markets/MarketsTokenDetails/MarketsTokenDetailsViewModel.swift b/Tangem/Modules/Markets/MarketsTokenDetails/MarketsTokenDetailsViewModel.swift index 0bce5c7111..01b27f4e63 100644 --- a/Tangem/Modules/Markets/MarketsTokenDetails/MarketsTokenDetailsViewModel.swift +++ b/Tangem/Modules/Markets/MarketsTokenDetails/MarketsTokenDetailsViewModel.swift @@ -226,6 +226,8 @@ class MarketsTokenDetailsViewModel: MarketsBaseViewModel { return } + Analytics.log(event: .marketsChartExchangesScreenOpened, params: [.token: tokenInfo.symbol.uppercased()]) + coordinator?.openExchangesList(tokenId: tokenInfo.id, numberOfExchangesListedOn: numberOfExchangesListedOn, presentationStyle: presentationStyle) } From 898a7a41597803d23b512ef9a1811eb8894a4447 Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov <80246944+fedorov-d@users.noreply.github.com> Date: Mon, 4 Nov 2024 10:35:09 +0400 Subject: [PATCH 9/9] IOS-8282 Change parameter key and separator --- Tangem/App/Services/Analytics/Analytics+ParameterKey.swift | 1 + .../SingleTokenNotifications/TokenNotificationEvent.swift | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Tangem/App/Services/Analytics/Analytics+ParameterKey.swift b/Tangem/App/Services/Analytics/Analytics+ParameterKey.swift index eecf9a5989..a0ecb84474 100644 --- a/Tangem/App/Services/Analytics/Analytics+ParameterKey.swift +++ b/Tangem/App/Services/Analytics/Analytics+ParameterKey.swift @@ -27,6 +27,7 @@ extension Analytics { case currency = "Currency Type" // fiat case success case token = "Token" + case tokens = "Tokens" case derivationPath = "Derivation Path" case derivation = "Derivation" case network = "Network" diff --git a/Tangem/App/Services/NotificationManagers/SingleTokenNotifications/TokenNotificationEvent.swift b/Tangem/App/Services/NotificationManagers/SingleTokenNotifications/TokenNotificationEvent.swift index 21d8ca7c2b..c8c4e296ee 100644 --- a/Tangem/App/Services/NotificationManagers/SingleTokenNotifications/TokenNotificationEvent.swift +++ b/Tangem/App/Services/NotificationManagers/SingleTokenNotifications/TokenNotificationEvent.swift @@ -256,7 +256,7 @@ extension TokenNotificationEvent { case .notEnoughFeeForTransaction(let configuration): return [.token: configuration.eventConfiguration.feeAmountTypeCurrencySymbol] case .someNetworksUnreachable(let networks): - return [.token: networks.map(\.tokenItem.currencySymbol).joined(separator: ",")] + return [.tokens: networks.map(\.tokenItem.currencySymbol).joined(separator: ", ")] case .rentFee, .noAccount, .existentialDepositWarning,