Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1001 from OpenBazaar/fixPurchaseNoMods
Browse files Browse the repository at this point in the history
Fix purchase no mods
  • Loading branch information
rmisio authored Oct 12, 2017
2 parents 89424fd + a422942 commit 0fcf63a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion js/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,8 @@
"noItems": "You must make at least one purchase.",
"missingAddress": "Please choose a valid shipping address.",
"missingShippingOption": "Please choose a valid shipping option.",
"needsModerator": "You must select a moderator to make a Moderated Payment."
"needsModerator": "You must select a moderator to make a Moderated Payment.",
"removeModerator": "An unmoderated purchase cannot have a moderator."
},
"orderFulfillmentModelErrors": {
"provideShipper": "Please provide a shipping carrier.",
Expand Down
5 changes: 5 additions & 0 deletions js/models/purchase/Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export default class extends BaseModel {
addError('moderated', app.polyglot.t('orderModelErrors.needsModerator'));
}

if (!this.moderated && attrs.moderator) {
// this should only happen if there is a developer error
addError('moderated', app.polyglot.t('orderModelErrors.removeModerator'));
}

if (Object.keys(errObj).length) return errObj;

return undefined;
Expand Down
1 change: 0 additions & 1 deletion js/templates/modals/purchase/purchase.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ <h2 class="h4 required"><%= ob.polyT('purchase.paymentTypeTitle') %></h2>
<input
type="checkbox"
name="moderated"
checked
id="purchaseModerated">
<label for="purchaseModerated"><%= ob.polyT('purchase.moderatedPayment') %></label>
<p class="clrT2 tx6">
Expand Down
12 changes: 7 additions & 5 deletions js/views/modals/purchase/Purchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export default class extends BaseModal {
this.getCachedEl('.js-moderatorNote').toggleClass('hide', !bool);
if (!bool) this.disableModerators();
this.order.moderated = bool;
this.getCachedEl('#purchaseModerated').prop('checked', bool);
this.moderators.noneSelected = !bool;
}

Expand Down Expand Up @@ -346,9 +347,10 @@ export default class extends BaseModal {
}

// set the moderator
if (this.order.moderated) {
this.order.set({ moderator: this.moderators.selectedIDs[0] }, { validate: true });
}
const moderator = this.order.moderated ? this.moderators.selectedIDs[0] : '';
this.order.set({ moderator });
this.order.set({}, { validate: true });


// cancel any existing order
if (this.orderSubmit) this.orderSubmit.abort();
Expand Down Expand Up @@ -475,7 +477,7 @@ export default class extends BaseModal {
if (cur !== 'BTC') {
btcTotal = convertCurrency(btcTotal, cur, 'BTC');
}
const allowModeration = btcTotal >= this.minModPrice;
const allowModeration = btcTotal >= this.minModPrice && this.moderatorIDs.length;
this.moderationOn(allowModeration);
this.getCachedEl('.js-modsNotAllowed').toggleClass('hide', allowModeration);
}
Expand Down Expand Up @@ -536,7 +538,7 @@ export default class extends BaseModal {
prices: this.prices,
minModPrice: this.minModPrice,
displayCurrency: app.settings.get('localCurrency'),
hasModerators: this.moderatorIDs.length,
hasModerators: !!this.moderatorIDs.length,
}));

super.render();
Expand Down

0 comments on commit 0fcf63a

Please sign in to comment.