mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: cleaner fetch blitz func
This commit is contained in:
1 parent
076785a9ad
commit
3e7a73c528
13 files changed
+82
-85
No files matched your search
@@ -3,7 +3,6 @@
|
|||||||
import { ContextMenu } from '@radix-ui/themes';
|
import { ContextMenu } from '@radix-ui/themes';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import * as Breakdown from '../../../components/Breakdown';
|
import * as Breakdown from '../../../components/Breakdown';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
|
||||||
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
||||||
import { resetSession } from '../../../core/blitzkrieg/resetSession';
|
import { resetSession } from '../../../core/blitzkrieg/resetSession';
|
||||||
import {
|
import {
|
||||||
@@ -88,10 +87,10 @@ export default function SessionPage({ naked = true }: SessionPageProps) {
|
|||||||
async function recalculateDiff() {
|
async function recalculateDiff() {
|
||||||
if (session.isTracking) {
|
if (session.isTracking) {
|
||||||
const { id, region } = session;
|
const { id, region } = session;
|
||||||
const careerRaw = await fetchBlitz<TanksStats>(
|
const careerRaw = await fetchBlitz<TanksStats>(region, 'tanks/stats', {
|
||||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
account_id: id,
|
||||||
);
|
});
|
||||||
const career = careerRaw[id].reduce<
|
const career = careerRaw[id]!.reduce<
|
||||||
Record<number, IndividualTankStats>
|
Record<number, IndividualTankStats>
|
||||||
>(
|
>(
|
||||||
(accumulator, curr) => ({
|
(accumulator, curr) => ({
|
||||||
@@ -103,7 +102,7 @@ export default function SessionPage({ naked = true }: SessionPageProps) {
|
|||||||
const awaitedTankDefinitions = await tankDefinitions;
|
const awaitedTankDefinitions = await tankDefinitions;
|
||||||
const awaitedTankAverages = await tankAverages;
|
const awaitedTankAverages = await tankAverages;
|
||||||
const careerWN8 =
|
const careerWN8 =
|
||||||
careerRaw[id].reduce(
|
careerRaw[id]!.reduce(
|
||||||
(accumulator, { tank_id, all }) =>
|
(accumulator, { tank_id, all }) =>
|
||||||
accumulator +
|
accumulator +
|
||||||
(awaitedTankAverages[tank_id] && all.battles > 0
|
(awaitedTankAverages[tank_id] && all.battles > 0
|
||||||
@@ -112,7 +111,7 @@ export default function SessionPage({ naked = true }: SessionPageProps) {
|
|||||||
: 0),
|
: 0),
|
||||||
0,
|
0,
|
||||||
) /
|
) /
|
||||||
careerRaw[id].reduce(
|
careerRaw[id]!.reduce(
|
||||||
(accumulator, { tank_id, all }) =>
|
(accumulator, { tank_id, all }) =>
|
||||||
accumulator +
|
accumulator +
|
||||||
(awaitedTankAverages[tank_id] && all.battles > 0
|
(awaitedTankAverages[tank_id] && all.battles > 0
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import {
|
|||||||
Region,
|
Region,
|
||||||
UNLOCALIZED_REGION_NAMES,
|
UNLOCALIZED_REGION_NAMES,
|
||||||
} from '../../../constants/regions';
|
} from '../../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
|
||||||
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
||||||
import { getClanAccountInfo } from '../../../core/blitz/getClanAccountInfo';
|
import { getClanAccountInfo } from '../../../core/blitz/getClanAccountInfo';
|
||||||
import getRatingInfo from '../../../core/blitz/getRatingInfo';
|
import getRatingInfo from '../../../core/blitz/getRatingInfo';
|
||||||
@@ -818,7 +817,9 @@ export default function Page() {
|
|||||||
} else {
|
} else {
|
||||||
setSearchLoading(true);
|
setSearchLoading(true);
|
||||||
const accountList = await fetchBlitz<AccountList>(
|
const accountList = await fetchBlitz<AccountList>(
|
||||||
`https://api.wotblitz.${region}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}`,
|
region,
|
||||||
|
'account/list',
|
||||||
|
{ search: encodedSearch },
|
||||||
);
|
);
|
||||||
const playerKeys = Object.keys(
|
const playerKeys = Object.keys(
|
||||||
leaderboard[region][season],
|
leaderboard[region][season],
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Locale } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { Region } from '../constants/regions';
|
import { Region } from '../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
|
||||||
import fetchBlitz from '../core/blitz/fetchBlitz';
|
import fetchBlitz from '../core/blitz/fetchBlitz';
|
||||||
import addClanChoices from '../core/discord/addClanChoices';
|
import addClanChoices from '../core/discord/addClanChoices';
|
||||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||||
@@ -49,17 +48,18 @@ export const searchClansCommand = new Promise<CommandRegistry>((resolve) => {
|
|||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const { translate } = translator(interaction.locale);
|
const { translate } = translator(interaction.locale);
|
||||||
const server = interaction.options.getString('region') as Region;
|
const region = interaction.options.getString('region') as Region;
|
||||||
const clan = interaction.options.getString('clan')!;
|
const clan = interaction.options.getString('clan')!;
|
||||||
const limit = interaction.options.getInteger('limit') ?? DEFAULT_LIMIT;
|
const limit = interaction.options.getInteger('limit') ?? DEFAULT_LIMIT;
|
||||||
const clanList = await fetchBlitz<ClanList>(
|
const clanList = await fetchBlitz<ClanList>(region, 'clans/list', {
|
||||||
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`,
|
search: clan,
|
||||||
);
|
limit,
|
||||||
|
});
|
||||||
|
|
||||||
return embedInfo(
|
return embedInfo(
|
||||||
translate('bot.commands.search_clans.body.title', [
|
translate('bot.commands.search_clans.body.title', [
|
||||||
markdownEscape(clan),
|
markdownEscape(clan),
|
||||||
translate(`common.regions.normal.${server}`),
|
translate(`common.regions.normal.${region}`),
|
||||||
]),
|
]),
|
||||||
clanList.length === 0
|
clanList.length === 0
|
||||||
? translate('bot.commands.search_clans.body.no_results')
|
? translate('bot.commands.search_clans.body.no_results')
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Locale } from 'discord.js';
|
import { Locale } from 'discord.js';
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { Region } from '../constants/regions';
|
import { Region } from '../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
|
||||||
import fetchBlitz from '../core/blitz/fetchBlitz';
|
import fetchBlitz from '../core/blitz/fetchBlitz';
|
||||||
import { AccountList } from '../core/blitz/searchPlayersAcrossRegions';
|
import { AccountList } from '../core/blitz/searchPlayersAcrossRegions';
|
||||||
import { usernamePattern } from '../core/blitz/searchPlayersAcrossRegions/constants';
|
import { usernamePattern } from '../core/blitz/searchPlayersAcrossRegions/constants';
|
||||||
@@ -50,22 +49,21 @@ export const searchPlayersCommand = new Promise<CommandRegistry>((resolve) => {
|
|||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const { translate } = translator(interaction.locale);
|
const { translate } = translator(interaction.locale);
|
||||||
const server = interaction.options.getString('region') as Region;
|
const region = interaction.options.getString('region') as Region;
|
||||||
const name = interaction.options.getString('username')!;
|
const name = interaction.options.getString('username')!;
|
||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||||
const trimmedSearch = name.trim();
|
const trimmedSearch = name.trim();
|
||||||
const players = usernamePattern.test(trimmedSearch)
|
const players = usernamePattern.test(trimmedSearch)
|
||||||
? await fetchBlitz<AccountList>(
|
? await fetchBlitz<AccountList>(region, 'account/list', {
|
||||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodeURIComponent(
|
search: trimmedSearch,
|
||||||
trimmedSearch,
|
limit,
|
||||||
)}&limit=${limit}`,
|
})
|
||||||
)
|
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
return embedInfo(
|
return embedInfo(
|
||||||
translate('bot.commands.search_players.body.title', [
|
translate('bot.commands.search_players.body.title', [
|
||||||
markdownEscape(trimmedSearch),
|
markdownEscape(trimmedSearch),
|
||||||
translate(`common.regions.normal.${server}`),
|
translate(`common.regions.normal.${region}`),
|
||||||
]),
|
]),
|
||||||
`\`\`\`${
|
`\`\`\`${
|
||||||
players.length === 0
|
players.length === 0
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { Region } from '../../constants/regions';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||||
import { patientFetch } from '../blitzkrieg/patientFetch';
|
import { patientFetch } from '../blitzkrieg/patientFetch';
|
||||||
|
|
||||||
type BlitzResponse<Data extends object> =
|
type BlitzResponse<Data extends object> =
|
||||||
@@ -58,10 +60,20 @@ async function manageQueue() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function fetchBlitz<Data extends object>(url: string) {
|
export default function fetchBlitz<Data extends object>(
|
||||||
|
region: Region,
|
||||||
|
path: string,
|
||||||
|
params: Record<string, string | number | undefined> = {},
|
||||||
|
) {
|
||||||
return new Promise<Data>((resolve) => {
|
return new Promise<Data>((resolve) => {
|
||||||
queue.push({
|
queue.push({
|
||||||
url,
|
url: `https://api.wotblitz.${region}/wotb/${path}/?${Object.entries({
|
||||||
|
application_id: WARGAMING_APPLICATION_ID,
|
||||||
|
...params,
|
||||||
|
})
|
||||||
|
.filter(([_, value]) => value !== undefined)
|
||||||
|
.map(([key, value]) => `${key}=${encodeURIComponent(value!)}`)
|
||||||
|
.join('&')}`,
|
||||||
resolve(data) {
|
resolve(data) {
|
||||||
resolve(data as Data);
|
resolve(data as Data);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
|
||||||
import fetchBlitz from './fetchBlitz';
|
import fetchBlitz from './fetchBlitz';
|
||||||
import { normalizeIds } from './normalizeIds';
|
import { normalizeIds } from './normalizeIds';
|
||||||
|
|
||||||
@@ -23,9 +22,9 @@ export async function getAccountAchievements<
|
|||||||
: IndividualAccountAchievements[],
|
: IndividualAccountAchievements[],
|
||||||
>(region: Region, ids: Ids) {
|
>(region: Region, ids: Ids) {
|
||||||
const object = await fetchBlitz<AccountAchievements>(
|
const object = await fetchBlitz<AccountAchievements>(
|
||||||
`https://api.wotblitz.${region}/wotb/account/achievements/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${normalizeIds(
|
region,
|
||||||
ids,
|
'account/achievements',
|
||||||
)}`,
|
{ account_id: normalizeIds(ids) },
|
||||||
);
|
);
|
||||||
|
|
||||||
if (typeof ids === 'number') {
|
if (typeof ids === 'number') {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
|
||||||
import fetchBlitz from './fetchBlitz';
|
import fetchBlitz from './fetchBlitz';
|
||||||
import { normalizeIds } from './normalizeIds';
|
import { normalizeIds } from './normalizeIds';
|
||||||
|
|
||||||
@@ -97,11 +96,10 @@ export async function getAccountInfo<
|
|||||||
? IndividualAccountInfo
|
? IndividualAccountInfo
|
||||||
: IndividualAccountInfo[],
|
: IndividualAccountInfo[],
|
||||||
>(region: Region, ids: Ids, extra: string[] = []) {
|
>(region: Region, ids: Ids, extra: string[] = []) {
|
||||||
const object = await fetchBlitz<AccountInfo>(
|
const object = await fetchBlitz<AccountInfo>(region, 'account/info', {
|
||||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${normalizeIds(
|
account_id: normalizeIds(ids),
|
||||||
ids,
|
extra: extra.length === 0 ? undefined : extra.join(','),
|
||||||
)}${extra.length === 0 ? '' : `&extra=${extra.join(',')}`}`,
|
});
|
||||||
);
|
|
||||||
|
|
||||||
if (typeof ids === 'number') {
|
if (typeof ids === 'number') {
|
||||||
return object[ids as number] as ReturnType;
|
return object[ids as number] as ReturnType;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
|
||||||
import fetchBlitz from './fetchBlitz';
|
import fetchBlitz from './fetchBlitz';
|
||||||
import { normalizeExtra } from './normalizeExtra';
|
|
||||||
import { normalizeIds } from './normalizeIds';
|
import { normalizeIds } from './normalizeIds';
|
||||||
|
|
||||||
type IndividualClanAccountInfo = {
|
type IndividualClanAccountInfo = {
|
||||||
@@ -30,11 +28,14 @@ export async function getClanAccountInfo<
|
|||||||
ReturnType = Ids extends number
|
ReturnType = Ids extends number
|
||||||
? IndividualClanAccountInfo
|
? IndividualClanAccountInfo
|
||||||
: IndividualClanAccountInfo[],
|
: IndividualClanAccountInfo[],
|
||||||
>(region: Region, ids: Ids, extra?: string[]) {
|
>(region: Region, ids: Ids, extra: string[] = []) {
|
||||||
const object = await fetchBlitz<ClanAccountInfo>(
|
const object = await fetchBlitz<ClanAccountInfo>(
|
||||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${normalizeIds(
|
region,
|
||||||
ids,
|
'clans/accountinfo',
|
||||||
)}${normalizeExtra(extra)}`,
|
{
|
||||||
|
account_id: normalizeIds(ids),
|
||||||
|
extra: extra.length === 0 ? undefined : extra.join(','),
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (typeof ids === 'number') {
|
if (typeof ids === 'number') {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
|
||||||
import fetchBlitz from './fetchBlitz';
|
import fetchBlitz from './fetchBlitz';
|
||||||
import { normalizeIds } from './normalizeIds';
|
import { normalizeIds } from './normalizeIds';
|
||||||
|
|
||||||
@@ -40,11 +39,9 @@ export async function getClanInfo<
|
|||||||
Ids extends number | number[],
|
Ids extends number | number[],
|
||||||
ReturnType = Ids extends number ? IndividualClanInfo : IndividualClanInfo[],
|
ReturnType = Ids extends number ? IndividualClanInfo : IndividualClanInfo[],
|
||||||
>(region: Region, ids: Ids) {
|
>(region: Region, ids: Ids) {
|
||||||
const object = await fetchBlitz<ClanInfo>(
|
const object = await fetchBlitz<ClanInfo>(region, 'clans/info', {
|
||||||
`https://api.wotblitz.${region}/wotb/clans/info/?application_id=${WARGAMING_APPLICATION_ID}&clan_id=${normalizeIds(
|
clan_id: normalizeIds(ids),
|
||||||
ids,
|
});
|
||||||
)}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (typeof ids === 'number') {
|
if (typeof ids === 'number') {
|
||||||
return object[ids as number] as ReturnType;
|
return object[ids as number] as ReturnType;
|
||||||
|
|||||||
@@ -1,19 +1,11 @@
|
|||||||
import { Locale } from 'discord.js';
|
|
||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
|
||||||
import { TanksStats } from '../../types/tanksStats';
|
import { TanksStats } from '../../types/tanksStats';
|
||||||
import { translator } from '../localization/translator';
|
|
||||||
import fetchBlitz from './fetchBlitz';
|
import fetchBlitz from './fetchBlitz';
|
||||||
|
|
||||||
export default async function getTankStats(
|
export default async function getTankStats(region: Region, id: number) {
|
||||||
region: Region,
|
const tankStats = await fetchBlitz<TanksStats>(region, 'tanks/stats', {
|
||||||
id: number,
|
account_id: id,
|
||||||
locale: Locale,
|
});
|
||||||
) {
|
|
||||||
const { t } = translator(locale);
|
|
||||||
const tankStats = await fetchBlitz<TanksStats>(
|
|
||||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return tankStats[id];
|
return tankStats[id];
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
|
||||||
import { ClanList } from '../../types/clanList';
|
import { ClanList } from '../../types/clanList';
|
||||||
import fetchBlitz from './fetchBlitz';
|
import fetchBlitz from './fetchBlitz';
|
||||||
|
|
||||||
@@ -15,9 +14,10 @@ export default async function searchClansAcrossRegions(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
fetchBlitz<ClanList>(
|
fetchBlitz<ClanList>('com', 'clans/list', {
|
||||||
`https://api.wotblitz.com/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
|
search,
|
||||||
).then((value) =>
|
limit: normalizedLimit,
|
||||||
|
}).then((value) =>
|
||||||
value
|
value
|
||||||
.map((account) => ({
|
.map((account) => ({
|
||||||
...account,
|
...account,
|
||||||
@@ -25,9 +25,10 @@ export default async function searchClansAcrossRegions(
|
|||||||
}))
|
}))
|
||||||
.splice(0, normalizedLimit),
|
.splice(0, normalizedLimit),
|
||||||
),
|
),
|
||||||
fetchBlitz<ClanList>(
|
fetchBlitz<ClanList>('eu', 'clans/list', {
|
||||||
`https://api.wotblitz.eu/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
|
search,
|
||||||
).then((value) =>
|
limit: normalizedLimit,
|
||||||
|
}).then((value) =>
|
||||||
value
|
value
|
||||||
.map((account) => ({
|
.map((account) => ({
|
||||||
...account,
|
...account,
|
||||||
@@ -35,9 +36,10 @@ export default async function searchClansAcrossRegions(
|
|||||||
}))
|
}))
|
||||||
.splice(0, normalizedLimit),
|
.splice(0, normalizedLimit),
|
||||||
),
|
),
|
||||||
fetchBlitz<ClanList>(
|
fetchBlitz<ClanList>('asia', 'clans/list', {
|
||||||
`https://api.wotblitz.asia/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
|
search,
|
||||||
).then((value) =>
|
limit: normalizedLimit,
|
||||||
|
}).then((value) =>
|
||||||
value
|
value
|
||||||
.map((account) => ({
|
.map((account) => ({
|
||||||
...account,
|
...account,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Region } from '../../../constants/regions';
|
import { Region } from '../../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
|
||||||
import fetchBlitz from '../fetchBlitz';
|
import fetchBlitz from '../fetchBlitz';
|
||||||
import { usernamePattern } from './constants';
|
import { usernamePattern } from './constants';
|
||||||
|
|
||||||
@@ -18,14 +17,14 @@ export default async function searchPlayersAcrossRegions(
|
|||||||
) {
|
) {
|
||||||
const trimmedSearch = search.trim();
|
const trimmedSearch = search.trim();
|
||||||
const normalizedLimit = Math.floor(limit / 3);
|
const normalizedLimit = Math.floor(limit / 3);
|
||||||
const encodedSearch = encodeURIComponent(trimmedSearch);
|
|
||||||
|
|
||||||
if (usernamePattern.test(trimmedSearch)) {
|
if (usernamePattern.test(trimmedSearch)) {
|
||||||
return (
|
return (
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
fetchBlitz<AccountList>(
|
fetchBlitz<AccountList>('com', 'account/list', {
|
||||||
`https://api.wotblitz.com/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
|
search,
|
||||||
).then(
|
limit: normalizedLimit,
|
||||||
|
}).then(
|
||||||
(value) =>
|
(value) =>
|
||||||
value &&
|
value &&
|
||||||
value.map((account) => ({
|
value.map((account) => ({
|
||||||
@@ -33,9 +32,10 @@ export default async function searchPlayersAcrossRegions(
|
|||||||
region: 'com' as Region,
|
region: 'com' as Region,
|
||||||
})),
|
})),
|
||||||
),
|
),
|
||||||
fetchBlitz<AccountList>(
|
fetchBlitz<AccountList>('eu', 'account/list', {
|
||||||
`https://api.wotblitz.eu/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
|
search,
|
||||||
).then(
|
limit: normalizedLimit,
|
||||||
|
}).then(
|
||||||
(value) =>
|
(value) =>
|
||||||
value &&
|
value &&
|
||||||
value.map((account) => ({
|
value.map((account) => ({
|
||||||
@@ -43,9 +43,10 @@ export default async function searchPlayersAcrossRegions(
|
|||||||
region: 'eu' as Region,
|
region: 'eu' as Region,
|
||||||
})),
|
})),
|
||||||
),
|
),
|
||||||
fetchBlitz<AccountList>(
|
fetchBlitz<AccountList>('asia', 'account/list', {
|
||||||
`https://api.wotblitz.asia/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
|
search,
|
||||||
).then(
|
limit: normalizedLimit,
|
||||||
|
}).then(
|
||||||
(value) =>
|
(value) =>
|
||||||
value &&
|
value &&
|
||||||
value.map((account) => ({
|
value.map((account) => ({
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
|
||||||
import { useSession } from '../../stores/session';
|
import { useSession } from '../../stores/session';
|
||||||
import { NormalizedTankStats, TanksStats } from '../../types/tanksStats';
|
import { NormalizedTankStats, TanksStats } from '../../types/tanksStats';
|
||||||
import fetchBlitz from '../blitz/fetchBlitz';
|
import fetchBlitz from '../blitz/fetchBlitz';
|
||||||
@@ -7,11 +6,9 @@ import fetchBlitz from '../blitz/fetchBlitz';
|
|||||||
export async function setSession(region: Region, id: number, nickname: string) {
|
export async function setSession(region: Region, id: number, nickname: string) {
|
||||||
// TODO: generalize this function and also check for more of these kind
|
// TODO: generalize this function and also check for more of these kind
|
||||||
const rawTankStats = (
|
const rawTankStats = (
|
||||||
await fetchBlitz<TanksStats>(
|
await fetchBlitz<TanksStats>(region, 'tanks/stats', { account_id: id })
|
||||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
)
|
|
||||||
)[id];
|
)[id];
|
||||||
const tankStats = rawTankStats.reduce<NormalizedTankStats>(
|
const tankStats = rawTankStats!.reduce<NormalizedTankStats>(
|
||||||
(accumulator, tank) => ({
|
(accumulator, tank) => ({
|
||||||
...accumulator,
|
...accumulator,
|
||||||
[tank.tank_id]: tank,
|
[tank.tank_id]: tank,
|
||||||
|
|||||||
Reference in new issue
Block a user