diff --git a/frontend/src/pro/Main.tsx b/frontend/src/pro/Main.tsx index ee99231c..f898ea44 100644 --- a/frontend/src/pro/Main.tsx +++ b/frontend/src/pro/Main.tsx @@ -26,6 +26,9 @@ import { import ToolBar from '../pro/ToolBar'; import LandingDialog from '../pro/LandingDialog'; +import defaultCoordinators from '../../static/federation.json'; +import { getHost } from '../utils'; + const getWindowSize = function (fontSize: number) { // returns window size in EM units return { @@ -80,7 +83,9 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { const [robot, setRobot] = useState(new Robot()); const [maker, setMaker] = useState(defaultMaker); const [info, setInfo] = useState(defaultInfo); + const [coordinators, setCoordinators] = useState(defaultCoordinators); const [fav, setFav] = useState({ type: null, currency: 0 }); + const [baseUrl, setBaseUrl] = useState(''); const [layout, setLayout] = useState(defaultLayout); const [openLanding, setOpenLanding] = useState(true); @@ -92,15 +97,34 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { if (typeof window !== undefined) { window.addEventListener('resize', onResize); } - fetchLimits(); - fetchBook(); - fetchInfo(); + + if (baseUrl != '') { + fetchBook(); + fetchLimits(); + } return () => { if (typeof window !== undefined) { window.removeEventListener('resize', onResize); } }; - }, []); + }, [baseUrl]); + + useEffect(() => { + let host = ''; + if (window.NativeRobosats === undefined) { + host = getHost(); + } else { + host = + settings.network === 'mainnet' + ? coordinators[0].mainnetOnion + : coordinators[0].testnetOnion; + } + setBaseUrl(`http://${host}`); + }, [settings.network]); + + useEffect(() => { + setWindowSize(getWindowSize(theme.typography.fontSize)); + }, [theme.typography.fontSize]); const onResize = function () { setWindowSize(getWindowSize(em)); @@ -112,7 +136,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { const fetchLimits = async () => { setLimits({ ...limits, loading: true }); - const data = apiClient.get('/api/limits/').then((data) => { + const data = apiClient.get(baseUrl, '/api/limits/').then((data) => { setLimits({ list: data ?? [], loading: false }); return data; }); @@ -121,7 +145,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { const fetchBook = function () { setBook({ ...book, loading: true }); - apiClient.get('/api/book/').then((data: any) => + apiClient.get(baseUrl, '/api/book/').then((data: any) => setBook({ loading: false, orders: data.not_found ? [] : data, @@ -130,7 +154,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { }; const fetchInfo = function () { - apiClient.get('/api/info/').then((data: any) => { + apiClient.get(baseUrl, '/api/info/').then((data: any) => { const versionInfo: any = checkVer(data.version.major, data.version.minor, data.version.patch); setInfo({ ...data, @@ -168,6 +192,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { >
{
{
fetchBook()} book={book} diff --git a/frontend/src/pro/Widgets/Depth.tsx b/frontend/src/pro/Widgets/Depth.tsx index c65afdee..518139c0 100644 --- a/frontend/src/pro/Widgets/Depth.tsx +++ b/frontend/src/pro/Widgets/Depth.tsx @@ -7,7 +7,7 @@ import DepthChart from '../../components/Charts/DepthChart'; interface DepthChartWidgetProps { layout: any; gridCellSize: number; - orders: Order[]; + orders: PublicOrder[]; currency: number; limitList: LimitList; windowSize: { width: number; height: number }; @@ -16,6 +16,7 @@ interface DepthChartWidgetProps { onMouseDown?: () => void; onMouseUp?: () => void; onTouchEnd?: () => void; + baseUrl: string; } const DepthChartWidget = React.forwardRef( @@ -25,6 +26,7 @@ const DepthChartWidget = React.forwardRef( gridCellSize, limitList, orders, + baseUrl, currency, windowSize, style, @@ -40,6 +42,7 @@ const DepthChartWidget = React.forwardRef( return ( void; setMaker: (state: Maker) => void; + baseUrl: string; style?: Object; className?: string; onMouseDown?: () => void; @@ -27,6 +28,7 @@ const MakerWidget = React.forwardRef( fetchLimits, fav, setFav, + baseUrl, style, className, onMouseDown, @@ -42,6 +44,7 @@ const MakerWidget = React.forwardRef( style={{ padding: 8, overflow: 'auto', width: '100%', height: '100%' }} >