Skip to content

Commit

Permalink
fix dropdown seed list border, scrollview and error message (#389)
Browse files Browse the repository at this point in the history
* fix seed border,scrollview and error message

* code clean up and fix changes requested

* add spacing between parameter calls on contentInset function

* fix further changes requested

* Fix change requested on PR

* fix changes on PR

* change dropdown border color

* Rename color,seed error lable and hex conversion

* fix changes requested
  • Loading branch information
macsleven authored and itswisdomagain committed May 18, 2019
1 parent b77bf0c commit baa5a21
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
5 changes: 2 additions & 3 deletions decred_wallet/Extensions/UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ extension UIColor {
static let decredBlue = UIColor.init(hex: "#2970FF")
static let decredGreen = UIColor.init(hex: "#41BF53")
static let decredOrange = UIColor.init(hex: "#ED6D47")

static let darkYellowWarning = UIColor.init(hex: "#E7C659")
static let green = UIColor.init(hex: "#2DD8A3")
// static let gray = UIColor(red: 132.0/255.0, green: 139.0/255.0, blue: 144.0/255.0, alpha: 1.0)
static let lightGray = UIColor.init(hex: "#C4CBD2")
static let lightGray = UIColor.init(hex: "#DEE1E3")
static let lighterGray = UIColor.init(hex: "#C4CBD2")
static let offWhite = UIColor(hex:"#F9FAFA")
static let yellowWarning = UIColor.init(hex: "#FFC84E")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import UIKit
class RecoverExistingWalletViewController: WalletSetupBaseViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tableView : UITableView!
@IBOutlet weak var wordSelectionDropDownContainer: UIView!

@IBOutlet weak var tableViewFooter: UIStackView!
@IBOutlet weak var tableViewFooterTopSpacingConstraint: NSLayoutConstraint!

@IBOutlet weak var lblEnterAllSeeds: UILabel!
@IBOutlet weak var invalidSeedLabel: UILabel!
@IBOutlet weak var btnConfirm: UIButton!

var validSeedWords: [String] = []
Expand All @@ -34,6 +32,10 @@ class RecoverExistingWalletViewController: WalletSetupBaseViewController, UITabl
registerObserverForKeyboardNotification()
self.hideKeyboardWhenTappedAround()

// set border for dropdown list
self.wordSelectionDropDownContainer.layer.borderWidth = 1
self.wordSelectionDropDownContainer.layer.borderColor = UIColor.appColors.lightGray.cgColor

// long press to proceed with test seed, only on testnet
if GlobalConstants.App.IsTestnet {
let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressConfirm))
Expand Down Expand Up @@ -63,6 +65,9 @@ class RecoverExistingWalletViewController: WalletSetupBaseViewController, UITabl
y: self.view.frame.origin.y,
width: self.view.frame.width,
height: window.origin.y + window.height - keyboardSize.height)

// add space at the bottom of table so that the seed word input fields do not touch the keyboard
self.tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0)
}
}

Expand All @@ -73,6 +78,9 @@ class RecoverExistingWalletViewController: WalletSetupBaseViewController, UITabl
y: self.view.frame.origin.y,
width: self.view.frame.width,
height: window.origin.y + window.height)

// remove space at the bottom of table that was added when keyboard was displayed
self.tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
}

Expand Down Expand Up @@ -102,65 +110,59 @@ class RecoverExistingWalletViewController: WalletSetupBaseViewController, UITabl
func seedWordEntered(for wordIndex: Int, seedWord: String, moveToNextField: Bool) {
self.userEnteredSeedWords[wordIndex] = seedWord

if (self.invalidSeedLabel.isHidden == false) {
self.invalidSeedLabel.isHidden = true
// increase top spacing so that confirm button is centered in display
self.tableViewFooterTopSpacingConstraint.constant = 30
UIView.animate(withDuration: 0.5) {
self.tableViewFooter.layoutIfNeeded()
}
}

if wordIndex < 32 && moveToNextField {
self.focusSeedWordInput(at: wordIndex + 1)
} else {
self.view.endEditing(true)
}

if self.validateSeed().valid {
self.activateConfirmButton()
self.btnConfirm.backgroundColor = UIColor.appColors.decredGreen
} else {
self.deactivateConfirmButton()
self.btnConfirm.backgroundColor = UIColor.appColors.lighterGray
}
}

func focusSeedWordInput(at tableRowIndex: Int) {
let tableIndexPath = IndexPath(row: tableRowIndex, section: 0)

let nextSeedWordCell = self.tableView.cellForRow(at: tableIndexPath) as? RecoveryWalletSeedWordCell
nextSeedWordCell?.seedWordAutoComplete.becomeFirstResponder()

self.tableView.scrollToRow(at: tableIndexPath, at: .middle, animated: true)
}

func activateConfirmButton() {
self.btnConfirm.backgroundColor = UIColor.appColors.decredGreen
self.lblEnterAllSeeds.isHidden = true

// increase top spacing since warning label is now hidden so as to position button in center
self.tableViewFooterTopSpacingConstraint.constant = 30
UIView.animate(withDuration: 0.5) {
self.tableViewFooter.layoutIfNeeded()
}

@IBAction func backButtonTap(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}

func deactivateConfirmButton() {
self.btnConfirm.backgroundColor = UIColor.appColors.lightGray
self.lblEnterAllSeeds.isHidden = false

@IBAction func onConfirm() {
if self.userEnteredSeedWords.contains("") {
self.lblEnterAllSeeds.text = "Not all seeds are entered. Please, check input fields and enter all seeds."
self.displaySeedError("Not all seeds are entered. Please, check input fields and enter all seeds.")
} else {
self.lblEnterAllSeeds.text = "You entered an incorrect seed. Please check your words."
let validatedSeed = self.validateSeed()
if validatedSeed.valid {
self.secureWallet(validatedSeed.seed)
} else {
self.displaySeedError("You entered an incorrect seed. Please check your words.")
}
}

}

func displaySeedError(_ errorMessage: String) {
// reduce top spacing so that warning label and confirm button are centered in display
self.tableViewFooterTopSpacingConstraint.constant = 10
UIView.animate(withDuration: 0.5) {
self.tableViewFooter.layoutIfNeeded()
}
}

@IBAction func backButtonTap(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}

@IBAction func onConfirm() {
let validatedSeed = self.validateSeed()
if validatedSeed.valid {
self.secureWallet(validatedSeed.seed)
}
self.invalidSeedLabel.text = errorMessage
self.invalidSeedLabel.isHidden = false
}

@objc func longPressConfirm() {
Expand Down
2 changes: 1 addition & 1 deletion decred_wallet/Features/Wallet Setup/WalletSetup.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@
</view>
<connections>
<outlet property="btnConfirm" destination="Z7B-hI-KRP" id="pGB-SP-2Cs"/>
<outlet property="lblEnterAllSeeds" destination="yKo-jo-2pm" id="lhc-gA-g9Z"/>
<outlet property="invalidSeedLabel" destination="yKo-jo-2pm" id="lhc-gA-g9Z"/>
<outlet property="tableView" destination="u2P-f0-vXF" id="cF0-FR-LwL"/>
<outlet property="tableViewFooter" destination="H36-9D-vfZ" id="c9f-JJ-8Hx"/>
<outlet property="tableViewFooterTopSpacingConstraint" destination="mhL-vS-edS" id="Bzz-Mf-IDu"/>
Expand Down

0 comments on commit baa5a21

Please sign in to comment.