Files
blitzkit/packages/website/src/components/WargamingAccountName.tsx
T

24 lines
735 B
TypeScript
Raw Normal View History

2025-09-27 18:28:35 -05:00
import { getAccountInfo, idToRegion } from "@blitzkit/core";
import { Text } from "@radix-ui/themes";
import { useMemo } from "react";
import usePromise from "react-promise-suspense";
import { App } from "../stores/app";
export function WargamingAccountName() {
2024-10-09 21:04:49 -05:00
const wargaming = App.use((state) => state.logins.wargaming);
2024-09-14 19:43:14 -05:00
const promise = useMemo(async () => {
2024-10-09 21:04:49 -05:00
if (!wargaming) return null;
2024-09-14 19:43:14 -05:00
const data = await getAccountInfo(
2024-10-09 21:04:49 -05:00
idToRegion(wargaming.id),
wargaming.id,
2024-09-14 19:43:14 -05:00
[],
2025-09-27 18:28:35 -05:00
{ access_token: wargaming.token }
2024-09-14 19:43:14 -05:00
);
return data?.nickname as string | undefined;
2024-09-21 20:26:58 -05:00
}, [wargaming]);
2024-09-14 19:43:14 -05:00
const nickname = usePromise(() => promise, []);
return nickname ?? <Text color="gray">Unknown Account</Text>;
}