Files
habitica/website/client/store/actions/shops.js
T
Keith Holliday 39d7581c6c Merge Develop onto Release (#9123)
* Some random quick (#9111)

* Switch group button directions

* Allowed admins to export challenges

* Added scoping to some stable styles

* Fixed challenge cloning

* Tasks tags (#9112)

* Added auto apply and exit

* Add challenge tag editing

* Fixed lint

* Skill fixes (#9113)

* Added local storage setting for spell drawer

* Added new spell styles

* Fixed typo

* Reset local creds if access is denied (#9114)

* various fixes: group leader's name at top of edit drop-down; Members List; etc (#9117)

* fix text describing location of subscription/gem gift box

* disable Copy As To-Do in Tavern, guilds, party because it's not working

* change members label on group pages to Member List

* remove outdated info about seeing number of Gems available to buy

* allow Danger Zone to be seen by players without local authentication

Also add an hr because the Danger Zone heading was crammed up against the button above it.

* put current group leader's name at top of Leader change drop-down

* Client Fixes (#9120)

* unduplicate logout code

* re-enable debug menu

* fix pets badge and equipping mounts

* close gift modal after sending gems

* armoire notifications

* Oct 1 fixes (#9121)

* Added default tags to task

* Added seasonal gear check and show spooky

* Disabled spooky sparkles

* Fixed challenge remove tasks modal

* Hid checklist

* Added group gems modal

* Purchase with amazon

* Added check for user health

* Added missing notification file
2017-10-01 20:42:02 -05:00

134 lines
3.9 KiB
JavaScript

import axios from 'axios';
import buyOp from 'common/script/ops/buy';
import buyQuestOp from 'common/script/ops/buyQuest';
import purchaseOp from 'common/script/ops/purchaseWithSpell';
import buyMysterySetOp from 'common/script/ops/buyMysterySet';
import hourglassPurchaseOp from 'common/script/ops/hourglassPurchase';
import sellOp from 'common/script/ops/sell';
import unlockOp from 'common/script/ops/unlock';
import buyArmoire from 'common/script/ops/buyArmoire';
import rerollOp from 'common/script/ops/reroll';
import { getDropClass } from 'client/libs/notifications';
export function buyItem (store, params) {
const user = store.state.user.data;
let opResult = buyOp(user, {params});
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/buy/${params.key}`),
};
}
export function buyQuestItem (store, params) {
const user = store.state.user.data;
let opResult = buyQuestOp(user, {params});
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/buy-quest/${params.key}`),
};
}
export function purchase (store, params) {
const user = store.state.user.data;
let opResult = purchaseOp(user, {params});
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/purchase/${params.type}/${params.key}`),
};
}
export function purchaseMysterySet (store, params) {
const user = store.state.user.data;
let opResult = buyMysterySetOp(user, {params, noConfirm: true});
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/buy-mystery-set/${params.key}`),
};
}
export function purchaseHourglassItem (store, params) {
const user = store.state.user.data;
let opResult = hourglassPurchaseOp(user, {params});
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/purchase-hourglass/${params.type}/${params.key}`),
};
}
export function unlock (store, params) {
const user = store.state.user.data;
let opResult = unlockOp(user, params);
return {
result: opResult,
httpCall: axios.post(`/api/v3/user/unlock?path=${params.query.path}`),
};
}
export function genericPurchase (store, params) {
switch (params.pinType) {
case 'mystery_set':
return purchaseMysterySet(store, params);
case 'armoire': // eslint-disable-line
let buyResult = buyArmoire(store.state.user.data);
// @TODO: We might need to abstract notifications to library rather than mixin
if (buyResult[1]) {
const resData = buyResult[0];
const item = resData.armoire;
store.state.notificationStore.push({
title: '',
text: buyResult[1],
type: item.type === 'experience' ? 'xp' : 'drop',
icon: item.type === 'experience' ? null : getDropClass({type: item.type, key: item.dropKey}),
timeout: true,
});
}
axios.post('/api/v3/user/buy-armoire');
return;
case 'fortify': {
let rerollResult = rerollOp(store.state.user.data);
axios.post('/api/v3/user/reroll');
return rerollResult;
}
case 'rebirth_orb':
return store.dispatch('user:rebirth');
case 'potion':
case 'marketGear':
return buyItem(store, params);
case 'background':
return unlock(store, {
query: {
path: `background.${params.key}`,
},
});
default:
if (params.pinType === 'quests' && params.currency === 'gold') {
return buyQuestItem(store, params);
} else if (params.currency === 'hourglasses') {
return purchaseHourglassItem(store, params);
} else {
return purchase(store, params);
}
}
}
export function sellItems (store, params) {
const user = store.state.user.data;
sellOp(user, {params, query: {amount: params.amount}});
axios
.post(`/api/v3/user/sell/${params.type}/${params.key}?amount=${params.amount}`);
// TODO
// .then((res) => console.log('equip', res))
// .catch((err) => console.error('equip', err));
}