Work in progress for integrating exchange

pull/2/head
Michael Scoff 7 years ago
parent 236dc2bd4b
commit 862c070033
  1. 16
      Trust.xcodeproj/project.pbxproj
  2. 21
      Trust/Assets.xcassets/chevron-right.imageset/Contents.json
  3. BIN
      Trust/Assets.xcassets/chevron-right.imageset/chevron-right.png
  4. 41
      Trust/Exchange/ViewControllers/ExchangeViewController.swift
  5. 5
      Trust/Exchange/ViewControllers/SelectTokenViewController.swift
  6. 32
      Trust/Exchange/ViewModels/ExchangeTokensViewModel.swift
  7. 112
      Trust/Exchange/Views/ExchangeTokenInputField.swift
  8. 65
      Trust/Exchange/Views/ExchangeTokensField.swift
  9. 6
      Trust/Extensions/UIView.swift
  10. 1
      Trust/Style/AppStyle.swift
  11. 2
      Trust/Transfer/Controllers/RequestViewController.swift

@ -66,6 +66,8 @@
293112171FC5555500966EEA /* ExchangeTokensViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293112161FC5555500966EEA /* ExchangeTokensViewModel.swift */; }; 293112171FC5555500966EEA /* ExchangeTokensViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293112161FC5555500966EEA /* ExchangeTokensViewModel.swift */; };
293112191FC55E5500966EEA /* SelectTokenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293112181FC55E5500966EEA /* SelectTokenViewController.swift */; }; 293112191FC55E5500966EEA /* SelectTokenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293112181FC55E5500966EEA /* SelectTokenViewController.swift */; };
2931121B1FC560E500966EEA /* ExchangeTokenTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2931121A1FC560E500966EEA /* ExchangeTokenTableViewCell.swift */; }; 2931121B1FC560E500966EEA /* ExchangeTokenTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2931121A1FC560E500966EEA /* ExchangeTokenTableViewCell.swift */; };
2931121D1FC65F2900966EEA /* ExchangeCurrencyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2931121C1FC65F2900966EEA /* ExchangeCurrencyView.swift */; };
293112201FC6619000966EEA /* ExchangeToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2931121F1FC6619000966EEA /* ExchangeToken.swift */; };
293204581F8DC6B20095B7C1 /* ExchangeRateCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293204571F8DC6B20095B7C1 /* ExchangeRateCoordinator.swift */; }; 293204581F8DC6B20095B7C1 /* ExchangeRateCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293204571F8DC6B20095B7C1 /* ExchangeRateCoordinator.swift */; };
2932045C1F8DCD6E0095B7C1 /* CurrencyRate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2932045B1F8DCD6E0095B7C1 /* CurrencyRate.swift */; }; 2932045C1F8DCD6E0095B7C1 /* CurrencyRate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2932045B1F8DCD6E0095B7C1 /* CurrencyRate.swift */; };
2932045E1F8EEE760095B7C1 /* BalanceCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2932045D1F8EEE760095B7C1 /* BalanceCoordinator.swift */; }; 2932045E1F8EEE760095B7C1 /* BalanceCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2932045D1F8EEE760095B7C1 /* BalanceCoordinator.swift */; };
@ -324,6 +326,8 @@
293112161FC5555500966EEA /* ExchangeTokensViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeTokensViewModel.swift; sourceTree = "<group>"; }; 293112161FC5555500966EEA /* ExchangeTokensViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeTokensViewModel.swift; sourceTree = "<group>"; };
293112181FC55E5500966EEA /* SelectTokenViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectTokenViewController.swift; sourceTree = "<group>"; }; 293112181FC55E5500966EEA /* SelectTokenViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectTokenViewController.swift; sourceTree = "<group>"; };
2931121A1FC560E500966EEA /* ExchangeTokenTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeTokenTableViewCell.swift; sourceTree = "<group>"; }; 2931121A1FC560E500966EEA /* ExchangeTokenTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeTokenTableViewCell.swift; sourceTree = "<group>"; };
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>"; };
293204571F8DC6B20095B7C1 /* ExchangeRateCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeRateCoordinator.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>"; }; 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>"; }; 2932045D1F8EEE760095B7C1 /* BalanceCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BalanceCoordinator.swift; sourceTree = "<group>"; };
@ -854,6 +858,14 @@
path = ViewModels; path = ViewModels;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
2931121E1FC6618800966EEA /* Types */ = {
isa = PBXGroup;
children = (
2931121F1FC6619000966EEA /* ExchangeToken.swift */,
);
path = Types;
sourceTree = "<group>";
};
293248881F88D586008A9818 /* Types */ = { 293248881F88D586008A9818 /* Types */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -1152,6 +1164,7 @@
298543011FC15F5300CB5081 /* Exchange */ = { 298543011FC15F5300CB5081 /* Exchange */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
2931121E1FC6618800966EEA /* Types */,
2985430D1FC18A3C00CB5081 /* ViewModels */, 2985430D1FC18A3C00CB5081 /* ViewModels */,
298543081FC1888700CB5081 /* Views */, 298543081FC1888700CB5081 /* Views */,
298543051FC15FA200CB5081 /* ViewControllers */, 298543051FC15FA200CB5081 /* ViewControllers */,
@ -1184,6 +1197,7 @@
2985430B1FC188D200CB5081 /* ExchangeTokensField.swift */, 2985430B1FC188D200CB5081 /* ExchangeTokensField.swift */,
298543091FC188A700CB5081 /* ExchangeTokenInputField.swift */, 298543091FC188A700CB5081 /* ExchangeTokenInputField.swift */,
2931121A1FC560E500966EEA /* ExchangeTokenTableViewCell.swift */, 2931121A1FC560E500966EEA /* ExchangeTokenTableViewCell.swift */,
2931121C1FC65F2900966EEA /* ExchangeCurrencyView.swift */,
); );
path = Views; path = Views;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1924,6 +1938,7 @@
290B2B5F1F9177860053C83E /* UIImage.swift in Sources */, 290B2B5F1F9177860053C83E /* UIImage.swift in Sources */,
291F52B21F6B814300B369AB /* MG Benchmark Tools.swift in Sources */, 291F52B21F6B814300B369AB /* MG Benchmark Tools.swift in Sources */,
291ED08F1F6F613200E7E93A /* GetTransactionRequest.swift in Sources */, 291ED08F1F6F613200E7E93A /* GetTransactionRequest.swift in Sources */,
2931121D1FC65F2900966EEA /* ExchangeCurrencyView.swift in Sources */,
293112171FC5555500966EEA /* ExchangeTokensViewModel.swift in Sources */, 293112171FC5555500966EEA /* ExchangeTokensViewModel.swift in Sources */,
295A59381F71C1B90092F0FC /* AccountsCoordinator.swift in Sources */, 295A59381F71C1B90092F0FC /* AccountsCoordinator.swift in Sources */,
296421971F70C1F200EB363B /* ErrorView.swift in Sources */, 296421971F70C1F200EB363B /* ErrorView.swift in Sources */,
@ -2054,6 +2069,7 @@
29850D2B1F6B30FF00791A49 /* TransactionViewController.swift in Sources */, 29850D2B1F6B30FF00791A49 /* TransactionViewController.swift in Sources */,
29C80D411FB2E1610037B1E0 /* EthplorerService.swift in Sources */, 29C80D411FB2E1610037B1E0 /* EthplorerService.swift in Sources */,
296AF9AB1F7380920058AF78 /* GetTransactionCountRequest.swift in Sources */, 296AF9AB1F7380920058AF78 /* GetTransactionCountRequest.swift in Sources */,
293112201FC6619000966EEA /* ExchangeToken.swift in Sources */,
298542F51FBD8E6A00CB5081 /* ConfigExplorer.swift in Sources */, 298542F51FBD8E6A00CB5081 /* ConfigExplorer.swift in Sources */,
29A13E2C1F6A955700E432A2 /* CreateWalletViewModel.swift in Sources */, 29A13E2C1F6A955700E432A2 /* CreateWalletViewModel.swift in Sources */,
29C80D4F1FB520AF0037B1E0 /* BalanceTokenViewModel.swift in Sources */, 29C80D4F1FB520AF0037B1E0 /* BalanceTokenViewModel.swift in Sources */,

