Skip to content

Commit

Permalink
Paravalidation notification and report updates. Bump build number.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Jan 29, 2023
1 parent 0b68971 commit c5341a8
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 29 deletions.
4 changes: 2 additions & 2 deletions SubVT.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 14 additions & 6 deletions SubVT/Classes/App/SubVTApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions SubVT/Classes/UI/Navigation/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum Screen: Hashable {
chartTitle: String
)
case paraVoteReport(
network: Network,
networkId: UInt64,
accountId: AccountId,
identityDisplay: String
)
Expand Down Expand Up @@ -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
)
Expand Down
27 changes: 16 additions & 11 deletions SubVT/Classes/UI/View/Reports/ParaVoteReportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
)
Expand Down
23 changes: 17 additions & 6 deletions SubVT/Classes/UI/View/Reports/ParaVoteReportViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ import SubVTData
class ParaVoteReportViewModel: ObservableObject {
@Published private(set) var fetchState: DataFetchState<String> = .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<AnyCancellable>()

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!
Expand All @@ -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<Int> {
if let first = self.data.first,
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? ""
)
Expand Down

0 comments on commit c5341a8

Please sign in to comment.