Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Apr 28, 2024
1 parent 92f513c commit 4b09d2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
16 changes: 7 additions & 9 deletions src/hooks/salePrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@ import { useSaleInfo } from '@/contexts/sales';
import { useRouter } from 'next/router';

interface SalePriceProps {
at: number;
at?: number;
}

const useSalePrice = ({ at }: SalePriceProps) => {
const {
state: { api, apiState },
} = useCoretimeApi();
const { saleInfo } = useSaleInfo();

const [currentPrice, setCurrentPrice] = useState(0);
const router = useRouter();
const { network } = router.query;

const fetchCurrentPrice = useCallback(async () => {
if (api && apiState === ApiState.READY) {
const fetchCurrentPrice = async (at: number) => {
if (at) {
const price = getCurrentPrice(saleInfo, at, network);
setCurrentPrice(price);
}
}, [api, apiState, saleInfo]);
};

useEffect(() => {
fetchCurrentPrice();
}, [fetchCurrentPrice]);
if (!at) return;
fetchCurrentPrice(at);
}, [at]);

return currentPrice;
};
Expand Down
18 changes: 9 additions & 9 deletions src/pages/purchase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Purchase = () => {
const { fetchRegions } = useRegions();

const { balance } = useBalances();
const currentPrice = useSalePrice({ at });
let currentPrice = useSalePrice({ at });
const {
saleStart,
currentPhase,
Expand All @@ -59,16 +59,16 @@ const Purchase = () => {
} = useSalePhase();

useEffect(() => {
if (!api || apiState !== ApiState.READY) return;
if (!currentPhase) return;

api.query.system.number().then((height) => {
if (currentPhase === SalePhase.Interlude) {
console.log(saleStart);
setAt(saleStart);
} else {
if ((currentPhase as SalePhase) === SalePhase.Interlude) {
setAt(saleStart);
} else {
if (!api || apiState !== ApiState.READY) return;
api.query.system.number().then((height) => {
setAt(parseHNString(height.toHuman() as string));
}
});
});
}
}, [saleStart, currentPhase]);

const purchase = async () => {
Expand Down

0 comments on commit 4b09d2a

Please sign in to comment.