import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useTheme } from '@mui/material/styles'; import { Link as LinkRouter } from 'react-router-dom'; import { Avatar, Badge, Button, CircularProgress, Dialog, DialogContent, Divider, FormControlLabel, Grid, IconButton, List, ListItemAvatar, ListItemButton, ListItemText, ListItem, ListItemIcon, Switch, TextField, Tooltip, Typography, } from '@mui/material'; import { EnableTelegramDialog } from '.'; import BoltIcon from '@mui/icons-material/Bolt'; import SendIcon from '@mui/icons-material/Send'; import NumbersIcon from '@mui/icons-material/Numbers'; import PasswordIcon from '@mui/icons-material/Password'; import ContentCopy from '@mui/icons-material/ContentCopy'; import PersonAddAltIcon from '@mui/icons-material/PersonAddAlt'; import EmojiEventsIcon from '@mui/icons-material/EmojiEvents'; import { UserNinjaIcon, BitcoinIcon } from '../Icons'; import { getCookie } from '../../utils/cookies'; import { copyToClipboard } from '../../utils/clipboard'; import { getWebln } from '../../utils/webln'; interface Props { isOpen: boolean; handleClickCloseProfile: () => void; nickname: string; activeOrderId: string | number; lastOrderId: string | number; referralCode: string; tgEnabled: boolean; tgBotName: string; tgToken: string; handleSubmitInvoiceClicked: (e: any, invoice: string) => void; host: string; showRewardsSpinner: boolean; withdrawn: boolean; badInvoice: boolean | string; earnedRewards: number; stealthInvoices: boolean; handleSetStealthInvoice: (stealth: boolean) => void; setAppState: (state: any) => void; // TODO: move to a ContextProvider } const ProfileDialog = ({ isOpen, handleClickCloseProfile, nickname, activeOrderId, lastOrderId, referralCode, tgEnabled, tgBotName, tgToken, handleSubmitInvoiceClicked, host, showRewardsSpinner, withdrawn, badInvoice, earnedRewards, setAppState, stealthInvoices, handleSetStealthInvoice, }: Props): JSX.Element => { const { t } = useTranslation(); const theme = useTheme(); const [rewardInvoice, setRewardInvoice] = useState(''); const [showRewards, setShowRewards] = useState(false); const [openClaimRewards, setOpenClaimRewards] = useState(false); const [weblnEnabled, setWeblnEnabled] = useState(false); const [openEnableTelegram, setOpenEnableTelegram] = useState(false); useEffect(() => { getWebln().then((webln) => { setWeblnEnabled(webln !== undefined); }); }, [showRewards]); const copyTokenHandler = () => { const robotToken = getCookie('robot_token'); if (robotToken) { copyToClipboard(robotToken); setAppState({ copiedToken: true }); } }; const copyReferralCodeHandler = () => { copyToClipboard(`http://${host}/ref/${referralCode}`); }; const handleWeblnInvoiceClicked = async (e: any) => { e.preventDefault(); if (earnedRewards) { const webln = await getWebln(); const invoice = webln.makeInvoice(earnedRewards).then(() => { if (invoice) { handleSubmitInvoiceClicked(e, invoice.paymentRequest); } }); } }; const handleClickEnableTelegram = () => { window.open('https://t.me/' + tgBotName + '?start=' + tgToken, '_blank').focus(); setOpenEnableTelegram(false); }; return ( {t('Your Profile')} {nickname ? ( ) : null} {activeOrderId ? ( ) : lastOrderId ? ( ) : ( )} {getCookie('robot_token') ? ( ), }} /> ) : ( t('Cannot remember') )} setOpenEnableTelegram(false)} tgBotName={tgBotName} tgToken={tgToken} onClickEnable={handleClickEnableTelegram} /> {tgEnabled ? ( {t('Telegram enabled')} ) : ( )} handleSetStealthInvoice(!stealthInvoices)} /> } /> {t('Rewards and compensations')} } control={ setShowRewards(!showRewards)} /> } /> {showRewards && ( <> ), }} /> {!openClaimRewards ? ( {`${earnedRewards} Sats`} ) : (
{ setRewardInvoice(e.target.value); }} /> {weblnEnabled && ( )}
)}
{showRewardsSpinner && (
)} {withdrawn && (
{t('There it goes, thank you!🥇')}
)} )}
); }; export default ProfileDialog;