diff --git a/frontend/src/basic/BottomBar.js b/frontend/src/basic/BottomBar.js deleted file mode 100644 index 38ac1b3f..00000000 --- a/frontend/src/basic/BottomBar.js +++ /dev/null @@ -1,642 +0,0 @@ -import React, { Component } from 'react'; -import { withTranslation } from 'react-i18next'; -import { - Badge, - Tooltip, - ListItemAvatar, - Paper, - Grid, - IconButton, - Select, - MenuItem, - ListItemText, - ListItem, - ListItemIcon, - ListItemButton, -} from '@mui/material'; -import MediaQuery from 'react-responsive'; -import Flags from 'country-flag-icons/react/3x2'; -import { Link as LinkRouter } from 'react-router-dom'; -import { apiClient } from '../services/api'; -import { systemClient } from '../services/System'; -import RobotAvatar from '../components/RobotAvatar'; - -// Icons -import BarChartIcon from '@mui/icons-material/BarChart'; -import PeopleIcon from '@mui/icons-material/People'; -import InventoryIcon from '@mui/icons-material/Inventory'; -import SellIcon from '@mui/icons-material/Sell'; -import SmartToyIcon from '@mui/icons-material/SmartToy'; -import PercentIcon from '@mui/icons-material/Percent'; -import PriceChangeIcon from '@mui/icons-material/PriceChange'; - -// Missing flags -import { CataloniaFlag, BasqueCountryFlag } from '../components/Icons'; - -import { - CommunityDialog, - ExchangeSummaryDialog, - ProfileDialog, - StatsDialog, - UpdateClientDialog, -} from '../components/Dialogs'; - -class BottomBar extends Component { - constructor(props) { - super(props); - this.state = { - profileShown: false, - openStatsForNerds: false, - openCommunity: false, - openExchangeSummary: false, - openClaimRewards: false, - openProfile: false, - showRewards: false, - rewardInvoice: null, - badInvoice: false, - showRewardsSpinner: false, - withdrawn: false, - }; - } - - handleClickOpenStatsForNerds = () => { - this.setState({ openStatsForNerds: true }); - }; - - handleClickCloseStatsForNerds = () => { - this.setState({ openStatsForNerds: false }); - }; - - handleClickOpenCommunity = () => { - this.setState({ openCommunity: true }); - }; - - handleClickCloseCommunity = () => { - this.setState({ openCommunity: false }); - }; - - handleClickOpenProfile = () => { - this.setState({ openProfile: true, profileShown: true }); - }; - - handleClickCloseProfile = () => { - this.setState({ openProfile: false }); - }; - - handleClickOpenExchangeSummary = () => { - this.setState({ openExchangeSummary: true }); - }; - - handleClickCloseExchangeSummary = () => { - this.setState({ openExchangeSummary: false }); - }; - - handleSubmitInvoiceClicked = (e, rewardInvoice) => { - this.setState({ badInvoice: false, showRewardsSpinner: true }); - - apiClient - .post('/api/reward/', { - invoice: rewardInvoice, - }) - .then((data) => { - this.setState({ badInvoice: data.bad_invoice, showRewardsSpinner: false }); - this.props.setInfo({ - ...this.props.info, - badInvoice: data.bad_invoice, - openClaimRewards: !data.successful_withdrawal, - withdrawn: !!data.successful_withdrawal, - showRewardsSpinner: false, - }); - this.props.setRobot({ - ...this.props.robot, - earnedRewards: data.successful_withdrawal ? 0 : this.props.robot.earnedRewards, - }); - }); - e.preventDefault(); - }; - - handleSetStealthInvoice = (wantsStealth) => { - apiClient - .put('/api/stealth/', { wantsStealth }) - .then((data) => - this.props.setRobot({ ...this.props.robot, stealthInvoices: data?.wantsStealth }), - ); - }; - - getHost() { - const url = - window.location != window.parent.location - ? this.getHost(document.referrer) - : document.location.href; - return url.split('/')[2]; - } - - showProfileButton = () => { - return ( - this.props.robot.avatarLoaded && - (this.props.robot.token - ? systemClient.getCookie('robot_token') === this.props.robot.token - : true) && - systemClient.getCookie('sessionid') - ); - }; - - bottomBarDesktop = () => { - const { t } = this.props; - const hasRewards = this.props.robot.earnedRewards > 0; - const hasOrder = !!( - (this.props.robot.activeOrderId > 0) & - !this.state.profileShown & - this.props.robot.avatarLoaded - ); - const fontSize = this.props.theme.typography.fontSize; - const fontSizeFactor = fontSize / 14; // default fontSize is 14 - const typographyProps = { - primaryTypographyProps: { fontSize }, - secondaryTypographyProps: { fontSize: (fontSize * 12) / 14 }, - }; - return ( - - - -
- - - - 0) & !this.state.profileShown - ? 'primary' - : undefined - } - nickname={this.props.robot.nickname} - onLoad={() => - this.props.setRobot({ ...this.props.robot, avatarLoaded: true }) - } - /> - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {this.LangSelect()} - - - - - - - - - - - - - - - - -
-
- ); - }; - - handleChangeLang = (e) => { - const { i18n } = this.props; - i18n.changeLanguage(e.target.value); - }; - - LangSelect = () => { - const { i18n } = this.props; - const lang = i18n.resolvedLanguage == null ? 'en' : i18n.resolvedLanguage.substring(0, 2); - const flagProps = { - width: 20, - height: 20, - }; - - return ( - - ); - }; - - bottomBarPhone = () => { - const { t } = this.props; - const hasRewards = this.props.robot.earnedRewards > 0; - const hasOrder = !!( - (this.props.info.active_order_id > 0) & - !this.state.profileShown & - this.props.robot.avatarLoaded - ); - return ( - - - -
- - - 0) & !this.state.profileShown - ? 'primary' - : undefined - } - nickname={this.props.robot.nickname} - onLoad={() => this.props.setRobot({ ...this.props.robot, avatarLoaded: true })} - /> - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {this.LangSelect()} - - - - - - - - - - - this.props.fetchInfo()} - onClick={this.handleClickOpenStatsForNerds} - > - - - - - -
-
- ); - }; - - render() { - return ( -
- - - - this.props.setInfo({ ...this.props.info, openUpdateClient: false }) - } - /> - - - - this.props.setRobot({ ...robot, ...newParam })} - stealthInvoices={this.props.robot.stealthInvoices} - handleSetStealthInvoice={this.handleSetStealthInvoice} - /> - - - - {this.bottomBarDesktop()} - - {this.bottomBarPhone()} -
- ); - } -} - -export default withTranslation()(BottomBar); diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index 104f8d36..74725df4 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -6,11 +6,11 @@ import UserGenPage from './UserGenPage'; import MakerPage from './MakerPage'; import BookPage from './BookPage'; import OrderPage from './OrderPage'; -import BottomBar from './BottomBar'; +import NavBar from './NavBar'; import { LearnDialog } from '../components/Dialogs'; import { apiClient } from '../services/api'; -import checkVer from '../utils/checkVer'; +import { checkVer } from '../utils'; import { Book, @@ -211,7 +211,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { bottom: 0, }} > - history.push(location)} diff --git a/frontend/src/basic/MakerPage/index.tsx b/frontend/src/basic/MakerPage/index.tsx index 23fc0985..070f3a15 100644 --- a/frontend/src/basic/MakerPage/index.tsx +++ b/frontend/src/basic/MakerPage/index.tsx @@ -5,7 +5,7 @@ import { Button, Grid, Paper, Collapse, Typography } from '@mui/material'; import { LimitList, Maker, Book, Favorites } from '../../models'; -import filterOrders from '../../utils/filterOrders'; +import { filterOrders } from '../../utils'; import MakerForm from '../../components/MakerForm'; import BookTable from '../../components/BookTable'; diff --git a/frontend/src/basic/NavBar/index.tsx b/frontend/src/basic/NavBar/index.tsx index e69de29b..6f58889d 100644 --- a/frontend/src/basic/NavBar/index.tsx +++ b/frontend/src/basic/NavBar/index.tsx @@ -0,0 +1,633 @@ +import React, { Component } from 'react'; +import { withTranslation } from 'react-i18next'; +import { + Badge, + Tooltip, + ListItemAvatar, + Paper, + Grid, + IconButton, + Select, + MenuItem, + ListItemText, + ListItem, + ListItemIcon, + ListItemButton, +} from '@mui/material'; +import MediaQuery from 'react-responsive'; +import Flags from 'country-flag-icons/react/3x2'; +import { Link as LinkRouter } from 'react-router-dom'; +import { apiClient } from '../../services/api'; +import { systemClient } from '../../services/System'; +import RobotAvatar from '../../components/RobotAvatar'; + +// Icons +import BarChartIcon from '@mui/icons-material/BarChart'; +import PeopleIcon from '@mui/icons-material/People'; +import InventoryIcon from '@mui/icons-material/Inventory'; +import SellIcon from '@mui/icons-material/Sell'; +import SmartToyIcon from '@mui/icons-material/SmartToy'; +import PercentIcon from '@mui/icons-material/Percent'; +import PriceChangeIcon from '@mui/icons-material/PriceChange'; + +// Missing flags +import { CataloniaFlag, BasqueCountryFlag } from '../../components/Icons'; + +import { + CommunityDialog, + ExchangeSummaryDialog, + ProfileDialog, + StatsDialog, + UpdateClientDialog, +} from '../../components/Dialogs'; + +class NavBar extends Component { + constructor(props) { + super(props); + this.state = { + profileShown: false, + openStatsForNerds: false, + openCommunity: false, + openExchangeSummary: false, + openClaimRewards: false, + openProfile: false, + showRewards: false, + rewardInvoice: null, + badInvoice: false, + showRewardsSpinner: false, + withdrawn: false, + }; + } + + handleClickOpenStatsForNerds = () => { + this.setState({ openStatsForNerds: true }); + }; + + handleClickCloseStatsForNerds = () => { + this.setState({ openStatsForNerds: false }); + }; + + handleClickOpenCommunity = () => { + this.setState({ openCommunity: true }); + }; + + handleClickCloseCommunity = () => { + this.setState({ openCommunity: false }); + }; + + handleClickOpenProfile = () => { + this.setState({ openProfile: true, profileShown: true }); + }; + + handleClickCloseProfile = () => { + this.setState({ openProfile: false }); + }; + + handleClickOpenExchangeSummary = () => { + this.setState({ openExchangeSummary: true }); + }; + + handleClickCloseExchangeSummary = () => { + this.setState({ openExchangeSummary: false }); + }; + + handleSubmitInvoiceClicked = (e, rewardInvoice) => { + this.setState({ badInvoice: false, showRewardsSpinner: true }); + + apiClient + .post('/api/reward/', { + invoice: rewardInvoice, + }) + .then((data) => { + this.setState({ badInvoice: data.bad_invoice, showRewardsSpinner: false }); + this.props.setInfo({ + ...this.props.info, + badInvoice: data.bad_invoice, + openClaimRewards: !data.successful_withdrawal, + withdrawn: !!data.successful_withdrawal, + showRewardsSpinner: false, + }); + this.props.setRobot({ + ...this.props.robot, + earnedRewards: data.successful_withdrawal ? 0 : this.props.robot.earnedRewards, + }); + }); + e.preventDefault(); + }; + + handleSetStealthInvoice = (wantsStealth) => { + apiClient + .put('/api/stealth/', { wantsStealth }) + .then((data) => + this.props.setRobot({ ...this.props.robot, stealthInvoices: data?.wantsStealth }), + ); + }; + + showProfileButton = () => { + return ( + this.props.robot.avatarLoaded && + (this.props.robot.token + ? systemClient.getCookie('robot_token') === this.props.robot.token + : true) && + systemClient.getCookie('sessionid') + ); + }; + + bottomBarDesktop = () => { + const { t } = this.props; + const hasRewards = this.props.robot.earnedRewards > 0; + const hasOrder = !!( + (this.props.robot.activeOrderId > 0) & + !this.state.profileShown & + this.props.robot.avatarLoaded + ); + const fontSize = this.props.theme.typography.fontSize; + const fontSizeFactor = fontSize / 14; // default fontSize is 14 + const typographyProps = { + primaryTypographyProps: { fontSize }, + secondaryTypographyProps: { fontSize: (fontSize * 12) / 14 }, + }; + return ( + + + +
+ + + + 0) & !this.state.profileShown + ? 'primary' + : undefined + } + nickname={this.props.robot.nickname} + onLoad={() => + this.props.setRobot({ ...this.props.robot, avatarLoaded: true }) + } + /> + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {this.LangSelect()} + + + + + + + + + + + + + + + + +
+
+ ); + }; + + handleChangeLang = (e) => { + const { i18n } = this.props; + i18n.changeLanguage(e.target.value); + }; + + LangSelect = () => { + const { i18n } = this.props; + const lang = i18n.resolvedLanguage == null ? 'en' : i18n.resolvedLanguage.substring(0, 2); + const flagProps = { + width: 20, + height: 20, + }; + + return ( + + ); + }; + + bottomBarPhone = () => { + const { t } = this.props; + const hasRewards = this.props.robot.earnedRewards > 0; + const hasOrder = !!( + (this.props.info.active_order_id > 0) & + !this.state.profileShown & + this.props.robot.avatarLoaded + ); + return ( + + + +
+ + + 0) & !this.state.profileShown + ? 'primary' + : undefined + } + nickname={this.props.robot.nickname} + onLoad={() => this.props.setRobot({ ...this.props.robot, avatarLoaded: true })} + /> + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {this.LangSelect()} + + + + + + + + + + + this.props.fetchInfo()} + onClick={this.handleClickOpenStatsForNerds} + > + + + + + +
+
+ ); + }; + + render() { + return ( +
+ + + + this.props.setInfo({ ...this.props.info, openUpdateClient: false }) + } + /> + + + + this.props.setRobot({ ...robot, ...newParam })} + stealthInvoices={this.props.robot.stealthInvoices} + handleSetStealthInvoice={this.handleSetStealthInvoice} + /> + + + + {this.bottomBarDesktop()} + + {this.bottomBarPhone()} +
+ ); + } +} + +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;