mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
feat: cc account tracking 2
This commit is contained in:
1 parent
d2b18360ed
commit
38fa15ab97
4 files changed
+48
-12
No files matched your search
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { MagnifyingGlassIcon } from '@radix-ui/react-icons';
|
||||
import { InfoCircledIcon, MagnifyingGlassIcon } from '@radix-ui/react-icons';
|
||||
import {
|
||||
AlertDialog,
|
||||
Button,
|
||||
@@ -16,6 +16,7 @@ import PageWrapper from '../../../components/PageWrapper';
|
||||
import { UNLOCALIZED_REGION_NAMES_SHORT } from '../../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
||||
import { getAccountInfo } from '../../../core/blitz/getAccountInfo';
|
||||
import getTankStats from '../../../core/blitz/getTankStats';
|
||||
import { idToRegion } from '../../../core/blitz/idToRegion';
|
||||
import searchPlayersAcrossRegions, {
|
||||
AccountListWithServer,
|
||||
@@ -44,15 +45,34 @@ export default function Page() {
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (!session.tracking) return;
|
||||
if (!session.tracking || !input.current) return;
|
||||
|
||||
const accountInfo = await getAccountInfo(
|
||||
idToRegion(session.player.id),
|
||||
let accountInfo = await getAccountInfo(
|
||||
session.player.region,
|
||||
session.player.id,
|
||||
);
|
||||
let tankStats = await getTankStats(
|
||||
session.player.region,
|
||||
session.player.id,
|
||||
);
|
||||
|
||||
if (accountInfo === null) {
|
||||
if (login?.id === session.player.id) {
|
||||
accountInfo = await getAccountInfo(
|
||||
idToRegion(session.player.id),
|
||||
session.player.id,
|
||||
[],
|
||||
{ access_token: login.token },
|
||||
);
|
||||
tankStats = await getTankStats(
|
||||
idToRegion(session.player.id),
|
||||
session.player.id,
|
||||
{ access_token: login.token },
|
||||
);
|
||||
|
||||
console.log(accountInfo, tankStats);
|
||||
|
||||
input.current.value = accountInfo.nickname;
|
||||
} else {
|
||||
setShowFurtherVerification(true);
|
||||
}
|
||||
@@ -68,13 +88,15 @@ export default function Page() {
|
||||
<AlertDialog.Content>
|
||||
<AlertDialog.Title>We need further verification</AlertDialog.Title>
|
||||
<AlertDialog.Description>
|
||||
You're trying to track a CC account with private statistics.
|
||||
Please sign in to verify the ownership of this account.
|
||||
You're trying to track a CC account which have private statistics.
|
||||
Please sign in to verify the ownership of this account. Individual
|
||||
tank statistics won't be available.
|
||||
</AlertDialog.Description>
|
||||
|
||||
{login && (
|
||||
<AlertDialog.Description mt="2" color="red">
|
||||
You are currently signed with a different account.
|
||||
<InfoCircledIcon /> You are currently signed with a different
|
||||
account.
|
||||
</AlertDialog.Description>
|
||||
)}
|
||||
|
||||
|
||||
@@ -60,10 +60,12 @@ async function manageQueue() {
|
||||
}
|
||||
}
|
||||
|
||||
export type FetchBlitzParams = Record<string, string | number | undefined>;
|
||||
|
||||
export default function fetchBlitz<Data extends object>(
|
||||
region: Region,
|
||||
path: string,
|
||||
params: Record<string, string | number | undefined> = {},
|
||||
params: FetchBlitzParams = {},
|
||||
) {
|
||||
return new Promise<Data>((resolve) => {
|
||||
queue.push({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import fetchBlitz from './fetchBlitz';
|
||||
import fetchBlitz, { FetchBlitzParams } from './fetchBlitz';
|
||||
import { normalizeIds } from './normalizeIds';
|
||||
|
||||
export interface AllStats {
|
||||
@@ -95,10 +95,16 @@ export async function getAccountInfo<
|
||||
ReturnType = Ids extends number
|
||||
? IndividualAccountInfo
|
||||
: IndividualAccountInfo[],
|
||||
>(region: Region, ids: Ids, extra: string[] = []) {
|
||||
>(
|
||||
region: Region,
|
||||
ids: Ids,
|
||||
extra: string[] = [],
|
||||
params: FetchBlitzParams = {},
|
||||
) {
|
||||
const object = await fetchBlitz<AccountInfo>(region, 'account/info', {
|
||||
account_id: normalizeIds(ids),
|
||||
extra: extra.length === 0 ? undefined : extra.join(','),
|
||||
...params,
|
||||
});
|
||||
|
||||
if (typeof ids === 'number') {
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { TanksStats } from '../../types/tanksStats';
|
||||
import fetchBlitz from './fetchBlitz';
|
||||
import fetchBlitz, { FetchBlitzParams } from './fetchBlitz';
|
||||
|
||||
export default async function getTankStats(region: Region, id: number) {
|
||||
export default async function getTankStats(
|
||||
region: Region,
|
||||
id: number,
|
||||
|
||||
params?: FetchBlitzParams,
|
||||
) {
|
||||
const tankStats = await fetchBlitz<TanksStats>(region, 'tanks/stats', {
|
||||
account_id: id,
|
||||
...params,
|
||||
});
|
||||
|
||||
return tankStats[id];
|
||||
|
||||
Reference in new issue
Block a user