import React, { useState } from 'react'; import { toast } from 'react-toastify'; import { ChevronRight, ChevronUp, ChevronDown } from 'react-feather'; import { useAccountState } from 'src/context/AccountContext'; import { useChannelFeesQuery } from 'src/graphql/queries/__generated__/getChannelFees.generated'; import { useUpdateFeesMutation } from 'src/graphql/mutations/__generated__/updateFees.generated'; import { InputWithDeco } from 'src/components/input/InputWithDeco'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; import { withApollo } from 'config/client'; import styled from 'styled-components'; import { useStatusState } from 'src/context/StatusContext'; import { ChannelFeeType } from 'src/graphql/types'; import { Card, CardWithTitle, SubTitle, SingleLine, Sub4Title, Separation, RightAlign, } from '../src/components/generic/Styled'; import { getErrorContent } from '../src/utils/error'; import { LoadingCard } from '../src/components/loading/LoadingCard'; import { FeeCard } from '../src/views/fees/FeeCard'; import { SecureButton } from '../src/components/buttons/secureButton/SecureButton'; import { AdminSwitch } from '../src/components/adminSwitch/AdminSwitch'; const WithPointer = styled.div` cursor: pointer; `; const FeesView = () => { const { minorVersion, revision } = useStatusState(); const canMax = (minorVersion === 7 && revision > 1) || minorVersion > 7; const canMin = (minorVersion === 8 && revision > 2) || minorVersion > 8; const [indexOpen, setIndexOpen] = useState(0); const [isEdit, setIsEdit] = useState(false); const [baseFee, setBaseFee] = useState(0); const [feeRate, setFeeRate] = useState(0); const [cltv, setCLTV] = useState(0); const [max, setMax] = useState(0); const [min, setMin] = useState(0); const { auth } = useAccountState(); const { loading, data } = useChannelFeesQuery({ skip: !auth, variables: { auth }, onError: error => toast.error(getErrorContent(error)), }); const [updateFees] = useUpdateFeesMutation({ onError: error => toast.error(getErrorContent(error)), onCompleted: data => { setBaseFee(0); setFeeRate(0); setCLTV(0); setMax(0); setMin(0); setIsEdit(false); data.updateFees ? toast.success('Channel Details Updated') : toast.error('Error updating fees'); }, refetchQueries: ['ChannelFees'], }); if (loading || !data || !data.getChannelFees) { return ; } return ( <> setIsEdit(prev => !prev)}> Update All Channel Details {isEdit ? : } {isEdit && ( <> setBaseFee(Number(value))} /> setFeeRate(Number(value))} /> setCLTV(Number(value))} /> {canMax && ( setMax(Number(value))} /> )} {canMin && ( setMin(Number(value))} /> )} Update Fees )} Channel Details {data.getChannelFees.map((channel, index) => ( ))} ); }; const Wrapped = () => ( ); export default withApollo(Wrapped);