Skip to content

Commit

Permalink
Clean up determineUnits work
Browse files Browse the repository at this point in the history
  • Loading branch information
kylanhurt committed Oct 17, 2023
1 parent 5d233ec commit 7fcb42c
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/components/AccountCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default defineComponent({
}
};
const determineRamUnit = (size: number) => {
const determineUnit = (size: number) => {
if (size > GIGA_UNIT.value) {
return {
unit: 'gb',
Expand All @@ -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,
);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -414,10 +414,6 @@ export default defineComponent({
return {
accountPageSettings,
MICRO_UNIT,
KILO_UNIT,
MEGA_UNIT,
GIGA_UNIT,
netUnit,
ramUnit,
stakedCPU,
Expand Down

0 comments on commit 7fcb42c

Please sign in to comment.