Skip to content

Commit

Permalink
fix mark requested tab after purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
w-i-n-s committed Jun 4, 2021
1 parent 53156e8 commit 1cc14fb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions NthKey/View/Settings/AnnounceView/AnnounceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct AnnounceView: View {
return
}

model.selectMainnetAfterPurchase = true
activeSheet = .subscription
}

Expand Down
24 changes: 21 additions & 3 deletions NthKey/View/Settings/AnnounceView/AnnounceViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
// license, see the accompanying file LICENSE.md

import UIKit
import Combine

final class AnnounceViewModel: ObservableObject {
@Published var network: WalletNetwork = .testnet
@Published var showPubKeyQR = false

var hasSubscription: Bool {
subsManager.hasSubscription
}
var hasSubscription: Bool = false

var pubKeyImage: UIImage? {
QRCodeBuilder.generateQRCode(from: ourPubKey)
Expand All @@ -24,14 +23,33 @@ final class AnnounceViewModel: ObservableObject {
SeedManager.ourPubKey(network: network.networkValue)
}

var selectMainnetAfterPurchase = false

private let subsManager: SubscriptionManager
private var cancellables = Set<AnyCancellable>()
private let fileSaveController: SettingsViewController = SettingsViewController()

init(subsManager: SubscriptionManager) {
self.subsManager = subsManager

setupObservables()
}

func exportPublicKey() {
fileSaveController.exportPublicKey(data: ourPubKey)
}

private func setupObservables() {
subsManager
.$hasSubscription
.sink { [weak self] value in
guard let self = self else { return }
self.hasSubscription = value

guard self.selectMainnetAfterPurchase && value else { return }
self.selectMainnetAfterPurchase = false
self.network = .mainnet
}
.store(in: &cancellables)
}
}
1 change: 1 addition & 0 deletions NthKey/View/Settings/Import Wallet/ImportWalletView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct ImportWalletView: View {
return
}

model.selectMainnetAfterPurchase = true
activeSheet = .subscription
}

Expand Down
18 changes: 15 additions & 3 deletions NthKey/View/Settings/Import Wallet/ImportWalletViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ final class ImportWalletViewModel: ObservableObject {
@Published var selectedNetwork: WalletNetwork
@Published var loadWalletError: DataProcessingError?

var hasSubscription: Bool {
subsManager.hasSubscription
}
var hasSubscription: Bool = false
var selectMainnetAfterPurchase: Bool = false

private let loadFileController: SettingsViewController = SettingsViewController()
private let dataManager: DataManager
Expand All @@ -41,6 +40,19 @@ final class ImportWalletViewModel: ObservableObject {
.map{ $0 as WalletNetwork? }
.assign(to: \.currentNetwork, on: self.dataManager)
.store(in: &cancellables)

// TODO: DRY TBC here and in AnnounceViewModel
subsManager
.$hasSubscription
.sink { [weak self] value in
guard let self = self else { return }
self.hasSubscription = value

guard self.selectMainnetAfterPurchase && value else { return }
self.selectMainnetAfterPurchase = false
self.selectedNetwork = .mainnet
}
.store(in: &cancellables)
}

func addWalletByFile() {
Expand Down

0 comments on commit 1cc14fb

Please sign in to comment.