Add some functions to retrieve node info

This commit is contained in:
Nicola Benaglia 2025-06-13 21:01:06 +02:00
parent 4cecd00da0
commit 0c42d041ba

View File

@ -51,10 +51,11 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
const [accountInfo, setAccountInfo] = useState(null); const [accountInfo, setAccountInfo] = useState(null);
const [mintingKey, setMintingKey] = useState(''); const [mintingKey, setMintingKey] = useState('');
const [rewardShares, setRewardShares] = useState([]); const [rewardShares, setRewardShares] = useState([]);
const [nodeInfos, setNodeInfos] = useState({}); const [nodeStatus, setNodeStatus] = useState({});
const [openSnack, setOpenSnack] = useState(false); const [openSnack, setOpenSnack] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [adminInfo, setAdminInfo] = useState({}); const [adminInfo, setAdminInfo] = useState({});
const [nodeHeightBlock, setNodeHeightBlock] = useState(null);
const [valueMintingTab, setValueMintingTab] = useState(0); const [valueMintingTab, setValueMintingTab] = useState(0);
const { isShow: isShowNext, onOk, show: showNext } = useModal(); const { isShow: isShowNext, onOk, show: showNext } = useModal();
const theme = useTheme(); const theme = useTheme();
@ -178,21 +179,51 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
return address; return address;
}; };
const getNodeInfos = async () => { const getAdminInfo = useCallback(async () => {
try {
const url = `${getBaseApiReact()}/admin/info`;
const response = await fetch(url);
const data = await response.json();
setAdminInfo(data);
} catch (error) {
console.log(error);
}
}, []);
const getNodeStatus = useCallback(async () => {
try { try {
const url = `${getBaseApiReact()}/admin/status`; const url = `${getBaseApiReact()}/admin/status`;
const response = await fetch(url, { const response = await fetch(url);
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
const data = await response.json(); const data = await response.json();
setNodeInfos(data); setNodeStatus(data);
} catch (error) { } catch (error) {
console.error('Request failed', error); console.error('Request failed', error);
} }
}; }, []);
const getNodeHeightBlock = useCallback(async () => {
try {
const nodeBlock = parseFloat(nodeStatus?.height) - 1440;
const url = `${getBaseApiReact()}/blocks/byheight/${nodeBlock}`;
const response = await fetch(url);
const data = await response.json();
setNodeHeightBlock(data);
} catch (error) {
console.error('Request failed', error);
}
}, []);
const getAddressLevel = useCallback(async () => {
try {
const url = `${getBaseApiReact()}/addresses/online/levels`;
const response = await fetch(url);
const data = await response.json();
// this.tier4Online = parseFloat(this.addressLevel[7].count) + parseFloat(this.addressLevel[8].count)
// setNodeStatus(data);
} catch (error) {
console.error('Request failed', error);
}
}, []);
const getRewardShares = useCallback(async (address) => { const getRewardShares = useCallback(async (address) => {
try { try {
@ -209,17 +240,6 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
} }
}, []); }, []);
const getAdminInfo = async () => {
try {
const url = `${getBaseApiReact()}/admin/info`;
const response = await fetch(url);
const data = await response.json();
setAdminInfo(data);
} catch (error) {
console.log(error);
}
};
const addMintingAccount = useCallback(async (val) => { const addMintingAccount = useCallback(async (val) => {
try { try {
setIsLoading(true); setIsLoading(true);
@ -464,14 +484,16 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
}; };
useEffect(() => { useEffect(() => {
getNodeInfos(); getAddressLevel();
getAdminInfo();
getMintingAccounts(); getMintingAccounts();
getNodeHeightBlock();
getNodeStatus();
}, []); }, []);
useEffect(() => { useEffect(() => {
if (!myAddress) return; if (!myAddress) return;
getRewardShares(myAddress); getRewardShares(myAddress);
getAccountInfo(myAddress); getAccountInfo(myAddress);
}, [myAddress]); }, [myAddress]);
@ -509,7 +531,7 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
const _levelUpBlocks = () => { const _levelUpBlocks = () => {
if ( if (
accountInfo?.blocksMinted === undefined || accountInfo?.blocksMinted === undefined ||
nodeInfos?.height === undefined nodeStatus?.height === undefined
) )
return null; return null;
let countBlocks = let countBlocks =
@ -521,13 +543,15 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
}; };
const StatCard = ({ label, value }: { label: string; value: string }) => ( const StatCard = ({ label, value }: { label: string; value: string }) => (
<Grid size={{ xs: 12, sm: 6 }}> <Grid size={{ xs: 4, sm: 6 }}>
<Box textAlign="center"> <Paper elevation={5}>
<Typography variant="subtitle1" fontWeight="bold"> <Box textAlign="center">
{label} <Typography variant="subtitle1" fontWeight="bold">
</Typography> {label}
<Typography>{value}</Typography> </Typography>
</Box> <Typography>{value}</Typography>
</Box>
</Paper>
</Grid> </Grid>
); );
@ -626,8 +650,12 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
}} }}
> >
<Container maxWidth="md" sx={{ py: 4 }}> <Container maxWidth="md" sx={{ py: 4 }}>
<Paper elevation={3} sx={{ p: 3, mb: 4, borderRadius: '10px' }}> <Paper elevation={2} sx={{ p: 3, mb: 4, borderRadius: '10px' }}>
<Typography variant="h6" gutterBottom> <Typography
variant="h3"
gutterBottom
sx={{ textAlign: 'center' }}
>
Blockchain Statistics Blockchain Statistics
</Typography> </Typography>
@ -636,19 +664,30 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
label="Avg. Qortal Blocktime" label="Avg. Qortal Blocktime"
value="72.84 Seconds" value="72.84 Seconds"
/> />
<StatCard <StatCard
label="Avg. Blocks Per Day" label="Avg. Blocks Per Day"
value="1186.16 Blocks" value="1186.16 Blocks"
/> />
<StatCard <StatCard
label="Avg. Created QORT Per Day" label="Avg. Created QORT Per Day"
value="3558.48 QORT" value="3558.48 QORT"
/> />
<StatCard
label="Nicola: nodeInfo"
value={nodeStatus?.height}
/>
</Grid> </Grid>
</Paper> </Paper>
<Paper elevation={3} sx={{ p: 3, mb: 4, borderRadius: '10px' }}> <Paper elevation={2} sx={{ p: 3, mb: 4, borderRadius: '10px' }}>
<Typography variant="h6" gutterBottom> <Typography
variant="h3"
gutterBottom
sx={{ textAlign: 'center' }}
>
Minting Account Details Minting Account Details
</Typography> </Typography>
@ -656,21 +695,25 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
<StatCard label="Current Status" value="(Minting)" /> <StatCard label="Current Status" value="(Minting)" />
<StatCard label="Current Level" value="Level 4" /> <StatCard label="Current Level" value="Level 4" />
<StatCard <StatCard
label="Blocks To Next Level" label="NICO: Blocks To Next Level"
value="139467 Blocks" value={nodeHeightBlock}
/> />
</Grid> </Grid>
<Box mt={2} textAlign="center"> <Box mt={2} textAlign="center">
<Typography> <Typography sx={{ textAlign: 'center' }}>
With a 24/7 Minting you will reach level 5 in{' '} With a 24/7 Minting you will reach level 5 in{' '}
<strong>117.58 days</strong>! <strong>117.58 days</strong>!
</Typography> </Typography>
</Box> </Box>
</Paper> </Paper>
<Paper elevation={3} sx={{ p: 3, borderRadius: '10px' }}> <Paper elevation={2} sx={{ p: 3, borderRadius: '10px' }}>
<Typography variant="h6" gutterBottom> <Typography
variant="h3"
gutterBottom
sx={{ textAlign: 'center' }}
>
Minting Rewards Info Minting Rewards Info
</Typography> </Typography>
@ -762,7 +805,7 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
{t('group:message.generic.node_minting', { {t('group:message.generic.node_minting', {
postProcess: 'capitalizeFirstChar', postProcess: 'capitalizeFirstChar',
})}{' '} })}{' '}
{nodeInfos?.isMintingPossible?.toString()} {nodeStatus?.isMintingPossible?.toString()}
</Typography> </Typography>
</Card> </Card>