Reuse amountToSend

pull/2/head
Michael Scoff 7 years ago
parent 07843bb664
commit d7ad3e53ab
  1. 9
      Trust/Transfer/Coordinators/SendTransactionCoordinator.swift

@ -122,10 +122,11 @@ class SendTransactionCoordinator {
return needsApproval ? 1 : 0 return needsApproval ? 1 : 0
}() }()
let amountToSend = (from.amount * pow(10, from.token.decimals).doubleValue).description
// approve amount // approve amount
if needsApproval { if needsApproval {
// ApproveERC20Encode // ApproveERC20Encode
let amountToSend = (from.amount * pow(10, from.token.decimals).doubleValue).description
let approveRequest = ApproveERC20Encode(address: exchangeConfig.contract, amount: amountToSend) let approveRequest = ApproveERC20Encode(address: exchangeConfig.contract, amount: amountToSend)
session.web3.request(request: approveRequest) { result in session.web3.request(request: approveRequest) { result in
switch result { switch result {
@ -137,13 +138,13 @@ class SendTransactionCoordinator {
configuration: configuration, configuration: configuration,
completion: completion completion: completion
) )
self.makeTrade(from: from, to: to, configuration: configuration, tradeNonce: tradeNonce, completion: completion) self.makeTrade(from: from, to: to, amountToSend: amountToSend, configuration: configuration, tradeNonce: tradeNonce, completion: completion)
case .failure(let error): case .failure(let error):
completion(.failure(AnyError(error))) completion(.failure(AnyError(error)))
} }
} }
} else { } else {
self.makeTrade(from: from, to: to, configuration: configuration, tradeNonce: tradeNonce, completion: completion) self.makeTrade(from: from, to: to, amountToSend: amountToSend, configuration: configuration, tradeNonce: tradeNonce, completion: completion)
} }
//Execute trade request //Execute trade request
@ -152,6 +153,7 @@ class SendTransactionCoordinator {
private func makeTrade( private func makeTrade(
from: SubmitExchangeToken, from: SubmitExchangeToken,
to: SubmitExchangeToken, to: SubmitExchangeToken,
amountToSend: String,
configuration: TransactionConfiguration, configuration: TransactionConfiguration,
tradeNonce: Int, tradeNonce: Int,
completion: @escaping (Result<SentTransaction, AnyError>) -> Void completion: @escaping (Result<SentTransaction, AnyError>) -> Void
@ -165,7 +167,6 @@ class SendTransactionCoordinator {
let dest = to.token.address let dest = to.token.address
let destAddress: Address = session.account.address let destAddress: Address = session.account.address
let amountToSend = (from.amount * pow(10, from.token.decimals).doubleValue).description
let request = ContractExchangeTrade( let request = ContractExchangeTrade(
source: source.address, source: source.address,
amount: amountToSend, amount: amountToSend,

Loading…
Cancel
Save