Skip to content

Commit

Permalink
fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Apr 22, 2024
1 parent 1daa543 commit 4508f20
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/hooks/salePhase.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiPromise } from '@polkadot/api';
import { useRouter } from 'next/router';
import { useCallback, useEffect, useState } from 'react';

import {
Expand All @@ -19,7 +20,6 @@ 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 Down Expand Up @@ -53,7 +53,7 @@ const useSalePhase = () => {
saleInfo,
blockNumber,
lastCommittedTimeslice,
network,
network
);

getBlockTimestamp(api, _saleStart, getBlockTime(network)).then(
Expand Down Expand Up @@ -90,7 +90,7 @@ const useSalePhase = () => {
},
]);
},
[saleInfo, config]
[saleInfo, config, network]
);

useEffect(() => {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/purchase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ const Purchase = () => {
</Box>
<Box>
{loading ||
!currentPhase ||
!progress ||
!saleStartTimestamp ||
!saleEndTimestamp ? (
!currentPhase ||
!progress ||
!saleStartTimestamp ||
!saleEndTimestamp ? (
<>
<Typography variant='h5' align='center'>
Connect your wallet
Expand Down
9 changes: 1 addition & 8 deletions src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@ export const getBlockTimestamp = async (
const currentHeight = parseHNString(resHeight.toString());
const currentTimestamp = parseHNString(resTimestamp.toString());
if (height <= currentHeight) {
try {
const hash = await api.rpc.chain.getBlockHash(height);
const apiAt = await api.at(hash);
const timestamp = Number((await apiAt.query.timestamp.now()).toJSON());
return timestamp;
} catch (_) {
return currentTimestamp - (currentHeight - height) * blockTime;
}
return currentTimestamp - (currentHeight - height) * blockTime;
} else {
return currentTimestamp + (height - currentHeight) * blockTime;
}
Expand Down

0 comments on commit 4508f20

Please sign in to comment.