@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "chevron-right.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 674 B

@ -7,28 +7,35 @@ class ExchangeViewController: UIViewController {
private let viewModel = ExchangeViewModel() private let viewModel = ExchangeViewModel()
let exchangeFields = ExchangeTokensField() let exchangeFields = ExchangeTokensField()
let currencyView = ExchangeCurrencyView()
let coordinator = ExchangeToksnCoordinator() let coordinator = ExchangeToksnCoordinator()
init() { init() {
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
exchangeFields.translatesAutoresizingMaskIntoConstraints = false exchangeFields.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(exchangeFields)
let stackView = UIStackView(arrangedSubviews: [
exchangeFields,
.spacer(height: 20),
currencyView,
])
stackView.axis = .vertical
stackView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(stackView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
exchangeFields.topAnchor.constraint(equalTo: view.layoutGuide.topAnchor, constant: 20), stackView.topAnchor.constraint(equalTo: view.layoutGuide.topAnchor, constant: 20),
exchangeFields.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
exchangeFields.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20), stackView.bottomAnchor.constraint(lessThanOrEqualTo: view.bottomAnchor, constant: -20),
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
]) ])
exchangeFields.didPressSwap = { [unowned self] in exchangeFields.didPress = { [unowned self] direction in
self.coordinator.swap() self.showSelectToken(direction: direction)
}
exchangeFields.didPressFrom = { [unowned self] in
self.showSelectToken(direction: .from)
} }
exchangeFields.didPressTo = { [unowned self] in exchangeFields.didPressAvailableBalance = { [unowned self] _ in
self.showSelectToken(direction: .to) self.exchangeFields.fromField.amountField.text = "\(self.coordinator.viewModel.availableBalance)"
} }
coordinator.didUpdate = { [weak self] viewModel in coordinator.didUpdate = { [weak self] viewModel in
@ -39,11 +46,18 @@ class ExchangeViewController: UIViewController {
view.backgroundColor = viewModel.backgroundColor view.backgroundColor = viewModel.backgroundColor
navigationItem.title = viewModel.title navigationItem.title = viewModel.title
exchangeFields.backgroundColor = .white
} }
func configure(viewModel: ExchangeTokensViewModel) { func configure(viewModel: ExchangeTokensViewModel) {
exchangeFields.to.symbolLabel.text = viewModel.toSymbol exchangeFields.fromField.symbolLabel.text = viewModel.fromSymbol
exchangeFields.from.symbolLabel.text = viewModel.fromSymbol exchangeFields.toField.symbolLabel.text = viewModel.toSymbol
exchangeFields.fromField.backgroundColor = Colors.veryLightGray
exchangeFields.toField.backgroundColor = Colors.veryLightGray
exchangeFields.availableBalanceLabel.attributedText = viewModel.attributedAvailableBalance
currencyView.currencyLabel.attributedText = viewModel.attributedCurrency
} }
func showSelectToken(direction: SelectTokenDirection) { func showSelectToken(direction: SelectTokenDirection) {
@ -63,5 +77,6 @@ class ExchangeViewController: UIViewController {
extension ExchangeViewController: SelectTokenViewControllerDelegate { extension ExchangeViewController: SelectTokenViewControllerDelegate {
func didSelect(token: ExchangeToken, in viewController: SelectTokenViewController) { func didSelect(token: ExchangeToken, in viewController: SelectTokenViewController) {
coordinator.changeToken(direction: viewController.direction, token: token) coordinator.changeToken(direction: viewController.direction, token: token)
navigationController?.popViewController(animated: true)
} }
} }

@ -54,11 +54,6 @@ class SelectTokenViewController: UITableViewController {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let token = tokens[indexPath.row] let token = tokens[indexPath.row]
tableView.deselectRow(at: indexPath, animated: true) tableView.deselectRow(at: indexPath, animated: true)
NSLog("didSelectRowAt \(token)")
delegate?.didSelect(token: token, in: self) delegate?.didSelect(token: token, in: self)
navigationController?.popViewController(animated: true)
} }
} }

@ -1,12 +1,8 @@
// Copyright SIX DAY LLC. All rights reserved. // Copyright SIX DAY LLC. All rights reserved.
import Foundation import Foundation
import UIKit
struct ExchangeToken { import BonMot
let name: String
let symbol: String
let balance: Double
}
struct ExchangeTokensViewModel { struct ExchangeTokensViewModel {
@ -28,4 +24,28 @@ struct ExchangeTokensViewModel {
var toSymbol: String { var toSymbol: String {
return to.symbol return to.symbol
} }
var attributedCurrency: NSAttributedString {
let baseStyle = StringStyle(
.lineHeightMultiple(1.2),
.font(UIFont.systemFont(ofSize: 15))
)
let greenStyle = baseStyle.byAdding(.color(Colors.green))
let conversationString = "1 \(fromSymbol) = 0.017648 \(toSymbol) ".styled(with: baseStyle)
let percentString = "(-%)".styled(with: greenStyle)
return (conversationString + percentString).styled(with: .alignment(.center))
}
var availableBalance: Double {
return 2.22
}
var attributedAvailableBalance: NSAttributedString {
return NSAttributedString(
string: "Available \(availableBalance) \(fromSymbol)",
attributes: [:]
)
}
} }

@ -4,13 +4,10 @@ import UIKit
class ExchangeTokenInputField: UIView { class ExchangeTokenInputField: UIView {
let floatLabelView = UIView()
let destinationLabel = UILabel()
let amountField = UITextField() let amountField = UITextField()
let tokenView = UIView()
let tokenImageView = UIImageView() let tokenImageView = UIImageView()
let symbolLabel = UILabel() let symbolLabel = UILabel()
let chevronDownImageView = UIImageView(image: R.image.chevronRight())
var didPress: (() -> Void)? var didPress: (() -> Void)?
@ -18,100 +15,75 @@ class ExchangeTokenInputField: UIView {
super.init(frame: .zero) super.init(frame: .zero)
// value
floatLabelView.translatesAutoresizingMaskIntoConstraints = false
destinationLabel.translatesAutoresizingMaskIntoConstraints = false
amountField.translatesAutoresizingMaskIntoConstraints = false amountField.translatesAutoresizingMaskIntoConstraints = false
amountField.backgroundColor = .red amountField.placeholder = "0"
amountField.font = UIFont.systemFont(ofSize: 26, weight: UIFontWeightMedium) amountField.font = UIFont.systemFont(ofSize: 22, weight: UIFontWeightMedium)
let inputStackView = UIStackView(arrangedSubviews: [
destinationLabel,
amountField,
])
inputStackView.translatesAutoresizingMaskIntoConstraints = false
inputStackView.axis = .vertical
inputStackView.spacing = 5
addSubview(floatLabelView)
floatLabelView.addSubview(inputStackView)
NSLayoutConstraint.activate([
inputStackView.centerYAnchor.constraint(equalTo: floatLabelView.centerYAnchor),
inputStackView.leadingAnchor.constraint(equalTo: floatLabelView.leadingAnchor),
inputStackView.trailingAnchor.constraint(equalTo: floatLabelView.trailingAnchor, constant: -15),
floatLabelView.topAnchor.constraint(equalTo: topAnchor),
floatLabelView.leadingAnchor.constraint(equalTo: leadingAnchor),
floatLabelView.bottomAnchor.constraint(equalTo: bottomAnchor),
])
// token view
symbolLabel.translatesAutoresizingMaskIntoConstraints = false symbolLabel.translatesAutoresizingMaskIntoConstraints = false
symbolLabel.textAlignment = .center symbolLabel.textAlignment = .center
symbolLabel.text = "ETH" symbolLabel.font = UIFont.systemFont(ofSize: 16, weight: UIFontWeightMedium)
symbolLabel.adjustsFontSizeToFitWidth = true
tokenImageView.translatesAutoresizingMaskIntoConstraints = false tokenImageView.translatesAutoresizingMaskIntoConstraints = false
tokenImageView.image = R.image.accounts_active() tokenImageView.image = R.image.accounts_active()
tokenImageView.contentMode = .scaleAspectFit
chevronDownImageView.translatesAutoresizingMaskIntoConstraints = false
chevronDownImageView.contentMode = .scaleAspectFit
chevronDownImageView.alpha = 0.5
tokenView.translatesAutoresizingMaskIntoConstraints = false let divider: UIView = .spacerWidth(1, backgroundColor: .lightGray)
tokenView.backgroundColor = .green
let tokenStackView = UIStackView(arrangedSubviews: [ let tokenStackView = UIStackView(arrangedSubviews: [
tokenImageView, tokenImageView,
symbolLabel, symbolLabel,
chevronDownImageView,
]) ])
tokenStackView.translatesAutoresizingMaskIntoConstraints = false tokenStackView.translatesAutoresizingMaskIntoConstraints = false
tokenStackView.axis = .vertical tokenStackView.axis = .horizontal
tokenStackView.spacing = 5 tokenStackView.spacing = 5
tokenView.addSubview(tokenStackView) let stackView = UIStackView(arrangedSubviews: [
addSubview(tokenView) amountField,
divider,
tokenStackView,
])
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .horizontal
stackView.alignment = .center
stackView.spacing = 5
addSubview(stackView)
let chevronDownImageView = UIImageView(image: R.image.chevronDown()) NSLayoutConstraint.activate([
chevronDownImageView.translatesAutoresizingMaskIntoConstraints = false stackView.topAnchor.constraint(equalTo: topAnchor),
stackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: StyleLayout.sideMargin),
stackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -StyleLayout.sideMargin),
stackView.bottomAnchor.constraint(equalTo: bottomAnchor),
stackView.heightAnchor.constraint(equalToConstant: 60),
tokenView.addSubview(chevronDownImageView) amountField.widthAnchor.constraint(equalToConstant: 120),
NSLayoutConstraint.activate([ symbolLabel.widthAnchor.constraint(equalToConstant: 50),
tokenStackView.centerXAnchor.constraint(equalTo: tokenView.centerXAnchor),
tokenStackView.centerYAnchor.constraint(equalTo: tokenView.centerYAnchor),
tokenView.topAnchor.constraint(equalTo: topAnchor), divider.topAnchor.constraint(equalTo: topAnchor, constant: StyleLayout.sideMargin),
tokenView.trailingAnchor.constraint(equalTo: trailingAnchor), divider.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -StyleLayout.sideMargin),
tokenView.bottomAnchor.constraint(equalTo: bottomAnchor),
tokenView.widthAnchor.constraint(equalToConstant: 100),
tokenView.leadingAnchor.constraint(equalTo: floatLabelView.trailingAnchor),
chevronDownImageView.leadingAnchor.constraint(equalTo: tokenStackView.trailingAnchor), tokenImageView.heightAnchor.constraint(equalToConstant: 36),
chevronDownImageView.centerYAnchor.constraint(equalTo: tokenStackView.centerYAnchor), tokenImageView.widthAnchor.constraint(equalToConstant: 36),
chevronDownImageView.centerYAnchor.constraint(equalTo: stackView.centerYAnchor),
chevronDownImageView.heightAnchor.constraint(equalToConstant: 12),
chevronDownImageView.widthAnchor.constraint(equalToConstant: 12),
]) ])
// main stack // main stack
let stackView = UIStackView(arrangedSubviews: [ tokenStackView.addGestureRecognizer(
floatLabelView,
tokenView,
])
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .horizontal
stackView.addGestureRecognizer(
UITapGestureRecognizer(target: self, action: #selector(self.tap)) UITapGestureRecognizer(target: self, action: #selector(self.tap))
) )
addSubview(stackView) layer.cornerRadius = 5
layer.masksToBounds = true
NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: topAnchor),
stackView.leadingAnchor.constraint(equalTo: leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
stackView.bottomAnchor.constraint(equalTo: bottomAnchor),
stackView.heightAnchor.constraint(equalToConstant: 100),
])
} }
func tap() { func tap() {

@ -4,58 +4,63 @@ import UIKit
class ExchangeTokensField: UIView { class ExchangeTokensField: UIView {
let from = ExchangeTokenInputField() let fromField = ExchangeTokenInputField()
let to = ExchangeTokenInputField() let toField = ExchangeTokenInputField()
let swapButton = UIButton()
lazy var availableBalanceLabel: UILabel = {
var didPressSwap: (() -> Void)? let label = UILabel()
var didPressTo: (() -> Void)? label.translatesAutoresizingMaskIntoConstraints = false
var didPressFrom: (() -> Void)? label.addGestureRecognizer(
UITapGestureRecognizer(target: self, action: #selector(self.availableBalance))
)
label.isUserInteractionEnabled = true
return label
}()
var didPress: ((SelectTokenDirection) -> Void)?
var didPressAvailableBalance: (() -> Void)?
init() { init() {
super.init(frame: .zero) super.init(frame: .zero)
from.translatesAutoresizingMaskIntoConstraints = false fromField.translatesAutoresizingMaskIntoConstraints = false
from.destinationLabel.text = "You send" toField.translatesAutoresizingMaskIntoConstraints = false
to.translatesAutoresizingMaskIntoConstraints = false
to.destinationLabel.text = "You get"
swapButton.translatesAutoresizingMaskIntoConstraints = false
swapButton.setImage(R.image.swap(), for: .normal)
swapButton.addTarget(self, action: #selector(swap), for: .touchUpInside)
swapButton.layer.cornerRadius = 20
swapButton.backgroundColor = .white
let stackView = UIStackView(arrangedSubviews: [ let stackView = UIStackView(arrangedSubviews: [
from, destinationLabel(text: "From"),
to, fromField,
availableBalanceLabel,
.spacer(height: 0),
destinationLabel(text: "To"),
toField,
]) ])
stackView.translatesAutoresizingMaskIntoConstraints = false stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.spacing = 10
stackView.axis = .vertical stackView.axis = .vertical
from.didPress = { [unowned self] in self.didPressFrom?() } fromField.didPress = { [unowned self] in self.didPress?(.from) }
to.didPress = { [unowned self] in self.didPressTo?() } toField.didPress = { [unowned self] in self.didPress?(.to) }
addSubview(stackView) addSubview(stackView)
addSubview(swapButton)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: topAnchor), stackView.topAnchor.constraint(equalTo: topAnchor),
stackView.leadingAnchor.constraint(equalTo: leadingAnchor), stackView.leadingAnchor.constraint(equalTo: leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: trailingAnchor), stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
stackView.bottomAnchor.constraint(equalTo: bottomAnchor), stackView.bottomAnchor.constraint(equalTo: bottomAnchor),
swapButton.centerYAnchor.constraint(equalTo: stackView.centerYAnchor),
swapButton.trailingAnchor.constraint(equalTo: stackView.trailingAnchor, constant: -80),
swapButton.widthAnchor.constraint(equalToConstant: 40),
swapButton.heightAnchor.constraint(equalToConstant: 40),
]) ])
} }
func swap() { private func destinationLabel(text: String) -> UILabel {
didPressSwap?() let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = text
return label
}
func availableBalance() {
didPressAvailableBalance?()
} }
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {

@ -29,18 +29,20 @@ extension UIView {
} }
} }
static func spacer(height: CGFloat = 1) -> UIView { static func spacer(height: CGFloat = 1, backgroundColor: UIColor = .clear) -> UIView {
let view = UIView(frame: .zero) let view = UIView(frame: .zero)
view.translatesAutoresizingMaskIntoConstraints = false view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = backgroundColor
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
view.heightAnchor.constraint(equalToConstant: height), view.heightAnchor.constraint(equalToConstant: height),
]) ])
return view return view
} }
static func spacerWidth(_ width: CGFloat = 1) -> UIView { static func spacerWidth(_ width: CGFloat = 1, backgroundColor: UIColor = .clear) -> UIView {
let view = UIView(frame: .zero) let view = UIView(frame: .zero)
view.translatesAutoresizingMaskIntoConstraints = false view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = backgroundColor
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
view.widthAnchor.constraint(equalToConstant: width), view.widthAnchor.constraint(equalToConstant: width),

@ -25,6 +25,7 @@ struct Colors {
static let veryLightOrange = UIColor(hex: "FFECC9") static let veryLightOrange = UIColor(hex: "FFECC9")
static let green = UIColor(hex: "2fbb4f") static let green = UIColor(hex: "2fbb4f")
static let lightGray = UIColor.lightGray static let lightGray = UIColor.lightGray
static let veryLightGray = UIColor(hex: "F6F6F6")
static let gray = UIColor.gray static let gray = UIColor.gray
static let darkGray = UIColor(hex: "606060") static let darkGray = UIColor(hex: "606060")
static let black = UIColor(hex: "313849") static let black = UIColor(hex: "313849")

@ -106,7 +106,7 @@ class RequestViewController: UIViewController {
func changeQRCode(value: Int) { func changeQRCode(value: Int) {
let string = "\(account.address.address)" let string = "\(account.address.address)"
// EIP67 format not being used much yet, use hex value for now // EIP67 format not being used much yet, use hex value for now
// let string = "ethereum:\(account.address.address)?value=\(value)" // let string = "ethereum:\(account.address.address)?value=\(value)"

Loading…
Cancel
Save