Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 101 additions & 56 deletions frontend/src/components/RobotInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ListItemIcon,
ListItemText,
Grid,
Box,
useTheme,
Divider,
Typography,
Expand Down Expand Up @@ -49,6 +50,7 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
const theme = useTheme();

const [rewardInvoice, setRewardInvoice] = useState<string>('');
const [routingBudgetPPM, setRoutingBudgetPPM] = useState<number>(1000);
const [showRewardsSpinner, setShowRewardsSpinner] = useState<boolean>(false);
const [withdrawn, setWithdrawn] = useState<boolean>(false);
const [badInvoice, setBadInvoice] = useState<string>('');
Expand All @@ -74,7 +76,7 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
if (robot?.token && robot.encPrivKey != null) {
void signCleartextMessage(rewardInvoice, robot.encPrivKey, robot?.token).then(
(signedInvoice) => {
void robot.fetchReward(federation, signedInvoice).then((data) => {
void robot.fetchReward(federation, signedInvoice, routingBudgetPPM).then((data) => {
setBadInvoice(data.bad_invoice ?? '');
setShowRewardsSpinner(false);
setWithdrawn(data.successful_withdrawal);
Expand Down Expand Up @@ -122,7 +124,16 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
</ListItemIcon>
)}
</ListItemButton>
<Dialog open={openOptions} key={coordinator.shortAlias} onClose={() => setOpenOptions(false)}>
<Dialog
open={openOptions}
key={coordinator.shortAlias}
onClose={() => {
setOpenOptions(false);
setOpenClaimRewards(false);
setRewardInvoice('');
setBadInvoice('');
}}
>
<DialogContent>
<List dense disablePadding={true}>
<ListItemButton
Expand Down Expand Up @@ -263,75 +274,101 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
</ListItemText>
</ListItem>

<ListItem>
<ListItemIcon>
<EmojiEvents />
</ListItemIcon>

{!openClaimRewards ? (
<ListItemText secondary={t('Your compensations')}>
<Grid container justifyContent='space-between'>
<Grid item xs={9}>
<Typography>{`${String(robot?.earnedRewards)} Sats`}</Typography>
</Grid>

<Grid item xs={3}>
<ListItem
secondaryAction={
!openClaimRewards && (
<Tooltip
placement='left'
enterTouchDelay={0}
title={
(robot?.earnedRewards ?? 0) === 0
? t('Nothing to claim yet')
: t('Claim your rewards')
}
>
<span>
<Button
disabled={robot?.earnedRewards === 0}
disabled={(robot?.earnedRewards ?? 0) === 0}
onClick={() => {
setOpenClaimRewards(true);
}}
variant='contained'
variant='outlined'
color='primary'
size='small'
>
{t('Claim')}
</Button>
</Grid>
</Grid>
</ListItemText>
</span>
</Tooltip>
)
}
>
<ListItemIcon>
<EmojiEvents />
</ListItemIcon>

{!openClaimRewards ? (
<ListItemText
primary={`${String(robot?.earnedRewards ?? 0)} Sats`}
secondary={t('Your compensations')}
/>
) : (
<form noValidate style={{ maxWidth: 270 }}>
<Grid container style={{ display: 'flex', alignItems: 'stretch' }}>
<Grid item style={{ display: 'flex', maxWidth: 160 }}>
<form noValidate style={{ width: '100%' }}>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
<Tooltip
placement='top'
enterTouchDelay={0}
title={t(
'Routing budget for the reward payment. Higher values may help if payment fails.',
)}
>
<TextField
error={Boolean(badInvoice)}
helperText={badInvoice ?? ''}
label={t('Invoice for {{amountSats}} Sats', {
amountSats: robot?.earnedRewards,
})}
label={t('Routing Budget (PPM)')}
type='number'
size='small'
value={rewardInvoice}
onChange={(e) => {
setRewardInvoice(e.target.value);
}}
fullWidth
value={routingBudgetPPM}
onChange={(e) => setRoutingBudgetPPM(Number(e.target.value))}
inputProps={{ min: 0, max: 10000 }}
/>
</Grid>
<Grid item alignItems='stretch' style={{ display: 'flex', maxWidth: 80 }}>
<Button
sx={{ maxHeight: 38 }}
disabled={rewardInvoice === ''}
onClick={(e) => {
handleSubmitInvoiceClicked(e, rewardInvoice);
}}
variant='contained'
color='primary'
size='small'
type='submit'
>
{t('Submit')}
</Button>
</Grid>
</Grid>
</Tooltip>
<TextField
error={Boolean(badInvoice)}
helperText={badInvoice ?? ''}
label={t('Invoice for {{amountSats}} Sats', {
amountSats: Math.floor(
(robot?.earnedRewards ?? 0) -
((robot?.earnedRewards ?? 0) * routingBudgetPPM) / 1000000,
),
})}
size='small'
fullWidth
value={rewardInvoice}
onChange={(e) => {
setRewardInvoice(e.target.value);
}}
/>
<Button
disabled={rewardInvoice === '' || showRewardsSpinner}
onClick={(e) => {
handleSubmitInvoiceClicked(e, rewardInvoice);
}}
variant='contained'
color='primary'
fullWidth
type='submit'
>
{showRewardsSpinner ? (
<CircularProgress size={24} color='inherit' />
) : (
t('Submit')
)}
</Button>
</Box>
</form>
)}
</ListItem>

{showRewardsSpinner && (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<CircularProgress />
</div>
)}

{withdrawn && (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Typography color='primary' variant='body2'>
Expand All @@ -342,7 +379,15 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
</List>
</DialogContent>
<DialogActions>
<Button onClick={() => setOpenOptions(false)} size='large'>
<Button
onClick={() => {
setOpenOptions(false);
setOpenClaimRewards(false);
setRewardInvoice('');
setBadInvoice('');
}}
size='large'
>
{t('Back')}
</Button>
</DialogActions>
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/models/Robot.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ class Robot {
fetchReward = async (
federation: Federation,
signedInvoice: string,
routingBudgetPPM?: number,
): Promise<null | {
bad_invoice?: string;
successful_withdrawal?: boolean;
}> => {
if (!federation) return null;

const coordinator = federation.getCoordinator(this.shortAlias);
const body: { invoice: string; routing_budget_ppm?: number } = {
invoice: signedInvoice,
};
if (routingBudgetPPM !== undefined) {
body.routing_budget_ppm = routingBudgetPPM;
}
const data = await apiClient
.post(
coordinator.url,
'/api/reward/',
{
invoice: signedInvoice,
},
{ tokenSHA256: this.tokenSHA256 },
)
.post(coordinator.url, '/api/reward/', body, { tokenSHA256: this.tokenSHA256 })
.catch((e) => {
console.log(e);
});
Expand Down
4 changes: 4 additions & 0 deletions frontend/static/locales/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,17 @@
"#51": "Phrases in components/RobotInfo/index.tsx",
"Active order!": "Active order!",
"Claim": "Retirar",
"Claim your rewards": "Claim your rewards",
"Enable Telegram Notifications": "Habilita notificacions a Telegram",
"Finished order": "Finished order",
"Inactive order": "Ordre inactiva",
"Invoice for {{amountSats}} Sats": "Factura per {{amountSats}} Sats",
"No active orders": "No hi ha ordres actives",
"No orders found": "No orders found",
"Nothing to claim yet": "Nothing to claim yet",
"One active order #{{orderID}}": "Anar a ordre activa #{{orderID}}",
"Routing Budget (PPM)": "Routing Budget (PPM)",
"Routing budget for the reward payment. Higher values may help if payment fails.": "Routing budget for the reward payment. Higher values may help if payment fails.",
"Submit": "Enviar",
"Telegram enabled": "Telegram activat",
"There it goes!": "Aquí va!",
Expand Down
4 changes: 4 additions & 0 deletions frontend/static/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,17 @@
"#51": "Phrases in components/RobotInfo/index.tsx",
"Active order!": "Aktivní objednávka!",
"Claim": "Vybrat",
"Claim your rewards": "Claim your rewards",
"Enable Telegram Notifications": "Povolit Telegram notifikace",
"Finished order": "Dokončená objednávka",
"Inactive order": "Neaktivní objednávka",
"Invoice for {{amountSats}} Sats": "Faktura pro {{amountSats}} Satů",
"No active orders": "Žádné aktivní objednávky",
"No orders found": "Nenalezeny žádné objednávky",
"Nothing to claim yet": "Nothing to claim yet",
"One active order #{{orderID}}": "Jedna aktivní objednávka #{{orderID}}",
"Routing Budget (PPM)": "Routing Budget (PPM)",
"Routing budget for the reward payment. Higher values may help if payment fails.": "Routing budget for the reward payment. Higher values may help if payment fails.",
"Submit": "Odeslat",
"Telegram enabled": "Telegram povolen",
"There it goes!": "A je to!",
Expand Down
4 changes: 4 additions & 0 deletions frontend/static/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,17 @@
"#51": "Phrases in components/RobotInfo/index.tsx",
"Active order!": "Aktive Bestellung!",
"Claim": "Erhalten",
"Claim your rewards": "Claim your rewards",
"Enable Telegram Notifications": "Telegram-Benachrichtigungen aktivieren",
"Finished order": "Finished order",
"Inactive order": "Inaktive Bestellung",
"Invoice for {{amountSats}} Sats": "Rechnung für {{amountSats}} Sats",
"No active orders": "Keine aktive Bestellung",
"No orders found": "No orders found",
"Nothing to claim yet": "Nothing to claim yet",
"One active order #{{orderID}}": "Eine aktive Bestellung #{{orderID}}",
"Routing Budget (PPM)": "Routing Budget (PPM)",
"Routing budget for the reward payment. Higher values may help if payment fails.": "Routing budget for the reward payment. Higher values may help if payment fails.",
"Submit": "Bestätigen",
"Telegram enabled": "Telegram aktiviert",
"There it goes!": "Da geht es hin!",
Expand Down
4 changes: 4 additions & 0 deletions frontend/static/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,17 @@
"#51": "Phrases in components/RobotInfo/index.tsx",
"Active order!": "Active order!",
"Claim": "Claim",
"Claim your rewards": "Claim your rewards",
"Enable Telegram Notifications": "Enable Telegram Notifications",
"Finished order": "Finished order",
"Inactive order": "Inactive order",
"Invoice for {{amountSats}} Sats": "Invoice for {{amountSats}} Sats",
"No active orders": "No active orders",
"No orders found": "No orders found",
"Nothing to claim yet": "Nothing to claim yet",
"One active order #{{orderID}}": "One active order #{{orderID}}",
"Routing Budget (PPM)": "Routing Budget (PPM)",
"Routing budget for the reward payment. Higher values may help if payment fails.": "Routing budget for the reward payment. Higher values may help if payment fails.",
"Submit": "Submit",
"Telegram enabled": "Telegram enabled",
"There it goes!": "There it goes!",
Expand Down
4 changes: 4 additions & 0 deletions frontend/static/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,17 @@
"#51": "Phrases in components/RobotInfo/index.tsx",
"Active order!": "¡Orden activa!",
"Claim": "Reclamar",
"Claim your rewards": "Claim your rewards",
"Enable Telegram Notifications": "Activar Notificaciones de Telegram",
"Finished order": "Finished order",
"Inactive order": "Orden inactiva",
"Invoice for {{amountSats}} Sats": "Factura de {{amountSats}} Sats",
"No active orders": "No hay órdenes activas",
"No orders found": "No orders found",
"Nothing to claim yet": "Nothing to claim yet",
"One active order #{{orderID}}": "Una orden activa #{{orderID}}",
"Routing Budget (PPM)": "Routing Budget (PPM)",
"Routing budget for the reward payment. Higher values may help if payment fails.": "Routing budget for the reward payment. Higher values may help if payment fails.",
"Submit": "Enviar",
"Telegram enabled": "Telegram activado",
"There it goes!": "¡Ahí va!",
Expand Down
4 changes: 4 additions & 0 deletions frontend/static/locales/eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,17 @@
"#51": "Phrases in components/RobotInfo/index.tsx",
"Active order!": "Eskaera aktiboa!",
"Claim": "Eskatu",
"Claim your rewards": "Claim your rewards",
"Enable Telegram Notifications": "Baimendu Telegram Jakinarazpenak",
"Finished order": "Finished order",
"Inactive order": "Eskaera ez aktiboa",
"Invoice for {{amountSats}} Sats": "{{amountSats}} Sateko faktura",
"No active orders": "Ez dago eskaera aktiboak",
"No orders found": "No orders found",
"Nothing to claim yet": "Nothing to claim yet",
"One active order #{{orderID}}": "Eskaera aktiboa #{{orderID}}",
"Routing Budget (PPM)": "Routing Budget (PPM)",
"Routing budget for the reward payment. Higher values may help if payment fails.": "Routing budget for the reward payment. Higher values may help if payment fails.",
"Submit": "Bidali",
"Telegram enabled": "Telegram baimendua",
"There it goes!": "Hementxe doa!",
Expand Down
4 changes: 4 additions & 0 deletions frontend/static/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,17 @@
"#51": "Phrases in components/RobotInfo/index.tsx",
"Active order!": "Ordre actif!",
"Claim": "Réclamer",
"Claim your rewards": "Claim your rewards",
"Enable Telegram Notifications": "Activer les notifications Telegram",
"Finished order": "Finished order",
"Inactive order": "Ordre inactif",
"Invoice for {{amountSats}} Sats": "Facture pour {{amountSats}} Sats",
"No active orders": "Aucun ordre actif",
"No orders found": "No orders found",
"Nothing to claim yet": "Nothing to claim yet",
"One active order #{{orderID}}": "Un ordre actif #{{orderID}}",
"Routing Budget (PPM)": "Routing Budget (PPM)",
"Routing budget for the reward payment. Higher values may help if payment fails.": "Routing budget for the reward payment. Higher values may help if payment fails.",
"Submit": "Soumettre",
"Telegram enabled": "Telegram activé",
"There it goes!": "Là ça va!",
Expand Down
4 changes: 4 additions & 0 deletions frontend/static/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,17 @@
"#51": "Phrases in components/RobotInfo/index.tsx",
"Active order!": "Ordine attivo!",
"Claim": "Richiedi",
"Claim your rewards": "Claim your rewards",
"Enable Telegram Notifications": "Abilita Notifiche Telegram",
"Finished order": "Finished order",
"Inactive order": "Ordine inattivo",
"Invoice for {{amountSats}} Sats": "Fattura per {{amountSats}} Sats",
"No active orders": "Nessun ordine attivo",
"No orders found": "No orders found",
"Nothing to claim yet": "Nothing to claim yet",
"One active order #{{orderID}}": "Un ordine attivo #{{orderID}}",
"Routing Budget (PPM)": "Routing Budget (PPM)",
"Routing budget for the reward payment. Higher values may help if payment fails.": "Routing budget for the reward payment. Higher values may help if payment fails.",
"Submit": "Invia",
"Telegram enabled": "Telegram abilitato",
"There it goes!": "Ecco!",
Expand Down
Loading
Loading