import React, { Component } from 'react'; import { withTranslation } from 'react-i18next'; import { Badge, Tooltip, ListItemAvatar, Avatar, 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'; // 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 './Icons'; import { CommunityDialog, ExchangeSummaryDialog, ProfileDialog, StatsDialog } from './Dialogs'; import { getCookie } from '../utils/cookies'; class BottomBar extends Component { constructor(props) { super(props); this.state = { openStatsForNerds: false, openCommuniy: false, openExchangeSummary: false, openClaimRewards: false, num_public_buy_orders: 0, num_public_sell_orders: 0, book_liquidity: 0, active_robots_today: 0, maker_fee: 0, taker_fee: 0, last_day_nonkyc_btc_premium: 0, last_day_volume: 0, lifetime_volume: 0, robosats_running_commit_hash: '000000000000000', openProfile: false, profileShown: false, alternative_site: 'robosats...', node_id: '00000000', showRewards: false, rewardInvoice: null, badInvoice: false, showRewardsSpinner: false, withdrawn: false, }; } componentDidMount() { this.getInfo(); } getInfo() { this.setState(null); apiClient.get('/api/info/') .then( (data) => this.setState(data) & this.props.setAppState({ nickname: data.nickname, loading: false, activeOrderId: data.active_order_id ? data.active_order_id : null, lastOrderId: data.last_order_id ? data.last_order_id : null, referralCode: data.referral_code, tgEnabled: data.tg_enabled, tgBotName: data.tg_bot_name, tgToken: data.tg_token, earnedRewards: data.earned_rewards, lastDayPremium: data.last_day_nonkyc_btc_premium, }), ); } handleClickOpenStatsForNerds = () => { this.setState({ openStatsForNerds: true }); }; handleClickCloseStatsForNerds = () => { this.setState({ openStatsForNerds: false }); }; handleClickOpenCommunity = () => { this.setState({ openCommuniy: true }); }; handleClickCloseCommunity = () => { this.setState({ openCommuniy: false }); }; handleClickOpenProfile = () => { this.getInfo(); this.setState({ openProfile: true, profileShown: true }); }; handleClickCloseProfile = () => { this.setState({ openProfile: false }); }; handleSubmitInvoiceClicked = (e, rewardInvoice) => { this.setState({ badInvoice: false, showRewardsSpinner: true, }); apiClient.post('/api/reward/', { invoice: rewardInvoice, }).then( (data) => this.setState({ badInvoice: data.bad_invoice, openClaimRewards: !data.successful_withdrawal, withdrawn: !!data.successful_withdrawal, showRewardsSpinner: false, }) & this.props.setAppState({ earnedRewards: data.successful_withdrawal ? 0 : this.props.earnedRewards, }), ); e.preventDefault(); }; handleSetStealthInvoice = (wantsStealth) => { apiClient.put('/api/stealth/', { wantsStealth }) .then((data) => this.props.setAppState({ 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.avatarLoaded && (this.props.token ? getCookie('robot_token') == this.props.token : true) && getCookie('sessionid') ); }; bottomBarDesktop = () => { const { t } = this.props; const hasRewards = this.props.earnedRewards > 0; const hasOrder = !!( (this.props.activeOrderId > 0) & !this.state.profileShown & this.props.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.props.profileShown ? '' : null } color='primary' > this.props.setAppState({ avatarLoaded: true }), }} src={ this.props.nickname ? window.location.origin + '/static/assets/avatars/' + this.props.nickname + '.png' : null } />
this.props.setAppState({ buyChecked: false, sellChecked: true, type: 0 }) & this.getInfo() } to={`/book/`} component={LinkRouter} > this.props.setAppState({ buyChecked: true, sellChecked: false, type: 1 }) & this.getInfo() } to={`/book/`} component={LinkRouter} > this.getInfo()} to={`/`} component={LinkRouter} > {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 ( ); }; handleClickOpenExchangeSummary = () => { // avoid calling getInfo while sessionid not yet set. Temporary fix. if (getCookie('sessionid')) { this.getInfo(); } this.setState({ openExchangeSummary: true }); }; handleClickCloseExchangeSummary = () => { this.setState({ openExchangeSummary: false }); }; bottomBarPhone = () => { const { t } = this.props; const hasRewards = this.props.earnedRewards > 0; const hasOrder = !!( (this.state.active_order_id > 0) & !this.state.profileShown & this.props.avatarLoaded ); return (
0) & !this.state.profileShown ? '' : null } color='primary' > this.props.setAppState({ avatarLoaded: true }), }} src={ this.props.nickname ? window.location.origin + '/static/assets/avatars/' + this.props.nickname + '.png' : null } />
this.props.setAppState({ buyChecked: false, sellChecked: true, type: 0 }) & this.getInfo() } to={`/book/`} component={LinkRouter} > this.props.setAppState({ buyChecked: true, sellChecked: false, type: 1 }) & this.getInfo() } to={`/book/`} component={LinkRouter} > this.getInfo()} to={`/`} component={LinkRouter} > {this.LangSelect()}
); }; render() { return (
{this.bottomBarDesktop()} {this.bottomBarPhone()}
); } } export default withTranslation()(BottomBar);