diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 52e0a4177..dca377759 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -71,12 +71,27 @@ export const eligibleCommand: CommandRegistry = { (await entries.reduce>( async (accumulator, [tankIdString, stats]) => { const tankId = parseInt(tankIdString); - const tankTier = (await tankopedia)[tankId].tier; + const tankopediaEntry = (await tankopedia)[tankId]; + + if (!tankopediaEntry) return accumulator; + + const tankTier = tankopediaEntry.tier; return (await accumulator) + tankTier * stats.battles; }, 0, - )) / stats.battles; + )) / + (await entries.reduce>( + async (accumulator, [tankIdString, stats]) => { + const tankId = parseInt(tankIdString); + const tankopediaEntry = (await tankopedia)[tankId]; + + if (!tankopediaEntry) return accumulator; + + return stats.battles; + }, + 0, + )); const WN8 = (await entries.reduce>( async (accumulator, [tankIdString, stats]) => { diff --git a/src/commands/ownedTanks.tsx b/src/commands/ownedTanks.tsx index 2d63ca6bd..3688ed767 100644 --- a/src/commands/ownedTanks.tsx +++ b/src/commands/ownedTanks.tsx @@ -7,6 +7,7 @@ import Wrapper from '../components/Wrapper.js'; import { BLITZ_SERVERS } from '../constants/servers.js'; import getTankStats from '../core/blitz/getTankStats.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; +import resolveTankName from '../core/blitz/resolveTankName.js'; import { TIER_ROMAN_NUMERALS, Tier, @@ -79,7 +80,10 @@ export const ownedTanksCommand: CommandRegistry = { const tankStats = await getTankStats(server, id); const tanks = ( await Promise.all( - tankStats.map(async (tankData) => (await tankopedia)[tankData.tank_id]), + tankStats.map(async (tankData) => ({ + ...(await tankopedia)[tankData.tank_id], + tank_id: tankData.tank_id, + })), ) ).filter((tank) => tank?.tier === tier); const clanData = await getWargamingResponse( @@ -106,14 +110,16 @@ export const ownedTanksCommand: CommandRegistry = { {tanks.length > 0 && ( - {tanks.map((tank) => ( - - ))} + {await Promise.all( + tanks.map(async (tank) => ( + + )), + )} )} diff --git a/src/components/AllStatsOverview/index.tsx b/src/components/AllStatsOverview/index.tsx index 3a2834d73..e1d309e4e 100644 --- a/src/components/AllStatsOverview/index.tsx +++ b/src/components/AllStatsOverview/index.tsx @@ -69,7 +69,9 @@ export default function AllStatsOverview({ > }
- + {type && ( + + )} + diff --git a/src/core/blitz/resolveTankName.ts b/src/core/blitz/resolveTankName.ts index 51ca38cea..8d3405c71 100644 --- a/src/core/blitz/resolveTankName.ts +++ b/src/core/blitz/resolveTankName.ts @@ -1,6 +1,6 @@ import { tankopedia } from './tankopedia.js'; export default async function resolveTankName(tankId: number) { - const tankopediaName = (await tankopedia)[tankId].name; + const tankopediaName = (await tankopedia)[tankId]?.name; return tankopediaName ? tankopediaName : `Unknown Tank ${tankId}`; } diff --git a/src/core/blitz/tankopedia.ts b/src/core/blitz/tankopedia.ts index d2b54cf41..4452a611d 100644 --- a/src/core/blitz/tankopedia.ts +++ b/src/core/blitz/tankopedia.ts @@ -13,7 +13,7 @@ export interface TankopediaEntry { } export interface Tankopedia { - [id: number]: TankopediaEntry; + [id: number]: TankopediaEntry | undefined; } console.log('Caching tankopedia...'); diff --git a/src/renderers/evolution.tsx b/src/renderers/evolution.tsx index 153d1a60b..26dec06bd 100644 --- a/src/renderers/evolution.tsx +++ b/src/renderers/evolution.tsx @@ -39,7 +39,7 @@ export default async function evolution( : undefined; } else { nameDiscriminator = `(${await resolveTankName(tankId!)})`; - image = (await tankopedia)[tankId!].images.normal; + image = (await tankopedia)[tankId!]?.images.normal; } let histories: Histories; diff --git a/src/renderers/stats.tsx b/src/renderers/stats.tsx index 03e0ef12f..6027869e1 100644 --- a/src/renderers/stats.tsx +++ b/src/renderers/stats.tsx @@ -49,7 +49,7 @@ export default async function stats( : undefined; } else if (type === 'tank') { nameDiscriminator = `(${await resolveTankName(tankId!)})`; - image = (await tankopedia)[tankId!].images.normal; + image = (await tankopedia)[tankId!]?.images.normal; } const tankStats = await getTankStatsDiffed(server, id, start, end); @@ -109,7 +109,11 @@ export default async function stats( tierWeights = await entries.reduce>( async (accumulator, [tankIdString, stats]) => { const tankId = parseInt(tankIdString); - const tier = (await tankopedia)[tankId].tier as Tier; + const tankopediaEntry = (await tankopedia)[tankId]; + + if (!tankopediaEntry) return accumulator; + + const tier = tankopediaEntry.tier as Tier; if ((await accumulator)[tier]) { (await accumulator)[tier]! += stats.battles; @@ -128,7 +132,7 @@ export default async function stats( WN8: stats ? calculateWN8((await tankAverages)[tankId!].all, tankStats[tankId!]) : undefined, - tier: (await tankopedia)[tankId!].tier, + tier: (await tankopedia)[tankId!]?.tier, }; } diff --git a/src/renderers/statsfull.tsx b/src/renderers/statsfull.tsx index c876c7bf9..cf2180786 100644 --- a/src/renderers/statsfull.tsx +++ b/src/renderers/statsfull.tsx @@ -47,7 +47,7 @@ export default async function statsfull( : undefined; } else if (type === 'tank') { nameDiscriminator = `(${await resolveTankName(tankId!)})`; - image = (await tankopedia)[tankId!].images.normal; + image = (await tankopedia)[tankId!]?.images.normal; } const tankStats = await getTankStatsDiffed(server, id, start, end); @@ -111,7 +111,7 @@ export default async function statsfull( if (!tankopediaEntry) return accumulator; - const tier = (await tankopedia)[tankId].tier as Tier; + const tier = tankopediaEntry.tier as Tier; if ((await accumulator)[tier]) { (await accumulator)[tier]! += stats.battles; @@ -128,7 +128,7 @@ export default async function statsfull( supplementaryStats = { WN8: calculateWN8((await tankAverages)[tankId!].all, tankStats[tankId!]), - tier: (await tankopedia)[tankId!].tier, + tier: (await tankopedia)[tankId!]?.tier, }; } diff --git a/src/renderers/today.tsx b/src/renderers/today.tsx index cd7f99a04..7183c2f5f 100644 --- a/src/renderers/today.tsx +++ b/src/renderers/today.tsx @@ -132,7 +132,7 @@ export default async function today({ server, id }: ResolvedPlayer) { icon={ tankId === 0 ? undefined - : (await tankopedia)[tankIdString as unknown as number].images + : (await tankopedia)[tankIdString as unknown as number]?.images .normal } /> diff --git a/src/types/accountInfo.ts b/src/types/accountInfo.ts index eae1a94d6..ab837d630 100644 --- a/src/types/accountInfo.ts +++ b/src/types/accountInfo.ts @@ -21,7 +21,7 @@ export interface AllStats { export interface SupplementaryStats { // if undefined, WN8 is not available for tanks without averages WN8?: number; - tier: number; + tier?: number; } export interface ClanStats {