Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Apr 28, 2024
1 parent 4b09d2a commit eaf1dbd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
21 changes: 11 additions & 10 deletions src/hooks/salePrice.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useRouter } from 'next/router';
import { useCallback, useEffect, useState } from 'react';

import { getCurrentPrice } from '@/utils/sale/utils';

import { useCoretimeApi } from '@/contexts/apis';
import { ApiState } from '@/contexts/apis/types';
import { useSaleInfo } from '@/contexts/sales';
import { useRouter } from 'next/router';

interface SalePriceProps {
at?: number;
Expand All @@ -18,17 +16,20 @@ const useSalePrice = ({ at }: SalePriceProps) => {
const router = useRouter();
const { network } = router.query;

const fetchCurrentPrice = async (at: number) => {
if (at) {
const price = getCurrentPrice(saleInfo, at, network);
setCurrentPrice(price);
}
};
const fetchCurrentPrice = useCallback(
async (at: number) => {
if (at) {
const price = getCurrentPrice(saleInfo, at, network);
setCurrentPrice(price);
}
},
[network, saleInfo]
);

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

return currentPrice;
};
Expand Down
7 changes: 4 additions & 3 deletions src/pages/purchase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useEffect, useState } from 'react';

import useSalePhase from '@/hooks/salePhase';
import useSalePrice from '@/hooks/salePrice';
import { getBlockTimestamp, parseHNString, sendTx } from '@/utils/functions';
import { parseHNString, sendTx } from '@/utils/functions';

import { CoreDetailsPanel, ProgressButton, SaleInfoPanel } from '@/components';
import Balance from '@/components/Elements/Balance';
Expand Down Expand Up @@ -48,7 +48,7 @@ const Purchase = () => {
const { fetchRegions } = useRegions();

const { balance } = useBalances();
let currentPrice = useSalePrice({ at });
const currentPrice = useSalePrice({ at });
const {
saleStart,
currentPhase,
Expand All @@ -61,6 +61,7 @@ const Purchase = () => {
useEffect(() => {
if (!currentPhase) return;

// If the sale hasn't started yet, get the price from when the sale begins.
if ((currentPhase as SalePhase) === SalePhase.Interlude) {
setAt(saleStart);
} else {
Expand All @@ -69,7 +70,7 @@ const Purchase = () => {
setAt(parseHNString(height.toHuman() as string));
});
}
}, [saleStart, currentPhase]);
}, [api, apiState, saleStart, currentPhase]);

const purchase = async () => {
if (!api || apiState !== ApiState.READY || !activeAccount || !activeSigner)
Expand Down
1 change: 0 additions & 1 deletion src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Decimal from 'decimal.js';

import {
CORETIME_DECIMALS,
NetworkType,
REGIONX_DECIMALS,
TxStatusHandlers,
} from '@/models';
Expand Down

0 comments on commit eaf1dbd

Please sign in to comment.