Add pair to send view controller.

pull/2/head
Oleg Gordiichuk 7 years ago committed by Michael Scoff
parent 2fff2225dd
commit e0685fb4af
  1. 8
      Podfile.lock
  2. 13
      Trust/InCoordinator.swift
  3. 5
      Trust/Transactions/Coordinators/TransactionCoordinator.swift
  4. 5
      Trust/Transfer/Coordinators/PaymentCoordinator.swift
  5. 52
      Trust/Transfer/ViewControllers/SendViewController.swift

@ -17,7 +17,8 @@ PODS:
- JSONRPCKit (2.0.0):
- Result (~> 3.0)
- KeychainSwift (10.0.0)
- Kingfisher (4.5.0)
- Kingfisher (4.6.1)
- libsodium (1.0.12)
- Lokalise (0.8.0)
- MBProgressHUD (1.1.0)
- Moya (10.0.1):
@ -80,7 +81,7 @@ EXTERNAL SOURCES:
CHECKOUT OPTIONS:
CryptoSwift:
:commit: 577e94f6060184f3ad72503aedd43d58272a8f2d
:commit: 289ef07b2f386d91a25b9393a96b0c3daa1d9114
:git: https://github.com/krzyzanowskim/CryptoSwift
JSONRPCKit:
:commit: 50d19a4f7ec593ac5e07cffa1e11c17f1fbe347d
@ -103,7 +104,8 @@ SPEC CHECKSUMS:
JavaScriptKit: 9ff565209e6efe21bcb9c6d6ca3e863a67a8ecf7
JSONRPCKit: 22132c575ba2dc6f2f4ae72fda4943a63efca686
KeychainSwift: f9f7910449a0c0fd2cabc889121530dd2c477c33
Kingfisher: 26ae0473102b77b575da51960c932431e3745407
Kingfisher: 1f9157d9c02b380cbd0b7cc890161195164eb634
libsodium: 9a8faa5ef2fa0d2d57bd7f7d79bf8fb7c1a9f0ea
Lokalise: 9547ef438a2d25cfba0b4c02201d3c39b3db35fb
MBProgressHUD: e7baa36a220447d8aeb12769bf0585582f3866d9
Moya: 9e621707ff754eeb51ff3ec51a3d54e517c0733a

