Add loading robot profile (#1176)

* Add loading robot profile

* Typo
This commit is contained in:
KoalaSat 2024-03-14 12:41:37 +01:00 committed by GitHub
parent a20defbbd3
commit 5f8c25c52c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 59 additions and 40 deletions

View File

@ -29,10 +29,19 @@ const ProfileDialog = ({ open = false, onClose }: Props): JSX.Element => {
const { federation } = useContext<UseFederationStoreType>(FederationContext);
const { garage, robotUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
const { t } = useTranslation();
const slot = garage.getSlot();
const [loading, setLoading] = useState<boolean>(true);
const [loadingCoordinators, setLoadingCoordinators] = useState<number>(
Object.values(slot?.robots ?? {}).length,
);
useEffect(() => {
setLoading(!garage.getSlot()?.hashId);
setLoadingCoordinators(
Object.values(slot?.robots ?? {}).filter((robot) => robot.loading).length,
);
}, [robotUpdatedAt]);
return (
@ -49,12 +58,11 @@ const ProfileDialog = ({ open = false, onClose }: Props): JSX.Element => {
<Typography component='h5' variant='h5'>
{t('Your Robot')}
</Typography>
<List>
<Divider />
<ListItem className='profileNickname'>
<ListItemText secondary={t('Your robot')}>
<ListItemText>
<Typography component='h6' variant='h6'>
{garage.getSlot()?.nickname !== undefined && (
<div style={{ position: 'relative', left: '-7px' }}>
@ -76,6 +84,15 @@ const ProfileDialog = ({ open = false, onClose }: Props): JSX.Element => {
</div>
)}
</Typography>
{loadingCoordinators > 0 ? (
<>
<b>{t('Looking for your robot!')}</b>
<LinearProgress />
</>
) : (
<></>
)}
</ListItemText>
<ListItemAvatar>
@ -95,15 +112,16 @@ const ProfileDialog = ({ open = false, onClose }: Props): JSX.Element => {
</Typography>
{Object.values(federation.coordinators).map((coordinator: Coordinator): JSX.Element => {
if (garage.getSlot()?.hashId) {
return (
<div key={coordinator.shortAlias}>
<RobotInfo coordinator={coordinator} onClose={onClose} />
</div>
);
} else {
return <div key={coordinator.shortAlias} />;
}
const coordinatorRobot = garage.getSlot()?.getRobot(coordinator.shortAlias);
return (
<div key={coordinator.shortAlias}>
<RobotInfo
coordinator={coordinator}
onClose={onClose}
disabled={coordinatorRobot?.loading}
/>
</div>
);
})}
</DialogContent>
</Dialog>

View File

@ -268,7 +268,7 @@ const AutocompletePayments: React.FC<AutocompletePaymentsProps> = (props) => {
options: props.optionsType === 'fiat' ? fiatMethods : swapMethods,
getOptionLabel: (option) => option.name,
onInputChange: (e) => {
setVal(e.target.value ?? '');
setVal(e?.target?.value ?? '');
},
onChange: (event, value) => {
props.onAutocompleteChange(value);

View File

@ -36,9 +36,10 @@ import { FederationContext, type UseFederationStoreType } from '../../contexts/F
interface Props {
coordinator: Coordinator;
onClose: () => void;
disabled?: boolean;
}
const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
const RobotInfo: React.FC<Props> = ({ coordinator, onClose, disabled }: Props) => {
const { garage } = useContext<UseGarageStoreType>(GarageContext);
const { setCurrentOrderId } = useContext<UseFederationStoreType>(FederationContext);
const navigate = useNavigate();
@ -117,7 +118,7 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
const robot = slot?.getRobot(coordinator.shortAlias);
return (
<Accordion>
<Accordion disabled={disabled}>
<AccordionSummary expandIcon={<ExpandMore />}>
{`${coordinator.longAlias}:`}
{(robot?.earnedRewards ?? 0) > 0 && (

View File

@ -80,13 +80,7 @@ export const FederationContextProvider = ({
useContext<UseAppStoreType>(AppContext);
const { setMaker, garage, setBadOrder } = useContext<UseGarageStoreType>(GarageContext);
const [federation, setFederation] = useState(initialFederationContext.federation);
const sortedCoordinators = useMemo(() => {
const sortedCoordinators = federationLottery(federation);
setMaker((maker) => {
return { ...maker, coordinator: sortedCoordinators[0] };
}); // default MakerForm coordinator is decided via sorted lottery
return sortedCoordinators;
}, []);
const sortedCoordinators = useMemo(() => federationLottery(federation), []);
const [coordinatorUpdatedAt, setCoordinatorUpdatedAt] = useState<string>(
new Date().toISOString(),
);
@ -103,6 +97,12 @@ export const FederationContextProvider = ({
setInterval(() => null, delay),
);
useEffect(() => {
setMaker((maker) => {
return { ...maker, coordinator: sortedCoordinators[0] };
}); // default MakerForm coordinator is decided via sorted lottery
}, []);
useEffect(() => {
// On bitcoin network change we reset book, limits and federation info and fetch everything again
const newFed = initialFederationContext.federation;
@ -144,9 +144,9 @@ export const FederationContextProvider = ({
const fetchCurrentOrder: () => void = () => {
const slot = garage?.getSlot();
const robot = slot?.getRobot();
if (currentOrderId.id && currentOrderId.shortAlias) {
if (robot && slot?.token && currentOrderId.id && currentOrderId.shortAlias) {
const coordinator = federation.getCoordinator(currentOrderId.shortAlias);
void coordinator?.fetchOrder(currentOrderId.id, robot, slot.token).then((order) => {
void coordinator?.fetchOrder(currentOrderId.id, robot, slot?.token).then((order) => {
onOrderReceived(order as Order);
});
} else if (slot?.token && slot?.activeShortAlias && robot?.activeOrderId) {

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "No tens un avatar robot",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "El teu Robot",
"Your robot": "El teu robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Guarda-ho!",
"Done": "Fet",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "Nemáš robota a avatar",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Your Robot",
"Your robot": "Tvůj robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Zálohuj to!",
"Done": "Hotovo",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "Du hast keinen Roboter-Avatar",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Your Robot",
"Your robot": "Dein Roboter",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Speicher ihn ab!",
"Done": "Fertig",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "You do not have a robot avatar",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Your Robot",
"Your robot": "Your robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Back it up!",
"Done": "Done",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "No tienes un avatar robot",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Your Robot",
"Your robot": "Tu Robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "¡Guárdalo!",
"Done": "Hecho",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "Ez daukazu robot avatarrik",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Your Robot",
"Your robot": "Zure robota",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Gorde ezazu!",
"Done": "Prest",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "Vous n'avez pas d'avatar robot",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Votre Robot",
"Your robot": "Votre robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Sauvegardez!",
"Done": "Fait",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "Non hai un avatar robot",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Il tuo Robot",
"Your robot": "Il tuo robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Salvalo!",
"Done": "Fatto",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "ロボットのアバターがありません",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Your Robot",
"Your robot": "あなたのロボット",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "バックアップを取ってください!",
"Done": "完了",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "You do not have a robot avatar",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Your Robot",
"Your robot": "Twój robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Utwórz kopię zapasową!",
"Done": "Done",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "Você não tem um avatar de robô",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Your Robot",
"Your robot": "Seu robô",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Apoia-la!",
"Done": "Feito",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "У Вас нет аватара робота",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Ваш Robot",
"Your robot": "Ваш Робот",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Сохраните его!",
"Done": "Готово",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "Du har ingen robotavatar",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Your Robot",
"Your robot": "Din robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Spara den!",
"Done": "Klar",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "Huna picha ya mwakilishi wa roboti",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Roboti yako",
"Your robot": "Roboti yako",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Fanya nakala rudufu!",
"Done": "Imekamilika",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "คุณไม่มีโรบอท",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Your Robot",
"Your robot": "โรบอทของคุณ",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "อย่าลืมบันทึก!",
"Done": "เสร็จสิ้น",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "你没有机器人头像",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "你的机器人",
"Your robot": "你的机器人",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "请备份!",
"Done": "完成",

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "你沒有機器人頭像",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "你的機器人",
"Your robot": "你的機器人",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "請備份!",
"Done": "完成",