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

View File

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

View File

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

View File

@ -80,13 +80,7 @@ export const FederationContextProvider = ({
useContext<UseAppStoreType>(AppContext); useContext<UseAppStoreType>(AppContext);
const { setMaker, garage, setBadOrder } = useContext<UseGarageStoreType>(GarageContext); const { setMaker, garage, setBadOrder } = useContext<UseGarageStoreType>(GarageContext);
const [federation, setFederation] = useState(initialFederationContext.federation); const [federation, setFederation] = useState(initialFederationContext.federation);
const sortedCoordinators = useMemo(() => { const sortedCoordinators = useMemo(() => federationLottery(federation), []);
const sortedCoordinators = federationLottery(federation);
setMaker((maker) => {
return { ...maker, coordinator: sortedCoordinators[0] };
}); // default MakerForm coordinator is decided via sorted lottery
return sortedCoordinators;
}, []);
const [coordinatorUpdatedAt, setCoordinatorUpdatedAt] = useState<string>( const [coordinatorUpdatedAt, setCoordinatorUpdatedAt] = useState<string>(
new Date().toISOString(), new Date().toISOString(),
); );
@ -103,6 +97,12 @@ export const FederationContextProvider = ({
setInterval(() => null, delay), setInterval(() => null, delay),
); );
useEffect(() => {
setMaker((maker) => {
return { ...maker, coordinator: sortedCoordinators[0] };
}); // default MakerForm coordinator is decided via sorted lottery
}, []);
useEffect(() => { useEffect(() => {
// On bitcoin network change we reset book, limits and federation info and fetch everything again // On bitcoin network change we reset book, limits and federation info and fetch everything again
const newFed = initialFederationContext.federation; const newFed = initialFederationContext.federation;
@ -144,9 +144,9 @@ export const FederationContextProvider = ({
const fetchCurrentOrder: () => void = () => { const fetchCurrentOrder: () => void = () => {
const slot = garage?.getSlot(); const slot = garage?.getSlot();
const robot = slot?.getRobot(); const robot = slot?.getRobot();
if (currentOrderId.id && currentOrderId.shortAlias) { if (robot && slot?.token && currentOrderId.id && currentOrderId.shortAlias) {
const coordinator = federation.getCoordinator(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); onOrderReceived(order as Order);
}); });
} else if (slot?.token && slot?.activeShortAlias && robot?.activeOrderId) { } 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", "You do not have a robot avatar": "No tens un avatar robot",
"#29": "Phrases in components/Dialogs/Profile.tsx", "#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:", "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",
"Your robot": "El teu robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx", "#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Guarda-ho!", "Back it up!": "Guarda-ho!",
"Done": "Fet", "Done": "Fet",

View File

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

View File

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

View File

@ -313,8 +313,8 @@
"You do not have a robot avatar": "You do not have a robot avatar", "You do not have a robot avatar": "You do not have a robot avatar",
"#29": "Phrases in components/Dialogs/Profile.tsx", "#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:", "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",
"Your robot": "Your robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx", "#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Back it up!", "Back it up!": "Back it up!",
"Done": "Done", "Done": "Done",

View File

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

View File

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

View File

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

View File

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

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", "#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:", "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",
"Your robot": "あなたのロボット",
"#30": "Phrases in components/Dialogs/StoreToken.tsx", "#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": "You do not have a robot avatar", "You do not have a robot avatar": "You do not have a robot avatar",
"#29": "Phrases in components/Dialogs/Profile.tsx", "#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:", "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",
"Your robot": "Twój robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx", "#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Utwórz kopię zapasową!", "Back it up!": "Utwórz kopię zapasową!",
"Done": "Done", "Done": "Done",

View File

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

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", "#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:", "Coordinators that know your robot:": "Coordinators that know your robot:",
"Looking for your robot!": "Looking for your robot!",
"Your Robot": "Ваш Robot", "Your Robot": "Ваш Robot",
"Your robot": "Ваш Робот",
"#30": "Phrases in components/Dialogs/StoreToken.tsx", "#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": "Du har ingen robotavatar", "You do not have a robot avatar": "Du har ingen robotavatar",
"#29": "Phrases in components/Dialogs/Profile.tsx", "#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:", "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",
"Your robot": "Din robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx", "#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "Spara den!", "Back it up!": "Spara den!",
"Done": "Klar", "Done": "Klar",

View File

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

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", "#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:", "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",
"Your robot": "โรบอทของคุณ",
"#30": "Phrases in components/Dialogs/StoreToken.tsx", "#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": "你没有机器人头像", "You do not have a robot avatar": "你没有机器人头像",
"#29": "Phrases in components/Dialogs/Profile.tsx", "#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:", "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", "#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": "你沒有機器人頭像", "You do not have a robot avatar": "你沒有機器人頭像",
"#29": "Phrases in components/Dialogs/Profile.tsx", "#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robot:": "Coordinators that know your robot:", "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", "#30": "Phrases in components/Dialogs/StoreToken.tsx",
"Back it up!": "請備份!", "Back it up!": "請備份!",
"Done": "完成", "Done": "完成",