Skip to content

Commit

Permalink
Apply new filter module for Transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Nov 15, 2023
1 parent 3cb340f commit a17d5fc
Show file tree
Hide file tree
Showing 32 changed files with 644 additions and 957 deletions.
132 changes: 56 additions & 76 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions UnstoppableWallet/UnstoppableWallet/Core/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ class App {
let balanceHiddenManager: BalanceHiddenManager
let balanceConversionManager: BalanceConversionManager

let scamFilterManager: ScamFilterManager

let appIconManager = AppIconManager()

let subscriptionManager: SubscriptionManager
Expand Down Expand Up @@ -306,8 +304,6 @@ class App {
balanceHiddenManager = BalanceHiddenManager(userDefaultsStorage: userDefaultsStorage)
balanceConversionManager = BalanceConversionManager(marketKit: marketKit, userDefaultsStorage: userDefaultsStorage)

scamFilterManager = ScamFilterManager(userDefaultsStorage: userDefaultsStorage)

contactManager = ContactBookManager(localStorage: localStorage, ubiquityContainerIdentifier: AppConfig.privateCloudContainer, helper: ContactBookHelper(), logger: logger)

subscriptionManager = SubscriptionManager(userDefaultsStorage: userDefaultsStorage, marketKit: marketKit)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ class BaseTransactionsService {
private let rateService: HistoricalRateService
private let nftMetadataService: NftMetadataService
private let balanceHiddenManager: BalanceHiddenManager
private let scamFilterManager: ScamFilterManager
private let poolGroupFactory = PoolGroupFactory()

private var cancellables = Set<AnyCancellable>()

let disposeBag = DisposeBag()
private let disposeBag = DisposeBag()
private var poolGroupDisposeBag = DisposeBag()

private var poolGroup = PoolGroup(pools: [])
Expand All @@ -40,8 +39,6 @@ class BaseTransactionsService {
}
}

private let canResetRelay = PublishRelay<Bool>()

private var lastRequestedCount = BaseTransactionsService.pageLimit
private var loading = false {
didSet {
Expand All @@ -60,29 +57,26 @@ class BaseTransactionsService {

let queue = DispatchQueue(label: "\(AppConfig.label).base-transactions-service")

init(rateService: HistoricalRateService, nftMetadataService: NftMetadataService, balanceHiddenManager: BalanceHiddenManager, scamFilterManager: ScamFilterManager) {
init(rateService: HistoricalRateService, nftMetadataService: NftMetadataService, balanceHiddenManager: BalanceHiddenManager) {
self.rateService = rateService
self.nftMetadataService = nftMetadataService
self.balanceHiddenManager = balanceHiddenManager
self.scamFilterManager = scamFilterManager

subscribe(disposeBag, rateService.ratesChangedObservable) { [weak self] in self?.handleRatesChanged() }
subscribe(disposeBag, rateService.rateUpdatedObservable) { [weak self] in self?.handle(rate: $0) }
subscribe(disposeBag, nftMetadataService.assetsBriefMetadataObservable) { [weak self] in self?.handle(assetsBriefMetadata: $0) }

scamFilterManager.$scamFilterEnabled.sink { [weak self] _ in self?.handleScamFilterEnabledChanged() }.store(in: &cancellables)
}

var _canReset: Bool {
typeFilter != .all
}

var _poolGroupType: PoolGroupFactory.PoolGroupType {
fatalError("Should be overridden in child service")
}

var scamFilterEnabled: Bool {
true
}

func _syncPoolGroup() {
poolGroup = poolGroupFactory.poolGroup(type: _poolGroupType, filter: typeFilter, scamFilterEnabled: scamFilterManager.scamFilterEnabled)
poolGroup = poolGroupFactory.poolGroup(type: _poolGroupType, filter: typeFilter, scamFilterEnabled: scamFilterEnabled)
_initPoolGroup()
}

Expand Down Expand Up @@ -266,10 +260,6 @@ class BaseTransactionsService {
itemDataRelay.accept(itemData)
}

func _syncCanReset() {
canResetRelay.accept(_canReset)
}

private func _syncSyncing() {
syncing = loading || poolGroupSyncing
}
Expand All @@ -293,16 +283,6 @@ class BaseTransactionsService {
}
}
}

func _resetFilters() {
typeFilter = .all
}

private func handleScamFilterEnabledChanged() {
queue.async {
self._syncPoolGroup()
}
}
}

extension BaseTransactionsService {
Expand All @@ -322,10 +302,6 @@ extension BaseTransactionsService {
syncingRelay.asObservable()
}

var canResetObservable: Observable<Bool> {
canResetRelay.asObservable()
}

var balanceHiddenObservable: Observable<Bool> {
balanceHiddenManager.balanceHiddenObservable
}
Expand All @@ -338,12 +314,6 @@ extension BaseTransactionsService {
ItemData(items: items, allLoaded: lastRequestedCount > items.count)
}

var canReset: Bool {
queue.sync {
_canReset
}
}

func set(typeFilter: TransactionTypeFilter) {
queue.async {
guard self.typeFilter != typeFilter else {
Expand All @@ -352,27 +322,11 @@ extension BaseTransactionsService {

self.typeFilter = typeFilter

self._syncCanReset()

// print("SYNC POOL GROUP: set type filter")
self._syncPoolGroup()
}
}

func reset() {
queue.async {
guard self._canReset else {
return
}

self._resetFilters()
self._syncCanReset()

// print("SYNC POOL GROUP: reset")
self._syncPoolGroup()
}
}

func record(uid: String) -> TransactionRecord? {
queue.sync {
items.first(where: { $0.record.uid == uid })?.record
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ComponentKit
import Foundation
import RxSwift
import RxCocoa
import MarketKit
import ComponentKit
import RxCocoa
import RxSwift

class BaseTransactionsViewModel {
private let service: BaseTransactionsService
Expand All @@ -14,7 +14,6 @@ class BaseTransactionsViewModel {

private let viewDataRelay = BehaviorRelay<ViewData>(value: ViewData(sectionViewItems: [], allLoaded: true, updateInfo: nil))
private var syncingRelay = BehaviorRelay<Bool>(value: false)
private var resetEnabledRelay = BehaviorRelay<Bool>(value: false)

private var sectionViewItems = [SectionViewItem]()

Expand All @@ -29,23 +28,17 @@ class BaseTransactionsViewModel {
subscribe(disposeBag, service.itemDataObservable) { [weak self] in self?.sync(itemData: $0) }
subscribe(disposeBag, service.itemUpdatedObservable) { [weak self] in self?.syncUpdated(item: $0) }
subscribe(disposeBag, service.syncingObservable) { [weak self] in self?.sync(syncing: $0) }
subscribe(disposeBag, service.canResetObservable) { [weak self] in self?.sync(canReset: $0) }
subscribe(disposeBag, contactLabelService.stateObservable) { [weak self] _ in self?.reSyncViewItems() }
subscribe(disposeBag, service.balanceHiddenObservable) { [weak self] _ in self?.reSyncViewItems() }

_sync(itemData: service.itemData)
_sync(syncing: service.syncing)
sync(canReset: service.canReset)
}

private func reSyncViewItems() {
_sync(itemData: service.itemData)
}

private func sync(canReset: Bool) {
resetEnabledRelay.accept(canReset)
}

private func sync(typeFilter: TransactionTypeFilter) {
guard let index = TransactionTypeFilter.allCases.firstIndex(of: typeFilter) else {
return
Expand Down Expand Up @@ -137,11 +130,9 @@ class BaseTransactionsViewModel {
return DateHelper.instance.formatTransactionDate(from: date)
}
}

}

extension BaseTransactionsViewModel {

var typeFilterIndexDriver: Driver<Int> {
typeFilterIndexRelay.asDriver()
}
Expand All @@ -154,10 +145,6 @@ extension BaseTransactionsViewModel {
syncingRelay.asDriver()
}

var resetEnabledDriver: Driver<Bool> {
resetEnabledRelay.asDriver()
}

var typeFilterViewItems: [FilterView.ViewItem] {
factory.typeFilterViewItems(typeFilters: TransactionTypeFilter.allCases)
}
Expand All @@ -184,23 +171,17 @@ extension BaseTransactionsViewModel {

var itemIndex = index

for i in 0..<sectionIndex {
for i in 0 ..< sectionIndex {
itemIndex += self.sectionViewItems[i].viewItems.count
}

self.service.loadMoreIfRequired(index: itemIndex)
self.service.fetchRate(index: itemIndex)
}
}

func onTapReset() {
service.reset()
}

}

extension BaseTransactionsViewModel {

class SectionViewItem {
let title: String
var viewItems: [ViewItem]
Expand Down Expand Up @@ -261,5 +242,4 @@ extension BaseTransactionsViewModel {
let sectionIndex: Int
let index: Int
}

}

This file was deleted.

Loading

0 comments on commit a17d5fc

Please sign in to comment.