Remove no longer necessary code which is slowing down app launch

pull/1644/head
Hwee-Boon Yar 5 years ago
parent 160dcc2895
commit 5eb1cd4244
  1. 7
      AlphaWallet/Tokens/Coordinators/SingleChainTokenCoordinator.swift
  2. 27
      AlphaWallet/Tokens/Types/TokensDataStore.swift

@ -65,7 +65,6 @@ class SingleChainTokenCoordinator: Coordinator {
DispatchQueue.main.async { [weak self] in
self?.autoDetectTransactedTokens()
self?.autoDetectPartnerTokens()
self?.refreshUponAssetDefinitionChanges()
}
}
}
@ -74,12 +73,6 @@ class SingleChainTokenCoordinator: Coordinator {
return session.server == server
}
private func refreshUponAssetDefinitionChanges() {
assetDefinitionStore.subscribe { [weak self] _ in
self?.storage.fetchTokenNamesForNonFungibleTokensIfEmpty()
}
}
///Implementation: We refresh once only, after all the auto detected tokens' data have been pulled because each refresh pulls every tokens' (including those that already exist before the this auto detection) price as well as balance, placing heavy and redundant load on the device. After a timeout, we refresh once just in case it took too long, so user at least gets the chance to see some auto detected tokens
private func autoDetectTransactedTokens() {
//TODO we don't auto detect tokens if we are running tests. Maybe better to move this into app delegate's application(_:didFinishLaunchingWithOptions:)

@ -160,13 +160,6 @@ class TokensDataStore {
//TODO not needed for setupCallForAssetAttributeCoordinators? Look for other callers of DataStore.updateDelegate
self.scheduledTimerForPricesUpdate()
self.scheduledTimerForEthBalanceUpdate()
//Since this is called at launch, we don't want it to block launching
DispatchQueue.global().async {
DispatchQueue.main.async { [weak self] in
self?.fetchTokenNamesForNonFungibleTokensIfEmpty()
}
}
}
private func addEthToken() {
@ -737,26 +730,6 @@ class TokensDataStore {
}, selector: #selector(Operation.main), userInfo: nil, repeats: true)
}
//This is related to Realm migration for version 49
func fetchTokenNamesForNonFungibleTokensIfEmpty() {
assetDefinitionStore.forEachContractWithXML { [weak self] contract in
guard let strongSelf = self else { return }
let localizedName = XMLHandler(contract: contract, assetDefinitionStore: assetDefinitionStore).getName(fallback: "")
guard !localizedName.isEmpty else { return }
if let storedToken = strongSelf.enabledObject.first(where: { contract.sameContract(as: $0.contractAddress) }), storedToken.name.isEmpty {
getContractName(for: contract) { result in
switch result {
case .success(let name):
//TODO multiple realm writes in a loop. Should we group them together?
strongSelf.updateTokenName(token: storedToken, to: name)
case .failure:
break
}
}
}
}
}
private func updateTokenName(token: TokenObject, to name: String) {
try! realm.write {
token.name = name

Loading…
Cancel
Save