Files
habitica/website/client/mixins/buy.js
Dominick Triola 631efd1adc 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
2019-07-12 17:09:49 +02:00

47 lines
1.2 KiB
JavaScript

export default {
methods: {
async makeGenericPurchase (item, type = 'buyModal', quantity = 1) {
try {
await this.$store.dispatch('shops:genericPurchase', {
pinType: item.pinType,
type: item.purchaseType,
key: item.key,
currency: item.currency,
quantity,
});
} catch (e) {
if (!e.request) {
// axios request errors already handled by app.vue
this.$store.dispatch('snackbars:add', {
title: '',
text: e.message,
type: 'error',
});
return;
} else {
throw e;
}
}
this.$root.$emit('playSound', 'Reward');
if (type !== 'buyModal') {
this.$emit('buyPressed', this.item);
return;
}
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 }));
},
},
};