Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d6dd402a2 | ||
|
|
24e7cdac14 | ||
|
|
cc1811da16 |
@@ -71,8 +71,7 @@
|
||||
"keplrDashboard": "https://testnet.keplr.app/",
|
||||
"strideZoneApp": "https://testnet.stride.zone",
|
||||
"accountExportLearnMore": "https://help.dydx.exchange/en/articles/8565867-secret-phrase-on-dydx-chain",
|
||||
"walletLearnMore": "https://www.dydx.academy/video/defi-wallet",
|
||||
"launchIncentive": "https://cloud.chaoslabs.co/"
|
||||
"walletLearnMore": "https://www.dydx.academy/video/defi-wallet"
|
||||
},
|
||||
"dydx-testnet-4": {
|
||||
"tos": "https://dydx.exchange/v4-terms",
|
||||
@@ -93,8 +92,7 @@
|
||||
"keplrDashboard": "https://testnet.keplr.app/",
|
||||
"strideZoneApp": "https://testnet.stride.zone",
|
||||
"accountExportLearnMore": "https://help.dydx.exchange/en/articles/8565867-secret-phrase-on-dydx-chain",
|
||||
"walletLearnMore": "https://www.dydx.academy/video/defi-wallet",
|
||||
"launchIncentive": "https://cloud.chaoslabs.co/"
|
||||
"walletLearnMore": "https://www.dydx.academy/video/defi-wallet"
|
||||
},
|
||||
"[mainnet chain id]": {
|
||||
"tos": "[HTTP link to TOS]",
|
||||
@@ -115,8 +113,7 @@
|
||||
"keplrDashboard": "[HTTP link to keplr dashboard, can be null]",
|
||||
"strideZoneApp": "[HTTP link to stride zone app, can be null]",
|
||||
"accountExportLearnMore": "[HTTP link to account export learn more, can be null]",
|
||||
"walletLearnMore": "[HTTP link to wallet learn more, can be null]",
|
||||
"launchIncentive": "[HTTP link to launch incentive host, can be null]"
|
||||
"walletLearnMore": "[HTTP link to wallet learn more, can be null]"
|
||||
}
|
||||
},
|
||||
"wallets": {
|
||||
|
||||
@@ -9,14 +9,16 @@ import type { ChartLine, TvWidget } from '@/constants/tvchart';
|
||||
|
||||
import { useStringGetter } from '@/hooks';
|
||||
|
||||
import { getCurrentMarketOrders, getCurrentMarketPositionData } from '@/state/accountSelectors';
|
||||
import {
|
||||
getCurrentMarketOrders,
|
||||
getCurrentMarketPositionData,
|
||||
getIsAccountConnected,
|
||||
} from '@/state/accountSelectors';
|
||||
import { getAppTheme, getAppColorMode } from '@/state/configsSelectors';
|
||||
|
||||
import { MustBigNumber } from '@/lib/numbers';
|
||||
import { getChartLineColors } from '@/lib/tradingView/utils';
|
||||
|
||||
let chartLines: Record<string, ChartLine> = {};
|
||||
|
||||
/**
|
||||
* @description Hook to handle drawing chart lines
|
||||
*/
|
||||
@@ -25,43 +27,47 @@ export const useChartLines = ({
|
||||
tvWidget,
|
||||
displayButton,
|
||||
isChartReady,
|
||||
chartLinesRef,
|
||||
}: {
|
||||
tvWidget: TvWidget | null;
|
||||
displayButton: HTMLElement | null;
|
||||
isChartReady?: boolean;
|
||||
isChartReady: boolean;
|
||||
chartLinesRef: React.MutableRefObject<Record<string, ChartLine>>;
|
||||
}) => {
|
||||
const [showOrderLines, setShowOrderLines] = useState(false);
|
||||
const [showOrderLines, setShowOrderLines] = useState(true);
|
||||
|
||||
const stringGetter = useStringGetter();
|
||||
|
||||
const appTheme = useSelector(getAppTheme);
|
||||
const appColorMode = useSelector(getAppColorMode);
|
||||
|
||||
const isAccountConnected = useSelector(getIsAccountConnected);
|
||||
|
||||
const currentMarketPositionData = useSelector(getCurrentMarketPositionData, shallowEqual);
|
||||
const currentMarketOrders: SubaccountOrder[] = useSelector(getCurrentMarketOrders, shallowEqual);
|
||||
|
||||
useEffect(() => {
|
||||
if (isChartReady && displayButton) {
|
||||
displayButton.onclick = () => {
|
||||
const newShowOrderLinesState = !showOrderLines;
|
||||
if (newShowOrderLinesState) {
|
||||
displayButton?.classList?.add('order-lines-active');
|
||||
} else {
|
||||
displayButton?.classList?.remove('order-lines-active');
|
||||
}
|
||||
setShowOrderLines(newShowOrderLinesState);
|
||||
};
|
||||
displayButton.onclick = () => setShowOrderLines(!showOrderLines);
|
||||
}
|
||||
}, [isChartReady, showOrderLines]);
|
||||
|
||||
useEffect(() => {
|
||||
if (tvWidget && isChartReady) {
|
||||
if (!isAccountConnected) {
|
||||
deleteChartLines();
|
||||
}
|
||||
}, [isAccountConnected]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isChartReady && tvWidget) {
|
||||
tvWidget.onChartReady(() => {
|
||||
tvWidget.chart().dataReady(() => {
|
||||
if (showOrderLines) {
|
||||
displayButton?.classList?.add('order-lines-active');
|
||||
drawOrderLines();
|
||||
drawPositionLine();
|
||||
} else {
|
||||
displayButton?.classList?.remove('order-lines-active');
|
||||
deleteChartLines();
|
||||
}
|
||||
});
|
||||
@@ -78,13 +84,13 @@ export const useChartLines = ({
|
||||
const key = currentMarketPositionData.id;
|
||||
const price = MustBigNumber(entryPrice).toNumber();
|
||||
|
||||
const maybePositionLine = chartLines[key]?.line;
|
||||
const maybePositionLine = chartLinesRef.current[key]?.line;
|
||||
const shouldShow = size && size !== 0;
|
||||
|
||||
if (!shouldShow) {
|
||||
if (maybePositionLine) {
|
||||
maybePositionLine.remove();
|
||||
delete chartLines[key];
|
||||
delete chartLinesRef.current[key];
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -106,9 +112,9 @@ export const useChartLines = ({
|
||||
.setQuantity(quantity);
|
||||
|
||||
if (positionLine) {
|
||||
const chartLine = { line: positionLine, chartLineType: 'position' };
|
||||
const chartLine: ChartLine = { line: positionLine, chartLineType: 'position' };
|
||||
setLineColors({ chartLine: chartLine });
|
||||
chartLines[key] = chartLine;
|
||||
chartLinesRef.current[key] = chartLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,12 +149,12 @@ export const useChartLines = ({
|
||||
!cancelReason &&
|
||||
(status === AbacusOrderStatus.open || status === AbacusOrderStatus.untriggered);
|
||||
|
||||
const maybeOrderLine = chartLines[key]?.line;
|
||||
const maybeOrderLine = chartLinesRef.current[key]?.line;
|
||||
|
||||
if (!shouldShow) {
|
||||
if (maybeOrderLine) {
|
||||
maybeOrderLine.remove();
|
||||
delete chartLines[key];
|
||||
delete chartLinesRef.current[key];
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -170,7 +176,7 @@ export const useChartLines = ({
|
||||
chartLineType: ORDER_SIDES[side.name],
|
||||
};
|
||||
setLineColors({ chartLine: chartLine });
|
||||
chartLines[key] = chartLine;
|
||||
chartLinesRef.current[key] = chartLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,10 +185,10 @@ export const useChartLines = ({
|
||||
};
|
||||
|
||||
const deleteChartLines = () => {
|
||||
Object.values(chartLines).forEach(({ line }) => {
|
||||
Object.values(chartLinesRef.current).forEach(({ line }) => {
|
||||
line.remove();
|
||||
});
|
||||
chartLines = {};
|
||||
chartLinesRef.current = {};
|
||||
};
|
||||
|
||||
const setLineColors = ({ chartLine }: { chartLine: ChartLine }) => {
|
||||
@@ -204,6 +210,4 @@ export const useChartLines = ({
|
||||
maybeQuantityColor &&
|
||||
line.setLineColor(maybeQuantityColor).setQuantityBackgroundColor(maybeQuantityColor);
|
||||
};
|
||||
|
||||
return { chartLines };
|
||||
};
|
||||
|
||||
@@ -38,7 +38,7 @@ export const useChartMarketAndResolution = ({
|
||||
* @description Hook to handle changing markets - intentionally should avoid triggering on change of resolutions.
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (currentMarketId && isWidgetReady) {
|
||||
if (isWidgetReady && currentMarketId !== tvWidget?.activeChart().symbol()) {
|
||||
const resolution = savedResolution || selectedResolution;
|
||||
tvWidget?.setSymbol(currentMarketId, resolution as ResolutionString, () => {});
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ class TestFlags {
|
||||
get showTradingRewards() {
|
||||
return !!this.queryParams.tradingrewards;
|
||||
}
|
||||
|
||||
get showCexWithdrawal() {
|
||||
return !!this.queryParams.cexwithdrawal;
|
||||
}
|
||||
}
|
||||
|
||||
export const testFlags = new TestFlags();
|
||||
|
||||
@@ -4,7 +4,7 @@ import styled, { type AnyStyledComponent, css } from 'styled-components';
|
||||
|
||||
import type { ResolutionString } from 'public/tradingview/charting_library';
|
||||
|
||||
import type { TvWidget } from '@/constants/tvchart';
|
||||
import type { ChartLine, TvWidget } from '@/constants/tvchart';
|
||||
|
||||
import {
|
||||
useChartLines,
|
||||
@@ -27,13 +27,16 @@ export const TvChart = () => {
|
||||
const displayButtonRef = useRef<HTMLElement | null>(null);
|
||||
const displayButton = displayButtonRef.current;
|
||||
|
||||
const chartLinesRef = useRef<Record<string, ChartLine>>({});
|
||||
const chartLines = chartLinesRef.current;
|
||||
|
||||
const { savedResolution } = useTradingView({ tvWidgetRef, displayButtonRef, setIsChartReady });
|
||||
useChartMarketAndResolution({
|
||||
tvWidget,
|
||||
isWidgetReady,
|
||||
savedResolution: savedResolution as ResolutionString | undefined,
|
||||
});
|
||||
const { chartLines } = useChartLines({ tvWidget, displayButton, isChartReady });
|
||||
useChartLines({ tvWidget, displayButton, isChartReady, chartLinesRef });
|
||||
useTradingViewTheme({ tvWidget, isWidgetReady, chartLines });
|
||||
|
||||
return (
|
||||
|
||||
@@ -63,11 +63,12 @@ export const SourceSelectMenu = ({
|
||||
return (
|
||||
<SearchSelectMenu
|
||||
items={[
|
||||
exchangeItems.length > 0 && {
|
||||
group: 'exchanges',
|
||||
groupLabel: stringGetter({ key: STRING_KEYS.EXCHANGES }),
|
||||
items: exchangeItems,
|
||||
},
|
||||
exchangeItems.length > 0 &&
|
||||
(testFlags.showCexWithdrawal || type === TransferType.deposit) && {
|
||||
group: 'exchanges',
|
||||
groupLabel: stringGetter({ key: STRING_KEYS.EXCHANGES }),
|
||||
items: exchangeItems,
|
||||
},
|
||||
chainItems.length > 0 && {
|
||||
group: 'chains',
|
||||
groupLabel: stringGetter({ key: STRING_KEYS.CHAINS }),
|
||||
|
||||
Reference in New Issue
Block a user