Merge pull request #2788 from vladyslav-iosdev/#2787

Move oneinchs execution to background queue #2787
pull/2786/head
Hwee-Boon Yar 3 years ago committed by GitHub
commit 78d924e117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      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 {

Loading…
Cancel
Save