Skip to content

Commit

Permalink
♻️ [api] use userinfo instead of credits api
Browse files Browse the repository at this point in the history
  • Loading branch information
jxn-30 committed Jul 13, 2024
1 parent b498eb5 commit 2f9ab7b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/modules/creditsextension/creditsextension.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ import { mapState } from 'pinia';
import { defineAPIStore, useAPIStore } from '@stores/api';
import { defineRootStore, useRootStore } from '@stores/index';
import type { CreditsInfo } from 'typings/api/Credits';
import type { IconDefinition } from '@fortawesome/fontawesome-svg-core';
import type { UserInfo } from 'typings/api/UserInfo';
import type VueI18n from 'vue-i18n';
export default Vue.extend<
Expand Down Expand Up @@ -230,7 +230,7 @@ export default Vue.extend<
highlight(): void;
},
{
creditsAPI: CreditsInfo;
creditsAPI: UserInfo;
credits: number;
creditsLocalized: string;
coins: number;
Expand Down Expand Up @@ -299,7 +299,7 @@ export default Vue.extend<
computed: {
...mapState(defineRootStore, ['credits', 'coins']),
...mapState(defineAPIStore, {
creditsAPI: 'credits',
creditsAPI: 'userinfo',
}),
creditsLocalized() {
return this.credits.toLocaleString();
Expand Down Expand Up @@ -382,7 +382,7 @@ export default Vue.extend<
'alerts'
).then(({ value: alerts }) => {
if (!alerts.length)
return useAPIStore().getCredits('creditsextension-initial');
return useAPIStore().getUserInfo('creditsextension-initial');
const alertValues = alerts.map(({ credits }) => credits).sort();
Expand All @@ -403,7 +403,7 @@ export default Vue.extend<
});
useAPIStore()
.getCredits('creditsextension-alerts-initial')
.getUserInfo('creditsextension-alerts-initial')
.then(
({ credits_user_current }) =>
(this.alertProgressPercentage =
Expand Down
4 changes: 2 additions & 2 deletions src/modules/redesign/components/coins/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default Vue.extend<
data() {
moment.locale(this.lightbox.rootStore.locale);
const apiStore = useAPIStore();
apiStore.getCredits('redesign/coins/list').then();
apiStore.getUserInfo('redesign/coins/list').then();
return {
moment,
search: '',
Expand Down Expand Up @@ -247,7 +247,7 @@ export default Vue.extend<
}).toString();
},
timestamps() {
let lastCoins = this.apiStore.credits.coins_user_current;
let lastCoins = this.apiStore.userinfo.coins_user_current;
const timestamps: [number, number][] = [[Date.now(), lastCoins]];
Expand Down
2 changes: 1 addition & 1 deletion src/modules/redesign/components/lightbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ export default Vue.extend<
const mountFeature = 'redesign-lightbox-mount';
this.apiStore.getAllianceInfo(mountFeature).then();
this.apiStore.getBuildings(mountFeature).then();
this.apiStore.getCredits(mountFeature).then();
this.apiStore.getUserInfo(mountFeature).then();
this.apiStore.getVehicles(mountFeature).then();
},
mounted() {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/telemetry/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default (
};

LSSM.$stores.api
.getCredits('telemetry')
.getUserInfo('telemetry')
.then(async ({ user_directplay_registered }) => {
if (user_directplay_registered) return;

Expand Down
11 changes: 6 additions & 5 deletions src/stores/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import MissionsWorker, {

import type { AllianceInfo } from 'typings/api/AllianceInfo';
import type { Building } from 'typings/Building';
import type { CreditsInfo } from 'typings/api/Credits';
import type { Mission } from 'typings/Mission';
import type { Schooling } from 'typings/api/Schoolings';
import type { Settings } from 'typings/api/Settings';
import type { UserInfo } from 'typings/api/UserInfo';
import type { Vehicle } from 'typings/Vehicle';
import type { BuildingMarkerAdd, RadioMessage } from 'typings/Ingame';

Expand All @@ -46,7 +46,7 @@ export interface APIs {
buildings: Record<Building['id'], Building>;
alliance_buildings: Record<Building['id'], Building>;
allianceinfo: AllianceInfo;
credits: CreditsInfo;
userinfo: UserInfo;
settings: Settings;
schoolings: Schooling[];
alliance_schoolings: Schooling[];
Expand Down Expand Up @@ -92,7 +92,7 @@ export const defineAPIStore = defineStore('api', () => {
finance_active: false,
users: [],
}),
credits: ref<APIs['credits']>({
userinfo: ref<APIs['userinfo']>({
credits_user_current: 0,
credits_user_total: 0,
user_name: '',
Expand Down Expand Up @@ -857,8 +857,9 @@ export const defineAPIStore = defineStore('api', () => {
// allianceinfo
getAllianceInfo: (feature: string) =>
_getStoredOrFetch('allianceinfo', feature),
// credits API
getCredits: (feature: string) => _getStoredOrFetch('credits', feature),
// userinfo API
getUserInfo: (feature: string) =>
_getStoredOrFetch('userinfo', feature),
// settings API
getSettings: (feature: string) =>
_getStoredOrFetch('settings', feature),
Expand Down
6 changes: 3 additions & 3 deletions src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ export const defineRootStore = defineStore('root', {
const old = this.credits;
this.credits = credits;
const apiStore = useAPIStore();
if (apiStore.credits) {
apiStore.credits.credits_user_current = credits;
if (apiStore.userinfo) {
apiStore.userinfo.credits_user_current = credits;
const diff = credits - old;
window.dispatchEvent(
new CustomEvent(`${PREFIX}_credits_update`, {
detail: { old, new: credits, diff },
})
);
if (diff > 0) apiStore.credits.credits_user_total += diff;
if (diff > 0) apiStore.userinfo.credits_user_total += diff;
}
},
updateCoins(coins: number) {
Expand Down
2 changes: 1 addition & 1 deletion typings/api/Credits.d.ts → typings/api/UserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Types for in game credits API `api/credits`.
*/

export interface CreditsInfo {
export interface UserInfo {
credits_user_current: number;
credits_user_total: number;
credits_alliance_current?: number;
Expand Down

0 comments on commit 2f9ab7b

Please sign in to comment.