Skip to content

Commit

Permalink
Merge pull request #807 from D8-X/dev
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
c40003141 authored Dec 26, 2024
2 parents 393b2fe + 947ec9f commit cbf7a86
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
16 changes: 10 additions & 6 deletions src/components/atoms-global-updates/AtomsGlobalUpdates.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAtomValue, useSetAtom } from 'jotai';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { useCallback, useEffect, useRef } from 'react';
import { type Address } from 'viem';
import { useAccount } from 'wagmi';
Expand All @@ -15,8 +15,8 @@ export const AtomsGlobalUpdates = () => {
const selectedPool = useAtomValue(selectedPoolAtom);
const setActivatedOneClickTrading = useSetAtom(activatedOneClickTradingAtom);
const setStorageKey = useSetAtom(storageKeyAtom);
const setPoolFee = useSetAtom(poolFeeAtom);
const setAddr0Fee = useSetAtom(addr0FeeAtom);
const [poolFee, setPoolFee] = useAtom(poolFeeAtom);
const [addr0Fee, setAddr0Fee] = useAtom(addr0FeeAtom);

const fetchFeeRef = useRef(false);
const fetchAddr0FeeRef = useRef(false);
Expand Down Expand Up @@ -70,9 +70,13 @@ export const AtomsGlobalUpdates = () => {
setAddr0Fee(undefined);
return;
}
fetchFee(chainId, selectedPool.poolSymbol, address).then();
fetchAddr0Fee(chainId, selectedPool.poolSymbol).then();
}, [chainId, selectedPool?.poolSymbol, address, fetchFee, fetchAddr0Fee, setPoolFee, setAddr0Fee]);
if (poolFee === undefined) {
fetchFee(chainId, selectedPool.poolSymbol, address).then();
}
if (addr0Fee === undefined) {
fetchAddr0Fee(chainId, selectedPool.poolSymbol).then();
}
}, [chainId, poolFee, addr0Fee, selectedPool?.poolSymbol, address, fetchFee, fetchAddr0Fee, setPoolFee, setAddr0Fee]);

return null;
};
6 changes: 4 additions & 2 deletions src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
gasTokenSymbolAtom,
oracleFactoryAddrAtom,
perpetualsAtom,
allPerpetualsAtom,
poolsAtom,
poolTokenBalanceAtom,
poolTokenDecimalsAtom,
Expand Down Expand Up @@ -81,6 +82,7 @@ export const Header = memo(({ window }: HeaderPropsI) => {
const setPools = useSetAtom(poolsAtom);
const setCollaterals = useSetAtom(collateralsAtom);
const setPerpetuals = useSetAtom(perpetualsAtom);
const setAllPerpetuals = useSetAtom(allPerpetualsAtom);
const setPositions = useSetAtom(positionsAtom);
const setOracleFactoryAddr = useSetAtom(oracleFactoryAddrAtom);
const setProxyAddr = useSetAtom(proxyAddrAtom);
Expand Down Expand Up @@ -170,15 +172,15 @@ export const Header = memo(({ window }: HeaderPropsI) => {
// Push the valid perpetuals into the perpetuals array
perpetuals.push(...validPerpetuals);
});

const filteredPerpetuals = perpetuals.filter(
(perpetual) => perpetual.state === 'NORMAL' || perpetual.isPredictionMarket
);
setPerpetuals(filteredPerpetuals);
setAllPerpetuals(perpetuals);
setOracleFactoryAddr(data.oracleFactoryAddr);
setProxyAddr(data.proxyAddr);
},
[setPools, setCollaterals, setPerpetuals, setOracleFactoryAddr, setProxyAddr, traderAPI]
[setPools, setCollaterals, setPerpetuals, setAllPerpetuals, setOracleFactoryAddr, setProxyAddr, traderAPI]
);

useEffect(() => {
Expand Down
10 changes: 8 additions & 2 deletions src/components/order-block/elements/action-block/ActionBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,13 @@ export const ActionBlock = memo(() => {
};

const isBuySellButtonActive = useMemo(() => {
if (!orderInfo || !address || !isEnabledChain(chainId) || selectedPerpetual?.state !== 'NORMAL') {
if (
!orderInfo ||
!address ||
!isEnabledChain(chainId) ||
selectedPerpetual?.state !== 'NORMAL' ||
poolFee === undefined
) {
return false;
}
if (!orderInfo.size || !perpetualStaticInfo?.lotSizeBC || orderInfo.size < perpetualStaticInfo.lotSizeBC) {
Expand All @@ -263,7 +269,7 @@ export const ActionBlock = memo(() => {
return false;
}
return !(orderInfo.orderType === OrderTypeE.Stop && (!orderInfo.triggerPrice || orderInfo.triggerPrice <= 0));
}, [orderInfo, address, chainId, perpetualStaticInfo?.lotSizeBC, selectedPerpetual?.state]);
}, [orderInfo, poolFee, address, chainId, perpetualStaticInfo?.lotSizeBC, selectedPerpetual?.state]);

const validityCheckButtonType = useMemo(() => {
if (isPredictionMarket && isMarketClosed) {
Expand Down
9 changes: 7 additions & 2 deletions src/components/trade-history-table/hooks/useTradesHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useAccount } from 'wagmi';

import { getTradesHistory } from 'network/history';
import { collateralToSettleConversionAtom, openOrdersAtom, perpetualsAtom, tradesHistoryAtom } from 'store/pools.store';
import {
collateralToSettleConversionAtom,
openOrdersAtom,
allPerpetualsAtom,
tradesHistoryAtom,
} from 'store/pools.store';
import type { TradeHistoryWithSymbolDataI } from 'types/types';
import { isEnabledChain } from 'utils/isEnabledChain';

Expand All @@ -12,7 +17,7 @@ export const useTradesHistory = () => {

const [tradesHistory, setTradesHistory] = useAtom(tradesHistoryAtom);
const openOrders = useAtomValue(openOrdersAtom);
const perpetuals = useAtomValue(perpetualsAtom);
const perpetuals = useAtomValue(allPerpetualsAtom);
const c2s = useAtomValue(collateralToSettleConversionAtom);

const updateTradesHistoryRef = useRef(false);
Expand Down
1 change: 1 addition & 0 deletions src/store/pools.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const traderAPIAtom = atom<TraderInterface | null>(null);
export const traderAPIBusyAtom = atom(false);
export const poolsAtom = atom<PoolWithIdI[]>([]);
export const perpetualsAtom = atom<PerpetualDataI[]>([]);
export const allPerpetualsAtom = atom<PerpetualDataI[]>([]);
export const poolFeeAtom = atom<number | undefined>(undefined);
export const addr0FeeAtom = atom<number | undefined>(undefined);
export const oracleFactoryAddrAtom = atom('');
Expand Down

0 comments on commit cbf7a86

Please sign in to comment.