+ );
+ }
+}
+
+export default withTranslation()(NavBar);
diff --git a/frontend/src/basic/OrderPage/index.js b/frontend/src/basic/OrderPage/index.js
index e4e7c892..26cc59db 100644
--- a/frontend/src/basic/OrderPage/index.js
+++ b/frontend/src/basic/OrderPage/index.js
@@ -44,12 +44,10 @@ import ArticleIcon from '@mui/icons-material/Article';
import HourglassTopIcon from '@mui/icons-material/HourglassTop';
import CheckIcon from '@mui/icons-material/Check';
-import { pn } from '../../utils/prettyNumbers';
+import { pn, getWebln, statusBadgeColor } from '../../utils';
import { systemClient } from '../../services/System';
-import { getWebln } from '../../utils/webln';
import { apiClient } from '../../services/api';
import RobotAvatar from '../../components/RobotAvatar';
-import statusBadgeColor from '../../utils/statusBadgeColor';
import { PaymentStringAsIcons } from '../../components/PaymentMethods';
class OrderPage extends Component {
diff --git a/frontend/src/basic/UserGenPage.js b/frontend/src/basic/UserGenPage.js
index dc1fe428..12be5ef5 100644
--- a/frontend/src/basic/UserGenPage.js
+++ b/frontend/src/basic/UserGenPage.js
@@ -21,9 +21,8 @@ import DownloadIcon from '@mui/icons-material/Download';
import { RoboSatsNoTextIcon } from '../components/Icons';
import { sha256 } from 'js-sha256';
-import { genBase62Token, tokenStrength } from '../utils/token';
-import { genKey } from '../utils/pgp';
-import { saveAsJson } from '../utils/saveFile';
+import { genBase62Token, tokenStrength, saveAsJson } from '../utils';
+import { genKey } from '../pgp';
import { systemClient } from '../services/System';
import { apiClient } from '../services/api/index';
import RobotAvatar from '../components/RobotAvatar';
diff --git a/frontend/src/components/BookTable/index.tsx b/frontend/src/components/BookTable/index.tsx
index 538f7bc3..4d755ea4 100644
--- a/frontend/src/components/BookTable/index.tsx
+++ b/frontend/src/components/BookTable/index.tsx
@@ -19,15 +19,12 @@ import {
import { DataGrid, GridPagination } from '@mui/x-data-grid';
import currencyDict from '../../../static/assets/currencies.json';
import { Book, Favorites } from '../../models';
-import filterOrders from '../../utils/filterOrders';
+import { filterOrders, hexToRgb, statusBadgeColor, pn, amountToString } from '../../utils';
import BookControl from './BookControl';
import { FlagWithProps } from '../Icons';
-import { pn, amountToString } from '../../utils/prettyNumbers';
import { PaymentStringAsIcons } from '../PaymentMethods';
import RobotAvatar from '../RobotAvatar';
-import hexToRgb from '../../utils/hexToRgb';
-import statusBadgeColor from '../../utils/statusBadgeColor';
// Icons
import { Fullscreen, FullscreenExit, Refresh } from '@mui/icons-material';
diff --git a/frontend/src/components/Charts/DepthChart/index.tsx b/frontend/src/components/Charts/DepthChart/index.tsx
index e00fe998..bf214c8c 100644
--- a/frontend/src/components/Charts/DepthChart/index.tsx
+++ b/frontend/src/components/Charts/DepthChart/index.tsx
@@ -23,12 +23,10 @@ import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
import { Order, LimitList } from '../../../models';
import RobotAvatar from '../../RobotAvatar';
-import { amountToString } from '../../../utils/prettyNumbers';
+import { amountToString, matchMedian, statusBadgeColor } from '../../../utils';
import currencyDict from '../../../../static/assets/currencies.json';
import { PaymentStringAsIcons } from '../../PaymentMethods';
import getNivoScheme from '../NivoScheme';
-import median from '../../../utils/match';
-import statusBadgeColor from '../../../utils/statusBadgeColor';
interface DepthChartProps {
orders: Order[];
@@ -93,7 +91,7 @@ const DepthChart: React.FC = ({
if (xType === 'base_amount') {
const prices: number[] = enrichedOrders.map((order) => order?.base_amount || 0);
- const medianValue = ~~median(prices);
+ const medianValue = ~~matchMedian(prices);
const maxValue = prices.sort((a, b) => b - a).slice(0, 1)[0] || 1500;
const maxRange = maxValue - medianValue;
const rangeSteps = maxRange / 10;
@@ -104,7 +102,7 @@ const DepthChart: React.FC = ({
} else {
if (lastDayPremium === undefined) {
const premiums: number[] = enrichedOrders.map((order) => order?.premium || 0);
- setCenter(~~median(premiums));
+ setCenter(~~matchMedian(premiums));
} else {
setCenter(lastDayPremium);
}
diff --git a/frontend/src/components/Dialogs/AuditPGP.tsx b/frontend/src/components/Dialogs/AuditPGP.tsx
index fd872a7d..b481469b 100644
--- a/frontend/src/components/Dialogs/AuditPGP.tsx
+++ b/frontend/src/components/Dialogs/AuditPGP.tsx
@@ -14,7 +14,7 @@ import {
Link,
} from '@mui/material';
-import { saveAsJson } from '../../utils/saveFile';
+import { saveAsJson } from '../../utils';
import { systemClient } from '../../services/System';
// Icons
diff --git a/frontend/src/components/Dialogs/ExchangeSummary.tsx b/frontend/src/components/Dialogs/ExchangeSummary.tsx
index 00165654..363c6fec 100644
--- a/frontend/src/components/Dialogs/ExchangeSummary.tsx
+++ b/frontend/src/components/Dialogs/ExchangeSummary.tsx
@@ -21,7 +21,7 @@ import PriceChangeIcon from '@mui/icons-material/PriceChange';
import BookIcon from '@mui/icons-material/Book';
import LinkIcon from '@mui/icons-material/Link';
-import { pn } from '../../utils/prettyNumbers';
+import { pn } from '../../utils';
interface Props {
open: boolean;
diff --git a/frontend/src/components/Dialogs/Info.tsx b/frontend/src/components/Dialogs/Info.tsx
index d6f7bd98..636a4703 100644
--- a/frontend/src/components/Dialogs/Info.tsx
+++ b/frontend/src/components/Dialogs/Info.tsx
@@ -14,6 +14,7 @@ import {
} from '@mui/material';
import SmoothImage from 'react-smooth-image';
import MediaQuery from 'react-responsive';
+import { pn } from '../../utils';
// Icons
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
@@ -148,7 +149,7 @@ const InfoDialog = ({ maxAmount, open, onClose }: Props): JSX.Element => {
{t(
'Maximum single trade size is {{maxAmount}} Satoshis to minimize lightning routing failure. There is no limits to the number of trades per day. A robot can only have one order at a time. However, you can use multiple robots simultaneously in different browsers (remember to back up your robot tokens!).',
- { maxAmount },
+ { maxAmount: pn(maxAmount) },
)}{' '}
diff --git a/frontend/src/components/Dialogs/Profile.tsx b/frontend/src/components/Dialogs/Profile.tsx
index 34c875cc..9c16e739 100644
--- a/frontend/src/components/Dialogs/Profile.tsx
+++ b/frontend/src/components/Dialogs/Profile.tsx
@@ -37,7 +37,7 @@ import EmojiEventsIcon from '@mui/icons-material/EmojiEvents';
import { UserNinjaIcon, BitcoinIcon } from '../Icons';
import { systemClient } from '../../services/System';
-import { getWebln } from '../../utils/webln';
+import { getHost, getWebln } from '../../utils';
import RobotAvatar from '../RobotAvatar';
interface Props {
@@ -51,7 +51,6 @@ interface Props {
tgBotName: string;
tgToken: string;
handleSubmitInvoiceClicked: (e: any, invoice: string) => void;
- host: string;
showRewardsSpinner: boolean;
withdrawn: boolean;
badInvoice: boolean | string;
@@ -72,7 +71,6 @@ const ProfileDialog = ({
tgBotName,
tgToken,
handleSubmitInvoiceClicked,
- host,
showRewardsSpinner,
withdrawn,
badInvoice,
@@ -83,6 +81,7 @@ const ProfileDialog = ({
}: Props): JSX.Element => {
const { t } = useTranslation();
const theme = useTheme();
+ const host = getHost();
const [rewardInvoice, setRewardInvoice] = useState('');
const [showRewards, setShowRewards] = useState(false);
diff --git a/frontend/src/components/Dialogs/Stats.tsx b/frontend/src/components/Dialogs/Stats.tsx
index e66e12a5..cdc2d461 100644
--- a/frontend/src/components/Dialogs/Stats.tsx
+++ b/frontend/src/components/Dialogs/Stats.tsx
@@ -23,7 +23,7 @@ import EqualizerIcon from '@mui/icons-material/Equalizer';
import { AmbossIcon, BitcoinSignIcon, RoboSatsNoTextIcon } from '../Icons';
-import { pn } from '../../utils/prettyNumbers';
+import { pn } from '../../utils';
interface Props {
open: boolean;
diff --git a/frontend/src/components/MakerForm/AmountRange.tsx b/frontend/src/components/MakerForm/AmountRange.tsx
index a53cb7ab..8580440d 100644
--- a/frontend/src/components/MakerForm/AmountRange.tsx
+++ b/frontend/src/components/MakerForm/AmountRange.tsx
@@ -14,7 +14,7 @@ import {
import { FlagWithProps } from '../Icons';
import RangeSlider from './RangeSlider';
import currencyDict from '../../../static/assets/currencies.json';
-import { pn } from '../../utils/prettyNumbers';
+import { pn } from '../../utils';
const RangeThumbComponent = function (props: object) {
const { children, ...other } = props;
diff --git a/frontend/src/components/MakerForm/MakerForm.tsx b/frontend/src/components/MakerForm/MakerForm.tsx
index fcd03c10..f6f12498 100644
--- a/frontend/src/components/MakerForm/MakerForm.tsx
+++ b/frontend/src/components/MakerForm/MakerForm.tsx
@@ -37,7 +37,7 @@ import { FlagWithProps } from '../Icons';
import AutocompletePayments from './AutocompletePayments';
import AmountRange from './AmountRange';
import currencyDict from '../../../static/assets/currencies.json';
-import { pn } from '../../utils/prettyNumbers';
+import { pn } from '../../utils';
import { SelfImprovement, Lock, HourglassTop, DeleteSweep, Edit } from '@mui/icons-material';
import { LoadingButton } from '@mui/lab';
diff --git a/frontend/src/components/TradeBox/EncryptedChat.js b/frontend/src/components/TradeBox/EncryptedChat.js
index 9e99990a..9da9b485 100644
--- a/frontend/src/components/TradeBox/EncryptedChat.js
+++ b/frontend/src/components/TradeBox/EncryptedChat.js
@@ -15,8 +15,8 @@ import {
Typography,
} from '@mui/material';
import ReconnectingWebSocket from 'reconnecting-websocket';
-import { encryptMessage, decryptMessage } from '../../utils/pgp';
-import { saveAsJson } from '../../utils/saveFile';
+import { encryptMessage, decryptMessage } from '../../pgp';
+import { saveAsJson } from '../../utils';
import { AuditPGPDialog } from '../Dialogs';
import RobotAvatar from '../RobotAvatar';
import { systemClient } from '../../services/System';
diff --git a/frontend/src/components/TradeBox/TradeSummary.tsx b/frontend/src/components/TradeBox/TradeSummary.tsx
index 270cf0b8..5c12301b 100644
--- a/frontend/src/components/TradeBox/TradeSummary.tsx
+++ b/frontend/src/components/TradeBox/TradeSummary.tsx
@@ -18,8 +18,7 @@ import {
AccordionDetails,
Typography,
} from '@mui/material';
-import { pn } from '../../utils/prettyNumbers';
-import { saveAsJson } from '../../utils/saveFile';
+import { pn, saveAsJson } from '../../utils';
import RobotAvatar from '../RobotAvatar';
// Icons
diff --git a/frontend/src/components/UnsafeAlert.js b/frontend/src/components/UnsafeAlert.js
index 13133ba2..fc582945 100644
--- a/frontend/src/components/UnsafeAlert.js
+++ b/frontend/src/components/UnsafeAlert.js
@@ -2,6 +2,7 @@ import React, { Component } from 'react';
import { withTranslation, Trans } from 'react-i18next';
import { Paper, Alert, AlertTitle, Button, Link } from '@mui/material';
import MediaQuery from 'react-responsive';
+import { getHost } from '../utils';
class UnsafeAlert extends Component {
constructor(props) {
@@ -12,18 +13,10 @@ class UnsafeAlert extends Component {
};
}
- getHost() {
- const url =
- window.location !== window.parent.location
- ? this.getHost(document.referrer)
- : document.location.href;
- return url.split('/')[2];
- }
-
isSelfhosted() {
const http = new XMLHttpRequest();
try {
- http.open('HEAD', `${location.protocol}//${this.getHost()}/selfhosted`, false);
+ http.open('HEAD', `${location.protocol}//${getHost()}/selfhosted`, false);
http.send();
return http.status === 200;
} catch {
@@ -72,7 +65,7 @@ class UnsafeAlert extends Component {
}
// Show unsafe alert
- if (!window.NativeRobosats && !this.safe_urls.includes(this.getHost())) {
+ if (!window.NativeRobosats && !this.safe_urls.includes(getHost())) {
return (
diff --git a/frontend/src/utils/pgp.js b/frontend/src/pgp/index.js
similarity index 100%
rename from frontend/src/utils/pgp.js
rename to frontend/src/pgp/index.js
diff --git a/frontend/src/utils/getHost.ts b/frontend/src/utils/getHost.ts
new file mode 100644
index 00000000..eca5acec
--- /dev/null
+++ b/frontend/src/utils/getHost.ts
@@ -0,0 +1,7 @@
+const getHost = function () {
+ const url =
+ window.location != window.parent.location ? document.referrer : document.location.href;
+ return url.split('/')[2];
+};
+
+export default getHost;
diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts
new file mode 100644
index 00000000..a0ae8ecc
--- /dev/null
+++ b/frontend/src/utils/index.ts
@@ -0,0 +1,11 @@
+export { default as checkVer } from './checkVer';
+export { default as filterOrders } from './filterOrders';
+export { default as getHost } from './getHost';
+export { default as hexToRgb } from './hexToRgb';
+export { default as matchMedian } from './match';
+export { default as pn } from './prettyNumbers';
+export { amountToString } from './prettyNumbers';
+export { default as saveAsJson } from './saveFile';
+export { default as statusBadgeColor } from './saveFile';
+export { genBase62Token, tokenStrength } from './token';
+export { default as getWebln } from './webln';
diff --git a/frontend/src/utils/match.ts b/frontend/src/utils/match.ts
index 230db93b..c0cc9c1c 100644
--- a/frontend/src/utils/match.ts
+++ b/frontend/src/utils/match.ts
@@ -1,7 +1,7 @@
-export const median = (arr: number[]) => {
+export const matchMedian = (arr: number[]) => {
const mid = Math.floor(arr.length / 2);
const nums = [...arr].sort((a, b) => a - b);
return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
};
-export default median;
+export default matchMedian;
diff --git a/frontend/src/utils/saveFile.js b/frontend/src/utils/saveFile.js
index a0a2637c..eab692c7 100644
--- a/frontend/src/utils/saveFile.js
+++ b/frontend/src/utils/saveFile.js
@@ -3,7 +3,7 @@
* @param {filename} data -- object to save
*/
-export const saveAsJson = (filename, dataObjToWrite) => {
+const saveAsJson = (filename, dataObjToWrite) => {
const blob = new Blob([JSON.stringify(dataObjToWrite, null, 2)], { type: 'text/json' });
const link = document.createElement('a');
@@ -20,3 +20,5 @@ export const saveAsJson = (filename, dataObjToWrite) => {
link.dispatchEvent(evt);
link.remove();
};
+
+export default saveAsJson;
diff --git a/frontend/src/utils/webln.ts b/frontend/src/utils/webln.ts
index 0327983e..aefecccb 100644
--- a/frontend/src/utils/webln.ts
+++ b/frontend/src/utils/webln.ts
@@ -1,6 +1,6 @@
import { requestProvider, WeblnProvider } from 'webln';
-export const getWebln = async (): Promise => {
+const getWebln = async (): Promise => {
const resultPromise = new Promise(async (resolve, reject) => {
try {
const webln = await requestProvider();
@@ -16,3 +16,5 @@ export const getWebln = async (): Promise => {
return await resultPromise;
};
+
+export default getWebln;