Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NT-327] Disable pledge button for invalid inputs #859

Merged
merged 14 commits into from
Sep 30, 2019

Conversation

dusi
Copy link
Contributor

@dusi dusi commented Sep 27, 2019

📲 What

If the amount input is invalid (< min pledge value OR > max pledge value) the Pledge button will be disabled.

🤔 Why

This should reflect our UI/UX approach for validating data on this screen and further actions users can perform. They should not be able to try pledging if the input is locally invalid since this would only result in failed requests.

🛠 How

Small refactor has been done to not only report back amount value, but also it's validity within the min/max bounds.

In addition to that I've tweaked the way initial payment method is selected (which previously was not reporting back to the view model - and was only set visually in UI). Now when the user fetches payment methods and the first payment method is set (as the default option) the vm reports back which allows us to enable/disable the Pledge button.

👀 See

Before 🐛 After 🦋
Screen Shot 2019-09-27 at 11 50 41 AM Screen Shot 2019-09-27 at 11 47 46 AM

✅ Acceptance criteria

  • Setting amount value to an invalid number (smaller than pledge min value) should disable
    Pledge button
  • Setting amount value to an invalid number (larger than pledge max value) should disable Pledge button
  • Setting amount value to a valid number (larger than or equal to pledge min value OR lower than or equal to pledge max value) should enable the Pledge button (if it was previously disabled)
  • Pledge button is enabled initially if there is at least one payment method and that method is indicating of being selected

@@ -7,7 +7,7 @@ import UIKit
protocol PledgeAmountViewControllerDelegate: AnyObject {
func pledgeAmountViewController(
_ viewController: PledgeAmountViewController,
didUpdateAmount amount: Double
didUpdate amount: (value: Double, isValid: Bool)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a tuple to wrap both value and its validity now

.takeWhen(self.selectButtonTappedProperty.signal)
.map { $0.id }

self.notifyDelegateOfCardSelected = Signal.merge(
creditCardInitial,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now make sure to notify delegate when payment methods get loaded initially and default card gets selected (if there's at least one card).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also fixed in #856

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know...I can see it looks slightly different to my approach...I can either way for the other PR to make it in or try reflecting those changes here.

.takeWhen(self.selectButtonTappedProperty.signal)
.map { $0.id }

self.notifyDelegateOfCardSelected = Signal.merge(
creditCardInitial,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also fixed in #856

@@ -23,7 +23,7 @@ public protocol PledgeViewModelInputs {
paymentData: (displayName: String?, network: String?, transactionIdentifier: String)
)
func paymentAuthorizationViewControllerDidFinish()
func pledgeAmountDidUpdate(to amount: Double)
func pledgeAmountDidUpdate(_ amount: (value: Double, isValid: Bool))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also update the parameter name here from amount to maybe value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd be happy to...any ideas what to replace value to?

pledgeAmountDidUPdate(_ value: (???: Double, isValid: Bool))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose if we introduced a typealias like:

typealias PledgeAmountData = (amount: Double, isValid: Bool)

Then that would allow us to change the delegate to something like:

func pledgeAmountViewController(
  _ viewController: PledgeAmountViewController,
  didUpdateWith data: PledgeAmountData
)

Then it'd also help name our VM input on PledgeViewModel:

func pledgeAmountViewControllerDidUpdate(with data: PledgeAmountData)

Copy link
Contributor

@justinswart justinswart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty solid, just the one comment and merge conflict to resolve 👍

@@ -23,7 +23,7 @@ public protocol PledgeViewModelInputs {
paymentData: (displayName: String?, network: String?, transactionIdentifier: String)
)
func paymentAuthorizationViewControllerDidFinish()
func pledgeAmountDidUpdate(to amount: Double)
func pledgeAmountDidUpdate(_ amount: (value: Double, isValid: Bool))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose if we introduced a typealias like:

typealias PledgeAmountData = (amount: Double, isValid: Bool)

Then that would allow us to change the delegate to something like:

func pledgeAmountViewController(
  _ viewController: PledgeAmountViewController,
  didUpdateWith data: PledgeAmountData
)

Then it'd also help name our VM input on PledgeViewModel:

func pledgeAmountViewControllerDidUpdate(with data: PledgeAmountData)

@justinswart justinswart merged commit 32de6d1 into master Sep 30, 2019
@justinswart justinswart deleted the disable-pledge-button-on-invalid-input branch September 30, 2019 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants