From 7fcb42c09c191a2149402ba049aaa0ae0fecfa7c Mon Sep 17 00:00:00 2001 From: Kylan Hurt Date: Tue, 17 Oct 2023 13:48:17 -0300 Subject: [PATCH] Clean up determineUnits work --- src/components/AccountCard.vue | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/components/AccountCard.vue b/src/components/AccountCard.vue index bb9e3dc3..d1ffaefd 100644 --- a/src/components/AccountCard.vue +++ b/src/components/AccountCard.vue @@ -156,7 +156,7 @@ export default defineComponent({ } }; - const determineRamUnit = (size: number) => { + const determineUnit = (size: number) => { if (size > GIGA_UNIT.value) { return { unit: 'gb', @@ -178,22 +178,21 @@ export default defineComponent({ const loadResources = () => { let ramDenominator; if (props.account !== system_account.value) { - // in most cases the max value unit is more im portant than the - // used value unit. So we use the max value unit. - // get max ram number + // display max resource unit value for readability const ramMaxNumber = Number(accountData.value.ram_quota); - // get denominator based on max number - ramDenominator = determineRamUnit(ramMaxNumber).denominator; + const ramUnitResult = determineUnit(ramMaxNumber); + ramDenominator = ramUnitResult.denominator; + ramUnit.value = ramUnitResult.unit; // get displayed number value ram_max.value = fixDec( ramMaxNumber / ramDenominator, ); // get units - ramUnit.value = determineRamUnit(ramMaxNumber).unit; const netUsedNumber = Number(accountData.value.net_limit.used); const netMaxNumber = Number(accountData.value.net_limit.max); - const netDenominator = determineRamUnit(netMaxNumber).denominator; - netUnit.value = determineRamUnit(netMaxNumber).unit; + const netUnitResult = determineUnit(netMaxNumber); + const netDenominator = netUnitResult.denominator; + netUnit.value = netUnitResult.unit; net_used.value = fixDec( netUsedNumber / netDenominator, ); @@ -225,8 +224,9 @@ export default defineComponent({ const ramUsedNumber = Number(accountData.value.ram_usage); // only change denominator and units if wasn't already set if (!ramDenominator) { - ramDenominator = determineRamUnit(ramUsedNumber).denominator; - ramUnit.value = determineRamUnit(ramUsedNumber).unit; + const ramUnitResult = determineUnit(ramUsedNumber); + ramDenominator = ramUnitResult.denominator; + ramUnit.value = ramUnitResult.unit; } ram_used.value = fixDec( ramUsedNumber / ramDenominator, @@ -414,10 +414,6 @@ export default defineComponent({ return { accountPageSettings, - MICRO_UNIT, - KILO_UNIT, - MEGA_UNIT, - GIGA_UNIT, netUnit, ramUnit, stakedCPU,