diff --git a/SubVT.xcodeproj/project.pbxproj b/SubVT.xcodeproj/project.pbxproj index b1378ef..3fb33bf 100644 --- a/SubVT.xcodeproj/project.pbxproj +++ b/SubVT.xcodeproj/project.pbxproj @@ -1798,7 +1798,7 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; CODE_SIGN_ENTITLEMENTS = SubVT/Resources/Config/SubVT.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 9; DEVELOPMENT_ASSET_PATHS = "\"SubVT/Preview Content\""; DEVELOPMENT_TEAM = TM389H3UFR; ENABLE_PREVIEWS = YES; @@ -1838,7 +1838,7 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; CODE_SIGN_ENTITLEMENTS = SubVT/Resources/Config/SubVT.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 9; DEVELOPMENT_ASSET_PATHS = "\"SubVT/Preview Content\""; DEVELOPMENT_TEAM = TM389H3UFR; ENABLE_PREVIEWS = YES; diff --git a/SubVT/Classes/App/SubVTApp.swift b/SubVT/Classes/App/SubVTApp.swift index 76b6334..0724e4d 100644 --- a/SubVT/Classes/App/SubVTApp.swift +++ b/SubVT/Classes/App/SubVTApp.swift @@ -148,13 +148,21 @@ extension AppDelegate: UNUserNotificationCenterDelegate { if let _ = userInfo["aps"] as? [String: Any], let customData = userInfo["notification_data"] as? [String: Any], let networkId = customData["network_id"] as? UInt64, - let _ = customData["notification_type_code"] as? String { + let notificationTypeCode = customData["notification_type_code"] as? String { if let validatorAccountId = customData["validator_account_id"] as? String, - let _ = customData["validator_display"] as? String { - self.router.push(screen: Screen.validatorDetails( - networkId: networkId, - accountId: AccountId(hex: validatorAccountId) - )) + let validatorDisplay = customData["validator_display"] as? String { + if notificationTypeCode == "chain_validator_stopped_para_validating" { + self.router.push(screen: Screen.paraVoteReport( + networkId: networkId, + accountId: AccountId(hex: validatorAccountId), + identityDisplay: validatorDisplay + )) + } else { + self.router.push(screen: Screen.validatorDetails( + networkId: networkId, + accountId: AccountId(hex: validatorAccountId) + )) + } } else { self.router.popToRoot() self.appState.currentTab = .notifications diff --git a/SubVT/Classes/UI/Navigation/Router.swift b/SubVT/Classes/UI/Navigation/Router.swift index 9d99d67..2abfd90 100644 --- a/SubVT/Classes/UI/Navigation/Router.swift +++ b/SubVT/Classes/UI/Navigation/Router.swift @@ -22,7 +22,7 @@ enum Screen: Hashable { chartTitle: String ) case paraVoteReport( - network: Network, + networkId: UInt64, accountId: AccountId, identityDisplay: String ) @@ -83,12 +83,12 @@ enum Screen: Hashable { chartTitle: chartTitle ) case .paraVoteReport( - let network, + let networkId, let accountId, let identityDisplay ): ParaVoteReportView( - network: network, + networkId: networkId, accountId: accountId, identityDisplay: identityDisplay ) diff --git a/SubVT/Classes/UI/View/Reports/ParaVoteReportView.swift b/SubVT/Classes/UI/View/Reports/ParaVoteReportView.swift index e355fb9..21cbe37 100644 --- a/SubVT/Classes/UI/View/Reports/ParaVoteReportView.swift +++ b/SubVT/Classes/UI/View/Reports/ParaVoteReportView.swift @@ -11,19 +11,21 @@ import SwiftUI struct ParaVoteReportView: View { @EnvironmentObject private var router: Router + @AppStorage(AppStorageKey.networks) private var networks: [Network]? = nil @StateObject private var viewModel = ParaVoteReportViewModel() @State private var displayState: BasicViewDisplayState = .notAppeared - private let network: Network + private let networkId: UInt64 private let accountId: AccountId private let identityDisplay: String + private var network = PreviewData.kusama init( - network: Network, + networkId: UInt64, accountId: AccountId, identityDisplay: String ) { - self.network = network + self.networkId = networkId self.accountId = accountId self.identityDisplay = identityDisplay } @@ -116,7 +118,7 @@ struct ParaVoteReportView: View { Text(String( format: localized("reports.paravalidation_votes.report_count_single"), self.network.display, - ParaVoteReportViewModel.fetchReportCount + self.viewModel.fetchReportCount )) .font(UI.Font.Common.listDescription) .foregroundColor(Color("Text")) @@ -131,7 +133,7 @@ struct ParaVoteReportView: View { format: localized("reports.paravalidation_votes.report_count_plural"), self.viewModel.data.count, self.network.display, - ParaVoteReportViewModel.fetchReportCount + self.viewModel.fetchReportCount )) .font(UI.Font.Common.listDescription) .foregroundColor(Color("Text")) @@ -154,7 +156,7 @@ struct ParaVoteReportView: View { } else { Text(String( format: localized("reports.paravalidation_votes.no_report_found"), - ParaVoteReportViewModel.fetchReportCount + self.viewModel.fetchReportCount )) .font(UI.Font.Common.listDescription) .foregroundColor(Color("Text")) @@ -215,10 +217,13 @@ struct ParaVoteReportView: View { ) .onAppear() { if self.displayState != .appeared { - self.viewModel.initialize( - network: self.network, - accountId: self.accountId - ) + if let networks = self.networks { + self.viewModel.initialize( + networks: networks, + networkId: self.networkId, + accountId: self.accountId + ) + } DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { self.displayState = .appeared DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { @@ -358,7 +363,7 @@ struct ParaVoteReportView: View { struct ParaVoteReportView_Previews: PreviewProvider { static var previews: some View { ParaVoteReportView( - network: PreviewData.kusama, + networkId: PreviewData.kusama.id, accountId: PreviewData.validatorSummary.accountId, identityDisplay: PreviewData.validatorSummary.identityDisplay ) diff --git a/SubVT/Classes/UI/View/Reports/ParaVoteReportViewModel.swift b/SubVT/Classes/UI/View/Reports/ParaVoteReportViewModel.swift index 60a9c63..82933cc 100644 --- a/SubVT/Classes/UI/View/Reports/ParaVoteReportViewModel.swift +++ b/SubVT/Classes/UI/View/Reports/ParaVoteReportViewModel.swift @@ -12,21 +12,24 @@ import SubVTData class ParaVoteReportViewModel: ObservableObject { @Published private(set) var fetchState: DataFetchState = .idle @Published private(set) var data: [(String, ParaVotesSummary)] = [] + @Published private(set) var network: Network = PreviewData.kusama private var accountId: AccountId! = nil - private var network: Network! = nil private var reportService: ReportService! = nil - static let fetchReportCount: UInt32 = 30 - private var cancellables = Set() func initialize( - network: Network, + networks: [Network], + networkId: UInt64, accountId: AccountId ) { + if let network = networks.first(where: { + $0.id == networkId + }) { + self.network = network + } self.accountId = accountId - self.network = network self.reportService = SubVTData.ReportService( host: self.network.reportServiceHost!, port: self.network.reportServicePort! @@ -37,6 +40,14 @@ class ParaVoteReportViewModel: ObservableObject { return self.data.count } + var fetchReportCount: UInt32 { + if self.network.tokenTicker == "KSM" { + return 30 + } else { + return 15 + } + } + /* var xAxisScale: ClosedRange { if let first = self.data.first, @@ -81,7 +92,7 @@ class ParaVoteReportViewModel: ObservableObject { self.fetchState = .loading self.reportService.getSessionValidatorReport( validatorAccountId: self.accountId, - startSessionIndex: currentSession.index - ParaVoteReportViewModel.fetchReportCount + 1, + startSessionIndex: currentSession.index - self.fetchReportCount + 1, endSessionIndex: currentSession.index ) .sink { diff --git a/SubVT/Classes/UI/View/Validator Details/ValidatorDetailsView.swift b/SubVT/Classes/UI/View/Validator Details/ValidatorDetailsView.swift index 0fe4000..040a660 100644 --- a/SubVT/Classes/UI/View/Validator Details/ValidatorDetailsView.swift +++ b/SubVT/Classes/UI/View/Validator Details/ValidatorDetailsView.swift @@ -312,7 +312,7 @@ struct ValidatorDetailsView: View { NavigationLink( value: Screen.paraVoteReport( - network: self.viewModel.network, + networkId: self.viewModel.network.id, accountId: self.accountId, identityDisplay: self.viewModel.validatorDetails?.identityDisplay ?? "" )