2024-09-08 10:17:40 -05:00
|
|
|
import { getAccountInfo, idToRegion } from '@blitzkit/core';
|
2024-09-14 19:43:14 -05:00
|
|
|
import { useStore } from '@nanostores/react';
|
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-09-15 14:51:01 -05:00
|
|
|
import { $wargamingLogin } from '../stores/wargamingLogin';
|
2024-09-03 22:10:57 -05:00
|
|
|
|
|
|
|
|
export function WargamingAccountName() {
|
2024-09-21 20:26:58 -05:00
|
|
|
const wargaming = useStore($wargamingLogin);
|
2024-09-14 19:43:14 -05:00
|
|
|
const promise = useMemo(async () => {
|
2024-09-21 20:26:58 -05:00
|
|
|
if (!wargaming.token) return null;
|
2024-09-14 19:43:14 -05:00
|
|
|
|
|
|
|
|
const data = await getAccountInfo(
|
2024-09-21 20:26:58 -05:00
|
|
|
idToRegion(Number(wargaming.id)),
|
|
|
|
|
Number(wargaming.id),
|
2024-09-14 19:43:14 -05:00
|
|
|
[],
|
|
|
|
|
{
|
2024-09-21 20:26:58 -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>;
|
|
|
|
|
}
|