mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-10 16:21:36 +00:00
Add swappable baseurls (network and coordinators)
This commit is contained in:
parent
8cf6b3bd32
commit
d7e464eb2e
@ -27,6 +27,7 @@ interface BookPageProps {
|
|||||||
hasRobot: boolean;
|
hasRobot: boolean;
|
||||||
setPage: (state: Page) => void;
|
setPage: (state: Page) => void;
|
||||||
setCurrentOrder: (state: number) => void;
|
setCurrentOrder: (state: number) => void;
|
||||||
|
baseUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BookPage = ({
|
const BookPage = ({
|
||||||
@ -43,6 +44,7 @@ const BookPage = ({
|
|||||||
hasRobot = false,
|
hasRobot = false,
|
||||||
setPage = () => null,
|
setPage = () => null,
|
||||||
setCurrentOrder = () => null,
|
setCurrentOrder = () => null,
|
||||||
|
baseUrl,
|
||||||
}: BookPageProps): JSX.Element => {
|
}: BookPageProps): JSX.Element => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@ -158,6 +160,7 @@ const BookPage = ({
|
|||||||
onCurrencyChange={handleCurrencyChange}
|
onCurrencyChange={handleCurrencyChange}
|
||||||
onTypeChange={handleTypeChange}
|
onTypeChange={handleTypeChange}
|
||||||
onOrderClicked={onOrderClicked}
|
onOrderClicked={onOrderClicked}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
@ -169,6 +172,7 @@ const BookPage = ({
|
|||||||
maxWidth={chartWidthEm} // EM units
|
maxWidth={chartWidthEm} // EM units
|
||||||
maxHeight={windowSize.height * 0.825 - 5} // EM units
|
maxHeight={windowSize.height * 0.825 - 5} // EM units
|
||||||
onOrderClicked={onOrderClicked}
|
onOrderClicked={onOrderClicked}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
@ -181,6 +185,7 @@ const BookPage = ({
|
|||||||
maxWidth={windowSize.width * 0.8} // EM units
|
maxWidth={windowSize.width * 0.8} // EM units
|
||||||
maxHeight={windowSize.height * 0.825 - 5} // EM units
|
maxHeight={windowSize.height * 0.825 - 5} // EM units
|
||||||
onOrderClicked={onOrderClicked}
|
onOrderClicked={onOrderClicked}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<BookTable
|
<BookTable
|
||||||
@ -195,6 +200,7 @@ const BookPage = ({
|
|||||||
onCurrencyChange={handleCurrencyChange}
|
onCurrencyChange={handleCurrencyChange}
|
||||||
onTypeChange={handleTypeChange}
|
onTypeChange={handleTypeChange}
|
||||||
onOrderClicked={onOrderClicked}
|
onOrderClicked={onOrderClicked}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -25,7 +25,7 @@ import {
|
|||||||
} from '../models';
|
} from '../models';
|
||||||
|
|
||||||
import { apiClient } from '../services/api';
|
import { apiClient } from '../services/api';
|
||||||
import { checkVer } from '../utils';
|
import { checkVer, getHost } from '../utils';
|
||||||
import { sha256 } from 'js-sha256';
|
import { sha256 } from 'js-sha256';
|
||||||
|
|
||||||
import defaultCoordinators from '../../static/federation.json';
|
import defaultCoordinators from '../../static/federation.json';
|
||||||
@ -59,6 +59,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
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 [coordinators, setCoordinators] = useState<Coordinator[]>(defaultCoordinators);
|
||||||
|
const [baseUrl, setBaseUrl] = useState<string>('');
|
||||||
const [fav, setFav] = useState<Favorites>({ type: null, currency: 0 });
|
const [fav, setFav] = useState<Favorites>({ type: null, currency: 0 });
|
||||||
|
|
||||||
const theme = useTheme();
|
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(() => {
|
useEffect(() => {
|
||||||
setWindowSize(getWindowSize(theme.typography.fontSize));
|
setWindowSize(getWindowSize(theme.typography.fontSize));
|
||||||
}, [theme.typography.fontSize]);
|
}, [theme.typography.fontSize]);
|
||||||
@ -115,7 +130,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,
|
||||||
@ -125,7 +140,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;
|
||||||
});
|
});
|
||||||
@ -134,7 +149,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
|
|
||||||
const fetchInfo = function () {
|
const fetchInfo = function () {
|
||||||
setInfo({ ...info, loading: true });
|
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);
|
const versionInfo: any = checkVer(data.version.major, data.version.minor, data.version.patch);
|
||||||
setInfo({
|
setInfo({
|
||||||
...data,
|
...data,
|
||||||
@ -162,7 +177,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setRobot({ ...robot, loading: true });
|
setRobot({ ...robot, loading: true });
|
||||||
apiClient.post('/api/user/', requestBody).then((data: any) => {
|
apiClient.post(baseUrl, '/api/user/', requestBody).then((data: any) => {
|
||||||
setCurrentOrder(
|
setCurrentOrder(
|
||||||
data.active_order_id
|
data.active_order_id
|
||||||
? data.active_order_id
|
? data.active_order_id
|
||||||
@ -207,6 +222,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
<RobotAvatar
|
<RobotAvatar
|
||||||
style={{ display: 'none' }}
|
style={{ display: 'none' }}
|
||||||
nickname={robot.nickname}
|
nickname={robot.nickname}
|
||||||
|
baseUrl={baseUrl}
|
||||||
onLoad={() => setRobot({ ...robot, avatarLoaded: true })}
|
onLoad={() => setRobot({ ...robot, avatarLoaded: true })}
|
||||||
/>
|
/>
|
||||||
<Box
|
<Box
|
||||||
@ -235,6 +251,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
theme={theme}
|
theme={theme}
|
||||||
robot={robot}
|
robot={robot}
|
||||||
setRobot={setRobot}
|
setRobot={setRobot}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Slide>
|
</Slide>
|
||||||
@ -262,6 +279,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
hasRobot={robot.avatarLoaded}
|
hasRobot={robot.avatarLoaded}
|
||||||
setPage={setPage}
|
setPage={setPage}
|
||||||
setCurrentOrder={setCurrentOrder}
|
setCurrentOrder={setCurrentOrder}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Slide>
|
</Slide>
|
||||||
@ -300,7 +318,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
appear={slideDirection.in != undefined}
|
appear={slideDirection.in != undefined}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<OrderPage theme={theme} history={history} {...props} />
|
<OrderPage theme={theme} history={history} {...props} baseUrl={baseUrl} />
|
||||||
</div>
|
</div>
|
||||||
</Slide>
|
</Slide>
|
||||||
)}
|
)}
|
||||||
@ -335,6 +353,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
setSlideDirection={setSlideDirection}
|
setSlideDirection={setSlideDirection}
|
||||||
currentOrder={currentOrder}
|
currentOrder={currentOrder}
|
||||||
hasRobot={robot.avatarLoaded}
|
hasRobot={robot.avatarLoaded}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
<MainDialogs
|
<MainDialogs
|
||||||
open={open}
|
open={open}
|
||||||
@ -345,6 +364,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
|
|||||||
info={info}
|
info={info}
|
||||||
robot={robot}
|
robot={robot}
|
||||||
closeAll={closeAll}
|
closeAll={closeAll}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
@ -31,6 +31,7 @@ interface MainDialogsProps {
|
|||||||
setPage: (state: Page) => void;
|
setPage: (state: Page) => void;
|
||||||
setCurrentOrder: (state: number) => void;
|
setCurrentOrder: (state: number) => void;
|
||||||
closeAll: OpenDialogs;
|
closeAll: OpenDialogs;
|
||||||
|
baseUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MainDialogs = ({
|
const MainDialogs = ({
|
||||||
@ -42,6 +43,7 @@ const MainDialogs = ({
|
|||||||
setRobot,
|
setRobot,
|
||||||
setPage,
|
setPage,
|
||||||
setCurrentOrder,
|
setCurrentOrder,
|
||||||
|
baseUrl,
|
||||||
}: MainDialogsProps): JSX.Element => {
|
}: MainDialogsProps): JSX.Element => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (info.openUpdateClient) {
|
if (info.openUpdateClient) {
|
||||||
@ -79,6 +81,7 @@ const MainDialogs = ({
|
|||||||
/>
|
/>
|
||||||
<ProfileDialog
|
<ProfileDialog
|
||||||
open={open.profile}
|
open={open.profile}
|
||||||
|
baseUrl={baseUrl}
|
||||||
onClose={() => setOpen({ ...open, profile: false })}
|
onClose={() => setOpen({ ...open, profile: false })}
|
||||||
robot={robot}
|
robot={robot}
|
||||||
setRobot={setRobot}
|
setRobot={setRobot}
|
||||||
|
@ -32,6 +32,7 @@ interface NavBarProps {
|
|||||||
closeAll: OpenDialogs;
|
closeAll: OpenDialogs;
|
||||||
currentOrder: number | null;
|
currentOrder: number | null;
|
||||||
hasRobot: boolean;
|
hasRobot: boolean;
|
||||||
|
baseUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NavBar = ({
|
const NavBar = ({
|
||||||
@ -46,6 +47,7 @@ const NavBar = ({
|
|||||||
height,
|
height,
|
||||||
currentOrder,
|
currentOrder,
|
||||||
hasRobot = false,
|
hasRobot = false,
|
||||||
|
baseUrl,
|
||||||
}: NavBarProps): JSX.Element => {
|
}: NavBarProps): JSX.Element => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -111,6 +113,7 @@ const NavBar = ({
|
|||||||
style={{ width: '2.3em', height: '2.3em', position: 'relative', top: '0.2em' }}
|
style={{ width: '2.3em', height: '2.3em', position: 'relative', top: '0.2em' }}
|
||||||
avatarClass={theme.palette.mode === 'dark' ? 'navBarAvatarDark' : 'navBarAvatar'}
|
avatarClass={theme.palette.mode === 'dark' ? 'navBarAvatarDark' : 'navBarAvatar'}
|
||||||
nickname={nickname}
|
nickname={nickname}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
|
@ -117,7 +117,7 @@ class OrderPage extends Component {
|
|||||||
|
|
||||||
getOrderDetails = (id) => {
|
getOrderDetails = (id) => {
|
||||||
this.setState({ orderId: 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) => {
|
orderDetailsReceived = (data) => {
|
||||||
@ -179,7 +179,7 @@ class OrderPage extends Component {
|
|||||||
|
|
||||||
sendWeblnInvoice = (invoice) => {
|
sendWeblnInvoice = (invoice) => {
|
||||||
apiClient
|
apiClient
|
||||||
.post('/api/order/?order_id=' + this.state.orderId, {
|
.post(this.props.baseUrl, '/api/order/?order_id=' + this.state.orderId, {
|
||||||
action: 'update_invoice',
|
action: 'update_invoice',
|
||||||
invoice,
|
invoice,
|
||||||
})
|
})
|
||||||
@ -418,7 +418,7 @@ class OrderPage extends Component {
|
|||||||
takeOrder = () => {
|
takeOrder = () => {
|
||||||
this.setState({ loading: true });
|
this.setState({ loading: true });
|
||||||
apiClient
|
apiClient
|
||||||
.post('/api/order/?order_id=' + this.state.orderId, {
|
.post(this.props.baseUrl, '/api/order/?order_id=' + this.state.orderId, {
|
||||||
action: 'take',
|
action: 'take',
|
||||||
amount: this.state.takeAmount,
|
amount: this.state.takeAmount,
|
||||||
})
|
})
|
||||||
@ -438,7 +438,7 @@ class OrderPage extends Component {
|
|||||||
handleClickConfirmCancelButton = () => {
|
handleClickConfirmCancelButton = () => {
|
||||||
this.setState({ loading: true });
|
this.setState({ loading: true });
|
||||||
apiClient
|
apiClient
|
||||||
.post('/api/order/?order_id=' + this.state.orderId, {
|
.post(this.props.baseUrl, '/api/order/?order_id=' + this.state.orderId, {
|
||||||
action: 'cancel',
|
action: 'cancel',
|
||||||
})
|
})
|
||||||
.then(() => this.getOrderDetails(this.state.orderId) & this.setState({ status: 4 }));
|
.then(() => this.getOrderDetails(this.state.orderId) & this.setState({ status: 4 }));
|
||||||
@ -538,7 +538,7 @@ class OrderPage extends Component {
|
|||||||
|
|
||||||
handleClickConfirmCollaborativeCancelButton = () => {
|
handleClickConfirmCollaborativeCancelButton = () => {
|
||||||
apiClient
|
apiClient
|
||||||
.post('/api/order/?order_id=' + this.state.orderId, {
|
.post(this.props.baseUrl, '/api/order/?order_id=' + this.state.orderId, {
|
||||||
action: 'cancel',
|
action: 'cancel',
|
||||||
})
|
})
|
||||||
.then(() => this.getOrderDetails(this.state.orderId) & this.setState({ status: 4 }));
|
.then(() => this.getOrderDetails(this.state.orderId) & this.setState({ status: 4 }));
|
||||||
@ -965,6 +965,7 @@ class OrderPage extends Component {
|
|||||||
width={330}
|
width={330}
|
||||||
data={this.state}
|
data={this.state}
|
||||||
completeSetState={this.completeSetState}
|
completeSetState={this.completeSetState}
|
||||||
|
baseUrl={this.props.baseUrl}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
@ -1011,6 +1012,7 @@ class OrderPage extends Component {
|
|||||||
width={330}
|
width={330}
|
||||||
data={this.state}
|
data={this.state}
|
||||||
completeSetState={this.completeSetState}
|
completeSetState={this.completeSetState}
|
||||||
|
baseUrl={this.props.baseUrl}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -71,7 +71,7 @@ class UserGenPage extends Component {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
requestBody.then((body) =>
|
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.setState({ found: data.found, bad_request: data.bad_request });
|
||||||
this.props.setCurrentOrder(
|
this.props.setCurrentOrder(
|
||||||
data.active_order_id
|
data.active_order_id
|
||||||
@ -126,7 +126,7 @@ class UserGenPage extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
delGeneratedUser() {
|
delGeneratedUser() {
|
||||||
apiClient.delete('/api/user');
|
apiClient.delete(this.props.baseUrl, '/api/user');
|
||||||
|
|
||||||
systemClient.deleteCookie('sessionid');
|
systemClient.deleteCookie('sessionid');
|
||||||
systemClient.deleteCookie('robot_token');
|
systemClient.deleteCookie('robot_token');
|
||||||
@ -241,6 +241,7 @@ class UserGenPage extends Component {
|
|||||||
}}
|
}}
|
||||||
tooltip={t('This is your trading avatar')}
|
tooltip={t('This is your trading avatar')}
|
||||||
tooltipPosition='top'
|
tooltipPosition='top'
|
||||||
|
baseUrl={this.props.baseUrl}
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -46,6 +46,7 @@ interface BookTableProps {
|
|||||||
onCurrencyChange?: (e: any) => void;
|
onCurrencyChange?: (e: any) => void;
|
||||||
onTypeChange?: (mouseEvent: any, val: number) => void;
|
onTypeChange?: (mouseEvent: any, val: number) => void;
|
||||||
onOrderClicked?: (id: number) => void;
|
onOrderClicked?: (id: number) => void;
|
||||||
|
baseUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BookTable = ({
|
const BookTable = ({
|
||||||
@ -65,6 +66,7 @@ const BookTable = ({
|
|||||||
onCurrencyChange,
|
onCurrencyChange,
|
||||||
onTypeChange,
|
onTypeChange,
|
||||||
onOrderClicked = () => null,
|
onOrderClicked = () => null,
|
||||||
|
baseUrl,
|
||||||
}: BookTableProps): JSX.Element => {
|
}: BookTableProps): JSX.Element => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@ -173,6 +175,7 @@ const BookTable = ({
|
|||||||
orderType={params.row.type}
|
orderType={params.row.type}
|
||||||
statusColor={statusBadgeColor(params.row.maker_status)}
|
statusColor={statusBadgeColor(params.row.maker_status)}
|
||||||
tooltip={t(params.row.maker_status)}
|
tooltip={t(params.row.maker_status)}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
</ListItemAvatar>
|
</ListItemAvatar>
|
||||||
<ListItemText primary={params.row.maker_nick} />
|
<ListItemText primary={params.row.maker_nick} />
|
||||||
@ -200,6 +203,7 @@ const BookTable = ({
|
|||||||
orderType={params.row.type}
|
orderType={params.row.type}
|
||||||
statusColor={statusBadgeColor(params.row.maker_status)}
|
statusColor={statusBadgeColor(params.row.maker_status)}
|
||||||
tooltip={t(params.row.maker_status)}
|
tooltip={t(params.row.maker_status)}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
</ListItemButton>
|
</ListItemButton>
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,8 +20,7 @@ import {
|
|||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { AddCircleOutline, RemoveCircleOutline } from '@mui/icons-material';
|
import { AddCircleOutline, RemoveCircleOutline } from '@mui/icons-material';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { PublicOrder, LimitList, Order } from '../../../models';
|
||||||
import { PublicOrder, LimitList } from '../../../models';
|
|
||||||
import RobotAvatar from '../../RobotAvatar';
|
import RobotAvatar from '../../RobotAvatar';
|
||||||
import { amountToString, matchMedian, statusBadgeColor } from '../../../utils';
|
import { amountToString, matchMedian, statusBadgeColor } from '../../../utils';
|
||||||
import currencyDict from '../../../../static/assets/currencies.json';
|
import currencyDict from '../../../../static/assets/currencies.json';
|
||||||
@ -38,6 +37,7 @@ interface DepthChartProps {
|
|||||||
fillContainer?: boolean;
|
fillContainer?: boolean;
|
||||||
elevation?: number;
|
elevation?: number;
|
||||||
onOrderClicked?: (id: number) => void;
|
onOrderClicked?: (id: number) => void;
|
||||||
|
baseUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DepthChart: React.FC<DepthChartProps> = ({
|
const DepthChart: React.FC<DepthChartProps> = ({
|
||||||
@ -50,9 +50,9 @@ const DepthChart: React.FC<DepthChartProps> = ({
|
|||||||
fillContainer = false,
|
fillContainer = false,
|
||||||
elevation = 6,
|
elevation = 6,
|
||||||
onOrderClicked = () => null,
|
onOrderClicked = () => null,
|
||||||
|
baseUrl,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const history = useHistory();
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [enrichedOrders, setEnrichedOrders] = useState<Order[]>([]);
|
const [enrichedOrders, setEnrichedOrders] = useState<Order[]>([]);
|
||||||
const [series, setSeries] = useState<Serie[]>([]);
|
const [series, setSeries] = useState<Serie[]>([]);
|
||||||
@ -233,6 +233,7 @@ const DepthChart: React.FC<DepthChartProps> = ({
|
|||||||
orderType={order.type}
|
orderType={order.type}
|
||||||
statusColor={statusBadgeColor(order.maker_status)}
|
statusColor={statusBadgeColor(order.maker_status)}
|
||||||
tooltip={t(order.maker_status)}
|
tooltip={t(order.maker_status)}
|
||||||
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -50,10 +50,12 @@ interface Props {
|
|||||||
setRobot: (state: Robot) => void;
|
setRobot: (state: Robot) => void;
|
||||||
setPage: (state: Page) => void;
|
setPage: (state: Page) => void;
|
||||||
setCurrentOrder: (state: number) => void;
|
setCurrentOrder: (state: number) => void;
|
||||||
|
baseUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProfileDialog = ({
|
const ProfileDialog = ({
|
||||||
open = false,
|
open = false,
|
||||||
|
baseUrl,
|
||||||
onClose,
|
onClose,
|
||||||
robot,
|
robot,
|
||||||
setRobot,
|
setRobot,
|
||||||
@ -110,7 +112,7 @@ const ProfileDialog = ({
|
|||||||
setShowRewardsSpinner(true);
|
setShowRewardsSpinner(true);
|
||||||
|
|
||||||
apiClient
|
apiClient
|
||||||
.post('/api/reward/', {
|
.post(baseUrl, '/api/reward/', {
|
||||||
invoice: rewardInvoice,
|
invoice: rewardInvoice,
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then((data: any) => {
|
||||||
@ -130,7 +132,7 @@ const ProfileDialog = ({
|
|||||||
|
|
||||||
const setStealthInvoice = (wantsStealth: boolean) => {
|
const setStealthInvoice = (wantsStealth: boolean) => {
|
||||||
apiClient
|
apiClient
|
||||||
.put('/api/stealth/', { wantsStealth })
|
.put(baseUrl, '/api/stealth/', { wantsStealth })
|
||||||
.then((data) => setRobot({ ...robot, stealthInvoices: data?.wantsStealth }));
|
.then((data) => setRobot({ ...robot, stealthInvoices: data?.wantsStealth }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ interface Props {
|
|||||||
tooltipPosition?: string;
|
tooltipPosition?: string;
|
||||||
avatarClass?: string;
|
avatarClass?: string;
|
||||||
onLoad?: () => void;
|
onLoad?: () => void;
|
||||||
|
baseUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RobotAvatar: React.FC<Props> = ({
|
const RobotAvatar: React.FC<Props> = ({
|
||||||
@ -32,6 +33,7 @@ const RobotAvatar: React.FC<Props> = ({
|
|||||||
avatarClass = 'flippedSmallAvatar',
|
avatarClass = 'flippedSmallAvatar',
|
||||||
imageStyle = {},
|
imageStyle = {},
|
||||||
onLoad = () => {},
|
onLoad = () => {},
|
||||||
|
baseUrl,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@ -39,7 +41,13 @@ const RobotAvatar: React.FC<Props> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (nickname != null) {
|
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]);
|
}, [nickname]);
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ class TradeBox extends Component {
|
|||||||
|
|
||||||
handleClickAgreeDisputeButton = () => {
|
handleClickAgreeDisputeButton = () => {
|
||||||
apiClient
|
apiClient
|
||||||
.post('/api/order/?order_id=' + this.props.data.id, {
|
.post(this.props.baseUrl, '/api/order/?order_id=' + this.props.data.id, {
|
||||||
action: 'dispute',
|
action: 'dispute',
|
||||||
})
|
})
|
||||||
.then((data) => this.props.completeSetState(data));
|
.then((data) => this.props.completeSetState(data));
|
||||||
@ -494,7 +494,7 @@ class TradeBox extends Component {
|
|||||||
handleClickPauseOrder = () => {
|
handleClickPauseOrder = () => {
|
||||||
this.props.completeSetState({ pauseLoading: true });
|
this.props.completeSetState({ pauseLoading: true });
|
||||||
apiClient
|
apiClient
|
||||||
.post('/api/order/?order_id=' + this.props.data.id, {
|
.post(this.props.baseUrl, '/api/order/?order_id=' + this.props.data.id, {
|
||||||
action: 'pause',
|
action: 'pause',
|
||||||
})
|
})
|
||||||
.then((data) => this.props.getOrderDetails(data.id));
|
.then((data) => this.props.getOrderDetails(data.id));
|
||||||
@ -642,7 +642,7 @@ class TradeBox extends Component {
|
|||||||
this.setState({ badInvoice: false, loadingSubmitInvoice: true });
|
this.setState({ badInvoice: false, loadingSubmitInvoice: true });
|
||||||
|
|
||||||
apiClient
|
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',
|
action: 'update_invoice',
|
||||||
invoice: this.state.invoice,
|
invoice: this.state.invoice,
|
||||||
})
|
})
|
||||||
@ -675,7 +675,7 @@ class TradeBox extends Component {
|
|||||||
this.setState({ badInvoice: false, loadingSubmitAddress: true });
|
this.setState({ badInvoice: false, loadingSubmitAddress: true });
|
||||||
|
|
||||||
apiClient
|
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',
|
action: 'update_address',
|
||||||
address: this.state.address,
|
address: this.state.address,
|
||||||
mining_fee_rate: Math.max(1, this.state.miningFee),
|
mining_fee_rate: Math.max(1, this.state.miningFee),
|
||||||
@ -698,7 +698,7 @@ class TradeBox extends Component {
|
|||||||
this.setState({ badInvoice: false });
|
this.setState({ badInvoice: false });
|
||||||
|
|
||||||
apiClient
|
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',
|
action: 'submit_statement',
|
||||||
statement: this.state.statement,
|
statement: this.state.statement,
|
||||||
})
|
})
|
||||||
@ -1205,7 +1205,7 @@ class TradeBox extends Component {
|
|||||||
|
|
||||||
handleClickConfirmButton = () => {
|
handleClickConfirmButton = () => {
|
||||||
apiClient
|
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',
|
action: 'confirm',
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
@ -1216,7 +1216,7 @@ class TradeBox extends Component {
|
|||||||
|
|
||||||
handleRatingUserChange = (e) => {
|
handleRatingUserChange = (e) => {
|
||||||
apiClient
|
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',
|
action: 'rate_user',
|
||||||
rating: e.target.value,
|
rating: e.target.value,
|
||||||
})
|
})
|
||||||
@ -1230,7 +1230,7 @@ class TradeBox extends Component {
|
|||||||
this.setState({ rating_platform: e.target.value });
|
this.setState({ rating_platform: e.target.value });
|
||||||
|
|
||||||
apiClient
|
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',
|
action: 'rate_platform',
|
||||||
rating: e.target.value,
|
rating: e.target.value,
|
||||||
})
|
})
|
||||||
@ -1356,7 +1356,7 @@ class TradeBox extends Component {
|
|||||||
bondless_taker: this.props.data.bondless_taker,
|
bondless_taker: this.props.data.bondless_taker,
|
||||||
};
|
};
|
||||||
apiClient
|
apiClient
|
||||||
.post('/api/make/', body)
|
.post(this.props.baseUrl, '/api/make/', body)
|
||||||
.then(
|
.then(
|
||||||
(data) =>
|
(data) =>
|
||||||
this.setState({ badRequest: data.bad_request }) &
|
this.setState({ badRequest: data.bad_request }) &
|
||||||
|
@ -23,17 +23,24 @@ class UnsafeAlert extends Component {
|
|||||||
|
|
||||||
checkClient() {
|
checkClient() {
|
||||||
const http = new XMLHttpRequest();
|
const http = new XMLHttpRequest();
|
||||||
const unsafeClient = !this.safe_urls.includes(getHost());
|
const host = getHost();
|
||||||
|
const unsafeClient = !this.safe_urls.includes(host);
|
||||||
try {
|
try {
|
||||||
http.open('HEAD', `${location.protocol}//${getHost()}/selfhosted`, false);
|
http.open('HEAD', `${location.protocol}//${host}/selfhosted`, false);
|
||||||
http.send();
|
http.send();
|
||||||
this.props.setSettings({
|
this.props.setSettings({
|
||||||
...this.props.settings,
|
...this.props.settings,
|
||||||
|
host,
|
||||||
unsafeClient,
|
unsafeClient,
|
||||||
selfhostedClient: http.status === 200,
|
selfhostedClient: http.status === 200,
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
this.props.setSettings({ ...this.props.settings, unsafeClient, selfhostedClient: false });
|
this.props.setSettings({
|
||||||
|
...this.props.settings,
|
||||||
|
host,
|
||||||
|
unsafeClient,
|
||||||
|
selfhostedClient: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ class BaseSettings {
|
|||||||
public freezeViewports: boolean = false;
|
public freezeViewports: boolean = false;
|
||||||
public network: 'mainnet' | 'testnet' | undefined = 'mainnet';
|
public network: 'mainnet' | 'testnet' | undefined = 'mainnet';
|
||||||
public coordinator: Coordinator | undefined = undefined;
|
public coordinator: Coordinator | undefined = undefined;
|
||||||
|
public host?: string;
|
||||||
public unsafeClient: boolean = false;
|
public unsafeClient: boolean = false;
|
||||||
public hostedClient: boolean = false;
|
public hostedClient: boolean = false;
|
||||||
}
|
}
|
||||||
|
1
frontend/src/services/Native/index.d.ts
vendored
1
frontend/src/services/Native/index.d.ts
vendored
@ -16,6 +16,7 @@ export interface NativeWebViewMessageHttp {
|
|||||||
category: 'http';
|
category: 'http';
|
||||||
type: 'post' | 'get' | 'put' | 'delete' | 'xhr';
|
type: 'post' | 'get' | 'put' | 'delete' | 'xhr';
|
||||||
path: string;
|
path: string;
|
||||||
|
baseUrl: string;
|
||||||
headers?: object;
|
headers?: object;
|
||||||
body?: object;
|
body?: object;
|
||||||
}
|
}
|
||||||
|
@ -38,39 +38,56 @@ class ApiNativeClient implements ApiClient {
|
|||||||
return response.json;
|
return response.json;
|
||||||
};
|
};
|
||||||
|
|
||||||
public put: (path: string, body: object) => Promise<object | undefined> = async (path, body) => {
|
public put: (baseUrl: string, path: string, body: object) => Promise<object | undefined> = async (
|
||||||
|
baseUrl,
|
||||||
|
path,
|
||||||
|
body,
|
||||||
|
) => {
|
||||||
return await new Promise((res, _rej) => res({}));
|
return await new Promise((res, _rej) => res({}));
|
||||||
};
|
};
|
||||||
|
|
||||||
public delete: (path: string) => Promise<object | undefined> = async (path) => {
|
public delete: (baseUrl: string, path: string) => Promise<object | undefined> = async (
|
||||||
|
baseUrl,
|
||||||
|
path,
|
||||||
|
) => {
|
||||||
return await window.NativeRobosats?.postMessage({
|
return await window.NativeRobosats?.postMessage({
|
||||||
category: 'http',
|
category: 'http',
|
||||||
type: 'delete',
|
type: 'delete',
|
||||||
|
baseUrl,
|
||||||
path,
|
path,
|
||||||
headers: this.getHeaders(),
|
headers: this.getHeaders(),
|
||||||
}).then(this.parseResponse);
|
}).then(this.parseResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
public post: (path: string, body: object) => Promise<object | undefined> = async (path, body) => {
|
public post: (baseUrl: string, path: string, body: object) => Promise<object | undefined> =
|
||||||
return await window.NativeRobosats?.postMessage({
|
async (baseUrl, path, body) => {
|
||||||
category: 'http',
|
return await window.NativeRobosats?.postMessage({
|
||||||
type: 'post',
|
category: 'http',
|
||||||
path,
|
type: 'post',
|
||||||
body,
|
baseUrl,
|
||||||
headers: this.getHeaders(),
|
path,
|
||||||
}).then(this.parseResponse);
|
body,
|
||||||
};
|
headers: this.getHeaders(),
|
||||||
|
}).then(this.parseResponse);
|
||||||
|
};
|
||||||
|
|
||||||
public get: (path: string) => Promise<object | undefined> = async (path) => {
|
public get: (baseUrl: string, path: string) => Promise<object | undefined> = async (
|
||||||
|
baseUrl,
|
||||||
|
path,
|
||||||
|
) => {
|
||||||
return await window.NativeRobosats?.postMessage({
|
return await window.NativeRobosats?.postMessage({
|
||||||
category: 'http',
|
category: 'http',
|
||||||
type: 'get',
|
type: 'get',
|
||||||
|
baseUrl,
|
||||||
path,
|
path,
|
||||||
headers: this.getHeaders(),
|
headers: this.getHeaders(),
|
||||||
}).then(this.parseResponse);
|
}).then(this.parseResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
public fileImageUrl: (path: string) => Promise<string | undefined> = async (path) => {
|
public fileImageUrl: (baseUrl: string, path: string) => Promise<string | undefined> = async (
|
||||||
|
baseUrl,
|
||||||
|
path,
|
||||||
|
) => {
|
||||||
if (!path) {
|
if (!path) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -85,6 +102,7 @@ class ApiNativeClient implements ApiClient {
|
|||||||
const fileB64 = await window.NativeRobosats?.postMessage({
|
const fileB64 = await window.NativeRobosats?.postMessage({
|
||||||
category: 'http',
|
category: 'http',
|
||||||
type: 'xhr',
|
type: 'xhr',
|
||||||
|
baseUrl,
|
||||||
path,
|
path,
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ApiClient } from '../api';
|
import { ApiClient } from '..';
|
||||||
import { systemClient } from '../../System';
|
import { systemClient } from '../../System';
|
||||||
|
|
||||||
class ApiWebClient implements ApiClient {
|
class ApiWebClient implements ApiClient {
|
||||||
@ -9,42 +9,48 @@ class ApiWebClient implements ApiClient {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
public post: (path: string, body: object) => Promise<object | undefined> = async (path, body) => {
|
public post: (baseUrl: string, path: string, body: object) => Promise<object> = async (
|
||||||
|
baseUrl,
|
||||||
|
path,
|
||||||
|
body,
|
||||||
|
) => {
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: this.getHeaders(),
|
headers: this.getHeaders(),
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
};
|
};
|
||||||
return await fetch(path, requestOptions).then(async (response) => await response.json());
|
return await fetch(baseUrl + path, requestOptions).then(
|
||||||
|
async (response) => await response.json(),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
public put: (path: string, body: object) => Promise<object | undefined> = async (path, body) => {
|
public put: (baseUrl: string, path: string, body: object) => Promise<object> = async (
|
||||||
|
baseUrl,
|
||||||
|
path,
|
||||||
|
body,
|
||||||
|
) => {
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: this.getHeaders(),
|
headers: this.getHeaders(),
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
};
|
};
|
||||||
return await fetch(path, requestOptions).then(async (response) => await response.json());
|
return await fetch(baseUrl + path, requestOptions).then(
|
||||||
|
async (response) => await response.json(),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
public delete: (path: string) => Promise<object | undefined> = async (path) => {
|
public delete: (baseUrl: string, path: string) => Promise<object> = async (baseUrl, path) => {
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: this.getHeaders(),
|
headers: this.getHeaders(),
|
||||||
};
|
};
|
||||||
return await fetch(path, requestOptions).then(async (response) => await response.json());
|
return await fetch(baseUrl + path, requestOptions).then(
|
||||||
|
async (response) => await response.json(),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
public get: (path: string) => Promise<object | undefined> = async (path) => {
|
public get: (baseUrl: string, path: string) => Promise<object> = async (baseUrl, path) => {
|
||||||
return await fetch(path).then(async (response) => await response.json());
|
return await fetch(baseUrl + path).then(async (response) => await response.json());
|
||||||
};
|
|
||||||
|
|
||||||
public fileImageUrl: (path: string) => Promise<string | undefined> = async (path) => {
|
|
||||||
if (!path) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return window.location.origin + path;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,11 +2,11 @@ import ApiWebClient from './ApiWebClient';
|
|||||||
import ApiNativeClient from './ApiNativeClient';
|
import ApiNativeClient from './ApiNativeClient';
|
||||||
|
|
||||||
export interface ApiClient {
|
export interface ApiClient {
|
||||||
post: (path: string, body: object) => Promise<object | undefined>;
|
post: (baseUrl: string, path: string, body: object) => Promise<object | undefined>;
|
||||||
put: (path: string, body: object) => Promise<object | undefined>;
|
put: (baseUrl: string, path: string, body: object) => Promise<object | undefined>;
|
||||||
get: (path: string) => Promise<object | undefined>;
|
get: (baseUrl: string, path: string) => Promise<object | undefined>;
|
||||||
delete: (path: string) => Promise<object | undefined>;
|
delete: (baseUrl: string, path: string) => Promise<object | undefined>;
|
||||||
fileImageUrl: (path: string) => Promise<string | undefined>;
|
fileImageUrl?: (baseUrl: string, path: string) => Promise<string | undefined>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const apiClient: ApiClient =
|
export const apiClient: ApiClient =
|
||||||
|
@ -59,7 +59,7 @@ const App = () => {
|
|||||||
sendTorStatus();
|
sendTorStatus();
|
||||||
if (data.type === 'get') {
|
if (data.type === 'get') {
|
||||||
torClient
|
torClient
|
||||||
.get(data.path, data.headers)
|
.get(data.baseUrl, data.path, data.headers)
|
||||||
.then((response: object) => {
|
.then((response: object) => {
|
||||||
injectMessageResolve(data.id, response);
|
injectMessageResolve(data.id, response);
|
||||||
})
|
})
|
||||||
@ -67,7 +67,7 @@ const App = () => {
|
|||||||
.finally(sendTorStatus);
|
.finally(sendTorStatus);
|
||||||
} else if (data.type === 'post') {
|
} else if (data.type === 'post') {
|
||||||
torClient
|
torClient
|
||||||
.post(data.path, data.body, data.headers)
|
.post(data.baseUrl, data.path, data.body, data.headers)
|
||||||
.then((response: object) => {
|
.then((response: object) => {
|
||||||
injectMessageResolve(data.id, response);
|
injectMessageResolve(data.id, response);
|
||||||
})
|
})
|
||||||
@ -75,7 +75,7 @@ const App = () => {
|
|||||||
.finally(sendTorStatus);
|
.finally(sendTorStatus);
|
||||||
} else if (data.type === 'delete') {
|
} else if (data.type === 'delete') {
|
||||||
torClient
|
torClient
|
||||||
.delete(data.path, data.headers)
|
.delete(data.baseUrl, data.path, data.headers)
|
||||||
.then((response: object) => {
|
.then((response: object) => {
|
||||||
injectMessageResolve(data.id, response);
|
injectMessageResolve(data.id, response);
|
||||||
})
|
})
|
||||||
@ -83,7 +83,7 @@ const App = () => {
|
|||||||
.finally(sendTorStatus);
|
.finally(sendTorStatus);
|
||||||
} else if (data.type === 'xhr') {
|
} else if (data.type === 'xhr') {
|
||||||
torClient
|
torClient
|
||||||
.request(data.path)
|
.request(data.baseUrl, data.path)
|
||||||
.then((response: object) => {
|
.then((response: object) => {
|
||||||
injectMessageResolve(data.id, response);
|
injectMessageResolve(data.id, response);
|
||||||
})
|
})
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
import Tor from 'react-native-tor';
|
import Tor from 'react-native-tor';
|
||||||
|
|
||||||
class TorClient {
|
class TorClient {
|
||||||
baseUrl: string;
|
|
||||||
daemon: ReturnType<typeof Tor>;
|
daemon: ReturnType<typeof Tor>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.baseUrl = 'http://robosats6tkf3eva7x2voqso3a5wcorsnw34jveyxfqi2fu7oyheasid.onion';
|
|
||||||
this.daemon = Tor({
|
this.daemon = Tor({
|
||||||
stopDaemonOnBackground: false,
|
stopDaemonOnBackground: false,
|
||||||
numberConcurrentRequests: 0,
|
numberConcurrentRequests: 0,
|
||||||
@ -26,10 +24,14 @@ class TorClient {
|
|||||||
await this.daemon.startIfNotStarted();
|
await this.daemon.startIfNotStarted();
|
||||||
};
|
};
|
||||||
|
|
||||||
public get: (path: string, headers: object) => Promise<object> = async (path, headers) => {
|
public get: (baseUrl: string, path: string, headers: object) => Promise<object> = async (
|
||||||
|
baseUrl,
|
||||||
|
path,
|
||||||
|
headers,
|
||||||
|
) => {
|
||||||
return await new Promise<object>(async (resolve, reject) => {
|
return await new Promise<object>(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const response = await this.daemon.get(`${this.baseUrl}${path}`, headers);
|
const response = await this.daemon.get(`${baseUrl}${path}`, headers);
|
||||||
|
|
||||||
resolve(response);
|
resolve(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -38,10 +40,14 @@ class TorClient {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
public delete: (path: string, headers: object) => Promise<object> = async (path, headers) => {
|
public delete: (baseUrl: string, path: string, headers: object) => Promise<object> = async (
|
||||||
|
baseUrl,
|
||||||
|
path,
|
||||||
|
headers,
|
||||||
|
) => {
|
||||||
return await new Promise<object>(async (resolve, reject) => {
|
return await new Promise<object>(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const response = await this.daemon.delete(`${this.baseUrl}${path}`, '', headers);
|
const response = await this.daemon.delete(`${baseUrl}${path}`, '', headers);
|
||||||
|
|
||||||
resolve(response);
|
resolve(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -50,11 +56,14 @@ class TorClient {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
public request: (path: string) => Promise<object> = async (path) => {
|
public request: (baseUrl: string, path: string) => Promise<object> = async (
|
||||||
|
baseUrl: string,
|
||||||
|
path,
|
||||||
|
) => {
|
||||||
return await new Promise<object>(async (resolve, reject) => {
|
return await new Promise<object>(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const response = await this.daemon
|
const response = await this.daemon
|
||||||
.request(`${this.baseUrl}${path}`, 'GET', '', {}, true)
|
.request(`${baseUrl}${path}`, 'GET', '', {}, true)
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
resolve(resp);
|
resolve(resp);
|
||||||
});
|
});
|
||||||
@ -66,22 +75,19 @@ class TorClient {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
public post: (path: string, body: object, headers: object) => Promise<object> = async (
|
public post: (baseUrl: string, path: string, body: object, headers: object) => Promise<object> =
|
||||||
path,
|
async (baseUrl, path, body, headers) => {
|
||||||
body,
|
return await new Promise<object>(async (resolve, reject) => {
|
||||||
headers,
|
try {
|
||||||
) => {
|
const json = JSON.stringify(body);
|
||||||
return await new Promise<object>(async (resolve, reject) => {
|
const response = await this.daemon.post(`${baseUrl}${path}`, json, headers);
|
||||||
try {
|
|
||||||
const json = JSON.stringify(body);
|
|
||||||
const response = await this.daemon.post(`${this.baseUrl}${path}`, json, headers);
|
|
||||||
|
|
||||||
resolve(response);
|
resolve(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TorClient;
|
export default TorClient;
|
||||||
|
Loading…
Reference in New Issue
Block a user