Remove TokenScript overriding properties like name. Speeds up time from app lunch to tokens visible

master
Hwee-Boon Yar 4 months ago
parent 0aebcd12a8
commit 1112e414ab
  1. 1
      AlphaWallet/Common/Services/Application.swift
  2. 2
      AlphaWallet/Tokens/Collectibles/ViewModels/NFTCollectionViewModel.swift
  3. 4
      AlphaWallet/Tokens/ViewModels/EthTokenViewCellViewModel.swift
  4. 2
      AlphaWallet/Tokens/ViewModels/FungibleTokenTabViewModel.swift
  5. 4
      AlphaWallet/Tokens/ViewModels/FungibleTokenViewCellViewModel.swift
  6. 2
      AlphaWallet/Tokens/ViewModels/NonFungibleTokenViewCellViewModel.swift
  7. 4
      AlphaWallet/Tokens/ViewModels/OpenSea/OpenSeaNonFungibleTokenViewCellViewModel.swift
  8. 2
      AlphaWallet/Tokens/ViewModels/WalletTokenViewCellViewModel.swift
  9. 3
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/TokensFilter.swift
  10. 24
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/TokensProcessingPipeline.swift

@ -298,6 +298,7 @@ class Application: WalletDependenciesProvidable {
var fetchers: [Wallet: WalletBalanceFetcherType] = [:]
for wallet in wallets {
//TODO faster if we only load one wallet. Avoid loading all wallets or reduce priority/frequency?
let dep = self.buildDependencies(for: wallet)
fetchers[wallet] = dep.fetcher
}

@ -95,7 +95,7 @@ final class NFTCollectionViewModel {
let actions = actions(for: tokenHolder)
let title = tokensService.tokenViewModelPublisher(for: token)
.compactMap { $0?.tokenScriptOverrides?.titleInPluralForm ?? "-" }
.compactMap { $0?.tokenScriptOverrides?.titleInPluralForm ?? $0?.name ?? "-" }
let viewState = Publishers.CombineLatest3(title, tokenHolders, actions)
.map { title, tokenHolders, actions in

@ -28,9 +28,9 @@ struct EthTokenViewCellViewModel: TokenIdentifiable {
accessoryType: UITableViewCell.AccessoryType = .none,
tokenImageFetcher: TokenImageFetcher) {
self.type = token.type
self.safeShortTitleInPluralForm = token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? ""
self.safeShortTitleInPluralForm = token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? token.name
self.amountShort = token.balance.amountShort
self.symbolInPluralForm = token.tokenScriptOverrides?.symbolInPluralForm ?? ""
self.symbolInPluralForm = token.tokenScriptOverrides?.symbolInPluralForm ?? token.symbol
self.ticker = token.balance.ticker
self.contractAddress = token.contractAddress
self.server = token.server

@ -53,7 +53,7 @@ class FungibleTokenTabViewModel {
let viewState = tokensPipeline
.tokenViewModelPublisher(for: token)
.map { $0?.tokenScriptOverrides?.titleInPluralForm }
.map { $0?.tokenScriptOverrides?.titleInPluralForm ?? $0?.name }
.map { FungibleTokenTabViewModel.ViewState(title: $0) }
.eraseToAnyPublisher()

@ -21,9 +21,9 @@ struct FungibleTokenViewCellViewModel: TokenIdentifiable {
init(token: TokenViewModel, isVisible: Bool = true, accessoryType: UITableViewCell.AccessoryType = .none, tokenImageFetcher: TokenImageFetcher) {
self.type = token.type
self.safeShortTitleInPluralForm = token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? ""
self.safeShortTitleInPluralForm = token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? token.name
self.amountShort = token.balance.amountShort
self.symbolInPluralForm = token.tokenScriptOverrides?.symbolInPluralForm ?? ""
self.symbolInPluralForm = token.tokenScriptOverrides?.symbolInPluralForm ?? token.symbol
self.ticker = token.balance.ticker
self.contractAddress = token.contractAddress
self.server = token.server

@ -30,7 +30,7 @@ struct NonFungibleTokenViewCellViewModel: TokenIdentifiable {
self.iconImage = tokenImageFetcher.image(token: token, size: .s750)
self.nonZeroBalanceCount = token.nonZeroBalance.count
self.symbol = token.symbol
self.safeShortTitleInPluralForm = token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? ""
self.safeShortTitleInPluralForm = token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? token.name
self.isVisible = isVisible
self.accessoryType = accessoryType
}

@ -17,7 +17,7 @@ struct OpenSeaNonFungibleTokenViewCellViewModel {
}
var titleAttributedString: NSAttributedString {
return .init(string: token.tokenScriptOverrides?.titleInPluralForm ?? "", attributes: [
return .init(string: token.tokenScriptOverrides?.titleInPluralForm ?? token.name, attributes: [
.font: Fonts.regular(size: 20),
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
])
@ -54,7 +54,7 @@ extension OpenSeaNonFungibleTokenViewCellViewModel: Hashable {
func hash(into hasher: inout Hasher) {
hasher.combine(token.contractAddress)
hasher.combine(token.server)
hasher.combine(token.tokenScriptOverrides?.titleInPluralForm)
hasher.combine(token.tokenScriptOverrides?.titleInPluralForm ?? token.name)
hasher.combine(token.nonZeroBalance)
}
}

@ -33,7 +33,7 @@ struct WalletTokenViewCellViewModel {
}
var titleAttributedString: NSAttributedString {
return NSAttributedString(string: token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? "", attributes: [
return NSAttributedString(string: token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? token.name, attributes: [
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
.font: Screen.TokenCard.Font.title,
])

@ -108,8 +108,7 @@ public class TokensFilter {
return token.name.trimmed.lowercased().contains(string) ||
token.symbol.trimmed.lowercased().contains(string) ||
token.contractAddress.eip55String.lowercased().contains(string) ||
(token.tokenScriptOverrides?.titleInPluralForm.trimmed.lowercased().contains(string) ?? false) ||
(token.tokenScriptOverrides?.title.trimmed.lowercased().contains(string) ?? false)
((token.tokenScriptOverrides?.titleInPluralForm ?? token.tokenScriptOverrides?.title ?? token.name).trimmed.lowercased().contains(string) ?? false)
}
switch filter {

@ -79,14 +79,12 @@ public final class WalletDataProcessingPipeline: TokensProcessingPipeline {
let whenCollectionHasChanged = Publishers.Merge5(whenTokensHasChanged, whenTickersChanged, whenSignatureOrBodyChanged, whenAttestationXMLChanged, whenCurrencyChanged)
.map { $0.map { TokenViewModel(token: $0) } }
.flatMapLatest { tokenViewModels in asFuture { await self.applyTickers(tokens: tokenViewModels) ?? [] } }
.flatMap { self.applyTokenScriptOverrides(tokens: $0) }
.receive(on: RunLoop.main)
.eraseToAnyPublisher()
let initialSnapshot: AnyPublisher<[TokenViewModel], Never> = asFuture { await self.tokensService.tokens }
.map { $0.map { TokenViewModel(token: $0) } }
.flatMap { [weak self] tokenViewModels in asFuture { await self?.applyTickers(tokens: tokenViewModels) ?? [] } }
.flatMap { self.applyTokenScriptOverrides(tokens: $0) }
.eraseToAnyPublisher()
return Publishers.Merge(whenCollectionHasChanged, initialSnapshot)
@ -138,7 +136,6 @@ public final class WalletDataProcessingPipeline: TokensProcessingPipeline {
public func tokenViewModel(for contract: AlphaWallet.Address, server: RPCServer) async -> TokenViewModel? {
if let token = await tokensService.token(for: contract, server: server) {
let viewModel = await applyTicker(token: TokenViewModel(token: token))
applyTokenScriptOverrides(token: viewModel)
return viewModel
} else {
return nil
@ -175,7 +172,6 @@ public final class WalletDataProcessingPipeline: TokensProcessingPipeline {
return Publishers.Merge4(wrapWithCurrentValueSubject(tokensService.tokenPublisher(for: contract, server: server), initialValue: nil), whenTickersHasChanged, whenSignatureOrBodyChanged, whenEventHasChanged)
.map { $0.flatMap { TokenViewModel(token: $0) } }
.flatMap { [weak self] tokenViewModels in asFuture { await self?.applyTicker(token: tokenViewModels) } }
.map { [weak self] in self?.applyTokenScriptOverrides(token: $0) }
.eraseToAnyPublisher()
}
@ -243,26 +239,6 @@ public final class WalletDataProcessingPipeline: TokensProcessingPipeline {
}.store(in: &cancelable)
}
private func applyTokenScriptOverrides(tokens: [TokenViewModel]) -> AnyPublisher<[TokenViewModel], Never> {
if Config().development.shouldDisableTokenScriptEffects {
return .just(tokens)
}
let overrides = tokens.map { token -> TokenViewModel in
guard let session = sessionsProvider.session(for: token.server) else { return token }
let overrides = session.tokenAdaptor.tokenScriptOverrides(token: token)
return token.override(tokenScriptOverrides: overrides)
}
return .just(overrides)
}
private func applyTokenScriptOverrides(token: TokenViewModel?) -> TokenViewModel? {
guard let token = token else { return token }
guard let session = sessionsProvider.session(for: token.server) else { return token }
let overrides = session.tokenAdaptor.tokenScriptOverrides(token: token)
return token.override(tokenScriptOverrides: overrides)
}
private func applyTickers(tokens: [TokenViewModel]) async -> [TokenViewModel] {
if Config().development.shouldDisableApplyingTickers {
return tokens

Loading…
Cancel
Save