import { VegaIcon, VegaIconNames } from '@vegaprotocol/ui-toolkit'; import { useT } from '../../../lib/use-t'; import classNames from 'classnames'; import BigNumber from 'bignumber.js'; import type { PartyActivityStreak } from '@vegaprotocol/types'; import { NetworkParams, useNetworkParams, } from '@vegaprotocol/network-parameters'; export const safeProgress = ( i: number, userTierIndex: number, total: number | string, progress?: number | string ) => { if (i < userTierIndex) return 100; if (i > userTierIndex) return 0; if (!progress || !total) return 0; if (new BigNumber(progress).isGreaterThan(total)) return 100; return new BigNumber(progress) .multipliedBy(100) .dividedBy(total || 1) .toNumber(); }; export const useGetUserTier = ( tiers: { minimum_activity_streak: number; reward_multiplier: string; vesting_multiplier: string; }[], progress?: number ) => { if (!progress) return 0; if (!tiers || tiers.length === 0) return 0; let userTier = 0; let i = 0; while ( i < tiers.length && tiers[userTier].minimum_activity_streak < progress ) { userTier = i; i++; } if ( i === tiers.length && tiers[userTier].minimum_activity_streak <= progress ) { userTier = i; } if (userTier > tiers.length) { userTier--; } return userTier; }; export const ActivityStreak = ({ tiers, streak, }: { tiers: { minimum_activity_streak: number; reward_multiplier: string; vesting_multiplier: string; }[]; streak?: PartyActivityStreak | null; }) => { const t = useT(); const userTierIndex = useGetUserTier(tiers, streak?.activeFor); const { params } = useNetworkParams([ NetworkParams.rewards_activityStreak_inactivityLimit, ]); const remaining = new BigNumber(params.rewards_activityStreak_inactivityLimit) .minus(streak?.inactiveFor || 0) .toNumber(); if (!tiers || tiers.length === 0) return null; const progressBarHeight = 'h-10'; return ( <>