From c72bfa9f7175a91e67cdc39adb30b60075eda325 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Sun, 16 Jul 2023 18:15:34 +0000 Subject: [PATCH] feat: added rewards --- src/commands/ratings.tsx | 21 ++++++++---- .../Leaderboard/components/Item.tsx | 33 ++++++++++++++++++- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/commands/ratings.tsx b/src/commands/ratings.tsx index bd0f7d673..1b9959c63 100644 --- a/src/commands/ratings.tsx +++ b/src/commands/ratings.tsx @@ -96,7 +96,7 @@ export interface RatingsNeighbors { } console.log('Caching ratings info...'); -const ratingsLeagueInfo = fetch( +const ratingsInfo = fetch( 'https://na.wotblitz.com/en/api/rating-leaderboards/season/', ) .then((response) => response.json() as Promise) @@ -183,21 +183,28 @@ export const ratingsCommand: CommandRegistry = { const { nickname } = await getWargamingResponse( `https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`, ).then((accounts) => accounts[player.id]); - const leagueInfo = (await ratingsLeagueInfo).leagues[leagueIndex]; - const items = result - .slice(0, limit) - .map((player) => ( + const awaitedInfo = await ratingsInfo; + const leagueInfo = awaitedInfo.leagues[leagueIndex]; + const items = result.slice(0, limit).map((player) => { + const reward = awaitedInfo.rewards.find( + (reward) => + player.number >= reward.from_position && + player.number <= reward.to_position, + ); + + return ( - )); + ); + }); return ( diff --git a/src/components/Leaderboard/components/Item.tsx b/src/components/Leaderboard/components/Item.tsx index dbc3ac48e..1dc9df991 100644 --- a/src/components/Leaderboard/components/Item.tsx +++ b/src/components/Leaderboard/components/Item.tsx @@ -6,7 +6,7 @@ export interface ItemProps { deltaPosition?: number; points: number; deltaPoints?: number; - reward: RatingsReward; + reward?: RatingsReward; nickname: string; clan?: string; } @@ -99,6 +99,37 @@ export function Item({ )} + +
+ {reward && ( + + )} + {reward?.type === 'stuff' && ( + + x {reward.count} + + )} +
); }