Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/switch ticker #827

Merged
merged 3 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/contexts/market_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,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 @@ -319,6 +318,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 @@ -613,8 +613,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
10 changes: 4 additions & 6 deletions src/contexts/user_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ export const UserProvider = ({children}: IUserProvider) => {
// const balance: IBalance | null = getBalance(openCFDs[index].targetAsset);
const transferR = transactionEngine.transferCFDOrderToTransaction(applyCloseCFDOrder);
if (!transferR.success) throw new CustomError(Code.FAILED_TO_CREATE_TRANSACTION);
// ++ TODO: send request to chain(use Lunar?) (20230324 - tzuhan)
// TODO: send request to chain(use Lunar?) (20230324 - tzuhan)
const signature: string = await lunar.signTypedData(transferR.data);
/* Info: (20230505 - Julian) 需要再驗證一次簽名是否正確 */
const success = lunar.verifyTypedData(transferR.data, signature);
Expand Down Expand Up @@ -1307,7 +1307,7 @@ export const UserProvider = ({children}: IUserProvider) => {
if (index === -1) throw new CustomError(Code.CFD_ORDER_NOT_FOUND);
const transferR = transactionEngine.transferCFDOrderToTransaction(applyUpdateCFDOrder);
if (!transferR.success) throw new CustomError(Code.FAILED_TO_CREATE_TRANSACTION);
// ++ TODO: send request to chain(use Lunar?) (20230324 - tzuhan)
// TODO: send request to chain(use Lunar?) (20230324 - tzuhan)
const signature: string = await lunar.signTypedData(transferR.data);
/* Info: (20230505 - Julian) 需要再驗證一次簽名是否正確 */
const success = lunar.verifyTypedData(transferR.data, signature);
Expand Down Expand Up @@ -1432,8 +1432,6 @@ export const UserProvider = ({children}: IUserProvider) => {
};
setWithdraws(prev => [...prev, withdrawOrder]);
updateBalance(balanceSnapshot);
// setHistories(prev => [...prev, acceptedWithdrawOrder]);

result.code = Code.SUCCESS;
result = {
success: success,
Expand Down Expand Up @@ -1667,10 +1665,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