Skip to content

Commit

Permalink
merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Apr 22, 2024
1 parent 29143b0 commit 1daa543
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/hooks/salePhase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApiPromise } from '@polkadot/api';
import { useCallback, useEffect, useState } from 'react';

import {
getBlockTime,
getBlockTimestamp,
parseHNString,
} from '@/utils/functions';
Expand All @@ -18,6 +19,7 @@ import { useCoretimeApi } from '@/contexts/apis';
import { ApiState } from '@/contexts/apis/types';
import { useSaleInfo } from '@/contexts/sales';
import { SalePhase } from '@/models';
import { useRouter } from 'next/router';

// Custom hook for fetching current phase
const useSalePhase = () => {
Expand All @@ -34,6 +36,9 @@ const useSalePhase = () => {
const [progress, setProgress] = useState<number | null>(0);
const [saleSections, setSaleSections] = useState<Section[]>([]);

const router = useRouter();
const { network } = router.query;

const fetchCurrentPhase = useCallback(
async (api: ApiPromise) => {
const blockNumber = (await api.query.system.number()).toJSON() as number;
Expand All @@ -43,17 +48,18 @@ const useSalePhase = () => {
).lastCommittedTimeslice.toString()
);

const _saleStart = getSaleStartInBlocks(saleInfo, config);
const _saleStart = getSaleStartInBlocks(saleInfo);
const _saleEnd = getSaleEndInBlocks(
saleInfo,
blockNumber,
lastCommittedTimeslice,
network,
);

getBlockTimestamp(api, _saleStart).then(
getBlockTimestamp(api, _saleStart, getBlockTime(network)).then(
(value: number) => setSaleStartTimestamp(value)
);
getBlockTimestamp(api, _saleEnd).then(
getBlockTimestamp(api, _saleEnd, getBlockTime(network)).then(
(value: number) => setSaleEndTimestamp(value)
);

Expand All @@ -62,6 +68,7 @@ const useSalePhase = () => {
config,
blockNumber,
lastCommittedTimeslice,
network
);
setProgress(progress);

Expand Down

0 comments on commit 1daa543

Please sign in to comment.