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

Feat/btc socket #257

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
492a25a
chore: update custom css url
trungbach Nov 27, 2023
7ddfca8
Merge branch 'main' into feat/add-chart-ui
trungbach Nov 27, 2023
e02561e
update: add some props
trungbach Nov 27, 2023
6a0ce9f
Update timezone chart
sonnx-oraichain Jan 10, 2024
638c53f
Update build code
sonnx-oraichain Jan 10, 2024
d4d6dac
feat: add socket chart
quangdz1704 Jan 22, 2024
20b79bc
fix: build
quangdz1704 Jan 23, 2024
5cacf3b
chore: bump version
quangdz1704 Jan 23, 2024
6ddbf35
chore: remove redundant code
quangdz1704 Jan 24, 2024
7a93b4d
fix: param and ws url
quangdz1704 Jan 24, 2024
820e45c
fix: add props fetch data
quangdz1704 Jan 25, 2024
b4c96ff
Merge branch 'main' into feat/add-chart-ui
quangdz1704 Jan 26, 2024
b7d3da0
fix: update ws chart
quangdz1704 Feb 2, 2024
cd4e225
fix sentry chart
haunv3 Feb 5, 2024
f92c8e5
Merge pull request #145 from oraichain/feat/update_base_url
meomeocoj Feb 16, 2024
64c2c71
fix: chart socket handle event (#156)
quangdz1704 Feb 19, 2024
c0b6004
chore: filter timpi/usdc chart
trungbach Feb 20, 2024
a678514
chore: filter timpi/usdc chart
trungbach Feb 20, 2024
aa93283
fix: comment ws (#177)
quangdz1704 Feb 21, 2024
bd14f31
Fix/ws chart (#178)
quangdz1704 Feb 21, 2024
4cfeebc
fix: try catch error load active chart
trungbach Feb 23, 2024
f9678dc
Merge branch 'main' into feat/add-chart-ui
trungbach Feb 23, 2024
129e4d5
chore: handle check chart ready
trungbach Feb 26, 2024
85c1430
Merge branch 'main' of https://github.com/oraichain/oraidex-sdk into …
trungbach Apr 1, 2024
925c650
chore: update color darkmode
trungbach Apr 1, 2024
f61deff
chore: update grid color
trungbach Apr 1, 2024
6c6a97d
Merge branch 'main' into feat/add-chart-ui
quangdz1704 Apr 15, 2024
a67bc2c
feat: add custom css color chart (#242)
quangdz1704 Apr 16, 2024
5b6d18e
fix: update chart dependency
quangdz1704 Apr 16, 2024
48b81b0
Merge branch 'main' of https://github.com/oraichain/oraidex-sdk into …
quangdz1704 May 2, 2024
5bf28c9
Feat/socket odt (#253)
quangdz1704 May 2, 2024
b90d217
fix: build ui common (#254)
quangdz1704 May 2, 2024
fc62d99
Fix/build UI (#255)
quangdz1704 May 2, 2024
f1bc9e0
fix: pair btc
quangdz1704 May 2, 2024
7956bb8
fix: parse pair
quangdz1704 May 2, 2024
9cb5b8e
fix: unsubcribe when unmount
quangdz1704 May 2, 2024
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
Prev Previous commit
Next Next commit
fix: update ws chart
  • Loading branch information
quangdz1704 committed Feb 2, 2024
commit b7d3da0b7ffc0bc926567cf86efd717509204aca
4 changes: 3 additions & 1 deletion packages/oraidex-common-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
},
"license": "MIT",
"dependencies": {
"@sentry/react": "^7.99.0",
"axios": "^0.26.1",
"axios-extensions": "^3.1.3",
"date-fns": "^3.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-use": "^17.4.0"
"react-use": "^17.4.0",
"react-use-websocket": "^4.5.0"
},
"devDependencies": {
"@storybook/addon-essentials": "7.5.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const SUPPORTED_RESOLUTIONS = {
360: "6h",
480: "8h",
1440: "1d"
}
};

export const FAVORITES_INTERVAL = ["5", "15", "60", "240", "1440"];

Expand All @@ -29,3 +29,5 @@ export const CHART_PERIODS = {
export const LAST_BAR_REFRESH_INTERVAL = 15000; // 15 seconds
export const TV_CHART_RELOAD_INTERVAL = 15 * 60 * 1000; // 15 minutes
export const DEFAULT_LIBRARY_URL = "https://chart.oraidex.io/charting_library.standalone.js";

export const EVENT_CHART_SOCKET = "ohlcv";
Original file line number Diff line number Diff line change
@@ -1,28 +1,50 @@
import { WEBSOCKET_RECONNECT_ATTEMPTS, WEBSOCKET_RECONNECT_INTERVAL } from "@oraichain/oraidex-common";
import { handleTradeEvent } from "./streaming";
import { useEffect, useState } from "react";
import { WS_URL } from "./requests";
import * as Sentry from "@sentry/react";
import useWebSocket from "react-use-websocket";
import { EVENT_CHART_SOCKET } from "./constants";

export type LastJsonMessageType = {
data: any;
event: string;
};

export const useChartSocket = (currentPair, socketUrl) => {
const [data, setData] = useState([]);

const { lastJsonMessage } = useWebSocket<LastJsonMessageType>(socketUrl || WS_URL, {
onOpen: () => {},
onClose: () => {
console.info("useChartSocket: WebSocket connection closed.");
},
onReconnectStop(numAttempts) {
if (numAttempts === WEBSOCKET_RECONNECT_ATTEMPTS)
console.info("useChartSocket: Reconnection reaches above limit. Unsubscribe to all!");
},
shouldReconnect: () => true,
onError: (error) => {
console.error("useChartSocket: Have something went wrong with connection.");
Sentry.captureException(`useChartSocket error with msg - ${error}`);
},
reconnectAttempts: WEBSOCKET_RECONNECT_ATTEMPTS,
reconnectInterval: WEBSOCKET_RECONNECT_INTERVAL
});

useEffect(() => {
const ws = new WebSocket(socketUrl || WS_URL);
ws.onmessage = (message) => {
const payload = JSON.parse(message.data);
console.info("[socket] Message:", payload);
if (payload.event === "spot") {
setData(payload.data);
if (lastJsonMessage && lastJsonMessage.data) {
const { data = [], event } = lastJsonMessage || {};

for (const ohlcv of payload.data) {
if (event === EVENT_CHART_SOCKET) {
setData(data);

for (const ohlcv of data) {
handleTradeEvent(ohlcv);
}
}
};

return () => {
ws.close();
};
}, [currentPair, socketUrl]);
}
}, [lastJsonMessage]);

return { currentPair, data };
};