From 4a279a93cb3786e37bf08a16664f82d5b580f2d9 Mon Sep 17 00:00:00 2001 From: Vladyslav shepitko Date: Fri, 21 May 2021 14:42:32 +0300 Subject: [PATCH] Move oneinchs execution to background queue #2787 --- AlphaWallet/Core/SwapToken/Oneinch/Oneinch.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/AlphaWallet/Core/SwapToken/Oneinch/Oneinch.swift b/AlphaWallet/Core/SwapToken/Oneinch/Oneinch.swift index 18f9b8e5f..ca93e90b2 100644 --- a/AlphaWallet/Core/SwapToken/Oneinch/Oneinch.swift +++ b/AlphaWallet/Core/SwapToken/Oneinch/Oneinch.swift @@ -30,6 +30,7 @@ class Oneinch: TokenActionsProvider, SwapTokenURLProviderType { ] //NOTE: we use dictionary to improve search tokens private var availableTokens: [AlphaWallet.Address: Oneinch.ERC20Token] = [:] + private let queue = DispatchQueue(label: "com.Oneinch.updateQueue") func url(token: TokenObject) -> URL? { var components = URLComponents() @@ -69,19 +70,19 @@ class Oneinch: TokenActionsProvider, SwapTokenURLProviderType { let config = Config() let provider = AlphaWalletProviderFactory.makeProvider() - provider.request(.oneInchTokens(config: config)).map { response -> [String: Oneinch.ERC20Token] in + provider.request(.oneInchTokens(config: config), callbackQueue: queue).map(on: queue, { response -> [String: Oneinch.ERC20Token] in try JSONDecoder().decode(ApiResponsePayload.self, from: response.data).tokens - }.map { data -> [Oneinch.ERC20Token] in + }).map(on: queue, { data -> [Oneinch.ERC20Token] in data.map { $0.value } - }.done { response in + }).done(on: queue, { response in for token in self.predefinedTokens + response { self.availableTokens[token.address] = token } - }.catch { error in + }).catch(on: queue, { error in let service = AlphaWalletService.oneInchTokens(config: config) let url = service.baseURL.appendingPathComponent(service.path) RemoteLogger.instance.logRpcOrOtherWebError("Oneinch error | \(error)", url: url.absoluteString) - } + }) } private func defaultOutputAddress(forInput input: AlphaWallet.Address) -> AlphaWallet.Address {