mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
* 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
47 lines
1.2 KiB
JavaScript
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 }));
|
|
},
|
|
},
|
|
};
|