Add search terms for filter for tickers available, non-zero balance in Wallet tab. For development

pull/3442/head
Hwee-Boon Yar 3 years ago
parent 170b018b32
commit 26111264b5
  1. 34
      AlphaWallet/Core/Coordinators/FilterTokensCoordinator.swift
  2. 2
      AlphaWallet/InCoordinator.swift
  3. 4
      AlphaWalletTests/Coordinators/TokensCoordinatorTests.swift
  4. 8
      AlphaWalletTests/Settings/ConfigTests.swift

@ -10,14 +10,24 @@ import UIKit
class FilterTokensCoordinator {
private enum FilterKeys: String {
case swap
enum Development: String {
//Mainly for development/debugging
case fiat
case balance = "bal"
case fiatAndBalance = "fiat bal"
case balanceAndFiat = "bal fiat"
}
}
private let assetDefinitionStore: AssetDefinitionStore
private let tokenActionsService: TokenActionsServiceType
private let coinTickersFetcher: CoinTickersFetcherType
init(assetDefinitionStore: AssetDefinitionStore, tokenActionsService: TokenActionsServiceType) {
init(assetDefinitionStore: AssetDefinitionStore, tokenActionsService: TokenActionsServiceType, coinTickersFetcher: CoinTickersFetcherType) {
self.assetDefinitionStore = assetDefinitionStore
self.tokenActionsService = tokenActionsService
self.coinTickersFetcher = coinTickersFetcher
}
func filterTokens(tokens: [TokenObject], filter: WalletFilter) -> [TokenObject] {
@ -47,6 +57,12 @@ class FilterTokensCoordinator {
return $0.type == .erc875
} else if lowercasedKeyword == "erc1155" || lowercasedKeyword == "erc 1155" {
return $0.type == .erc1155
} else if lowercasedKeyword == FilterKeys.Development.balance.rawValue {
return $0.hasNonZeroBalance
} else if lowercasedKeyword == FilterKeys.Development.fiat.rawValue {
return $0.hasTicker(coinTickersFetcher: coinTickersFetcher)
} else if lowercasedKeyword == FilterKeys.Development.fiatAndBalance.rawValue || lowercasedKeyword == FilterKeys.Development.balanceAndFiat.rawValue {
return $0.hasNonZeroBalance && $0.hasTicker(coinTickersFetcher: coinTickersFetcher)
} else if lowercasedKeyword == "tokenscript" {
let xmlHandler = XMLHandler(token: $0, assetDefinitionStore: assetDefinitionStore)
return xmlHandler.hasNoBaseAssetDefinition && (xmlHandler.server?.matches(server: $0.server) ?? false)
@ -145,3 +161,19 @@ class FilterTokensCoordinator {
return result
}
}
fileprivate extension TokenObject {
var hasNonZeroBalance: Bool {
switch type {
case .nativeCryptocurrency, .erc20:
return !valueBigInt.isZero
case .erc875, .erc721, .erc721ForTickets, .erc1155:
return !nonZeroBalance.isEmpty
}
}
func hasTicker(coinTickersFetcher: CoinTickersFetcherType) -> Bool {
let ticker = coinTickersFetcher.ticker(for: addressAndRPCServer)
return ticker != nil
}
}

@ -90,7 +90,7 @@ class InCoordinator: NSObject, Coordinator {
}()
lazy var filterTokensCoordinator: FilterTokensCoordinator = {
return .init(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService)
return .init(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService, coinTickersFetcher: coinTickersFetcher)
}()
private lazy var activitiesService: ActivitiesServiceType = createActivitiesService()

@ -29,12 +29,12 @@ class TokensCoordinatorTests: XCTestCase {
sessions: sessions,
keystore: FakeKeystore(),
config: config,
tokenCollection: .init(filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService), tokenDataStores: []),
tokenCollection: .init(filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService, coinTickersFetcher: FakeCoinTickersFetcher()), tokenDataStores: []),
nativeCryptoCurrencyPrices: .init(),
assetDefinitionStore: AssetDefinitionStore(),
eventsDataStore: FakeEventsDataStore(),
promptBackupCoordinator: PromptBackupCoordinator(keystore: FakeKeystore(), wallet: .make(), config: config, analyticsCoordinator: FakeAnalyticsService()),
filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService),
filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService, coinTickersFetcher: FakeCoinTickersFetcher()),
analyticsCoordinator: FakeAnalyticsService(),
tokenActionsService: tokenActionsService,
walletConnectCoordinator: .fake(),

@ -34,10 +34,10 @@ class ConfigTests: XCTestCase {
let vc1 = TokensViewController(
sessions: sessions,
account: .make(),
tokenCollection: .init(filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService), tokenDataStores: [FakeTokensDataStore()]),
tokenCollection: .init(filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService, coinTickersFetcher: FakeCoinTickersFetcher()), tokenDataStores: [FakeTokensDataStore()]),
assetDefinitionStore: assetDefinitionStore,
eventsDataStore: FakeEventsDataStore(),
filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService),
filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService, coinTickersFetcher: FakeCoinTickersFetcher()),
config: .make(),
walletConnectCoordinator: .fake(),
walletBalanceCoordinator: FakeWalletBalanceCoordinator()
@ -50,10 +50,10 @@ class ConfigTests: XCTestCase {
let vc2 = TokensViewController(
sessions: sessions,
account: .make(),
tokenCollection: .init(filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService), tokenDataStores: [FakeTokensDataStore()]),
tokenCollection: .init(filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService, coinTickersFetcher: FakeCoinTickersFetcher()), tokenDataStores: [FakeTokensDataStore()]),
assetDefinitionStore: assetDefinitionStore,
eventsDataStore: FakeEventsDataStore(),
filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService),
filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService, coinTickersFetcher: FakeCoinTickersFetcher()),
config: .make(),
walletConnectCoordinator: .fake(),
walletBalanceCoordinator: FakeWalletBalanceCoordinator()

Loading…
Cancel
Save