mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-19 04:31:35 +00:00
Add baseUrl to apiClient on pro frontend
This commit is contained in:
parent
53dd8777cb
commit
56f9c35b50
@ -26,6 +26,9 @@ import {
|
|||||||
import ToolBar from '../pro/ToolBar';
|
import ToolBar from '../pro/ToolBar';
|
||||||
import LandingDialog from '../pro/LandingDialog';
|
import LandingDialog from '../pro/LandingDialog';
|
||||||
|
|
||||||
|
import defaultCoordinators from '../../static/federation.json';
|
||||||
|
import { getHost } from '../utils';
|
||||||
|
|
||||||
const getWindowSize = function (fontSize: number) {
|
const getWindowSize = function (fontSize: number) {
|
||||||
// returns window size in EM units
|
// returns window size in EM units
|
||||||
return {
|
return {
|
||||||
@ -80,7 +83,9 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
const [robot, setRobot] = useState<Robot>(new Robot());
|
const [robot, setRobot] = useState<Robot>(new Robot());
|
||||||
const [maker, setMaker] = useState<Maker>(defaultMaker);
|
const [maker, setMaker] = useState<Maker>(defaultMaker);
|
||||||
const [info, setInfo] = useState<Info>(defaultInfo);
|
const [info, setInfo] = useState<Info>(defaultInfo);
|
||||||
|
const [coordinators, setCoordinators] = useState<Coordinator[]>(defaultCoordinators);
|
||||||
const [fav, setFav] = useState<Favorites>({ type: null, currency: 0 });
|
const [fav, setFav] = useState<Favorites>({ type: null, currency: 0 });
|
||||||
|
const [baseUrl, setBaseUrl] = useState<string>('');
|
||||||
const [layout, setLayout] = useState<Layout>(defaultLayout);
|
const [layout, setLayout] = useState<Layout>(defaultLayout);
|
||||||
|
|
||||||
const [openLanding, setOpenLanding] = useState<boolean>(true);
|
const [openLanding, setOpenLanding] = useState<boolean>(true);
|
||||||
@ -92,15 +97,34 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
if (typeof window !== undefined) {
|
if (typeof window !== undefined) {
|
||||||
window.addEventListener('resize', onResize);
|
window.addEventListener('resize', onResize);
|
||||||
}
|
}
|
||||||
fetchLimits();
|
|
||||||
fetchBook();
|
if (baseUrl != '') {
|
||||||
fetchInfo();
|
fetchBook();
|
||||||
|
fetchLimits();
|
||||||
|
}
|
||||||
return () => {
|
return () => {
|
||||||
if (typeof window !== undefined) {
|
if (typeof window !== undefined) {
|
||||||
window.removeEventListener('resize', onResize);
|
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 () {
|
const onResize = function () {
|
||||||
setWindowSize(getWindowSize(em));
|
setWindowSize(getWindowSize(em));
|
||||||
@ -112,7 +136,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
|
|
||||||
const fetchLimits = async () => {
|
const fetchLimits = async () => {
|
||||||
setLimits({ ...limits, loading: true });
|
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 });
|
setLimits({ list: data ?? [], loading: false });
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
@ -121,7 +145,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
|
|
||||||
const fetchBook = function () {
|
const fetchBook = function () {
|
||||||
setBook({ ...book, loading: true });
|
setBook({ ...book, loading: true });
|
||||||
apiClient.get('/api/book/').then((data: any) =>
|
apiClient.get(baseUrl, '/api/book/').then((data: any) =>
|
||||||
setBook({
|
setBook({
|
||||||
loading: false,
|
loading: false,
|
||||||
orders: data.not_found ? [] : data,
|
orders: data.not_found ? [] : data,
|
||||||
@ -130,7 +154,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fetchInfo = function () {
|
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);
|
const versionInfo: any = checkVer(data.version.major, data.version.minor, data.version.patch);
|
||||||
setInfo({
|
setInfo({
|
||||||
...data,
|
...data,
|
||||||
@ -168,6 +192,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
>
|
>
|
||||||
<div key='Maker'>
|
<div key='Maker'>
|
||||||
<MakerWidget
|
<MakerWidget
|
||||||
|
baseUrl={baseUrl}
|
||||||
limits={limits}
|
limits={limits}
|
||||||
fetchLimits={fetchLimits}
|
fetchLimits={fetchLimits}
|
||||||
fav={fav}
|
fav={fav}
|
||||||
@ -178,6 +203,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
</div>
|
</div>
|
||||||
<div key='Book'>
|
<div key='Book'>
|
||||||
<BookWidget
|
<BookWidget
|
||||||
|
baseUrl={baseUrl}
|
||||||
book={book}
|
book={book}
|
||||||
layout={layout[1]}
|
layout={layout[1]}
|
||||||
gridCellSize={gridCellSize}
|
gridCellSize={gridCellSize}
|
||||||
@ -189,6 +215,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
</div>
|
</div>
|
||||||
<div key='DepthChart'>
|
<div key='DepthChart'>
|
||||||
<DepthChartWidget
|
<DepthChartWidget
|
||||||
|
baseUrl={baseUrl}
|
||||||
orders={book.orders}
|
orders={book.orders}
|
||||||
gridCellSize={gridCellSize}
|
gridCellSize={gridCellSize}
|
||||||
limitList={limits.list}
|
limitList={limits.list}
|
||||||
|
@ -5,6 +5,7 @@ import { Paper, useTheme } from '@mui/material';
|
|||||||
import BookTable from '../../components/BookTable';
|
import BookTable from '../../components/BookTable';
|
||||||
|
|
||||||
interface BookWidgetProps {
|
interface BookWidgetProps {
|
||||||
|
baseUrl: string;
|
||||||
layout: any;
|
layout: any;
|
||||||
gridCellSize?: number;
|
gridCellSize?: number;
|
||||||
book: Book;
|
book: Book;
|
||||||
@ -23,6 +24,7 @@ const BookWidget = React.forwardRef(
|
|||||||
(
|
(
|
||||||
{
|
{
|
||||||
layout,
|
layout,
|
||||||
|
baseUrl,
|
||||||
gridCellSize = 2,
|
gridCellSize = 2,
|
||||||
book,
|
book,
|
||||||
fetchBook,
|
fetchBook,
|
||||||
@ -42,6 +44,7 @@ const BookWidget = React.forwardRef(
|
|||||||
return (
|
return (
|
||||||
<Paper elevation={3} style={{ width: '100%', height: '100%' }}>
|
<Paper elevation={3} style={{ width: '100%', height: '100%' }}>
|
||||||
<BookTable
|
<BookTable
|
||||||
|
baseUrl={baseUrl}
|
||||||
elevation={0}
|
elevation={0}
|
||||||
clickRefresh={() => fetchBook()}
|
clickRefresh={() => fetchBook()}
|
||||||
book={book}
|
book={book}
|
||||||
|
@ -7,7 +7,7 @@ import DepthChart from '../../components/Charts/DepthChart';
|
|||||||
interface DepthChartWidgetProps {
|
interface DepthChartWidgetProps {
|
||||||
layout: any;
|
layout: any;
|
||||||
gridCellSize: number;
|
gridCellSize: number;
|
||||||
orders: Order[];
|
orders: PublicOrder[];
|
||||||
currency: number;
|
currency: number;
|
||||||
limitList: LimitList;
|
limitList: LimitList;
|
||||||
windowSize: { width: number; height: number };
|
windowSize: { width: number; height: number };
|
||||||
@ -16,6 +16,7 @@ interface DepthChartWidgetProps {
|
|||||||
onMouseDown?: () => void;
|
onMouseDown?: () => void;
|
||||||
onMouseUp?: () => void;
|
onMouseUp?: () => void;
|
||||||
onTouchEnd?: () => void;
|
onTouchEnd?: () => void;
|
||||||
|
baseUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DepthChartWidget = React.forwardRef(
|
const DepthChartWidget = React.forwardRef(
|
||||||
@ -25,6 +26,7 @@ const DepthChartWidget = React.forwardRef(
|
|||||||
gridCellSize,
|
gridCellSize,
|
||||||
limitList,
|
limitList,
|
||||||
orders,
|
orders,
|
||||||
|
baseUrl,
|
||||||
currency,
|
currency,
|
||||||
windowSize,
|
windowSize,
|
||||||
style,
|
style,
|
||||||
@ -40,6 +42,7 @@ const DepthChartWidget = React.forwardRef(
|
|||||||
return (
|
return (
|
||||||
<Paper elevation={3} style={{ width: '100%', height: '100%' }}>
|
<Paper elevation={3} style={{ width: '100%', height: '100%' }}>
|
||||||
<DepthChart
|
<DepthChart
|
||||||
|
baseUrl={baseUrl}
|
||||||
elevation={0}
|
elevation={0}
|
||||||
orders={orders}
|
orders={orders}
|
||||||
currency={currency}
|
currency={currency}
|
||||||
|
@ -11,6 +11,7 @@ interface MakerWidgetProps {
|
|||||||
maker: Maker;
|
maker: Maker;
|
||||||
setFav: (state: Favorites) => void;
|
setFav: (state: Favorites) => void;
|
||||||
setMaker: (state: Maker) => void;
|
setMaker: (state: Maker) => void;
|
||||||
|
baseUrl: string;
|
||||||
style?: Object;
|
style?: Object;
|
||||||
className?: string;
|
className?: string;
|
||||||
onMouseDown?: () => void;
|
onMouseDown?: () => void;
|
||||||
@ -27,6 +28,7 @@ const MakerWidget = React.forwardRef(
|
|||||||
fetchLimits,
|
fetchLimits,
|
||||||
fav,
|
fav,
|
||||||
setFav,
|
setFav,
|
||||||
|
baseUrl,
|
||||||
style,
|
style,
|
||||||
className,
|
className,
|
||||||
onMouseDown,
|
onMouseDown,
|
||||||
@ -42,6 +44,7 @@ const MakerWidget = React.forwardRef(
|
|||||||
style={{ padding: 8, overflow: 'auto', width: '100%', height: '100%' }}
|
style={{ padding: 8, overflow: 'auto', width: '100%', height: '100%' }}
|
||||||
>
|
>
|
||||||
<MakerForm
|
<MakerForm
|
||||||
|
baseUrl={baseUrl}
|
||||||
limits={limits}
|
limits={limits}
|
||||||
fetchLimits={fetchLimits}
|
fetchLimits={fetchLimits}
|
||||||
maker={maker}
|
maker={maker}
|
||||||
|
Loading…
Reference in New Issue
Block a user