mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
114 lines
3.8 KiB
TypeScript
114 lines
3.8 KiB
TypeScript
import React, { useCallback, useState } from 'react';
|
|
|
|
import type { CustomAbi } from 'types/api/account';
|
|
|
|
import useApiQuery from 'lib/api/useApiQuery';
|
|
import { CUSTOM_ABI } from 'stubs/account';
|
|
import { Button } from '@luxfi/ui/button';
|
|
import { Skeleton } from '@luxfi/ui/skeleton';
|
|
import { useDisclosure } from 'toolkit/hooks/useDisclosure';
|
|
import CustomAbiModal from 'ui/customAbi/CustomAbiModal/CustomAbiModal';
|
|
import CustomAbiListItem from 'ui/customAbi/CustomAbiTable/CustomAbiListItem';
|
|
import CustomAbiTable from 'ui/customAbi/CustomAbiTable/CustomAbiTable';
|
|
import DeleteCustomAbiModal from 'ui/customAbi/DeleteCustomAbiModal';
|
|
import AccountPageDescription from 'ui/shared/AccountPageDescription';
|
|
import DataFetchAlert from 'ui/shared/DataFetchAlert';
|
|
import PageTitle from 'ui/shared/Page/PageTitle';
|
|
import useRedirectForInvalidAuthToken from 'ui/snippets/auth/useRedirectForInvalidAuthToken';
|
|
|
|
const CustomAbiPage: React.FC = () => {
|
|
const customAbiModalProps = useDisclosure();
|
|
const deleteModalProps = useDisclosure();
|
|
useRedirectForInvalidAuthToken();
|
|
|
|
const [ customAbiModalData, setCustomAbiModalData ] = useState<CustomAbi>();
|
|
const [ deleteModalData, setDeleteModalData ] = useState<CustomAbi>();
|
|
|
|
const { data, isPlaceholderData, isError } = useApiQuery('general:custom_abi', {
|
|
queryOptions: {
|
|
placeholderData: Array(3).fill(CUSTOM_ABI),
|
|
},
|
|
});
|
|
|
|
const onEditClick = useCallback((data: CustomAbi) => {
|
|
setCustomAbiModalData(data);
|
|
customAbiModalProps.onOpen();
|
|
}, [ customAbiModalProps ]);
|
|
|
|
const onCustomAbiModalOpenChange = useCallback(({ open }: { open: boolean }) => {
|
|
!open && setCustomAbiModalData(undefined);
|
|
customAbiModalProps.onOpenChange({ open });
|
|
}, [ customAbiModalProps ]);
|
|
|
|
const onDeleteClick = useCallback((data: CustomAbi) => {
|
|
setDeleteModalData(data);
|
|
deleteModalProps.onOpen();
|
|
}, [ deleteModalProps ]);
|
|
|
|
const onDeleteModalOpenChange = useCallback(({ open }: { open: boolean }) => {
|
|
!open && setDeleteModalData(undefined);
|
|
deleteModalProps.onOpenChange({ open });
|
|
}, [ deleteModalProps ]);
|
|
|
|
const description = (
|
|
<AccountPageDescription>
|
|
Add custom ABIs for any contract and access when logged into your account. Helpful for debugging, functional testing and contract interaction.
|
|
</AccountPageDescription>
|
|
);
|
|
|
|
const content = (() => {
|
|
if (isError) {
|
|
return <DataFetchAlert/>;
|
|
}
|
|
|
|
const list = (
|
|
<>
|
|
<div className="block lg:hidden">
|
|
{ data?.map((item, index) => (
|
|
<CustomAbiListItem
|
|
key={ item.id + (isPlaceholderData ? String(index) : '') }
|
|
item={ item }
|
|
isLoading={ isPlaceholderData }
|
|
onDeleteClick={ onDeleteClick }
|
|
onEditClick={ onEditClick }
|
|
/>
|
|
)) }
|
|
</div>
|
|
<div className="hidden lg:block">
|
|
<CustomAbiTable
|
|
data={ data }
|
|
isLoading={ isPlaceholderData }
|
|
onDeleteClick={ onDeleteClick }
|
|
onEditClick={ onEditClick }
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
|
|
return (
|
|
<>
|
|
{ description }
|
|
{ Boolean(data?.length) && list }
|
|
<Skeleton mt={ 8 } loading={ isPlaceholderData } display="inline-block">
|
|
<Button
|
|
onClick={ customAbiModalProps.onOpen }
|
|
>
|
|
Add custom ABI
|
|
</Button>
|
|
</Skeleton>
|
|
<CustomAbiModal open={ customAbiModalProps.open } onOpenChange={ onCustomAbiModalOpenChange } data={ customAbiModalData }/>
|
|
{ deleteModalData && <DeleteCustomAbiModal open={ deleteModalProps.open } onOpenChange={ onDeleteModalOpenChange } data={ deleteModalData }/> }
|
|
</>
|
|
);
|
|
})();
|
|
|
|
return (
|
|
<>
|
|
<PageTitle title="Custom ABI"/>
|
|
{ content }
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default CustomAbiPage;
|