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