mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-06-24 08:31:20 +00:00
Add functions
This commit is contained in:
parent
0c42d041ba
commit
f28d66ddc7
@ -42,6 +42,8 @@ import { useAtom, useSetAtom } from 'jotai';
|
|||||||
import { memberGroupsAtom, txListAtom } from '../../atoms/global';
|
import { memberGroupsAtom, txListAtom } from '../../atoms/global';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { TransitionUp } from '../../common/Transitions.tsx';
|
import { TransitionUp } from '../../common/Transitions.tsx';
|
||||||
|
import { averageBlockDay, averageBlockTime, levelUpBlocks } from './Stats.tsx';
|
||||||
|
import { node } from 'slate';
|
||||||
|
|
||||||
export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
|
export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
|
||||||
const setTxList = useSetAtom(txListAtom);
|
const setTxList = useSetAtom(txListAtom);
|
||||||
@ -55,7 +57,7 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
|
|||||||
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 [nodeHeightBlock, setNodeHeightBlock] = useState({});
|
||||||
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();
|
||||||
@ -201,17 +203,23 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const getNodeHeightBlock = useCallback(async () => {
|
useEffect(() => {
|
||||||
try {
|
if (nodeStatus?.height) {
|
||||||
const nodeBlock = parseFloat(nodeStatus?.height) - 1440;
|
const getNodeHeightBlock = async () => {
|
||||||
const url = `${getBaseApiReact()}/blocks/byheight/${nodeBlock}`;
|
try {
|
||||||
const response = await fetch(url);
|
const nodeBlock = nodeStatus.height - 1440;
|
||||||
const data = await response.json();
|
const url = `${getBaseApiReact()}/blocks/byheight/${nodeBlock}`;
|
||||||
setNodeHeightBlock(data);
|
const response = await fetch(url);
|
||||||
} catch (error) {
|
const data = await response.json();
|
||||||
console.error('Request failed', error);
|
setNodeHeightBlock(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Request failed', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
getNodeHeightBlock();
|
||||||
}
|
}
|
||||||
}, []);
|
}, [nodeStatus]);
|
||||||
|
|
||||||
const getAddressLevel = useCallback(async () => {
|
const getAddressLevel = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
@ -487,7 +495,6 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
|
|||||||
getAddressLevel();
|
getAddressLevel();
|
||||||
getAdminInfo();
|
getAdminInfo();
|
||||||
getMintingAccounts();
|
getMintingAccounts();
|
||||||
getNodeHeightBlock();
|
|
||||||
getNodeStatus();
|
getNodeStatus();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -497,30 +504,6 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
|
|||||||
getAccountInfo(myAddress);
|
getAccountInfo(myAddress);
|
||||||
}, [myAddress]);
|
}, [myAddress]);
|
||||||
|
|
||||||
const _blocksNeed = () => {
|
|
||||||
if (accountInfo?.level === 0) {
|
|
||||||
return 7200; // TODO manage these magic numbers in a proper location
|
|
||||||
} else if (accountInfo?.level === 1) {
|
|
||||||
return 72000;
|
|
||||||
} else if (accountInfo?.level === 2) {
|
|
||||||
return 201600;
|
|
||||||
} else if (accountInfo?.level === 3) {
|
|
||||||
return 374400;
|
|
||||||
} else if (accountInfo?.level === 4) {
|
|
||||||
return 618400;
|
|
||||||
} else if (accountInfo?.level === 5) {
|
|
||||||
return 964000;
|
|
||||||
} else if (accountInfo?.level === 6) {
|
|
||||||
return 1482400;
|
|
||||||
} else if (accountInfo?.level === 7) {
|
|
||||||
return 2173600;
|
|
||||||
} else if (accountInfo?.level === 8) {
|
|
||||||
return 3037600;
|
|
||||||
} else if (accountInfo?.level === 9) {
|
|
||||||
return 4074400;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setOpenSnack(false);
|
setOpenSnack(false);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -528,20 +511,6 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
|
|||||||
}, 250);
|
}, 250);
|
||||||
};
|
};
|
||||||
|
|
||||||
const _levelUpBlocks = () => {
|
|
||||||
if (
|
|
||||||
accountInfo?.blocksMinted === undefined ||
|
|
||||||
nodeStatus?.height === undefined
|
|
||||||
)
|
|
||||||
return null;
|
|
||||||
let countBlocks =
|
|
||||||
_blocksNeed() -
|
|
||||||
(accountInfo?.blocksMinted + accountInfo?.blocksMintedAdjustment);
|
|
||||||
|
|
||||||
let countBlocksString = countBlocks.toString();
|
|
||||||
return '' + countBlocksString;
|
|
||||||
};
|
|
||||||
|
|
||||||
const StatCard = ({ label, value }: { label: string; value: string }) => (
|
const StatCard = ({ label, value }: { label: string; value: string }) => (
|
||||||
<Grid size={{ xs: 4, sm: 6 }}>
|
<Grid size={{ xs: 4, sm: 6 }}>
|
||||||
<Paper elevation={5}>
|
<Paper elevation={5}>
|
||||||
@ -654,31 +623,32 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
|
|||||||
<Typography
|
<Typography
|
||||||
variant="h3"
|
variant="h3"
|
||||||
gutterBottom
|
gutterBottom
|
||||||
sx={{ textAlign: 'center' }}
|
sx={{ textAlign: 'center' }} // TODO translate
|
||||||
>
|
>
|
||||||
Blockchain Statistics
|
Blockchain Statistics
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<StatCard
|
<StatCard
|
||||||
label="Avg. Qortal Blocktime"
|
label="Avg. Qortal Blocktime (seconds)"
|
||||||
value="72.84 Seconds"
|
value={averageBlockTime(
|
||||||
|
adminInfo,
|
||||||
|
nodeHeightBlock
|
||||||
|
).toFixed(2)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<StatCard
|
<StatCard
|
||||||
label="Avg. Blocks Per Day"
|
label="Avg. Blocks Per Day"
|
||||||
value="1186.16 Blocks"
|
value={averageBlockDay(
|
||||||
|
adminInfo,
|
||||||
|
nodeHeightBlock
|
||||||
|
).toFixed(2)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<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>
|
||||||
|
|
||||||
@ -695,8 +665,8 @@ 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="NICO: Blocks To Next Level"
|
label="Blocks To Next Level"
|
||||||
value={nodeHeightBlock}
|
value={levelUpBlocks(accountInfo, nodeStatus) || ''}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
@ -798,7 +768,7 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
|
|||||||
{t('group:message.generic.next_level', {
|
{t('group:message.generic.next_level', {
|
||||||
postProcess: 'capitalizeFirstChar',
|
postProcess: 'capitalizeFirstChar',
|
||||||
})}{' '}
|
})}{' '}
|
||||||
{_levelUpBlocks()}
|
{levelUpBlocks(accountInfo, nodeStatus)}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Typography>
|
<Typography>
|
||||||
|
97
src/components/Minting/Stats.tsx
Normal file
97
src/components/Minting/Stats.tsx
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
export const averageBlockDay = (adminInfo, nodeHeightBlock) => {
|
||||||
|
const time = adminInfo.currentTimestamp - nodeHeightBlock.timestamp;
|
||||||
|
const average: number = time / 1000 / 1440;
|
||||||
|
const averageBlockDay = 86400 / average;
|
||||||
|
return averageBlockDay;
|
||||||
|
};
|
||||||
|
|
||||||
|
const accountTargetBlocks = (level: number) => {
|
||||||
|
if (level === 0) {
|
||||||
|
return 7200;
|
||||||
|
} else if (level === 1) {
|
||||||
|
return 72000;
|
||||||
|
} else if (level === 2) {
|
||||||
|
return 201600;
|
||||||
|
} else if (level === 3) {
|
||||||
|
return 374400;
|
||||||
|
} else if (level === 4) {
|
||||||
|
return 618400;
|
||||||
|
} else if (level === 5) {
|
||||||
|
return 964000;
|
||||||
|
} else if (level === 6) {
|
||||||
|
return 1482400;
|
||||||
|
} else if (level === 7) {
|
||||||
|
return 2173600;
|
||||||
|
} else if (level === 8) {
|
||||||
|
return 3037600;
|
||||||
|
} else if (level === 9) {
|
||||||
|
return 4074400;
|
||||||
|
} else {
|
||||||
|
return 0; // fallback: should never reach this point
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const accountLevel = (level: number) => {
|
||||||
|
if (level === 0) {
|
||||||
|
return '1';
|
||||||
|
} else if (level === 1) {
|
||||||
|
return '2';
|
||||||
|
} else if (level === 2) {
|
||||||
|
return '3';
|
||||||
|
} else if (level === 3) {
|
||||||
|
return '4';
|
||||||
|
} else if (level === 4) {
|
||||||
|
return '5';
|
||||||
|
} else if (level === 5) {
|
||||||
|
return '6';
|
||||||
|
} else if (level === 6) {
|
||||||
|
return '7';
|
||||||
|
} else if (level === 7) {
|
||||||
|
return '8';
|
||||||
|
} else if (level === 8) {
|
||||||
|
return '9';
|
||||||
|
} else if (level === 9) {
|
||||||
|
return '10';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const levelUpBlocks = (accountInfo, nodeStatus) => {
|
||||||
|
if (
|
||||||
|
accountInfo?.blocksMinted === undefined ||
|
||||||
|
nodeStatus?.height === undefined
|
||||||
|
)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
const countBlocks =
|
||||||
|
accountTargetBlocks(accountInfo?.level) -
|
||||||
|
(accountInfo?.blocksMinted + accountInfo?.blocksMintedAdjustment);
|
||||||
|
|
||||||
|
const countBlocksString = countBlocks.toString();
|
||||||
|
return countBlocksString;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const levelUpDays = (
|
||||||
|
accountInfo,
|
||||||
|
adminInfo,
|
||||||
|
nodeHeightBlock,
|
||||||
|
nodeStatus
|
||||||
|
) => {
|
||||||
|
if (
|
||||||
|
accountInfo?.blocksMinted === undefined ||
|
||||||
|
nodeStatus?.height === undefined
|
||||||
|
)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
const countBlocks =
|
||||||
|
accountTargetBlocks(accountInfo?.level) -
|
||||||
|
(accountInfo?.blocksMinted + accountInfo?.blocksMintedAdjustment);
|
||||||
|
|
||||||
|
const countDays = countBlocks / averageBlockDay(adminInfo, nodeHeightBlock);
|
||||||
|
return countDays.toFixed(2);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const averageBlockTime = (adminInfo, nodeHeightBlock) => {
|
||||||
|
const avgBlockString = adminInfo.currentTimestamp - nodeHeightBlock.timestamp;
|
||||||
|
const averageTimeString = avgBlockString / 1000 / 1440;
|
||||||
|
return averageTimeString;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user