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";
// 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)
fetch('/api/info/')
.then((response) => response.json())
.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,
earnedRewards: data.earned_rewards,}));
}
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,
});
const requestOptions = {
method: 'POST',
headers: {'Content-Type':'application/json', 'X-CSRFToken': getCookie('csrftoken'),},
body: JSON.stringify({
'invoice': rewardInvoice,
}),
};
fetch('/api/reward/', requestOptions)
.then((response) => response.json())
.then((data) => this.setState({
badInvoice:data.bad_invoice,
openClaimRewards: data.successful_withdrawal ? false : true,
withdrawn: data.successful_withdrawal ? true : false,
showRewardsSpinner: false,
})
& this.props.setAppState({
earnedRewards: data.successful_withdrawal ? 0 : this.props.earnedRewards,
})
);
e.preventDefault();
}
getHost(){
var 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;
var hasRewards = this.props.earnedRewards > 0 ? true: false;
var hasOrder = this.props.activeOrderId > 0 & !this.state.profileShown & this.props.avatarLoaded ? true : false;
return(