Skip to content

Commit

Permalink
Update badges when icloud not available.
Browse files Browse the repository at this point in the history
- Add warning text in contact settings when not available
- Fix coin technical analytics UI
  • Loading branch information
ant013 committed Jul 19, 2023
1 parent f34df2b commit f0b0ff8
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 104 deletions.
6 changes: 6 additions & 0 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,7 @@
ABC9AAA26F0215D41AE50C57 /* SwapInputCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A90E8831B7B909124AB2 /* SwapInputCell.swift */; };
ABC9AAB720B0187F782E18AB /* WalletConnectV2SocketConnectionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A0483AEAEB88DFBDD873 /* WalletConnectV2SocketConnectionService.swift */; };
ABC9AAB941B036B4CA08334B /* WalletConnectV2PairingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9AFD222C4514B22C3E43F /* WalletConnectV2PairingViewModel.swift */; };
ABC9AADE6C4251FCC9222125 /* ManageBarButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A6CFDF38D413679D2088 /* ManageBarButtonView.swift */; };
ABC9AAEE109F50E3500DD6D4 /* SendBitcoinFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A3DC5DA5B7BFDBF72B5D /* SendBitcoinFactory.swift */; };
ABC9AAEF5D444F5BCB9D0CE2 /* UniswapV3ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A1C2F1CC07FD4CDFC591 /* UniswapV3ViewModel.swift */; };
ABC9AB0F8FE5808DB889C081 /* WalletConnectScanQrViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A3DBB89D0AE0C127742B /* WalletConnectScanQrViewModel.swift */; };
Expand Down Expand Up @@ -2183,6 +2184,7 @@
ABC9AD12C685D7260D65F914 /* SimpleActivateModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9AF9AABCDDAE5E7D0244C /* SimpleActivateModule.swift */; };
ABC9AD1C8D0CE88A604D5250 /* SendBinanceFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9AD0DD32AB4B9BAB79F11 /* SendBinanceFactory.swift */; };
ABC9AD27E074CF3FA292C647 /* IndicatorAdviceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A044BFF4E76CD17835CA /* IndicatorAdviceView.swift */; };
ABC9AD3001AAA0570B503876 /* ManageBarButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A6CFDF38D413679D2088 /* ManageBarButtonView.swift */; };
ABC9AD3276132B33F6045AFF /* MarketCategoryMarketCapFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9ADC1A3B17225B6CC0869 /* MarketCategoryMarketCapFetcher.swift */; };
ABC9AD41E7C88963F6512905 /* ChartIndicatorsRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A3758FE2D56036DF27FF /* ChartIndicatorsRepository.swift */; };
ABC9AD49CCD14F97CD912454 /* SendBitcoinAdapterService.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A1BD3B1B53C72DDF923A /* SendBitcoinAdapterService.swift */; };
Expand Down Expand Up @@ -3649,6 +3651,7 @@
ABC9A6663522498A53CF4174 /* KdfParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KdfParams.swift; sourceTree = "<group>"; };
ABC9A696DCBBE4761E77311C /* SendBitcoinService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendBitcoinService.swift; sourceTree = "<group>"; };
ABC9A6B2EF46FF7EDA4728D3 /* CheckboxView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxView.swift; sourceTree = "<group>"; };
ABC9A6CFDF38D413679D2088 /* ManageBarButtonView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManageBarButtonView.swift; sourceTree = "<group>"; };
ABC9A6CFF0208D48FE778028 /* WalletConnectV1MainRequestViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletConnectV1MainRequestViewModel.swift; sourceTree = "<group>"; };
ABC9A6D56EBB7FFAD68CFD66 /* IntegerAmountInputViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntegerAmountInputViewModel.swift; sourceTree = "<group>"; };
ABC9A6DE5C760A5D0C90B70E /* ChartIndicatorFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartIndicatorFactory.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6729,6 +6732,7 @@
ABC9AC4A19838CA08603E17B /* ContactBookService.swift */,
ABC9A3C708CD81CFE4C5BC5C /* ContactBookViewModel.swift */,
ABC9A5518367F0DDDB94D320 /* ContactBookModule.swift */,
ABC9A6CFDF38D413679D2088 /* ManageBarButtonView.swift */,
);
path = ContactBookList;
sourceTree = "<group>";
Expand Down Expand Up @@ -8929,6 +8933,7 @@
ABC9A0EE5E5B31405569BF3F /* IndicatorAdviceCell.swift in Sources */,
ABC9AD27E074CF3FA292C647 /* IndicatorAdviceView.swift in Sources */,
ABC9A305CBB28F2B19EB00D2 /* CoinDetailAdviceViewController.swift in Sources */,
ABC9AADE6C4251FCC9222125 /* ManageBarButtonView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -10183,6 +10188,7 @@
ABC9A74F192AB94CFD1D1649 /* IndicatorAdviceCell.swift in Sources */,
ABC9AFE47A405844612EB01A /* IndicatorAdviceView.swift in Sources */,
ABC9A0866C672D2D560DA23C /* CoinDetailAdviceViewController.swift in Sources */,
ABC9AD3001AAA0570B503876 /* ManageBarButtonView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion UnstoppableWallet/UnstoppableWallet/Core/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class App {
let cexAssetManager: CexAssetManager

let appManager: AppManager
let contactManager: ContactBookManager?
let contactManager: ContactBookManager
let cloudAccountBackupManager: CloudAccountBackupManager

init() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ContactBookManager {

private let fileStorage = FileDataStorage()

let localUrl: URL
let localUrl: URL?
var iCloudUrl: URL? {
FileManager
.default
Expand All @@ -68,17 +68,13 @@ class ContactBookManager {
}
}

init?(localStorage: LocalStorage, ubiquityContainerIdentifier: String?, helper: ContactBookHelper, logger: Logger? = nil) {
guard let localUrl = ContactBookManager.localUrl else {
return nil
}

init(localStorage: LocalStorage, ubiquityContainerIdentifier: String?, helper: ContactBookHelper, logger: Logger? = nil) {
self.ubiquityContainerIdentifier = ubiquityContainerIdentifier

logger?.debug("=C-MANAGER> INIT")
self.localStorage = localStorage
self.helper = helper
self.localUrl = localUrl
localUrl = ContactBookManager.localUrl
self.logger = logger

logger?.debug("=C-MANAGER> Want to Sync LocalFile")
Expand All @@ -90,6 +86,10 @@ class ContactBookManager {
// ================================ LOCAL ==================================================== //
func syncLocalFile() {
state = .loading
guard let localUrl else {
state = .failed(ContactBookManager.StorageError.localUrlNotAvailable)
return
}

logger?.debug("=C-MANAGER> SYNC")
fileStorage
Expand Down Expand Up @@ -118,6 +118,11 @@ class ContactBookManager {
syncRemoteStorage()
}
} catch {
guard let localUrl else {
state = .failed(ContactBookManager.StorageError.localUrlNotAvailable)
return
}

// if file can't be parsed we need delete it and show empty book
fileStorage
.deleteFile(url: localUrl)
Expand Down Expand Up @@ -184,6 +189,11 @@ class ContactBookManager {
}

private func sync(iCloudData: Data, localBook: ContactBook) {
guard let localUrl else {
state = .failed(ContactBookManager.StorageError.localUrlNotAvailable)
return
}

do {
// if there no local book yet, just get empty. When it's come from local - resync change localfile
logger?.debug("=C-MANAGER> LOCAL BOOK : \(localBook.contacts.count)")
Expand Down Expand Up @@ -364,6 +374,11 @@ extension ContactBookManager {
}

func update(contact: Contact) throws {
guard let localUrl else {
state = .failed(ContactBookManager.StorageError.localUrlNotAvailable)
return
}

guard let contactBook = state.data else {
throw StorageError.notReady
}
Expand All @@ -378,6 +393,11 @@ extension ContactBookManager {
}

func delete(_ contactUid: String) throws {
guard let localUrl else {
state = .failed(ContactBookManager.StorageError.localUrlNotAvailable)
return
}

guard let contactBook = state.data else {
throw StorageError.notReady
}
Expand Down Expand Up @@ -405,6 +425,11 @@ extension ContactBookManager {
}

func restore(contacts:[BackupContact]) throws {
guard let localUrl else {
state = .failed(ContactBookManager.StorageError.localUrlNotAvailable)
return
}

let newContactBook = helper.contactBook(contacts: contacts, lastVersion: state.data?.version)

try save(url: localUrl, newContactBook)
Expand All @@ -423,6 +448,7 @@ extension ContactBookManager {

enum StorageError: Error {
case cloudUrlNotAvailable
case localUrlNotAvailable
case notReady
case cantParseData
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extension CoinDetailAdviceViewController: SectionsDataSource {
}

func buildSections() -> [SectionProtocol] {
[Section(id: "mergin-section", headerState: .margin(height: .margin12))] +
viewItems.map { section in
Section(
id: "header-\(section.name)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TechnicalIndicatorService {
tasks.forEach { task in task.cancel() }
tasks = Set()

state = .loading
Task { [weak self, marketKit, coinUid, currency, period] in
do {
let points = try await marketKit.chartPoints(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ import MarketKit
class ContactBookAddressModule {

static func viewController(contactUid: String?, existAddresses: [ContactAddress], currentAddress: ContactAddress? = nil, onSaveAddress: @escaping (ContactAddress?) -> ()) -> UIViewController? {
guard let contactManager = App.shared.contactManager else {
return nil
}

let service: ContactBookAddressService
let addressService: AddressService
if let currentAddress {
guard let blockchain = try? App.shared.marketKit.blockchain(uid: currentAddress.blockchainUid) else {
return nil
}
addressService = AddressService(mode: .blockchainType, marketKit: App.shared.marketKit, contactBookManager: nil, blockchainType: blockchain.type)
service = ContactBookAddressService(marketKit: App.shared.marketKit, addressService: addressService, contactBookManager: contactManager, currentContactUid: contactUid, mode: .edit(currentAddress), blockchain: blockchain)
service = ContactBookAddressService(marketKit: App.shared.marketKit, addressService: addressService, contactBookManager: App.shared.contactManager, currentContactUid: contactUid, mode: .edit(currentAddress), blockchain: blockchain)
} else {
let blockchainUids = BlockchainType
.supported
Expand All @@ -32,7 +28,7 @@ class ContactBookAddressModule {
return nil
}
addressService = AddressService(mode: .blockchainType, marketKit: App.shared.marketKit, contactBookManager: nil, blockchainType: firstBlockchain.type)
service = ContactBookAddressService(marketKit: App.shared.marketKit, addressService: addressService, contactBookManager: contactManager, currentContactUid: contactUid, mode: .create(existAddresses), blockchain: firstBlockchain)
service = ContactBookAddressService(marketKit: App.shared.marketKit, addressService: addressService, contactBookManager: App.shared.contactManager, currentContactUid: contactUid, mode: .create(existAddresses), blockchain: firstBlockchain)
}

let viewModel = ContactBookAddressViewModel(service: service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@ import ThemeKit
class ContactBookContactModule {

static func viewController(mode: Mode, onUpdateContact: (() -> ())? = nil) -> UIViewController? {
guard let contactManager = App.shared.contactManager else {
return nil
}

let service: ContactBookContactService

switch mode {
case .new:
service = ContactBookContactService(
contactManager: contactManager,
contactManager: App.shared.contactManager,
marketKit: App.shared.marketKit,
contact: nil
)
case .exist(let uid, let newAddresses):
service = ContactBookContactService(
contactManager: contactManager,
contactManager: App.shared.contactManager,
marketKit: App.shared.marketKit,
contact: contactManager.all?.first(where: { $0.uid == uid }),
contact: App.shared.contactManager.all?.first(where: { $0.uid == uid }),
newAddresses: newAddresses
)
case let .add(address):
service = ContactBookContactService(
contactManager: contactManager,
contactManager: App.shared.contactManager,
marketKit: App.shared.marketKit,
contact: nil,
newAddresses: [address]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ struct ContactBookModule {
extension ContactBookModule {

static func viewController(mode: Mode, presented: Bool = false) -> UIViewController? {
guard let contactManager = App.shared.contactManager else {
return nil
}

let service = ContactBookService(marketKit: App.shared.marketKit, contactManager: contactManager, blockchainType: mode.blockchainType)
let service = ContactBookService(marketKit: App.shared.marketKit, contactManager: App.shared.contactManager, blockchainType: mode.blockchainType)
let viewModel = ContactBookViewModel(service: service)

let viewController = ContactBookViewController(viewModel: viewModel, mode: mode, presented: presented)
Expand All @@ -66,12 +62,8 @@ extension ContactBookModule {
}

static func showAddition(contactAddress: ContactAddress, parentViewController: UIViewController?) {
guard let contactManager = App.shared.contactManager else {
return
}

// if all contacts has address for blockchain just show add-new controller
if contactManager.all?.isEmpty ?? true {
if App.shared.contactManager.all?.isEmpty ?? true {
showAddContact(mode: .new, contactAddress: contactAddress, parentViewController: parentViewController)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ContactBookService {
}
}

private let iCloudAvailableErrorRelay = BehaviorRelay<Bool>(value: false)

var emptyBook: Bool {
_contacts.isEmpty
}
Expand Down Expand Up @@ -58,6 +60,14 @@ class ContactBookService {
self.blockchainType = blockchainType

subscribe(disposeBag, contactManager.stateObservable) { [weak self] _ in self?.sync() }
subscribe(disposeBag, contactManager.iCloudErrorObservable) { [weak self] error in
if error != nil, (self?.contactManager.remoteSync ?? false) {
self?.iCloudAvailableErrorRelay.accept(true)
} else {
self?.iCloudAvailableErrorRelay.accept(false)
}
}

sync()
}

Expand All @@ -78,6 +88,10 @@ extension ContactBookService {
itemsRelay.asObservable()
}

var iCloudAvailableErrorObservable: Observable<Bool> {
iCloudAvailableErrorRelay.asObservable()
}

func set(filter: String) {
self.filter = filter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ContactBookViewController: ThemeSearchViewController {

private let disposeBag = DisposeBag()
private let tableView = SectionsTableView(style: .grouped)
private let manageBarButtonView = ManageBarButtonView()
private let notFoundPlaceholder = PlaceholderView()

private var viewItems: [ContactBookViewModel.ViewItem] = []
Expand Down Expand Up @@ -43,7 +44,10 @@ class ContactBookViewController: ThemeSearchViewController {
let addContact = UIBarButtonItem(image: UIImage(named: "user_plus_24"), style: .plain, target: self, action: #selector(onCreateContact))
addContact.tintColor = .themeJacob

let settingsItem = UIBarButtonItem(image: UIImage(named: "manage_2_24"), style: .plain, target: self, action: #selector(onTapSettings))
let settingsItem = UIBarButtonItem(customView: manageBarButtonView)
manageBarButtonView.onTap = { [weak self] in
self?.onTapSettings()
}
settingsItem.tintColor = .themeJacob

navigationItem.rightBarButtonItems = [settingsItem, addContact]
Expand Down Expand Up @@ -87,6 +91,7 @@ class ContactBookViewController: ThemeSearchViewController {

subscribe(disposeBag, viewModel.viewItemsDriver) { [weak self] in self?.onUpdate(viewItems: $0) }
subscribe(disposeBag, viewModel.emptyListDriver) { [weak self] in self?.set(emptyList: $0) }
subscribe(disposeBag, viewModel.showBadgeDriver) { [weak self] in self?.manageBarButtonView.isBadgeHidden = !$0 }

tableView.buildSections()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ extension ContactBookViewModel {
viewItemsRelay.asDriver()
}

var showBadgeDriver: Driver<Bool> {
service.iCloudAvailableErrorObservable.asDriver(onErrorJustReturn: true)
}

var emptyListDriver: Driver<ViewItemListType?> {
emptyListRelay.asDriver()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import UIKit
import ThemeKit
import SnapKit
import ComponentKit

class ManageBarButtonView: UIView {
private let button = UIButton()
private let badgeView = UIView()

var onTap: (() -> ())?

init() {
super.init(frame: .zero)

addSubview(badgeView)
badgeView.snp.makeConstraints { maker in
maker.trailing.top.equalToSuperview().inset(-CGFloat.margin4)
maker.size.equalTo(CGFloat.margin8)
}

badgeView.backgroundColor = .themeLucian
badgeView.cornerRadius = .cornerRadius4
badgeView.isHidden = true

addSubview(button)
button.snp.makeConstraints { maker in
maker.edges.equalToSuperview()
}
button.setImage(UIImage(named: "manage_2_24")?.withTintColor(.themeJacob), for: .normal)
button.addTarget(self, action: #selector(onTapButton), for: .touchUpInside)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc private func onTapButton() {
onTap?()
}

}

extension ManageBarButtonView {

var isBadgeHidden: Bool {
get {
badgeView.isHidden
}
set {
badgeView.isHidden = newValue
}
}

}
Loading

0 comments on commit f0b0ff8

Please sign in to comment.