Add exchange call to trade

pull/2/head
Michael Scoff 7 years ago
parent 0576d57749
commit 16a79b5b69
  1. 8
      Trust.xcodeproj/project.pbxproj
  2. 8
      Trust/Exchange/Coordinators/ExchangeCoordinator.swift
  3. 21
      Trust/Exchange/Types/ExchangeConfig.swift
  4. 5
      Trust/Exchange/Types/ExchangeTokens.swift
  5. 20
      Trust/Transfer/Controllers/ConfirmPaymentViewController.swift
  6. 34
      Trust/Transfer/Coordinators/SendTransactionCoordinator.swift

@ -69,6 +69,8 @@
2931121D1FC65F2900966EEA /* ExchangeCurrencyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2931121C1FC65F2900966EEA /* ExchangeCurrencyView.swift */; };
293112201FC6619000966EEA /* ExchangeToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2931121F1FC6619000966EEA /* ExchangeToken.swift */; };
293112221FC67F1300966EEA /* ExchangeTokens.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293112211FC67F1300966EEA /* ExchangeTokens.swift */; };
293112261FC8154E00966EEA /* ContractExchangeTrade.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293112251FC8154E00966EEA /* ContractExchangeTrade.swift */; };
293112281FC8174B00966EEA /* ExchangeConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293112271FC8174B00966EEA /* ExchangeConfig.swift */; };
293204581F8DC6B20095B7C1 /* ExchangeRateCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293204571F8DC6B20095B7C1 /* ExchangeRateCoordinator.swift */; };
2932045C1F8DCD6E0095B7C1 /* CurrencyRate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2932045B1F8DCD6E0095B7C1 /* CurrencyRate.swift */; };
2932045E1F8EEE760095B7C1 /* BalanceCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2932045D1F8EEE760095B7C1 /* BalanceCoordinator.swift */; };
@ -330,6 +332,8 @@
2931121C1FC65F2900966EEA /* ExchangeCurrencyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeCurrencyView.swift; sourceTree = "<group>"; };
2931121F1FC6619000966EEA /* ExchangeToken.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeToken.swift; sourceTree = "<group>"; };
293112211FC67F1300966EEA /* ExchangeTokens.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeTokens.swift; sourceTree = "<group>"; };
293112251FC8154E00966EEA /* ContractExchangeTrade.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContractExchangeTrade.swift; sourceTree = "<group>"; };
293112271FC8174B00966EEA /* ExchangeConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeConfig.swift; sourceTree = "<group>"; };
293204571F8DC6B20095B7C1 /* ExchangeRateCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeRateCoordinator.swift; sourceTree = "<group>"; };
2932045B1F8DCD6E0095B7C1 /* CurrencyRate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyRate.swift; sourceTree = "<group>"; };
2932045D1F8EEE760095B7C1 /* BalanceCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BalanceCoordinator.swift; sourceTree = "<group>"; };
@ -701,6 +705,7 @@
children = (
291795001F95F5E200539A30 /* GetBalance.swift */,
2963B6BE1F9AB9A2003063C1 /* ContractERC20Transfer.swift */,
293112251FC8154E00966EEA /* ContractExchangeTrade.swift */,
);
path = Commands;
sourceTree = "<group>";
@ -865,6 +870,7 @@
children = (
2931121F1FC6619000966EEA /* ExchangeToken.swift */,
293112211FC67F1300966EEA /* ExchangeTokens.swift */,
293112271FC8174B00966EEA /* ExchangeConfig.swift */,
);
path = Types;
sourceTree = "<group>";
@ -2029,6 +2035,7 @@
2963A28A1FC402940095447D /* LocalizedOperationObject.swift in Sources */,
29FF12FB1F74CC8200AFD326 /* EthereumAddressRule.swift in Sources */,
2931121B1FC560E500966EEA /* ExchangeTokenTableViewCell.swift in Sources */,
293112261FC8154E00966EEA /* ContractExchangeTrade.swift in Sources */,
29CA4B791F6FBFD50032313D /* Balance.swift in Sources */,
291F52A71F6B766100B369AB /* BalanceRequest.swift in Sources */,
2932488A1F88D593008A9818 /* OnePasswordConfig.swift in Sources */,
@ -2047,6 +2054,7 @@
29AD8A061F93DC8C008E10E7 /* PushDevice.swift in Sources */,
29B6AED41F7CA09600EC6DE3 /* TransactionConfigurationViewController.swift in Sources */,
29B933F51F860074009FCABB /* SendTransactionCoordinator.swift in Sources */,
293112281FC8174B00966EEA /* ExchangeConfig.swift in Sources */,
2932045C1F8DCD6E0095B7C1 /* CurrencyRate.swift in Sources */,
291F52A51F6B762300B369AB /* EtherServiceRequest.swift in Sources */,
298542FB1FBEA03300CB5081 /* SendInputErrors.swift in Sources */,

