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-435] - Pledge maximum adding shipping rules #911

Merged
merged 20 commits into from
Oct 30, 2019

Conversation

Scollaco
Copy link
Contributor

📲 What

  • Includes shipping cost on maximum pledge amount.
  • Move minimum pledge label to above stepper.
  • Add an error label that appears when pledge amount is greater the maximum pledge amount.

🤔 Why

  • To make it easier for the user to see what's the maximum possible amount to pledge.

JIRA ticket

🛠 How

  • Passing the value of the shipping cost to the PledgeAmountViewModel and updating the max pledge by subtracting the currency's max pledge and shipping cost
  • Added a new Label to PledgeAmountViewController that appears whenever the amount is greater than the new max pledge amount

👀 See

max_pledge

♿️ Accessibility

  • Works with VoiceOver
  • Supports Dynamic Type

✅ Acceptance criteria

Project with no Shipping Rules:

  • Select a project with no Shipping Rules and type an amount greater than the maximum pledge amount (e.g $10000 for US projects). A label should appear with the text Please enter a pledge amount between [reward min] and [currency max pledge].
  • The Done button should be `disabled.

Project with Shipping Rules:

  • Select a project with Shipping Rules and type an amount equals to the currency max pledge amount (e.g $10000 for US projects) minus shipping Cost. Then select a new shipping rule with greater shipping cost. A label should appear with the text Please enter a pledge amount between [reward min] and [new max]
  • The Done button should be `disabled.

@Scollaco Scollaco changed the title Pledge maximum adding shipping rules [NT-435] - Pledge maximum adding shipping rules Oct 25, 2019
@@ -68,6 +68,8 @@ public protocol PledgeViewModelOutputs {
var submitButtonIsLoading: Signal<Bool, Never> { get }
var submitButtonTitle: Signal<String, Never> { get }
var title: Signal<String, Never> { get }
var updateMaximumPledgeAmount: Signal<Double, Never> { get }
var updatePledgeFailedWithError: Signal<String, Never> { get }
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this output re-added during a merge? I believe it's now removed on master.

@@ -156,6 +160,10 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge
let pledgeAmountIsValid = self.pledgeAmountDataSignal
.map { $0.isValid }

pledgeAmountIsValid.observeValues { v in
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 remove this?

Copy link
Contributor

Choose a reason for hiding this comment

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

lol who dis?

Copy link
Contributor Author

@Scollaco Scollaco Oct 29, 2019

Choose a reason for hiding this comment

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

Used for debugging purposes and missed it during cleanup. 🤦‍♂

project,
self.pledgeAmountDataSignal
)
.takeWhen(Signal.merge(showApplePayAlert))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this .merge?

@@ -575,6 +583,8 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge

self.notifyDelegateUpdatePledgeDidSucceedWithMessage = updateBackingCompletionEvents
.mapConst(Strings.Got_it_your_changes_have_been_saved())
self.updatePledgeFailedWithError = updateBackingEvent.errors()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is removed on master.

@@ -15,6 +15,7 @@ public protocol PledgeAmountViewModelInputs {
func stepperValueChanged(_ value: Double)
func textFieldDidEndEditing(_ value: String?)
func textFieldValueChanged(_ value: String?)
func updateMaximumPledgeAmount(with shippingCost: Double)
Copy link
Contributor

Choose a reason for hiding this comment

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

The input should be named based on the event that occurred, so in this case I think it's selectedShippingAmountChanged(to amount: Double).

let maxValue = minAndMax
.map(second)
.combineLatest(with: shippingCost)
.map { max, shippingCost in
Copy link
Contributor

Choose a reason for hiding this comment

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

Swift is so fancy this can actually be .map(-) 😄

@@ -156,6 +160,10 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge
let pledgeAmountIsValid = self.pledgeAmountDataSignal
.map { $0.isValid }

pledgeAmountIsValid.observeValues { v in
Copy link
Contributor

Choose a reason for hiding this comment

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

lol who dis?

@@ -706,6 +716,8 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge
public let submitButtonIsLoading: Signal<Bool, Never>
public let submitButtonTitle: Signal<String, Never>
public let title: Signal<String, Never>
public let updateMaximumPledgeAmount: Signal<Double, Never>
public let updatePledgeFailedWithError: Signal<String, Never>
Copy link
Contributor

Choose a reason for hiding this comment

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

☝️

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.

Cool 🚢 after these last changes!

@@ -156,6 +163,10 @@ final class PledgeAmountViewController: UIViewController {
@objc func textFieldDidChange(_ textField: UITextField) {
self.viewModel.inputs.textFieldValueChanged(textField.text)
}

func selectedShippingAmountChanged(to amount: Double) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we put this under // MARK: - Accessors

@@ -117,6 +118,8 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge

let pledgeTotal = Signal.combineLatest(pledgeAmount, shippingCost).map(+)

self.selectedShippingAmountChanged = shippingCost
Copy link
Contributor

Choose a reason for hiding this comment

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

So typically we'd want this sort of information to be sent via a delegate but in this case our PledgeViewController will have two delegates 🤔. I think this is a bit of an anti-pattern and points to a larger architectural problem that we have with our VCs talking directly to each other. I have thoughts on how we can improve this but it's outside the scope of this work.

In any case, I would suggest at least renaming this output to make what this is doing a bit clearer - something like notifyPledgeAmountViewControllerShippingAmountChanged.

We're likely going to want to do some refactoring here down the line but I don't want to hold this up to do that right now.

Please make this change before merging though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree with that and I think it will be a fun problem to solve. A discussion in this topic with the team would be worth it. But for now, thanks for you input 😄

@Scollaco Scollaco merged commit 2a206e2 into master Oct 30, 2019
@Scollaco Scollaco deleted the pledge-maximum-adding-shipping-rules branch October 30, 2019 15:23
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