@ -62,7 +62,13 @@ class InCoordinator: Coordinator {
account: account,
config: config
)
MigrationInitializer(account: account, chainID: config.chainID).perform()
let tokensStorage = TokensDataStore(
session: session,
configuration: RealmConfiguration.configuration(for: session.account, chainID: session.config.chainID)
)
let transactionsStorage = TransactionsStorage(
configuration: RealmConfiguration.configuration(for: account, chainID: session.config.chainID)
@ -71,7 +77,8 @@ class InCoordinator: Coordinator {
let transactionCoordinator = TransactionCoordinator(
session: session,
storage: transactionsStorage,
keystore: keystore
keystore: keystore,
tokensStorage: tokensStorage
)
transactionCoordinator.rootViewController.tabBarItem = UITabBarItem(title: NSLocalizedString("transactions.tabbar.item.title", value: "Transactions", comment: ""), image: R.image.feed(), selectedImage: nil)
transactionCoordinator.delegate = self
@ -102,10 +109,6 @@ class InCoordinator: Coordinator {
}
if inCoordinatorViewModel.tokensAvailable {
let tokensStorage = TokensDataStore(
session: session,
configuration: RealmConfiguration.configuration(for: session.account, chainID: session.config.chainID)
)
let tokenCoordinator = TokensCoordinator(
session: session,
keystore: keystore,

@ -28,6 +28,7 @@ class TransactionCoordinator: Coordinator {
weak var delegate: TransactionCoordinatorDelegate?
let session: WalletSession
let tokensStorage: TokensDataStore
let navigationController: UINavigationController
var coordinators: [Coordinator] = []
@ -35,12 +36,14 @@ class TransactionCoordinator: Coordinator {
session: WalletSession,
navigationController: UINavigationController = NavigationController(),
storage: TransactionsStorage,
keystore: Keystore
keystore: Keystore,
tokensStorage: TokensDataStore
) {
self.session = session
self.keystore = keystore
self.navigationController = navigationController
self.storage = storage
self.tokensStorage = tokensStorage
NotificationCenter.default.addObserver(self, selector: #selector(didEnterForeground), name: .UIApplicationWillEnterForeground, object: nil)
}

@ -16,6 +16,7 @@ class PaymentCoordinator: Coordinator {
var coordinators: [Coordinator] = []
let navigationController: UINavigationController
let keystore: Keystore
let storage: TokensDataStore
lazy var transferType: TransferType = {
switch self.flow {
@ -30,13 +31,15 @@ class PaymentCoordinator: Coordinator {
navigationController: UINavigationController = UINavigationController(),
flow: PaymentFlow,
session: WalletSession,
keystore: Keystore
keystore: Keystore,
storage:TokensDataStore
) {
self.navigationController = navigationController
self.navigationController.modalPresentationStyle = .formSheet
self.session = session
self.flow = flow
self.keystore = keystore
self.storage = storage
}
func start() {

@ -30,6 +30,15 @@ class SendViewController: FormViewController {
static let address = "address"
static let amount = "amount"
}
struct Pair {
let left: String
let right: String
func swapPair() -> Pair {
return Pair(left: right, right: left)
}
}
let session: WalletSession
let transferType: TransferType
@ -41,6 +50,10 @@ class SendViewController: FormViewController {
return form.rowBy(tag: Values.amount) as? TextFloatLabelRow
}
private var gasPrice: BigInt?
lazy var currentPair: Pair = {
return Pair(left: viewModel.symbol, right: Config().currency.rawValue)
}()
init(
session: WalletSession,
@ -79,13 +92,19 @@ class SendViewController: FormViewController {
maxButton.translatesAutoresizingMaskIntoConstraints = false
maxButton.setTitle(NSLocalizedString("send.max.button.title", value: "Max", comment: ""), for: .normal)
maxButton.addTarget(self, action: #selector(useMaxAmount), for: .touchUpInside)
let fiatButton = Button(size: .normal, style: .borderless)
fiatButton.translatesAutoresizingMaskIntoConstraints = false
fiatButton.setTitle(currentPair.right, for: .normal)
fiatButton.addTarget(self, action: #selector(fiatAction), for: .touchUpInside)
let amountRightView = UIStackView(arrangedSubviews: [
maxButton,
fiatButton,
])
amountRightView.translatesAutoresizingMaskIntoConstraints = false
amountRightView.distribution = .equalSpacing
amountRightView.spacing = 10
amountRightView.spacing = 1
amountRightView.axis = .horizontal
form = Section()
@ -107,9 +126,10 @@ class SendViewController: FormViewController {
$0.validationOptions = .validatesOnDemand
}.cellUpdate {[weak self] cell, _ in
cell.textField.textAlignment = .left
cell.textField.placeholder = "\(self?.viewModel.symbol ?? "") " + NSLocalizedString("send.amount.textField.placeholder", value: "Amount", comment: "")
cell.textField.delegate = self
cell.textField.placeholder = "\(self?.currentPair.left ?? "") " + NSLocalizedString("send.amount.textField.placeholder", value: "Amount", comment: "")
cell.textField.keyboardType = .decimalPad
//cell.textField.rightView = maxButton // TODO Enable it's ready
cell.textField.rightView = amountRightView
cell.textField.rightViewMode = .always
}
@ -202,6 +222,15 @@ class SendViewController: FormViewController {
amountRow?.value = value
amountRow?.reload()
}
@objc func fiatAction(sender: UIButton) {
let swappedPair = currentPair.swapPair()
//New pair for future calculation we should swap pair each time we press fiat button.
self.currentPair = swappedPair
//Update button title and realod cell.
sender.setTitle(currentPair.right, for: .normal)
amountRow?.reload()
}
func activateAmountView() {
amountRow?.cell.textField.becomeFirstResponder()
@ -210,6 +239,10 @@ class SendViewController: FormViewController {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func updatePairPrice(with amount:String) {
}
}
extension SendViewController: QRCodeReaderDelegate {
@ -227,3 +260,14 @@ extension SendViewController: QRCodeReaderDelegate {
activateAmountView()
}
}
extension SendViewController: UITextFieldDelegate {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let text = (textField.text as NSString?)?.replacingCharacters(in: range, with: string)
guard let amount = text, Double(amount) != nil else {
return true
}
self.updatePairPrice(with: amount)
return true
}
}

Loading…
Cancel
Save