import React, { useState } from 'react'; import { Dialog, DialogTitle, DialogContent, TextField, DialogActions, Button, CircularProgress, } from '@material-ui/core'; // styles import useStyles from './styles'; import { lndOpenChannelSyncRequest, } from '../../squeakclient/requests'; export default function OpenChannelDialog({ open, pubkey, handleClose, ...props }) { const classes = useStyles(); const [amount, setAmount] = useState(''); const [satperbyte, setSatperbyte] = useState(''); const [loading, setLoading] = useState(false); const resetFields = () => { setAmount(''); setSatperbyte(''); }; const handleChangeAmount = (event) => { setAmount(event.target.value); }; const handleChangeSatPerBytes = (event) => { setSatperbyte(event.target.value); }; const handleResponse = (response) => { // TODO: go to channel page instead of showing alert. setLoading(false); handleClose(); alert('Open channel pending.'); }; const handleErr = (err) => { setLoading(false); handleClose(); alert(`Error opening channel: ${err}`); }; const openChannel = (pubkey, amount) => { setLoading(true); lndOpenChannelSyncRequest(pubkey, amount, satperbyte, handleResponse, handleErr); }; function handleSubmit(event) { event.preventDefault(); console.log('pubkey:', pubkey); console.log('amount:', amount); console.log('satperbyte:', satperbyte); if (!amount) { alert('Amount cannot be empty.'); return; } openChannel(pubkey, amount, satperbyte); } function PubKeyInput() { return ( ); } function LocalFundingAmountInput() { return ( ); } function SatPerByteInput() { return ( ); } function CancelButton() { return ( ); } function OpenChannelButton() { return (
{loading && }
); } return ( Open Channel
{PubKeyInput()} {LocalFundingAmountInput()} {SatPerByteInput()} {CancelButton()} {OpenChannelButton()}
); }