Merge pull request #13 from houdiniproject/fix_for_partial_dollar_campaign_amounts

Fix for javascript failures when partial dollars are used for campaign gift levels
This commit is contained in:
Eric Schultz 2018-03-28 15:57:51 -05:00 committed by GitHub
commit 7fa0039d14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -17,6 +17,10 @@ format.camelToWords = function(str, os) {
format.dollarsToCents = function(dollars) {
dollars = dollars.toString().replace(/[$,]/g, '')
if(!isNaN(dollars) && dollars.match(/^-?\d+\.\d$/)) {
// could we use toFixed instead? Probably but this is straightforward.
dollars = dollars + "0"
}
if(isNaN(dollars) || !dollars.match(/^-?\d+(\.\d\d)?$/)) throw "Invalid dollar amount: " + dollars
return Math.round(Number(dollars) * 100)
}

View file

@ -187,7 +187,7 @@ function showSingleAmount(isRecurring, state) {
var desig = state.params$().designation
return h('section.u-centered', [
h('p.singleAmount-message', [
h('strong', app.currency_symbol + state.params$().single_amount)
h('strong', app.currency_symbol + format.centsToDollars(format.dollarsToCents(state.params$().single_amount)))
, h('span.u-padding--0', { class: {'u-hide': !isRecurring} }, ' monthly')
, h('span', {class: {'u-hide': !state.params$().designation && !gift.id}}, [ ' for ' + (desig || gift.name) ])
])