Merge pull request #3940 from oa-s/#3939

Remove `CallbackQueueProvider` protocol, remove GetERC875BalanceCoordinator callback implementation #3939
pull/3937/head
Crypto Pank 3 years ago committed by GitHub
commit a6184dcc3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      AlphaWallet/Market/Coordinators/ImportMagicLinkCoordinator.swift
  2. 4
      AlphaWallet/Tokens/Coordinators/GetERC20BalanceCoordinator.swift
  3. 5
      AlphaWallet/Tokens/Coordinators/GetERC721BalanceCoordinator.swift
  4. 5
      AlphaWallet/Tokens/Coordinators/GetERC721ForTicketsBalanceCoordinator.swift
  5. 31
      AlphaWallet/Tokens/Coordinators/GetERC875BalanceCoordinator.swift
  6. 21
      AlphaWallet/Tokens/Coordinators/GetNativeCryptoCurrencyBalanceCoordinator.swift

@ -258,17 +258,8 @@ class ImportMagicLinkCoordinator: Coordinator {
private func handleNormalLinks(signedOrder: SignedOrder, recoverAddress: AlphaWallet.Address, contractAsAddress: AlphaWallet.Address) {
getERC875TokenBalanceCoordinator = GetERC875BalanceCoordinator(forServer: server)
getERC875TokenBalanceCoordinator?.getERC875TokenBalance(for: recoverAddress, contract: contractAsAddress) { [weak self] result in
getERC875TokenBalanceCoordinator?.getERC875TokenBalance(for: recoverAddress, contract: contractAsAddress).done({ [weak self] balance in
guard let strongSelf = self else { return }
guard let balance = try? result.dematerialize() else {
if let reachabilityManager = NetworkReachabilityManager(), !reachabilityManager.isReachable {
strongSelf.showImportError(errorMessage: R.string.localizable.aClaimTokenNoConnectivityTryAgain())
} else {
strongSelf.showImportError(errorMessage: R.string.localizable.aClaimTokenInvalidLinkTryAgain())
}
return
}
let filteredTokens: [String] = strongSelf.checkERC875TokensAreAvailable(
indices: signedOrder.order.indices,
balance: balance
@ -284,7 +275,13 @@ class ImportMagicLinkCoordinator: Coordinator {
)
strongSelf.completeOrderHandling(signedOrder: signedOrder)
}
}).catch({ [weak self] _ in
if let reachabilityManager = NetworkReachabilityManager(), !reachabilityManager.isReachable {
self?.showImportError(errorMessage: R.string.localizable.aClaimTokenNoConnectivityTryAgain())
} else {
self?.showImportError(errorMessage: R.string.localizable.aClaimTokenInvalidLinkTryAgain())
}
})
}
static func isOrderExpired(_ signedOrder: SignedOrder) -> Bool {

@ -6,9 +6,9 @@ import Result
import web3swift
import PromiseKit
class GetERC20BalanceCoordinator: CallbackQueueProvider {
class GetERC20BalanceCoordinator {
private let server: RPCServer
internal let queue: DispatchQueue?
private let queue: DispatchQueue?
init(forServer server: RPCServer, queue: DispatchQueue? = nil) {
self.server = server

@ -8,9 +8,8 @@ import BigInt
import PromiseKit
import Result
class GetERC721BalanceCoordinator: CallbackQueueProvider {
var queue: DispatchQueue?
class GetERC721BalanceCoordinator {
private let queue: DispatchQueue?
private let server: RPCServer
init(forServer server: RPCServer, queue: DispatchQueue? = nil) {

@ -5,9 +5,8 @@ import Result
import BigInt
import PromiseKit
class GetERC721ForTicketsBalanceCoordinator: CallbackQueueProvider {
var queue: DispatchQueue?
class GetERC721ForTicketsBalanceCoordinator {
private let queue: DispatchQueue?
private let server: RPCServer
init(forServer server: RPCServer, queue: DispatchQueue? = nil) {

@ -4,9 +4,8 @@ import Foundation
import Result
import PromiseKit
class GetERC875BalanceCoordinator: CallbackQueueProvider {
var queue: DispatchQueue?
class GetERC875BalanceCoordinator {
private let queue: DispatchQueue?
private let server: RPCServer
init(forServer server: RPCServer, queue: DispatchQueue? = nil) {
@ -15,33 +14,13 @@ class GetERC875BalanceCoordinator: CallbackQueueProvider {
}
func getERC875TokenBalance(for address: AlphaWallet.Address, contract: AlphaWallet.Address) -> Promise<[String]> {
return Promise { seal in
getERC875TokenBalance(for: address, contract: contract) { result in
switch result {
case .success(let values):
seal.fulfill(values)
case .failure(let error):
seal.reject(error)
}
}
}
}
func getERC875TokenBalance(
for address: AlphaWallet.Address,
contract: AlphaWallet.Address,
completion: @escaping (AWResult<[String], AnyError>) -> Void
) {
let function = GetERC875Balance()
callSmartContract(withServer: server, contract: contract, functionName: function.name, abiString: function.abi, parameters: [address.eip55String] as [AnyObject], timeout: TokensDataStore.fetchContractDataTimeout).done(on: queue, { balanceResult in
let balances = self.adapt(balanceResult["0"])
completion(.success(balances))
}).catch(on: queue, {
completion(.failure(AnyError($0)))
return callSmartContract(withServer: server, contract: contract, functionName: function.name, abiString: function.abi, parameters: [address.eip55String] as [AnyObject], timeout: TokensDataStore.fetchContractDataTimeout).map(on: queue, { balanceResult -> [String] in
return GetERC875BalanceCoordinator.adapt(balanceResult["0"])
})
}
private func adapt(_ values: Any?) -> [String] {
private static func adapt(_ values: Any?) -> [String] {
guard let array = values as? [Data] else { return [] }
return array.map { each in
let value = each.toHexString()

@ -8,22 +8,9 @@ import Result
import web3swift
import PromiseKit
protocol CallbackQueueProvider {
var queue: DispatchQueue? { get }
}
extension CallbackQueueProvider {
var callbackQueue: CallbackQueue? {
if let value = queue {
return .dispatchQueue(value)
}
return nil
}
}
class GetNativeCryptoCurrencyBalanceCoordinator: CallbackQueueProvider {
let server: RPCServer
internal let queue: DispatchQueue?
class GetNativeCryptoCurrencyBalanceCoordinator {
private let server: RPCServer
private let queue: DispatchQueue?
init(forServer server: RPCServer, queue: DispatchQueue? = nil) {
self.server = server
@ -32,6 +19,6 @@ class GetNativeCryptoCurrencyBalanceCoordinator: CallbackQueueProvider {
func getBalance(for address: AlphaWallet.Address) -> Promise<Balance> {
let request = EtherServiceRequest(server: server, batch: BatchFactory().create(BalanceRequest(address: address)))
return Session.send(request, callbackQueue: callbackQueue)
return Session.send(request, callbackQueue: queue.flatMap { .dispatchQueue($0) })
}
}

Loading…
Cancel
Save