Skip to content

Commit

Permalink
Merge pull request #811 from CAFECA-IO/bug/switch_ticker
Browse files Browse the repository at this point in the history
Bug/switch ticker
  • Loading branch information
Luphia authored Jun 5, 2023
2 parents 7310c7e + e50db21 commit 72aab2f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/contexts/market_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ export const MarketProvider = ({children}: IMarketProvider) => {
const ticker: ITickerData = availableTickersRef.current[tickerId];
if (!ticker) return {...defaultResultFailed};
setSelectedTicker(ticker);
notificationCtx.emitter.emit(TideBitEvent.TICKER_CHANGE, ticker);
await listMarketTrades(ticker.instId);
syncCandlestickData();
// ++ TODO: get from api
Expand All @@ -278,6 +277,7 @@ export const MarketProvider = ({children}: IMarketProvider) => {
if (isGetTickerLiveStatisticsSuccess)
setTickerLiveStatistics(tickerLiveStatistics as ITickerLiveStatistics);
await getGuaranteedStopFeePercentage(ticker.instId);
notificationCtx.emitter.emit(TideBitEvent.TICKER_CHANGE, ticker);
return {...defaultResultSuccess};
};

Expand Down Expand Up @@ -570,8 +570,8 @@ export const MarketProvider = ({children}: IMarketProvider) => {
const init = async () => {
await getTideBitPromotion();
await getWebsiteReserve();
await listTickers();
await listCurrencies();
await listTickers();
setIsCFDTradable(true);
return await Promise.resolve();
};
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/user_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1642,10 +1642,10 @@ export const UserProvider = ({children}: IUserProvider) => {
);
React.useMemo(
() =>
notificationCtx.emitter.on(TideBitEvent.TICKER_CHANGE, (ticker: ITickerData) => {
notificationCtx.emitter.on(TideBitEvent.TICKER_CHANGE, async (ticker: ITickerData) => {
if (!selectedTickerRef.current || ticker.instId !== selectedTickerRef.current?.instId) {
setSelectedTicker(ticker);
listCFDs(ticker?.currency);
await listCFDs(ticker?.currency);
}
}),
[]
Expand Down
13 changes: 2 additions & 11 deletions src/contexts/worker_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const WorkerProvider = ({children}: IWorkerProvider) => {
const [publicChannel, setPublicChannel, publicChannelRef] = useState<Channel | null>(null);
const jobQueueOfWS = useRef<((...args: []) => Promise<void>)[]>([]);
const jobQueueOfAPI = useRef<((...args: []) => Promise<void>)[]>([]);
const [sockedId, setSocketId, sockedIdRef] = useState<string | null>(null);
const [socketId, setSocketId, socketIdRef] = useState<string | null>(null);
/* Deprecated: callback in requestHandler (Tzuhan - 20230420)
const requests = useRef<IRequest>({});
*/
Expand Down Expand Up @@ -139,19 +139,10 @@ export const WorkerProvider = ({children}: IWorkerProvider) => {
},
},
});
// eslint-disable-next-line no-console
console.log('pusher', pusher);
setPuser(pusher);
pusher.connection.bind('connected', function () {
const socketId = pusher.connection.socket_id;
// Deprecated: [debug] (20230523 - tzuhan)
// eslint-disable-next-line no-console
console.log('pusher My socket ID is ' + socketId);
setSocketId(sockedId);
setSocketId(socketId);
const channel = pusherRef.current?.subscribe(PusherChannel.GLOBAL_CHANNEL);
// Deprecated: [debug] (20230523 - tzuhan)
// eslint-disable-next-line no-console
console.log('channel ', channel);
if (channel) {
setPublicChannel(channel);
subscribeTickers();
Expand Down
8 changes: 4 additions & 4 deletions src/pages/trade/cfd/[tickerId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const Trading = (props: IPageProps) => {
}
}, []);

useEffect(() => {
if ((marketCtx?.selectedTickerRef?.current?.currency?.toString() ?? '') === currency) return;
redirectToTicker();
}, [marketCtx.availableTickers]);
// useEffect(() => {
// if ((marketCtx?.selectedTickerRef?.current?.currency?.toString() ?? '') === currency) return;
// redirectToTicker();
// }, [marketCtx.availableTickers]);

if (!router.isFallback && !props.tickerId) {
return <Error statusCode={404} />;
Expand Down

1 comment on commit 72aab2f

@vercel
Copy link

@vercel vercel bot commented on 72aab2f Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tidebit-defi – ./

tidebit-defi.vercel.app
tidebit-defi-git-main-cafeca.vercel.app
tidebit-defi-cafeca.vercel.app

Please sign in to comment.