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-330] Set initial amount from Backing #863

Merged
merged 6 commits into from Oct 2, 2019

Conversation

justinswart
Copy link
Contributor

@justinswart justinswart commented Sep 30, 2019

πŸ“² What

Follow-up to #858, this sets the initial pledge amount to that of the Backing if it is set in the Project's Personalization.

βœ… Acceptance criteria

  • Navigate to Pledge for a live project, the initial amount should be that of the reward that you selected.
  • Back the project and navigate to Update Pledge, the initial pledge amount should be the amount that you backed it for.
  • The pledge amount that is shown does not include the shipping amount.

private func amountFromBacking(_ backing: Backing?) -> Double? {
guard let amount = backing?.amount else { return nil }

return amount - Double(backing?.shippingAmount ?? 0)
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 it's usually better when doing arithmetic using money types to use Decimal:

let shippingAmount: Double = backing?.shippingAmount ?? 0
let pledgeAmount = Decimal(amount) - Decimal(shippingAmount)

return (pledgeAmount as NSDecimalNumber).doubleValue

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yeah good point - although we seem to have been a little inconsistent with this πŸ€¦β€β™‚

https://github.com/kickstarter/ios-oss/blob/master/Library/ViewModels/BackingViewModel.swift#L176

But I'll change that here!

@justinswart justinswart mentioned this pull request Oct 1, 2019
1 task
let backing = Backing.template
|> Backing.lens.reward .~ Reward.postcards
|> Backing.lens.rewardId .~ Reward.postcards.id
|> Backing.lens.shippingAmount .~ 116
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd really chose some easier numbers here for better understanding of what's going on in here πŸ˜„

Copy link
Contributor

@dusi dusi left a comment

Choose a reason for hiding this comment

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

🚒 🚒 🚒
🚒 🚒 🚒
🚒 🚒 🚒

@justinswart justinswart merged commit c4ad2e1 into master Oct 2, 2019
@justinswart justinswart deleted the update-pledge-amount-from-backing branch October 2, 2019 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants