diff --git a/frontend/src/basic/BookPage/index.tsx b/frontend/src/basic/BookPage/index.tsx
index d96960ef..f317d395 100644
--- a/frontend/src/basic/BookPage/index.tsx
+++ b/frontend/src/basic/BookPage/index.tsx
@@ -27,6 +27,7 @@ interface BookPageProps {
hasRobot: boolean;
setPage: (state: Page) => void;
setCurrentOrder: (state: number) => void;
+ baseUrl: string;
}
const BookPage = ({
@@ -43,6 +44,7 @@ const BookPage = ({
hasRobot = false,
setPage = () => null,
setCurrentOrder = () => null,
+ baseUrl,
}: BookPageProps): JSX.Element => {
const { t } = useTranslation();
const history = useHistory();
@@ -158,6 +160,7 @@ const BookPage = ({
onCurrencyChange={handleCurrencyChange}
onTypeChange={handleTypeChange}
onOrderClicked={onOrderClicked}
+ baseUrl={baseUrl}
/>
@@ -169,6 +172,7 @@ const BookPage = ({
maxWidth={chartWidthEm} // EM units
maxHeight={windowSize.height * 0.825 - 5} // EM units
onOrderClicked={onOrderClicked}
+ baseUrl={baseUrl}
/>
@@ -181,6 +185,7 @@ const BookPage = ({
maxWidth={windowSize.width * 0.8} // EM units
maxHeight={windowSize.height * 0.825 - 5} // EM units
onOrderClicked={onOrderClicked}
+ baseUrl={baseUrl}
/>
) : (
)}
diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx
index 7f582022..04e813a1 100644
--- a/frontend/src/basic/Main.tsx
+++ b/frontend/src/basic/Main.tsx
@@ -25,7 +25,7 @@ import {
} from '../models';
import { apiClient } from '../services/api';
-import { checkVer } from '../utils';
+import { checkVer, getHost } from '../utils';
import { sha256 } from 'js-sha256';
import defaultCoordinators from '../../static/federation.json';
@@ -59,6 +59,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
const [maker, setMaker] = useState(defaultMaker);
const [info, setInfo] = useState(defaultInfo);
const [coordinators, setCoordinators] = useState(defaultCoordinators);
+ const [baseUrl, setBaseUrl] = useState('');
const [fav, setFav] = useState({ type: null, currency: 0 });
const theme = useTheme();
@@ -105,6 +106,20 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
};
}, []);
+ useEffect(() => {
+ let host = '';
+ if (window.NativeRobosats === undefined) {
+ host = getHost();
+ } else {
+ host =
+ settings.network === 'mainnet'
+ ? coordinators[0].mainnetOnion
+ : coordinators[0].testnetOnion;
+ }
+ setBaseUrl(`http://${host}`);
+ console.log(`http://${host}`);
+ }, [settings.network]);
+
useEffect(() => {
setWindowSize(getWindowSize(theme.typography.fontSize));
}, [theme.typography.fontSize]);
@@ -115,7 +130,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,
@@ -125,7 +140,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;
});
@@ -134,7 +149,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
const fetchInfo = function () {
setInfo({ ...info, loading: true });
- apiClient.get('/api/info/').then((data: Info) => {
+ apiClient.get(baseUrl, '/api/info/').then((data: Info) => {
const versionInfo: any = checkVer(data.version.major, data.version.minor, data.version.patch);
setInfo({
...data,
@@ -162,7 +177,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
}
setRobot({ ...robot, loading: true });
- apiClient.post('/api/user/', requestBody).then((data: any) => {
+ apiClient.post(baseUrl, '/api/user/', requestBody).then((data: any) => {
setCurrentOrder(
data.active_order_id
? data.active_order_id
@@ -207,6 +222,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
setRobot({ ...robot, avatarLoaded: true })}
/>
{
theme={theme}
robot={robot}
setRobot={setRobot}
+ baseUrl={baseUrl}
/>
@@ -262,6 +279,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
hasRobot={robot.avatarLoaded}
setPage={setPage}
setCurrentOrder={setCurrentOrder}
+ baseUrl={baseUrl}
/>
@@ -300,7 +318,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
appear={slideDirection.in != undefined}
>
-
+
)}
@@ -335,6 +353,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
setSlideDirection={setSlideDirection}
currentOrder={currentOrder}
hasRobot={robot.avatarLoaded}
+ baseUrl={baseUrl}
/>
{
info={info}
robot={robot}
closeAll={closeAll}
+ baseUrl={baseUrl}
/>
);
diff --git a/frontend/src/basic/MainDialogs/index.tsx b/frontend/src/basic/MainDialogs/index.tsx
index f9a250aa..eaa70329 100644
--- a/frontend/src/basic/MainDialogs/index.tsx
+++ b/frontend/src/basic/MainDialogs/index.tsx
@@ -31,6 +31,7 @@ interface MainDialogsProps {
setPage: (state: Page) => void;
setCurrentOrder: (state: number) => void;
closeAll: OpenDialogs;
+ baseUrl: string;
}
const MainDialogs = ({
@@ -42,6 +43,7 @@ const MainDialogs = ({
setRobot,
setPage,
setCurrentOrder,
+ baseUrl,
}: MainDialogsProps): JSX.Element => {
useEffect(() => {
if (info.openUpdateClient) {
@@ -79,6 +81,7 @@ const MainDialogs = ({
/>
setOpen({ ...open, profile: false })}
robot={robot}
setRobot={setRobot}
diff --git a/frontend/src/basic/NavBar/NavBar.tsx b/frontend/src/basic/NavBar/NavBar.tsx
index 79b2ae1f..70e74e23 100644
--- a/frontend/src/basic/NavBar/NavBar.tsx
+++ b/frontend/src/basic/NavBar/NavBar.tsx
@@ -32,6 +32,7 @@ interface NavBarProps {
closeAll: OpenDialogs;
currentOrder: number | null;
hasRobot: boolean;
+ baseUrl: string;
}
const NavBar = ({
@@ -46,6 +47,7 @@ const NavBar = ({
height,
currentOrder,
hasRobot = false,
+ baseUrl,
}: NavBarProps): JSX.Element => {
const theme = useTheme();
const { t } = useTranslation();
@@ -111,6 +113,7 @@ const NavBar = ({
style={{ width: '2.3em', height: '2.3em', position: 'relative', top: '0.2em' }}
avatarClass={theme.palette.mode === 'dark' ? 'navBarAvatarDark' : 'navBarAvatar'}
nickname={nickname}
+ baseUrl={baseUrl}
/>
) : (
<>>
diff --git a/frontend/src/basic/OrderPage/index.js b/frontend/src/basic/OrderPage/index.js
index 26cc59db..9554bb45 100644
--- a/frontend/src/basic/OrderPage/index.js
+++ b/frontend/src/basic/OrderPage/index.js
@@ -117,7 +117,7 @@ class OrderPage extends Component {
getOrderDetails = (id) => {
this.setState({ orderId: id });
- apiClient.get('/api/order/?order_id=' + id).then(this.orderDetailsReceived);
+ apiClient.get(this.props.baseUrl, '/api/order/?order_id=' + id).then(this.orderDetailsReceived);
};
orderDetailsReceived = (data) => {
@@ -179,7 +179,7 @@ class OrderPage extends Component {
sendWeblnInvoice = (invoice) => {
apiClient
- .post('/api/order/?order_id=' + this.state.orderId, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.state.orderId, {
action: 'update_invoice',
invoice,
})
@@ -418,7 +418,7 @@ class OrderPage extends Component {
takeOrder = () => {
this.setState({ loading: true });
apiClient
- .post('/api/order/?order_id=' + this.state.orderId, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.state.orderId, {
action: 'take',
amount: this.state.takeAmount,
})
@@ -438,7 +438,7 @@ class OrderPage extends Component {
handleClickConfirmCancelButton = () => {
this.setState({ loading: true });
apiClient
- .post('/api/order/?order_id=' + this.state.orderId, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.state.orderId, {
action: 'cancel',
})
.then(() => this.getOrderDetails(this.state.orderId) & this.setState({ status: 4 }));
@@ -538,7 +538,7 @@ class OrderPage extends Component {
handleClickConfirmCollaborativeCancelButton = () => {
apiClient
- .post('/api/order/?order_id=' + this.state.orderId, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.state.orderId, {
action: 'cancel',
})
.then(() => this.getOrderDetails(this.state.orderId) & this.setState({ status: 4 }));
@@ -965,6 +965,7 @@ class OrderPage extends Component {
width={330}
data={this.state}
completeSetState={this.completeSetState}
+ baseUrl={this.props.baseUrl}
/>
@@ -1011,6 +1012,7 @@ class OrderPage extends Component {
width={330}
data={this.state}
completeSetState={this.completeSetState}
+ baseUrl={this.props.baseUrl}
/>
diff --git a/frontend/src/basic/UserGenPage.js b/frontend/src/basic/UserGenPage.js
index 23fd4f34..83dc166c 100644
--- a/frontend/src/basic/UserGenPage.js
+++ b/frontend/src/basic/UserGenPage.js
@@ -71,7 +71,7 @@ class UserGenPage extends Component {
};
});
requestBody.then((body) =>
- apiClient.post('/api/user/', body).then((data) => {
+ apiClient.post(this.props.baseUrl, '/api/user/', body).then((data) => {
this.setState({ found: data.found, bad_request: data.bad_request });
this.props.setCurrentOrder(
data.active_order_id
@@ -126,7 +126,7 @@ class UserGenPage extends Component {
};
delGeneratedUser() {
- apiClient.delete('/api/user');
+ apiClient.delete(this.props.baseUrl, '/api/user');
systemClient.deleteCookie('sessionid');
systemClient.deleteCookie('robot_token');
@@ -241,6 +241,7 @@ class UserGenPage extends Component {
}}
tooltip={t('This is your trading avatar')}
tooltipPosition='top'
+ baseUrl={this.props.baseUrl}
/>
diff --git a/frontend/src/components/BookTable/index.tsx b/frontend/src/components/BookTable/index.tsx
index eacbcb3f..08a490b9 100644
--- a/frontend/src/components/BookTable/index.tsx
+++ b/frontend/src/components/BookTable/index.tsx
@@ -46,6 +46,7 @@ interface BookTableProps {
onCurrencyChange?: (e: any) => void;
onTypeChange?: (mouseEvent: any, val: number) => void;
onOrderClicked?: (id: number) => void;
+ baseUrl: string;
}
const BookTable = ({
@@ -65,6 +66,7 @@ const BookTable = ({
onCurrencyChange,
onTypeChange,
onOrderClicked = () => null,
+ baseUrl,
}: BookTableProps): JSX.Element => {
const { t } = useTranslation();
const theme = useTheme();
@@ -173,6 +175,7 @@ const BookTable = ({
orderType={params.row.type}
statusColor={statusBadgeColor(params.row.maker_status)}
tooltip={t(params.row.maker_status)}
+ baseUrl={baseUrl}
/>
@@ -200,6 +203,7 @@ const BookTable = ({
orderType={params.row.type}
statusColor={statusBadgeColor(params.row.maker_status)}
tooltip={t(params.row.maker_status)}
+ baseUrl={baseUrl}
/>
diff --git a/frontend/src/components/Charts/DepthChart/index.tsx b/frontend/src/components/Charts/DepthChart/index.tsx
index d6d3aae8..d28b165a 100644
--- a/frontend/src/components/Charts/DepthChart/index.tsx
+++ b/frontend/src/components/Charts/DepthChart/index.tsx
@@ -20,8 +20,7 @@ import {
} from '@mui/material';
import { AddCircleOutline, RemoveCircleOutline } from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
-import { useHistory } from 'react-router-dom';
-import { PublicOrder, LimitList } from '../../../models';
+import { PublicOrder, LimitList, Order } from '../../../models';
import RobotAvatar from '../../RobotAvatar';
import { amountToString, matchMedian, statusBadgeColor } from '../../../utils';
import currencyDict from '../../../../static/assets/currencies.json';
@@ -38,6 +37,7 @@ interface DepthChartProps {
fillContainer?: boolean;
elevation?: number;
onOrderClicked?: (id: number) => void;
+ baseUrl: string;
}
const DepthChart: React.FC = ({
@@ -50,9 +50,9 @@ const DepthChart: React.FC = ({
fillContainer = false,
elevation = 6,
onOrderClicked = () => null,
+ baseUrl,
}) => {
const { t } = useTranslation();
- const history = useHistory();
const theme = useTheme();
const [enrichedOrders, setEnrichedOrders] = useState([]);
const [series, setSeries] = useState([]);
@@ -233,6 +233,7 @@ const DepthChart: React.FC = ({
orderType={order.type}
statusColor={statusBadgeColor(order.maker_status)}
tooltip={t(order.maker_status)}
+ baseUrl={baseUrl}
/>
diff --git a/frontend/src/components/Dialogs/Profile.tsx b/frontend/src/components/Dialogs/Profile.tsx
index 6dcab0bb..a8d13a3c 100644
--- a/frontend/src/components/Dialogs/Profile.tsx
+++ b/frontend/src/components/Dialogs/Profile.tsx
@@ -50,10 +50,12 @@ interface Props {
setRobot: (state: Robot) => void;
setPage: (state: Page) => void;
setCurrentOrder: (state: number) => void;
+ baseUrl: string;
}
const ProfileDialog = ({
open = false,
+ baseUrl,
onClose,
robot,
setRobot,
@@ -110,7 +112,7 @@ const ProfileDialog = ({
setShowRewardsSpinner(true);
apiClient
- .post('/api/reward/', {
+ .post(baseUrl, '/api/reward/', {
invoice: rewardInvoice,
})
.then((data: any) => {
@@ -130,7 +132,7 @@ const ProfileDialog = ({
const setStealthInvoice = (wantsStealth: boolean) => {
apiClient
- .put('/api/stealth/', { wantsStealth })
+ .put(baseUrl, '/api/stealth/', { wantsStealth })
.then((data) => setRobot({ ...robot, stealthInvoices: data?.wantsStealth }));
};
diff --git a/frontend/src/components/RobotAvatar/index.tsx b/frontend/src/components/RobotAvatar/index.tsx
index 5abfd4ff..14ef140a 100644
--- a/frontend/src/components/RobotAvatar/index.tsx
+++ b/frontend/src/components/RobotAvatar/index.tsx
@@ -18,6 +18,7 @@ interface Props {
tooltipPosition?: string;
avatarClass?: string;
onLoad?: () => void;
+ baseUrl: string;
}
const RobotAvatar: React.FC = ({
@@ -32,6 +33,7 @@ const RobotAvatar: React.FC = ({
avatarClass = 'flippedSmallAvatar',
imageStyle = {},
onLoad = () => {},
+ baseUrl,
}) => {
const { t } = useTranslation();
const theme = useTheme();
@@ -39,7 +41,13 @@ const RobotAvatar: React.FC = ({
useEffect(() => {
if (nickname != null) {
- apiClient.fileImageUrl('/static/assets/avatars/' + nickname + '.png').then(setAvatarSrc);
+ if (window.NativeRobosats === undefined) {
+ setAvatarSrc(baseUrl + '/static/assets/avatars/' + nickname + '.png');
+ } else {
+ apiClient
+ .fileImageUrl(baseUrl, '/static/assets/avatars/' + nickname + '.png')
+ .then(setAvatarSrc);
+ }
}
}, [nickname]);
diff --git a/frontend/src/components/TradeBox/index.js b/frontend/src/components/TradeBox/index.js
index c962bd65..3a7c2c5c 100644
--- a/frontend/src/components/TradeBox/index.js
+++ b/frontend/src/components/TradeBox/index.js
@@ -137,7 +137,7 @@ class TradeBox extends Component {
handleClickAgreeDisputeButton = () => {
apiClient
- .post('/api/order/?order_id=' + this.props.data.id, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.props.data.id, {
action: 'dispute',
})
.then((data) => this.props.completeSetState(data));
@@ -494,7 +494,7 @@ class TradeBox extends Component {
handleClickPauseOrder = () => {
this.props.completeSetState({ pauseLoading: true });
apiClient
- .post('/api/order/?order_id=' + this.props.data.id, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.props.data.id, {
action: 'pause',
})
.then((data) => this.props.getOrderDetails(data.id));
@@ -642,7 +642,7 @@ class TradeBox extends Component {
this.setState({ badInvoice: false, loadingSubmitInvoice: true });
apiClient
- .post('/api/order/?order_id=' + this.props.data.id, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.props.data.id, {
action: 'update_invoice',
invoice: this.state.invoice,
})
@@ -675,7 +675,7 @@ class TradeBox extends Component {
this.setState({ badInvoice: false, loadingSubmitAddress: true });
apiClient
- .post('/api/order/?order_id=' + this.props.data.id, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.props.data.id, {
action: 'update_address',
address: this.state.address,
mining_fee_rate: Math.max(1, this.state.miningFee),
@@ -698,7 +698,7 @@ class TradeBox extends Component {
this.setState({ badInvoice: false });
apiClient
- .post('/api/order/?order_id=' + this.props.data.id, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.props.data.id, {
action: 'submit_statement',
statement: this.state.statement,
})
@@ -1205,7 +1205,7 @@ class TradeBox extends Component {
handleClickConfirmButton = () => {
apiClient
- .post('/api/order/?order_id=' + this.props.data.id, {
+ .post(this.props.baseUrl, this.props.baseUrl, '/api/order/?order_id=' + this.props.data.id, {
action: 'confirm',
})
.then((data) => {
@@ -1216,7 +1216,7 @@ class TradeBox extends Component {
handleRatingUserChange = (e) => {
apiClient
- .post('/api/order/?order_id=' + this.props.data.id, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.props.data.id, {
action: 'rate_user',
rating: e.target.value,
})
@@ -1230,7 +1230,7 @@ class TradeBox extends Component {
this.setState({ rating_platform: e.target.value });
apiClient
- .post('/api/order/?order_id=' + this.props.data.id, {
+ .post(this.props.baseUrl, '/api/order/?order_id=' + this.props.data.id, {
action: 'rate_platform',
rating: e.target.value,
})
@@ -1356,7 +1356,7 @@ class TradeBox extends Component {
bondless_taker: this.props.data.bondless_taker,
};
apiClient
- .post('/api/make/', body)
+ .post(this.props.baseUrl, '/api/make/', body)
.then(
(data) =>
this.setState({ badRequest: data.bad_request }) &
diff --git a/frontend/src/components/UnsafeAlert.js b/frontend/src/components/UnsafeAlert.js
index 5a481cf1..590437cb 100644
--- a/frontend/src/components/UnsafeAlert.js
+++ b/frontend/src/components/UnsafeAlert.js
@@ -23,17 +23,24 @@ class UnsafeAlert extends Component {
checkClient() {
const http = new XMLHttpRequest();
- const unsafeClient = !this.safe_urls.includes(getHost());
+ const host = getHost();
+ const unsafeClient = !this.safe_urls.includes(host);
try {
- http.open('HEAD', `${location.protocol}//${getHost()}/selfhosted`, false);
+ http.open('HEAD', `${location.protocol}//${host}/selfhosted`, false);
http.send();
this.props.setSettings({
...this.props.settings,
+ host,
unsafeClient,
selfhostedClient: http.status === 200,
});
} catch {
- this.props.setSettings({ ...this.props.settings, unsafeClient, selfhostedClient: false });
+ this.props.setSettings({
+ ...this.props.settings,
+ host,
+ unsafeClient,
+ selfhostedClient: false,
+ });
}
}
diff --git a/frontend/src/models/Settings.model.ts b/frontend/src/models/Settings.model.ts
index 2b8ed817..3d134b98 100644
--- a/frontend/src/models/Settings.model.ts
+++ b/frontend/src/models/Settings.model.ts
@@ -46,6 +46,7 @@ class BaseSettings {
public freezeViewports: boolean = false;
public network: 'mainnet' | 'testnet' | undefined = 'mainnet';
public coordinator: Coordinator | undefined = undefined;
+ public host?: string;
public unsafeClient: boolean = false;
public hostedClient: boolean = false;
}
diff --git a/frontend/src/services/Native/index.d.ts b/frontend/src/services/Native/index.d.ts
index 2b0fb8d3..4ed495e8 100644
--- a/frontend/src/services/Native/index.d.ts
+++ b/frontend/src/services/Native/index.d.ts
@@ -16,6 +16,7 @@ export interface NativeWebViewMessageHttp {
category: 'http';
type: 'post' | 'get' | 'put' | 'delete' | 'xhr';
path: string;
+ baseUrl: string;
headers?: object;
body?: object;
}
diff --git a/frontend/src/services/api/ApiNativeClient/index.ts b/frontend/src/services/api/ApiNativeClient/index.ts
index f772876e..219cc8bb 100644
--- a/frontend/src/services/api/ApiNativeClient/index.ts
+++ b/frontend/src/services/api/ApiNativeClient/index.ts
@@ -38,39 +38,56 @@ class ApiNativeClient implements ApiClient {
return response.json;
};
- public put: (path: string, body: object) => Promise