From 631efd1adcc0785b0f6de363a355a8952d10f4f8 Mon Sep 17 00:00:00 2001 From: Dominick Triola Date: Fri, 12 Jul 2019 08:09:49 -0700 Subject: [PATCH] Ask for confirmation when buying quests (#11251) * Trigger confirmation modal for quests that have a currency of gems https://github.com/HabitRPG/habitica/issues/11244 * Trigger purchase confirmation dialog for gold-purchasable quests * Refactor to use confirmPurchase method --- website/client/components/shops/buyModal.vue | 9 ++------- .../client/components/shops/quests/buyQuestModal.vue | 3 +++ website/client/mixins/buy.js | 10 ++++++++++ website/common/locales/en/character.json | 1 + 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/website/client/components/shops/buyModal.vue b/website/client/components/shops/buyModal.vue index 66a1478ce5..de3038cc18 100644 --- a/website/client/components/shops/buyModal.vue +++ b/website/client/components/shops/buyModal.vue @@ -402,13 +402,8 @@ return; } - if (this.item.currency === 'gems' && - !confirm(this.$t('purchaseFor', { cost: this.item.value * this.selectedAmountToBuy }))) { - return; - } - - if (this.item.currency === 'hourglasses' && - !confirm(this.$t('purchaseForHourglasses', { cost: this.item.value }))) { + const shouldConfirmPurchase = this.item.currency === 'gems' || this.item.currency === 'hourglasses'; + if (shouldConfirmPurchase && !this.confirmPurchase(this.item.currency, this.item.value * this.selectedAmountToBuy)) { return; } diff --git a/website/client/components/shops/quests/buyQuestModal.vue b/website/client/components/shops/quests/buyQuestModal.vue index f61e7138ba..bb7000a436 100644 --- a/website/client/components/shops/quests/buyQuestModal.vue +++ b/website/client/components/shops/quests/buyQuestModal.vue @@ -265,6 +265,9 @@ this.$emit('change', $event); }, buyItem () { + if (!this.confirmPurchase(this.item.currency, this.item.value * this.selectedAmountToBuy)) { + return; + } this.makeGenericPurchase(this.item, 'buyQuestModal', this.selectedAmountToBuy); this.purchased(this.item.text); this.hideDialog(); diff --git a/website/client/mixins/buy.js b/website/client/mixins/buy.js index f4240cab2f..7b709861e4 100644 --- a/website/client/mixins/buy.js +++ b/website/client/mixins/buy.js @@ -32,5 +32,15 @@ export default { this.$root.$emit('buyModal::boughtItem', item); }, + confirmPurchase (currency, cost) { + const currencyToPurchaseForKey = { + gems: 'purchaseFor', + gold: 'purchaseForGold', + hourglasses: 'purchaseForHourglasses', + }; + + const purchaseForKey = currencyToPurchaseForKey[currency]; + return confirm(this.$t(purchaseForKey, { cost })); + }, }, }; diff --git a/website/common/locales/en/character.json b/website/common/locales/en/character.json index 79a845437a..8a1d6160c6 100644 --- a/website/common/locales/en/character.json +++ b/website/common/locales/en/character.json @@ -169,6 +169,7 @@ "dieText": "You've lost a Level, all your Gold, and a random piece of Equipment. Arise, Habiteer, and try again! Curb those negative Habits, be vigilant in completion of Dailies, and hold death at arm's length with a Health Potion if you falter!", "sureReset": "Are you sure? This will reset your character's class and allocated Stat Points (you'll get them all back to re-allocate), and costs 3 Gems.", "purchaseFor": "Purchase for <%= cost %> Gems?", + "purchaseForGold": "Purchase for <%= cost %> Gold?", "purchaseForHourglasses": "Purchase for <%= cost %> Hourglasses?", "notEnoughMana": "Not enough mana.", "invalidTarget": "You can't cast a skill on that.",