import React, { useState } from 'react';
import { useQuery, useMutation } from '@apollo/react-hooks';
import { CHANNEL_FEES } from '../src/graphql/query';
import {
Card,
CardWithTitle,
SubTitle,
SingleLine,
Sub4Title,
Separation,
DarkSubTitle,
RightAlign,
ResponsiveLine,
NoWrapTitle,
} from '../src/components/generic/Styled';
import { useAccount } from '../src/context/AccountContext';
import { toast } from 'react-toastify';
import { getErrorContent } from '../src/utils/error';
import { LoadingCard } from '../src/components/loading/LoadingCard';
import { FeeCard } from '../src/views/fees/FeeCard';
import { UPDATE_FEES } from '../src/graphql/mutation';
import { XSvg, ChevronRight } from '../src/components/generic/Icons';
import { SecureButton } from '../src/components/buttons/secureButton/SecureButton';
import { AdminSwitch } from '../src/components/adminSwitch/AdminSwitch';
import { ColorButton } from '../src/components/buttons/colorButton/ColorButton';
import { Input } from '../src/components/input/Input';
const FeesView = () => {
const [indexOpen, setIndexOpen] = useState(0);
const [isEdit, setIsEdit] = useState(false);
const [baseFee, setBaseFee] = useState(0);
const [feeRate, setFeeRate] = useState(0);
const { host, viewOnly, cert, sessionAdmin } = useAccount();
const auth = {
host,
macaroon: viewOnly !== '' ? viewOnly : sessionAdmin,
cert,
};
const { loading, data } = useQuery(CHANNEL_FEES, {
variables: { auth },
onError: error => toast.error(getErrorContent(error)),
});
const [updateFees] = useMutation(UPDATE_FEES, {
onError: error => toast.error(getErrorContent(error)),
onCompleted: data => {
setIsEdit(false);
data.updateFees
? toast.success('Fees Updated')
: toast.error('Error updating fees');
},
refetchQueries: ['GetChannelFees'],
});
if (loading || !data || !data.getChannelFees) {
return ;
}
return (
<>
Update Channel Fees
Channel Fees
setIsEdit(prev => !prev)}>
{isEdit ? : 'Update'}
{isEdit && (
<>
{'Base Fee:'}
setBaseFee(Number(e.target.value))}
/>
{'Fee Rate:'}
setFeeRate(Number(e.target.value))}
/>
Update Fees
>
)}
Channel Fees
{data.getChannelFees.map((channel: any, index: number) => (
))}
>
);
};
export default FeesView;