Alexander Zinchuk 97d3d31f10 Giveaway: Creating giveaway in channels (#4339)
Co-authored-by: zubiden <19638254+zubiden@users.noreply.github.com>
2024-04-19 13:37:50 +04:00

29 lines
882 B
TypeScript

import type { ApiBoostsStatus } from '../../../api/types';
export function getBoostProgressInfo(boostInfo: ApiBoostsStatus, freezeOnLevelUp?: boolean) {
const {
level, boosts, currentLevelBoosts, nextLevelBoosts, hasMyBoost, prepaidGiveaways,
} = boostInfo;
const isJustUpgraded = freezeOnLevelUp && boosts === currentLevelBoosts && hasMyBoost;
const currentLevel = isJustUpgraded ? level - 1 : level;
const hasNextLevel = Boolean(nextLevelBoosts);
const levelProgress = (!nextLevelBoosts || isJustUpgraded) ? 1
: (boosts - currentLevelBoosts) / (nextLevelBoosts - currentLevelBoosts);
const remainingBoosts = nextLevelBoosts ? nextLevelBoosts - boosts : 0;
const isMaxLevel = nextLevelBoosts === undefined;
return {
currentLevel,
hasNextLevel,
boosts,
levelProgress,
remainingBoosts,
isMaxLevel,
prepaidGiveaways,
};
}