mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-22 22:25:21 +01:00
* feat: ✨ server sso auth * chore: 🔧 continue sso integration * fix: 🐛 correct filter * chore: 🔧 add resolver types * chore: 🔧 linter sort imports * fix: 🐛 duplicate imports * chore: 🔧 change auth context * feat: ✨ add accounts read and query * fix: 🐛 small changes * chore: 🔧 continue integration * chore: 🔧 add auth * chore: 🔧 switch to new context * fix: 🐛 imports and account context * chore: 🔧 add session token query * chore: 🔧 change server auth * chore: 🔧 add sso to server accounts query * chore: 🔧 cleanup and small fixes * chore: 🔧 separate generated files * refactor: ♻️ change graphql imports * fix: 🐛 add id to params * fix: 🐛 auth changes * chore: 🔧 improve logging and account fixes * chore: 🔧 change footer * chore: 🔧 remove console logs * chore: 🔧 add spacing * fix: 🐛 final changes
129 lines
4.1 KiB
TypeScript
129 lines
4.1 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { toast } from 'react-toastify';
|
|
import { ChevronRight, X } 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 {
|
|
Card,
|
|
CardWithTitle,
|
|
SubTitle,
|
|
SingleLine,
|
|
Sub4Title,
|
|
Separation,
|
|
DarkSubTitle,
|
|
RightAlign,
|
|
ResponsiveLine,
|
|
NoWrapTitle,
|
|
} 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';
|
|
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 { 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 => {
|
|
setIsEdit(false);
|
|
data.updateFees
|
|
? toast.success('Fees Updated')
|
|
: toast.error('Error updating fees');
|
|
},
|
|
refetchQueries: ['ChannelFees'],
|
|
});
|
|
|
|
if (loading || !data || !data.getChannelFees) {
|
|
return <LoadingCard title={'Fees'} />;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<AdminSwitch>
|
|
<CardWithTitle>
|
|
<SubTitle>Update Channel Fees</SubTitle>
|
|
<Card>
|
|
<SingleLine>
|
|
<Sub4Title>Channel Fees</Sub4Title>
|
|
<ColorButton onClick={() => setIsEdit(prev => !prev)}>
|
|
{isEdit ? <X size={18} /> : 'Update'}
|
|
</ColorButton>
|
|
</SingleLine>
|
|
{isEdit && (
|
|
<>
|
|
<Separation />
|
|
<ResponsiveLine>
|
|
<NoWrapTitle>
|
|
<DarkSubTitle>{'Base Fee:'}</DarkSubTitle>
|
|
</NoWrapTitle>
|
|
<Input
|
|
placeholder={'Sats'}
|
|
type={'number'}
|
|
onChange={e => setBaseFee(Number(e.target.value))}
|
|
/>
|
|
</ResponsiveLine>
|
|
<ResponsiveLine>
|
|
<NoWrapTitle>
|
|
<DarkSubTitle>{'Fee Rate:'}</DarkSubTitle>
|
|
</NoWrapTitle>
|
|
<Input
|
|
placeholder={'Sats/Million'}
|
|
type={'number'}
|
|
onChange={e => setFeeRate(Number(e.target.value))}
|
|
/>
|
|
</ResponsiveLine>
|
|
<RightAlign>
|
|
<SecureButton
|
|
callback={updateFees}
|
|
variables={{
|
|
...(baseFee !== 0 && { baseFee }),
|
|
...(feeRate !== 0 && { feeRate }),
|
|
}}
|
|
disabled={baseFee === 0 && feeRate === 0}
|
|
fullWidth={true}
|
|
withMargin={'16px 0 0'}
|
|
>
|
|
Update Fees
|
|
<ChevronRight size={18} />
|
|
</SecureButton>
|
|
</RightAlign>
|
|
</>
|
|
)}
|
|
</Card>
|
|
</CardWithTitle>
|
|
</AdminSwitch>
|
|
<CardWithTitle>
|
|
<SubTitle>Channel Fees</SubTitle>
|
|
<Card>
|
|
{data.getChannelFees.map((channel: any, index: number) => (
|
|
<FeeCard
|
|
channelInfo={channel}
|
|
index={index + 1}
|
|
setIndexOpen={setIndexOpen}
|
|
indexOpen={indexOpen}
|
|
key={index}
|
|
/>
|
|
))}
|
|
</Card>
|
|
</CardWithTitle>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default FeesView;
|