Fix bug that would flash opposite state of updateOBSTextVisibility for a split second on price update

This commit is contained in:
Wizzard 2024-03-02 17:42:10 -05:00
parent 382db88249
commit 8c5ee1faf2
1 changed files with 10 additions and 4 deletions

14
main.js
View File

@ -28,6 +28,10 @@ function restartCalculations() {
calculationInterval = setInterval(checkStatusAndUpdateOBS, 5000);
}
let obsVisibilityState = {
makingMoney: null
};
discordClient.login(discordToken);
discordClient.on('ready', async () => {
@ -73,10 +77,8 @@ function updateEnvValue(key, value) {
}
function createStatsEmbed(tokenData = {}) {
// Function to format numbers with commas
const formatNumber = (num) => new Intl.NumberFormat().format(num);
// Formatting the numbers using the formatNumber function
const marketCapFormatted = tokenData.marketCap ? `$${formatNumber(tokenData.marketCap)}` : 'N/A';
const priceFormatted = tokenData.price ? `$${formatNumber(tokenData.price)}` : 'N/A';
const liquidityFormatted = tokenData.liquidity ? `$${formatNumber(tokenData.liquidity)}` : 'N/A';
@ -215,8 +217,12 @@ const setSourceVisibility = (sourceName, visible) => {
};
const updateOBSTextVisibility = (makingMoney) => {
setSourceVisibility("TextGreen", makingMoney);
setSourceVisibility("TextRed", !makingMoney);
if (obsVisibilityState.makingMoney !== makingMoney) {
setSourceVisibility("TextGreen", makingMoney);
setSourceVisibility("TextRed", !makingMoney);
obsVisibilityState.makingMoney = makingMoney;
}
};
const checkStatusAndUpdateOBS = async () => {