Add percenteage, refactor sync conditions

This commit is contained in:
Nicola Benaglia 2025-06-25 08:38:10 +02:00
parent 540ed77e6d
commit 44e9a435c4
14 changed files with 149 additions and 134 deletions

View File

@ -25,9 +25,7 @@ export const CoreSyncStatus = () => {
useEffect(() => {
const getNodeInfos = async () => {
try {
setIsUsingGateway(
!!getBaseApiReact()?.includes('ext-node.qortal.link')
);
setIsUsingGateway(getBaseApiReact()?.includes('ext-node.qortal.link'));
const url = `${getBaseApiReact()}/admin/status`;
const response = await fetch(url, {
method: 'GET',
@ -82,27 +80,27 @@ export const CoreSyncStatus = () => {
: '';
let imagePath = syncingImg;
let message = t('core:minting.status.synchronizing', {
postProcess: 'capitalizeFirstChar',
});
let message: string = '';
if (isMintingPossible && !isUsingGateway) {
if (isUsingGateway) {
imagePath = syncingImg;
message = `${t('core:minting.status.no_status')}`;
} else if (isMintingPossible) {
if (isSynchronizing) {
imagePath = syncingImg;
message = `${t(`core:minting.status.synchronizing`, { percent: syncPercent, postProcess: 'capitalizeFirstChar' })} ${t('core:minting.status.minting')}`;
} else {
imagePath = syncedMintingImg;
message = `${t(`core:minting.status.${isSynchronizing ? 'synchronizing' : 'synchronized'}`, { postProcess: 'capitalizeFirstChar' })} ${t('core:minting.status.minting')}`;
} else if (isSynchronizing === true && syncPercent === 99) {
imagePath = syncingImg;
} else if (isSynchronizing && !isMintingPossible && syncPercent === 100) {
imagePath = syncingImg;
message = `${t('core:minting.status.synchronizing', { postProcess: 'capitalizeFirstChar' })} ${!isUsingGateway ? t('core:minting.status.not_minting') : ''}`;
} else if (!isSynchronizing && !isMintingPossible && syncPercent === 100) {
message = `${t(`core:minting.status.synchronized`, { percent: syncPercent, postProcess: 'capitalizeFirstChar' })} ${t('core:minting.status.minting')}`;
}
} else if (!isMintingPossible) {
if (syncPercent == 100) {
imagePath = syncedImg;
message = `${t('core:minting.status.synchronized', { postProcess: 'capitalizeFirstChar' })} ${!isUsingGateway ? t('core:minting.status.not_minting') : ''}`;
} else if (isSynchronizing && isMintingPossible && syncPercent === 100) {
message = `${t(`core:minting.status.synchronized`, { percent: syncPercent, postProcess: 'capitalizeFirstChar' })} ${t('core:minting.status.not_minting')}`;
} else {
imagePath = syncingImg;
message = `${t('core:minting.status.synchronizing', { postProcess: 'capitalizeFirstChar' })} ${!isUsingGateway ? t('core:minting.status.minting') : ''}`;
} else if (!isSynchronizing && isMintingPossible && syncPercent === 100) {
imagePath = syncedMintingImg;
message = `${t('core:minting.status.synchronized', { postProcess: 'capitalizeFirstChar' })} ${!isUsingGateway ? t('core:minting.status.minting') : ''}`;
message = `${t(`core:minting.status.synchronizing`, { percent: syncPercent, postProcess: 'capitalizeFirstChar' })} ${t('core:minting.status.not_minting')}`;
}
}
return (

View File

@ -96,6 +96,7 @@ interface ReadOnlySlateProps {
content: any;
mode?: string;
}
const ReadOnlySlate: FC<ReadOnlySlateProps> = ({ content, mode }) => {
const [load, setLoad] = useState(false);
const editor = useMemo(() => withReact(createEditor()), []);
@ -103,11 +104,15 @@ const ReadOnlySlate: FC<ReadOnlySlateProps> = ({ content, mode }) => {
const performUpdate = useCallback(async () => {
setLoad(true);
try {
await new Promise<void>((res) => {
setTimeout(() => {
res();
}, 250);
});
} catch (error) {
console.log(error);
}
setLoad(false);
}, []);
useEffect(() => {

View File

@ -698,10 +698,14 @@ export const Minting = ({ setIsOpenMinting, myAddress, show }) => {
label={t('core:minting.average_blocktime', {
postProcess: 'capitalizeEachFirstChar',
})}
value={averageBlockTime(
adminInfo,
nodeHeightBlock
).toFixed(2)}
value={t('core:time.second', {
count: parseFloat(
averageBlockTime(adminInfo, nodeHeightBlock).toFixed(
2
)
),
postProcess: 'capitalizeEachFirstChar',
})}
/>
<StatCard

View File

@ -299,7 +299,7 @@ export const countRewardDay = (
);
return countRewardDay34;
} else if (level === 5 || level === 6) {
if (this.tier4Online < 30) {
if (tier4Online < 30) {
const countRewardDay56 = parseFloat(
(
(((blockReward(nodeStatus) / 100) *
@ -324,7 +324,7 @@ export const countRewardDay = (
return countRewardDay56;
}
} else if (level === 7 || level === 8) {
if (this.tier4Online < 30) {
if (tier4Online < 30) {
const countRewardDay78 = parseFloat(
(
(((blockReward(nodeStatus) / 100) *
@ -368,7 +368,6 @@ export const mintingStatus = (nodeStatus): string => {
nodeStatus.isMintingPossible === true &&
nodeStatus.isSynchronizing === true
) {
// this.cssMinting = 'blue';
return i18n.t('core:minting.status.minting', {
postProcess: 'capitalizeFirstChar',
});
@ -376,7 +375,6 @@ export const mintingStatus = (nodeStatus): string => {
nodeStatus.isMintingPossible === true &&
nodeStatus.isSynchronizing === false
) {
// this.cssMinting = 'blue';
return i18n.t('core:minting.status.minting', {
postProcess: 'capitalizeFirstChar',
});
@ -384,7 +382,6 @@ export const mintingStatus = (nodeStatus): string => {
nodeStatus.isMintingPossible === false &&
nodeStatus.isSynchronizing === true
) {
// this.cssMinting = 'red';
return i18n.t('core:minting.status.synchronizing', {
postProcess: 'capitalizeFirstChar',
}) +
@ -396,7 +393,6 @@ export const mintingStatus = (nodeStatus): string => {
nodeStatus.isMintingPossible === false &&
nodeStatus.isSynchronizing === false
) {
// this.cssMinting = 'red';
return i18n.t('core:minting.status.not_minting', {
postProcess: 'capitalizeFirstChar',
});

View File

@ -1,26 +1,24 @@
// @ts-nocheck
import {bytes_to_base64 as bytesToBase64, Sha512} from 'asmcrypto.js'
import utils from '../utils/utils'
import { crypto as crypto2 } from '../constants/decryptWallet'
import { bytes_to_base64 as bytesToBase64, Sha512 } from 'asmcrypto.js';
import utils from '../utils/utils';
import { crypto as crypto2 } from '../constants/decryptWallet';
import BcryptWorker from './bcryptworker.worker.js?worker';
const stringtoUTF8Array = (message)=> {
const stringtoUTF8Array = (message) => {
if (typeof message === 'string') {
var s = unescape(encodeURIComponent(message)) // UTF-8
message = new Uint8Array(s.length)
var s = unescape(encodeURIComponent(message)); // UTF-8
message = new Uint8Array(s.length);
for (var i = 0; i < s.length; i++) {
message[i] = s.charCodeAt(i) & 0xff
message[i] = s.charCodeAt(i) & 0xff;
}
}
return message
}
return message;
};
const bcryptInWorker = (hashBase64, salt) => {
return new Promise((resolve, reject) => {
const worker = new BcryptWorker()
const worker = new BcryptWorker();
worker.onmessage = (e) => {
const { result, error } = e.data;
if (error) {
@ -38,63 +36,75 @@ const bcryptInWorker = (hashBase64, salt) => {
});
};
const stringToUTF8Array=(message)=> {
const stringToUTF8Array = (message) => {
if (typeof message !== 'string') return message; // Assuming you still want to pass through non-string inputs unchanged
const encoder = new TextEncoder(); // TextEncoder defaults to UTF-8
return encoder.encode(message);
}
const computekdf = async (req)=> {
const { salt, key, nonce, staticSalt, staticBcryptSalt } = req
const combinedBytes = utils.appendBuffer(new Uint8Array([]), stringToUTF8Array(`${staticSalt}${key}${nonce}`))
};
const sha512Hash = new Sha512().process(combinedBytes).finish().result
const sha512HashBase64 = bytesToBase64(sha512Hash)
const computekdf = async (req) => {
const { salt, key, nonce, staticSalt, staticBcryptSalt } = req;
const combinedBytes = utils.appendBuffer(
new Uint8Array([]),
stringToUTF8Array(`${staticSalt}${key}${nonce}`)
);
const result = await bcryptInWorker(sha512HashBase64.substring(0, 72), staticBcryptSalt);
return { key, nonce, result }
}
const sha512Hash = new Sha512().process(combinedBytes).finish().result;
const sha512HashBase64 = bytesToBase64(sha512Hash);
const result = await bcryptInWorker(
sha512HashBase64.substring(0, 72),
staticBcryptSalt
);
return { key, nonce, result };
};
export const doInitWorkers = (numberOfWorkers) => {
const workers = []
const workers = [];
try {
for (let i = 0; i < numberOfWorkers; i++) {
workers.push({})
workers.push({});
}
} catch (e) {}
} catch (e) {
}
return workers
}
return workers;
};
export const kdf = async (seed, salt, threads) => {
const workers = threads
const salt2 = new Uint8Array(salt)
const workers = threads;
const salt2 = new Uint8Array(salt);
salt = new Uint8Array(salt)
const seedParts = await Promise.all(workers.map((worker, index) => {
const nonce = index
salt = new Uint8Array(salt);
const seedParts = await Promise.all(
workers.map((worker, index) => {
const nonce = index;
return computekdf({
key: seed,
salt,
nonce,
staticSalt: crypto2.staticSalt,
staticBcryptSalt: crypto2.staticBcryptSalt
}).then(data => {
let jsonData
staticBcryptSalt: crypto2.staticBcryptSalt,
}).then((data) => {
let jsonData;
try {
jsonData = JSON.parse(data)
data = jsonData
jsonData = JSON.parse(data);
data = jsonData;
} catch (e) {
// ...
}
// if (seed !== data.key) throw new Error(kst3 + seed + ' !== ' + data.key)
// if (nonce !== data.nonce) throw new Error(kst4)
return data.result
return data.result;
});
})
}))
const result = new Sha512().process(stringtoUTF8Array(crypto2.staticSalt + seedParts.reduce((a, c) => a + c))).finish().result
return result
}
);
const result = new Sha512()
.process(
stringtoUTF8Array(crypto2.staticSalt + seedParts.reduce((a, c) => a + c))
)
.finish().result;
return result;
};

View File

@ -334,8 +334,8 @@
"minting": "(Prägung)",
"not_minting": "(nicht punktieren)",
"no_status": "kein Status",
"synchronized": "synchronisiert",
"synchronizing": "Synchronisierung..."
"synchronized": "synchronisiert ({{ percent }}%)",
"synchronizing": "Synchronisierung ({{ percent }}%)..."
},
"status_title": "Münzstatus",
"tier_share_per_block": "Stufenanteil pro Block",

View File

@ -336,8 +336,8 @@
"minting": "(minting)",
"not_minting": "(not minting)",
"no_status": "no status",
"synchronized": "synchronized",
"synchronizing": "synchronizing..."
"synchronized": "synchronized ({{ percent }}%)",
"synchronizing": "synchronizing ({{ percent }}%)..."
},
"status_title": "minting status",
"tier_share_per_block": "tier share per block",
@ -399,6 +399,8 @@
"hour_other": "{{count}} hours",
"minute_one": "{{count}} minute",
"minute_other": "{{count}} minutes",
"second_one": "{{count}} second",
"second_other": "{{count}} seconds",
"time": "time"
},
"title": "title",

View File

@ -335,8 +335,8 @@
"minting": "(acuñado)",
"not_minting": "(no acuñar)",
"no_status": "sin estado",
"synchronized": "sincronizado",
"synchronizing": "sincronización..."
"synchronized": "sincronizado ({{ percent }}%)",
"synchronizing": "sincronización ({{ percent }}%)..."
},
"status_title": "estado de acuñación",
"tier_share_per_block": "porción del nivel por bloque",

View File

@ -335,8 +335,8 @@
"minting": "(Frappe)",
"not_minting": "(pas de la frappe)",
"no_status": "pas de statut",
"synchronized": "synchronisé",
"synchronizing": "synchronisation..."
"synchronized": "synchronisé ({{ percent }}%)",
"synchronizing": "synchronisation ({{ percent }}%)..."
},
"status_title": "statut de frappe",
"tier_share_per_block": "part du niveau par bloc",

View File

@ -334,8 +334,8 @@
"minting": "(minting)",
"not_minting": "(non minting)",
"no_status": "nessun stato",
"synchronized": "sincronizzato",
"synchronizing": "sincronizzazione..."
"synchronized": "sincronizzato ({{ percent }}%)",
"synchronizing": "sincronizzazione ({{ percent }}%)..."
},
"status_title": "stato minting",
"tier_share_per_block": "quota della fascia per blocco",

View File

@ -335,8 +335,8 @@
"minting": "(鋳造)",
"not_minting": "(造りではありません)",
"no_status": "ステータスなし",
"synchronized": "同期",
"synchronizing": "同期..."
"synchronized": "同期 ({{ percent }}%)",
"synchronizing": "同期 ({{ percent }}%)..."
},
"status_title": "ミントステータス",
"tier_share_per_block": "ブロックごとのティアシェア",

View File

@ -335,8 +335,8 @@
"minting": "(добыча)",
"not_minting": "(не шахта)",
"no_status": "нет статуса",
"synchronized": "синхронизированный",
"synchronizing": "синхронизация..."
"synchronized": "синхронизированный ({{ percent }}%)",
"synchronizing": "синхронизация ({{ percent }}%)..."
},
"status_title": "Статус майтинга",
"tier_share_per_block": "доля уровня за блок",

View File

@ -335,8 +335,8 @@
"minting": "(铸造)",
"not_minting": "(不是铸造)",
"no_status": "没有状态",
"synchronized": "同步",
"synchronizing": "同步..."
"synchronized": "同步 ({{ percent }}%)",
"synchronizing": "同步 ({{ percent }}%)..."
},
"status_title": "铸造状态",
"tier_share_per_block": "每个区块的等级份额",

View File

@ -71,7 +71,7 @@ async function uploadChunkWithRetry(endpoint, formData, index, maxRetries = 3) {
if (attempt >= maxRetries) {
throw new Error(`Chunk ${index} failed after ${maxRetries} attempts`);
}
// Wait 10 seconds before next retry
// Wait 25 seconds before next retry
await new Promise((res) => setTimeout(res, 25_000));
}
}