@ -49,6 +49,14 @@ extension ExchangeCoordinator: ExchangeViewControllerDelegate {
transaction: transaction,
viewModel: viewModel
)
controller.delegate = self
navigationController.pushViewController(controller, animated: true)
}
}
extension ExchangeCoordinator: ConfirmPaymentViewControllerDelegate {
func didCompleted(transaction: SentTransaction, in viewController: ConfirmPaymentViewController) {
navigationController.popViewController(animated: true)
navigationController.displaySuccess(title: "Exchange \(transaction.id)")
}
}

@ -0,0 +1,21 @@
// Copyright SIX DAY LLC. All rights reserved.
import Foundation
struct ExchangeConfig {
let server: RPCServer
init(server: RPCServer) {
self.server = server
}
var contract: Address {
switch server {
case .main, .oraclesTest:
return Address(address: "")
case .kovan:
return Address(address: "0x11542d7807dfb2b44937f756b9092c76e814f8ed")
}
}
}

@ -7,11 +7,12 @@ struct ExchangeTokens {
switch server {
case .main, .oraclesTest:
return [
ExchangeToken(name: "OmiseGO", address: Address(address: "0x0x6b662ffde8f1d2240eb4eefa211463be0eb258a1"), symbol: "OMG", image: R.image.token_omg()),
ExchangeToken(name: "Ethereum", address: Address(address: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"), symbol: "ETH", image: R.image.token_eth()),
]
case .kovan:
return [
ExchangeToken(name: "OmiseGO", address: Address(address: "0x0x6b662ffde8f1d2240eb4eefa211463be0eb258a1"), symbol: "OMG", image: R.image.token_omg()),
ExchangeToken(name: "Ethereum", address: Address(address: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"), symbol: "ETH", image: R.image.token_eth()),
ExchangeToken(name: "OmiseGO", address: Address(address: "0x6b662ffde8f1d2240eb4eefa211463be0eb258a1"), symbol: "OMG", image: R.image.token_omg()),
ExchangeToken(name: "DigixDAO", address: Address(address: "0xd27763c026260bb8cfcf47a3d2ca18f03cb9da55"), symbol: "DGD", image: R.image.token_dgd()),
ExchangeToken(name: "Civic", address: Address(address: "0x3d1bdb333d4bbd0bf84519c506c953ef869ef179"), symbol: "CVC", image: R.image.token_cvc()),
ExchangeToken(name: "FunFair", address: Address(address: "0x0f679d211f23764c3020e2dca0d6277b9abb5b72"), symbol: "FUN", image: R.image.token_fun()),

@ -41,7 +41,7 @@ class ConfirmPaymentViewController: UIViewController {
return TransactionConfiguration(
speed: TransactionSpeed.custom(
gasPrice: TransactionSpeed.cheap.gasPrice,
gasLimit: GethNewBigInt(210000)
gasLimit: GethNewBigInt(300000)
)
)
}
@ -136,7 +136,23 @@ class ConfirmPaymentViewController: UIViewController {
self.hideLoading()
}
case .exchange(let from, let to):
break //
let exchangeConfig = ExchangeConfig(server: Config().server)
self.sendTransactionCoordinator.trade(
contract: exchangeConfig.contract,
from: from,
to: to,
configuration: self.configuration,
completion: { [weak self] result in
guard let `self` = self else { return }
switch result {
case .success(let transaction):
self.delegate?.didCompleted(transaction: transaction, in: self)
case .failure(let error):
self.displayError(error: error)
}
self.hideLoading()
}
)
}
}
}

@ -105,4 +105,38 @@ class SendTransactionCoordinator {
completion(.failure(AnyError(error)))
}
}
func trade(
contract: Address,
from: SubmitExchangeToken,
to: SubmitExchangeToken,
configuration: TransactionConfiguration,
completion: @escaping (Result<SentTransaction, AnyError>) -> Void
) {
let request = ContractExchangeTrade(
source: from.token.address.address,
amount: String(100000),
dest: to.token.address.address,
destAddress: session.account.address.address,
maxDestAmount: "9999999",
minConversionRate: 1,
throwOnFailure: false,
walletId: "0x00"
)
session.web3.request(request: request) { result in
switch result {
case .success(let res):
NSLog("result \(res)")
self.send(
address: contract,
value: 1,
data: Data(hex: res.drop0x),
configuration: configuration,
completion: completion
)
case .failure(let error):
completion(.failure(AnyError(error)))
}
}
}
}

Loading…
Cancel
Save