Skip to content

Commit

Permalink
Add completion to estimateGasLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
vikmeup committed Apr 30, 2018
1 parent 702b0fc commit f7894a9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Trust/Transfer/Controllers/TransactionConfigurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,23 @@ class TransactionConfigurator {

func load(completion: @escaping (Result<Void, AnyError>) -> Void) {
if requestEstimateGas {
estimateGasLimit()
estimateGasLimit { [weak self] result in
guard let `self` = self else { return }
switch result {
case .success(let gasLimit):
self.refreshGasLimit(gasLimit)
case .failure: break
}
}
}
loadNonce(completion: completion)
}

func estimateGasLimit() {
func estimateGasLimit(completion: @escaping (Result<BigInt, AnyError>) -> Void) {
let request = EstimateGasRequest(
transaction: signTransaction
)
Session.send(EtherServiceRequest(batch: BatchFactory().create(request))) { [weak self] result in
guard let `self` = self else { return }
Session.send(EtherServiceRequest(batch: BatchFactory().create(request))) { result in
switch result {
case .success(let gasLimit):
let gasLimit: BigInt = {
Expand All @@ -103,9 +109,9 @@ class TransactionConfigurator {
}
return limit + (limit * 20 / 100)
}()
self.refreshGasLimit(gasLimit)
completion(.success(gasLimit))
case .failure(let error):
NSLog("estimateGasLimit \(error)")
completion(.failure(AnyError(error)))
}
}
}
Expand Down

0 comments on commit f7894a9

Please sign in to comment.