2024-09-08 10:17:40 -05:00
|
|
|
import { getAccountInfo, idToRegion } from '@blitzkit/core';
|
2024-09-03 22:10:57 -05:00
|
|
|
import { Text } from '@radix-ui/themes';
|
2024-09-14 19:43:14 -05:00
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
import usePromise from 'react-promise-suspense';
|
2024-10-09 21:04:49 -05:00
|
|
|
import { App } from '../stores/app';
|
2024-09-03 22:10:57 -05:00
|
|
|
|
|
|
|
|
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
|
|
|
[],
|
2024-10-09 21:04:49 -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, []);
|
2024-09-03 22:10:57 -05:00
|
|
|
|
|
|
|
|
return nickname ?? <Text color="gray">Unknown Account</Text>;
|
|
|
|
|
}
|