Skip to content

fix: make unstaked vesting amounts non-rounded and unlock date to use days #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/staking/app/vested-stakes/modules/VestingEndTimeModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import { Module, ModuleText, ModuleTitle, ModuleTooltip } from '@session/ui/comp
import { LoadingText } from '@session/ui/components/loading-text';
import { Tooltip } from '@session/ui/ui/tooltip';
import { useTranslations } from 'next-intl';
import { useMemo } from 'react';

export function useVestingEndTime() {
const contract = useActiveVestingContract();
const date = contract ? new Date(contract?.time_end * 1000) : null;
const date = useMemo(() => (contract ? new Date(contract.time_end * 1000) : null), [contract]);
const formattedDate = useFormatDate(date, { dateStyle: 'full', timeStyle: 'long' });
const relativeTime = useRelativeTime(date, { addSuffix: false });

const unit = useMemo(
() => (date && date.getTime() - Date.now() > 24 * 60 * 60 * 1000 ? 'day' : undefined),
[date]
);

const relativeTime = useRelativeTime(date, { addSuffix: false, unit });
const isEnded = (date?.getTime() ?? 0) < Date.now();
return { date, formattedDate, relativeTime, isEnded };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useVestingEndTime } from '@/app/vested-stakes/modules/VestingEndTimeMod
import { ModuleDynamicQueryText } from '@/components/ModuleDynamic';
import type { QUERY_STATUS } from '@/lib/query';
import { useActiveVestingContractAddress } from '@/providers/vesting-provider';
import { addresses, isValidChainId } from '@session/contracts';
import { SENT_DECIMALS, addresses, isValidChainId } from '@session/contracts';
import { formatSENTBigInt } from '@session/contracts/hooks/Token';
import { Module, ModuleTitle, ModuleTooltip } from '@session/ui/components/Module';
import { useERC20Balance } from '@session/wallet/hooks/useERC20Balance';
Expand All @@ -25,6 +25,7 @@ export function useVestingUnstakedBalance() {

return {
formattedAmount: formatSENTBigInt(amount),
formattedAmountAccurate: formatSENTBigInt(amount, SENT_DECIMALS),
amount,
status,
refetch,
Expand Down
3 changes: 2 additions & 1 deletion apps/staking/components/Vesting/VestingHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NodeCard } from '@/components/NodeCard';
import { useVesting } from '@/providers/vesting-provider';
import { ButtonDataTestId } from '@/testing/data-test-ids';
import { zodResolver } from '@hookform/resolvers/zod';
import { SENT_DECIMALS } from '@session/contracts';
import { formatSENTBigInt } from '@session/contracts/hooks/Token';
import { PubKey } from '@session/ui/components/PubKey';
import { Button } from '@session/ui/ui/button';
Expand Down Expand Up @@ -118,7 +119,7 @@ export function VestingHandler({
<NodeItem>
<NodeItemLabel>{dictCard('balance')}</NodeItemLabel>
<NodeItemValue>
{formatSENTBigInt(contract.initial_amount)}
{formatSENTBigInt(contract.initial_amount, SENT_DECIMALS)}
</NodeItemValue>
</NodeItem>
</FormLabel>
Expand Down
5 changes: 3 additions & 2 deletions apps/staking/components/Vesting/VestingInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useNetworkBalances } from '@/hooks/useNetworkBalances';
import { DYNAMIC_MODULE } from '@/lib/constants';
import { useActiveVestingContract } from '@/providers/vesting-provider';
import { ButtonDataTestId } from '@/testing/data-test-ids';
import { SENT_DECIMALS } from '@session/contracts';
import { formatSENTBigInt } from '@session/contracts/hooks/Token';
import { EditButton } from '@session/ui/components/EditButton';
import { PubKey } from '@session/ui/components/PubKey';
Expand All @@ -15,7 +16,7 @@ import { useTranslations } from 'next-intl';
export function useVestingInitialBalance() {
const vestingContract = useActiveVestingContract();
const balance = vestingContract?.initial_amount ?? 0n;
const formattedBalance = formatSENTBigInt(balance);
const formattedBalance = formatSENTBigInt(balance, SENT_DECIMALS);
return { balance, formattedBalance };
}

Expand All @@ -39,7 +40,7 @@ export function VestingInfo({
const address = vestingContract?.address;

const { totalStakedFormatted } = useTotalStaked(vestingContract?.address);
const { formattedAmount: vestingUnstakedBalance } = useVestingUnstakedBalance();
const { formattedAmountAccurate: vestingUnstakedBalance } = useVestingUnstakedBalance();
const { unclaimed } = useNetworkBalances({ addressOverride: address });
const formattedUnclaimedRewardsAmount = formatSENTBigInt(
unclaimed,
Expand Down