From 07e3660388422fd459f3a77126eba986c638b848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 14 Oct 2023 10:58:48 -0500 Subject: [PATCH] feat: core chunk 3 --- .vscode/settings.json | 1 + .../blitz/fetchWargaming.ts} | 10 ++++------ src/_core/blitz/getAccountAchievements.ts | 4 ++-- src/_core/blitz/getAccountInfo.ts | 4 ++-- src/_core/blitz/getClanAccountInfo.ts | 4 ++-- src/_core/blitz/getClanInfo.ts | 4 ++-- src/{core => _core}/blitz/getRatingsInfo.ts | 2 +- src/{core => _core}/blitz/getTankStats.ts | 10 +++++----- src/{core => _core}/blitz/getTreeType.ts | 2 +- src/_core/blitzkrieg/emblemIdToURL.ts | 3 +++ src/app/embeds/session/page.tsx | 4 ++-- src/app/tools/session/page.tsx | 4 ++-- src/commands/evolution.tsx | 4 ++-- src/commands/fullStats.tsx | 4 ++-- src/commands/ownedTanks.tsx | 8 ++++---- src/commands/ratings.tsx | 2 +- src/commands/searchClans.ts | 4 ++-- src/commands/searchPlayers.ts | 4 ++-- src/commands/stats.tsx | 4 ++-- src/core/blitz/getClanLogo.ts | 3 --- src/core/blitz/listClans.ts | 8 ++++---- src/core/blitz/listPlayers.ts | 8 ++++---- src/core/blitz/tankopedia.ts | 8 ++++---- src/core/blitzstars/getTankHistories.ts | 2 +- src/renderers/today.tsx | 4 ++-- 25 files changed, 57 insertions(+), 58 deletions(-) rename src/{core/blitz/getWargamingResponse.ts => _core/blitz/fetchWargaming.ts} (66%) rename src/{core => _core}/blitz/getRatingsInfo.ts (82%) rename src/{core => _core}/blitz/getTankStats.ts (54%) rename src/{core => _core}/blitz/getTreeType.ts (83%) create mode 100644 src/_core/blitzkrieg/emblemIdToURL.ts delete mode 100644 src/core/blitz/getClanLogo.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 30edbe1b0..9a808967a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -43,6 +43,7 @@ "wargaming", "webp", "winrate", + "wotblitz", "zustand" ], "deno.enable": false, diff --git a/src/core/blitz/getWargamingResponse.ts b/src/_core/blitz/fetchWargaming.ts similarity index 66% rename from src/core/blitz/getWargamingResponse.ts rename to src/_core/blitz/fetchWargaming.ts index 2c4848455..ac8c2d1ba 100644 --- a/src/core/blitz/getWargamingResponse.ts +++ b/src/_core/blitz/fetchWargaming.ts @@ -1,6 +1,6 @@ -import throwError from '../node/throwError'; +import throwError from '../../core/node/throwError'; -export type WargamingResponse = +export type BlitzResponse = | { status: 'error'; error: { field: string; message: string; code: 402; value: null }; @@ -10,12 +10,10 @@ export type WargamingResponse = data: Data; }; -export default async function getWargamingResponse( - url: string, -) { +export default async function fetchBlitz(url: string) { const data = (await fetch(url).then((response) => response.json(), - )) as WargamingResponse; + )) as BlitzResponse; if (data.status === 'ok') { return data.data; diff --git a/src/_core/blitz/getAccountAchievements.ts b/src/_core/blitz/getAccountAchievements.ts index 52073afd3..edb21ca14 100644 --- a/src/_core/blitz/getAccountAchievements.ts +++ b/src/_core/blitz/getAccountAchievements.ts @@ -1,6 +1,6 @@ import { Region } from '../../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; -import getWargamingResponse from '../../core/blitz/getWargamingResponse'; +import fetchBlitz from './fetchWargaming'; import { normalizeIds } from './normalizeIds'; interface IndividualAccountAchievements { @@ -22,7 +22,7 @@ export async function getAccountAchievements< ? IndividualAccountAchievements : IndividualAccountAchievements[], >(region: Region, ids: Ids) { - const object = await getWargamingResponse( + const object = await fetchBlitz( `https://api.wotblitz.${region}/wotb/account/achievements/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${normalizeIds( ids, )}`, diff --git a/src/_core/blitz/getAccountInfo.ts b/src/_core/blitz/getAccountInfo.ts index 20e5c6644..5852ea073 100644 --- a/src/_core/blitz/getAccountInfo.ts +++ b/src/_core/blitz/getAccountInfo.ts @@ -1,6 +1,6 @@ import { Region } from '../../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; -import getWargamingResponse from '../../core/blitz/getWargamingResponse'; +import fetchBlitz from './fetchWargaming'; import { normalizeIds } from './normalizeIds'; export interface AllStats { @@ -75,7 +75,7 @@ export async function getAccountInfo< ? IndividualAccountInfo : IndividualAccountInfo[], >(region: Region, ids: Ids) { - const object = await getWargamingResponse( + const object = await fetchBlitz( `https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${normalizeIds( ids, )}`, diff --git a/src/_core/blitz/getClanAccountInfo.ts b/src/_core/blitz/getClanAccountInfo.ts index b25a32253..9fee45c89 100644 --- a/src/_core/blitz/getClanAccountInfo.ts +++ b/src/_core/blitz/getClanAccountInfo.ts @@ -1,6 +1,6 @@ import { Region } from '../../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; -import getWargamingResponse from '../../core/blitz/getWargamingResponse'; +import fetchBlitz from './fetchWargaming'; import { normalizeExtra } from './normalizeExtra'; import { normalizeIds } from './normalizeIds'; @@ -31,7 +31,7 @@ export async function getClanAccountInfo< ? IndividualClanAccountInfo : IndividualClanAccountInfo[], >(region: Region, ids: Ids, extra?: string[]) { - const object = await getWargamingResponse( + const object = await fetchBlitz( `https://api.wotblitz.${region}/wotb/clans/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${normalizeIds( ids, )}${normalizeExtra(extra)}`, diff --git a/src/_core/blitz/getClanInfo.ts b/src/_core/blitz/getClanInfo.ts index a28c9e740..625daca67 100644 --- a/src/_core/blitz/getClanInfo.ts +++ b/src/_core/blitz/getClanInfo.ts @@ -1,6 +1,6 @@ import { Region } from '../../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; -import getWargamingResponse from '../../core/blitz/getWargamingResponse'; +import fetchBlitz from './fetchWargaming'; import { normalizeIds } from './normalizeIds'; export interface IndividualClanInfo { @@ -40,7 +40,7 @@ export async function getClanInfo< Ids extends number | number[], ReturnType = Ids extends number ? IndividualClanInfo : IndividualClanInfo[], >(region: Region, ids: Ids) { - const object = await getWargamingResponse( + const object = await fetchBlitz( `https://api.wotblitz.${region}/wotb/clans/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${normalizeIds( ids, )}`, diff --git a/src/core/blitz/getRatingsInfo.ts b/src/_core/blitz/getRatingsInfo.ts similarity index 82% rename from src/core/blitz/getRatingsInfo.ts rename to src/_core/blitz/getRatingsInfo.ts index 56588cdac..8c4c85aa5 100644 --- a/src/core/blitz/getRatingsInfo.ts +++ b/src/_core/blitz/getRatingsInfo.ts @@ -1,6 +1,6 @@ import { RatingsInfo } from '../../commands/ratings'; import { Region } from '../../constants/regions'; -import regionToRegionSubdomain from './regionToRegionSubdomain'; +import regionToRegionSubdomain from '../../core/blitz/regionToRegionSubdomain'; export default async function getRatingsInfo(region: Region) { const response = await fetch( diff --git a/src/core/blitz/getTankStats.ts b/src/_core/blitz/getTankStats.ts similarity index 54% rename from src/core/blitz/getTankStats.ts rename to src/_core/blitz/getTankStats.ts index 8ff5766ba..bf1e3c60c 100644 --- a/src/core/blitz/getTankStats.ts +++ b/src/_core/blitz/getTankStats.ts @@ -1,18 +1,18 @@ -import { REGION_NAMES, Region } from '../../constants/regions'; +import { Region } from '../../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; +import throwError from '../../core/node/throwError'; import { TanksStats } from '../../types/tanksStats'; -import throwError from '../node/throwError'; -import getWargamingResponse from './getWargamingResponse'; +import fetchBlitz from './fetchWargaming'; export default async function getTankStats(region: Region, id: number) { - const tankStats = await getWargamingResponse( + const tankStats = await fetchBlitz( `https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); if (tankStats[id] === null) { throw throwError( 'No tank stats available', - `Wargaming says there is no tank stats for this account. This account may not have any battles/tanks or exist in the ${REGION_NAMES[region]} server.`, + "This player doesn't have any stats for tanks available. This may not be the player you are looking for.", ); } diff --git a/src/core/blitz/getTreeType.ts b/src/_core/blitz/getTreeType.ts similarity index 83% rename from src/core/blitz/getTreeType.ts rename to src/_core/blitz/getTreeType.ts index 5c5e4f1ec..ae43ca2fc 100644 --- a/src/core/blitz/getTreeType.ts +++ b/src/_core/blitz/getTreeType.ts @@ -1,5 +1,5 @@ import { TreeTypeEnum } from '../../components/Tanks'; -import { tankopedia } from './tankopedia'; +import { tankopedia } from '../../core/blitz/tankopedia'; export default async function getTreeType(id: number) { const entry = (await tankopedia)[id]; diff --git a/src/_core/blitzkrieg/emblemIdToURL.ts b/src/_core/blitzkrieg/emblemIdToURL.ts new file mode 100644 index 000000000..e07dd2ba8 --- /dev/null +++ b/src/_core/blitzkrieg/emblemIdToURL.ts @@ -0,0 +1,3 @@ +export function emblemIdToURL(emblemId: number) { + return `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${emblemId}.png`; +} diff --git a/src/app/embeds/session/page.tsx b/src/app/embeds/session/page.tsx index 2af6e33f6..95984a340 100644 --- a/src/app/embeds/session/page.tsx +++ b/src/app/embeds/session/page.tsx @@ -2,13 +2,13 @@ import { ContextMenu } from '@radix-ui/themes'; import { useEffect, useState } from 'react'; +import fetchBlitz from '../../../_core/blitz/fetchWargaming'; import calculateWN8 from '../../../_core/statistics/calculateWN8'; import { deltaTankStats } from '../../../_core/statistics/deltaTankStats'; import * as Breakdown from '../../../components/Breakdown'; import { TreeTypeEnum } from '../../../components/Tanks'; import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID'; import getWN8Percentile from '../../../core/blitz/getWN8Percentile'; -import getWargamingResponse from '../../../core/blitz/getWargamingResponse'; import { TankopediaEntry, tankopedia } from '../../../core/blitz/tankopedia'; import { tankAverages } from '../../../core/blitzstars/tankAverages'; import { useSession } from '../../../stores/session'; @@ -73,7 +73,7 @@ export default function SessionPage() { async function recalculateDiff() { if (session.isTracking) { const { id, region } = session; - const careerRaw = await getWargamingResponse( + const careerRaw = await fetchBlitz( `https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const career = careerRaw[id].reduce< diff --git a/src/app/tools/session/page.tsx b/src/app/tools/session/page.tsx index 906988e7f..a946386a7 100644 --- a/src/app/tools/session/page.tsx +++ b/src/app/tools/session/page.tsx @@ -18,10 +18,10 @@ import { } from '@radix-ui/themes'; import { debounce } from 'lodash'; import { ChangeEvent, useRef, useState } from 'react'; +import fetchBlitz from '../../../_core/blitz/fetchWargaming'; import PageWrapper from '../../../components/PageWrapper'; import { REGION_NAMES, Region } from '../../../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID'; -import getWargamingResponse from '../../../core/blitz/getWargamingResponse'; import listPlayers, { AccountListWithServer, } from '../../../core/blitz/listPlayers'; @@ -54,7 +54,7 @@ export default function Page() { input.current!.value = nickname; const rawTankStats = ( - await getWargamingResponse( + await fetchBlitz( `https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ) )[id]; diff --git a/src/commands/evolution.tsx b/src/commands/evolution.tsx index 6390302f4..c389bb632 100644 --- a/src/commands/evolution.tsx +++ b/src/commands/evolution.tsx @@ -4,11 +4,11 @@ import { } from 'discord.js'; import { getAccountInfo } from '../_core/blitz/getAccountInfo'; import { getClanAccountInfo } from '../_core/blitz/getClanAccountInfo'; +import { emblemIdToURL } from '../_core/blitzkrieg/emblemIdToURL'; import * as Graph from '../components/Graph'; import NoData, { NoDataType } from '../components/NoData'; import TitleBar from '../components/TitleBar'; import Wrapper from '../components/Wrapper'; -import { getClanLogo } from '../core/blitz/getClanLogo'; import resolveTankId from '../core/blitz/resolveTankId'; import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton'; import getPlayerHistories from '../core/blitzstars/getPlayerHistories'; @@ -41,7 +41,7 @@ async function render( ) { const accountInfo = await getAccountInfo(region, id); const clan = (await getClanAccountInfo(region, id))?.clan; - const logo = clan ? getClanLogo(clan.emblem_set_id) : undefined; + const logo = clan ? emblemIdToURL(clan.emblem_set_id) : undefined; const histories = await (type === 'player' ? getPlayerHistories(region, id, { start, diff --git a/src/commands/fullStats.tsx b/src/commands/fullStats.tsx index 08903fa3e..dcefd2a01 100644 --- a/src/commands/fullStats.tsx +++ b/src/commands/fullStats.tsx @@ -1,13 +1,13 @@ import { SlashCommandBuilder } from 'discord.js'; import { getAccountInfo } from '../_core/blitz/getAccountInfo'; import { getClanAccountInfo } from '../_core/blitz/getClanAccountInfo'; +import { emblemIdToURL } from '../_core/blitzkrieg/emblemIdToURL'; import { StatFilters, filterStats } from '../_core/statistics/filterStats'; import GenericAllStats from '../components/GenericAllStats'; import NoData, { NoDataType } from '../components/NoData'; import TierWeights from '../components/TierWeights'; import TitleBar from '../components/TitleBar'; import Wrapper from '../components/Wrapper'; -import { getClanLogo } from '../core/blitz/getClanLogo'; import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription'; import { getTierWeights } from '../core/blitzkrieg/getTierWeights'; import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton'; @@ -38,7 +38,7 @@ async function render( ) { const { nickname } = await getAccountInfo(region, id); const clan = (await getClanAccountInfo(region, id))?.clan; - const clanImage = clan ? getClanLogo(clan.emblem_set_id) : undefined; + const clanImage = clan ? emblemIdToURL(clan.emblem_set_id) : undefined; const diffedTankStats = await getDiffedTankStats(region, id, start, end); const { stats, supplementary, filteredOrder } = await filterStats( diffedTankStats, diff --git a/src/commands/ownedTanks.tsx b/src/commands/ownedTanks.tsx index 6c9870b63..b8a15792d 100644 --- a/src/commands/ownedTanks.tsx +++ b/src/commands/ownedTanks.tsx @@ -1,13 +1,13 @@ import { SlashCommandBuilder } from 'discord.js'; import { getAccountInfo } from '../_core/blitz/getAccountInfo'; import { getClanAccountInfo } from '../_core/blitz/getClanAccountInfo'; +import getTankStats from '../_core/blitz/getTankStats'; +import getTreeType from '../_core/blitz/getTreeType'; +import { emblemIdToURL } from '../_core/blitzkrieg/emblemIdToURL'; import NoData, { NoDataType } from '../components/NoData'; import * as Tanks from '../components/Tanks'; import TitleBar from '../components/TitleBar'; import Wrapper from '../components/Wrapper'; -import { getClanLogo } from '../core/blitz/getClanLogo'; -import getTankStats from '../core/blitz/getTankStats'; -import getTreeType from '../core/blitz/getTreeType'; import resolveTankName from '../core/blitz/resolveTankName'; import { TIER_ROMAN_NUMERALS, @@ -67,7 +67,7 @@ export const ownedTanksCommand: CommandRegistry = { name={accountInfo.nickname} image={ clanAccountInfo?.clan - ? getClanLogo(clanAccountInfo.clan.emblem_set_id) + ? emblemIdToURL(clanAccountInfo.clan.emblem_set_id) : undefined } description={`Tier ${TIER_ROMAN_NUMERALS[tier as Tier]} tanks`} diff --git a/src/commands/ratings.tsx b/src/commands/ratings.tsx index 4a909b35b..305a0723e 100644 --- a/src/commands/ratings.tsx +++ b/src/commands/ratings.tsx @@ -7,12 +7,12 @@ import { import { BlitzkriegRatingsLeaderboard } from '../../scripts/buildRatingsLeaderboard'; import { getAccountInfo } from '../_core/blitz/getAccountInfo'; import { getClanAccountInfo } from '../_core/blitz/getClanAccountInfo'; +import getRatingsInfo from '../_core/blitz/getRatingsInfo'; import getArchivedRatingsInfo from '../_core/blitzkrieg/getArchivedRatingsInfo'; import * as Leaderboard from '../components/Leaderboard'; import TitleBar from '../components/TitleBar'; import Wrapper from '../components/Wrapper'; import { REGION_NAMES_SHORT, Region } from '../constants/regions'; -import getRatingsInfo from '../core/blitz/getRatingsInfo'; import regionToRegionSubdomain from '../core/blitz/regionToRegionSubdomain'; import getMidnightLeaderboard, { DATABASE_REPO, diff --git a/src/commands/searchClans.ts b/src/commands/searchClans.ts index 28016ce85..dfe60053c 100644 --- a/src/commands/searchClans.ts +++ b/src/commands/searchClans.ts @@ -1,8 +1,8 @@ import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; +import fetchBlitz from '../_core/blitz/fetchWargaming'; import { REGION_NAMES, Region } from '../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; -import getWargamingResponse from '../core/blitz/getWargamingResponse'; import addClanChoices from '../core/discord/addClanChoices'; import addRegionChoices from '../core/discord/addRegionChoices'; import embedInfo from '../core/discord/embedInfo'; @@ -30,7 +30,7 @@ export const searchClansCommand: CommandRegistry = { const server = interaction.options.getString('region') as Region; const clan = interaction.options.getString('clan')!; const limit = interaction.options.getInteger('limit') ?? 25; - const clanList = await getWargamingResponse( + const clanList = await fetchBlitz( `https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`, ); diff --git a/src/commands/searchPlayers.ts b/src/commands/searchPlayers.ts index 87d66c640..8b2eacf8e 100644 --- a/src/commands/searchPlayers.ts +++ b/src/commands/searchPlayers.ts @@ -1,8 +1,8 @@ import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; +import fetchBlitz from '../_core/blitz/fetchWargaming'; import { REGION_NAMES, Region } from '../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; -import getWargamingResponse from '../core/blitz/getWargamingResponse'; import { AccountList, usernamePattern } from '../core/blitz/listPlayers'; import addRegionChoices from '../core/discord/addRegionChoices'; import addUsernameChoices from '../core/discord/addUsernameChoices'; @@ -34,7 +34,7 @@ export const searchPlayersCommand: CommandRegistry = { const limit = interaction.options.getInteger('limit') ?? 25; const trimmedSearch = name.trim(); const players = usernamePattern.test(trimmedSearch) - ? await getWargamingResponse( + ? await fetchBlitz( `https://api.wotblitz.${server}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodeURIComponent( trimmedSearch, )}&limit=${limit}`, diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 0c9ad0f76..0b5b0aa61 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -1,12 +1,12 @@ import { SlashCommandBuilder } from 'discord.js'; import { getAccountInfo } from '../_core/blitz/getAccountInfo'; import { getClanAccountInfo } from '../_core/blitz/getClanAccountInfo'; +import { emblemIdToURL } from '../_core/blitzkrieg/emblemIdToURL'; import { StatFilters, filterStats } from '../_core/statistics/filterStats'; import AllStatsOverview from '../components/AllStatsOverview'; import NoData, { NoDataType } from '../components/NoData'; import TitleBar from '../components/TitleBar'; import Wrapper from '../components/Wrapper'; -import { getClanLogo } from '../core/blitz/getClanLogo'; import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription'; import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton'; import getDiffedTankStats from '../core/blitzstars/getDiffedTankStats'; @@ -36,7 +36,7 @@ async function render( ) { const { nickname } = await getAccountInfo(region, id); const clan = (await getClanAccountInfo(region, id))?.clan; - const clanImage = clan ? getClanLogo(clan.emblem_set_id) : undefined; + const clanImage = clan ? emblemIdToURL(clan.emblem_set_id) : undefined; const diffedTankStats = await getDiffedTankStats(region, id, start, end); const { stats, supplementary } = await filterStats(diffedTankStats, filters); const filterDescriptions = await filtersToDescription(filters); diff --git a/src/core/blitz/getClanLogo.ts b/src/core/blitz/getClanLogo.ts deleted file mode 100644 index 17354e727..000000000 --- a/src/core/blitz/getClanLogo.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function getClanLogo(emblemId: number) { - return `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${emblemId}.png` -} \ No newline at end of file diff --git a/src/core/blitz/listClans.ts b/src/core/blitz/listClans.ts index a0475bd62..e047aed81 100644 --- a/src/core/blitz/listClans.ts +++ b/src/core/blitz/listClans.ts @@ -1,7 +1,7 @@ +import fetchBlitz from '../../_core/blitz/fetchWargaming'; import { Region } from '../../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; import { Clan, ClanList } from '../../types/clanList'; -import getWargamingResponse from './getWargamingResponse'; export type ClanListWithRegion = (Clan & { region: 'com' | 'eu' | 'asia'; @@ -14,7 +14,7 @@ export default async function listClans(search: string, limit = 9) { return ( await Promise.all([ - getWargamingResponse( + fetchBlitz( `https://api.wotblitz.com/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => @@ -24,7 +24,7 @@ export default async function listClans(search: string, limit = 9) { region: 'com' as Region, })), ), - getWargamingResponse( + fetchBlitz( `https://api.wotblitz.eu/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => @@ -34,7 +34,7 @@ export default async function listClans(search: string, limit = 9) { region: 'eu' as Region, })), ), - getWargamingResponse( + fetchBlitz( `https://api.wotblitz.asia/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => diff --git a/src/core/blitz/listPlayers.ts b/src/core/blitz/listPlayers.ts index 15f3bae99..0a4242b04 100644 --- a/src/core/blitz/listPlayers.ts +++ b/src/core/blitz/listPlayers.ts @@ -1,6 +1,6 @@ +import fetchBlitz from '../../_core/blitz/fetchWargaming'; import { Region } from '../../constants/regions'; import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; -import getWargamingResponse from './getWargamingResponse'; interface Account { nickname: string; @@ -22,7 +22,7 @@ export default async function listPlayers(search: string, limit = 9) { if (usernamePattern.test(trimmedSearch)) { return ( await Promise.all([ - getWargamingResponse( + fetchBlitz( `https://api.wotblitz.com/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => @@ -32,7 +32,7 @@ export default async function listPlayers(search: string, limit = 9) { region: 'com' as Region, })), ), - getWargamingResponse( + fetchBlitz( `https://api.wotblitz.eu/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => @@ -42,7 +42,7 @@ export default async function listPlayers(search: string, limit = 9) { region: 'eu' as Region, })), ), - getWargamingResponse( + fetchBlitz( `https://api.wotblitz.asia/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => diff --git a/src/core/blitz/tankopedia.ts b/src/core/blitz/tankopedia.ts index b77049f0f..a525d86bd 100644 --- a/src/core/blitz/tankopedia.ts +++ b/src/core/blitz/tankopedia.ts @@ -1,8 +1,8 @@ import { deburr } from 'lodash'; +import fetchBlitz from '../../_core/blitz/fetchWargaming'; +import { TreeTypeString } from '../../components/Tanks'; import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; import { context } from '../blitzkrieg/context'; -import getWargamingResponse from './getWargamingResponse'; -import { TreeTypeString } from '../../components/Tanks'; export interface TankopediaEntry { name: string; @@ -16,7 +16,7 @@ export interface TankopediaEntry { type: string; description: string; } -type asd = TreeTypeString +type asd = TreeTypeString; export interface Tankopedia { [id: number]: TankopediaEntry | undefined; } @@ -71,7 +71,7 @@ export interface TankopediaInfo { // this is blocking because info is needed for command creation console.log('Caching tankopedia info...'); -export const tankopediaInfo = getWargamingResponse( +export const tankopediaInfo = fetchBlitz( `https://api.wotblitz.com/wotb/encyclopedia/info/?application_id=${WARGAMING_APPLICATION_ID}`, ); console.log('Cached tankopedia info'); diff --git a/src/core/blitzstars/getTankHistories.ts b/src/core/blitzstars/getTankHistories.ts index 3b5ed9d14..b37a6b508 100644 --- a/src/core/blitzstars/getTankHistories.ts +++ b/src/core/blitzstars/getTankHistories.ts @@ -1,3 +1,4 @@ +import getTankStats from '../../_core/blitz/getTankStats'; import { Region } from '../../constants/regions'; import { GetHistoriesOptions, @@ -5,7 +6,6 @@ import { History, getHistoriesDefaultOptions, } from '../../types/histories'; -import getTankStats from '../blitz/getTankStats'; import { emptyAllStats } from './getDiffedTankStats'; export interface TankHistory extends History { diff --git a/src/renderers/today.tsx b/src/renderers/today.tsx index d4a908e2c..2496fefb6 100644 --- a/src/renderers/today.tsx +++ b/src/renderers/today.tsx @@ -1,12 +1,12 @@ import { AllStats, getAccountInfo } from '../_core/blitz/getAccountInfo'; import { getClanAccountInfo } from '../_core/blitz/getClanAccountInfo'; +import getTankStats from '../_core/blitz/getTankStats'; +import getTreeType from '../_core/blitz/getTreeType'; import calculateWN8 from '../_core/statistics/calculateWN8'; import * as Breakdown from '../components/Breakdown'; import NoData, { NoDataType } from '../components/NoData'; import TitleBar from '../components/TitleBar'; import Wrapper from '../components/Wrapper'; -import getTankStats from '../core/blitz/getTankStats'; -import getTreeType from '../core/blitz/getTreeType'; import getWN8Percentile from '../core/blitz/getWN8Percentile'; import resolveTankName from '../core/blitz/resolveTankName'; import sumStats from '../core/blitz/sumStats';