mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* add prefix to API resources * fix pw tests * refactor config * remove unnecessary prefixes in resource names * fixes * update screenshots
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { Text } from '@chakra-ui/react';
|
|
import React, { useCallback } from 'react';
|
|
|
|
import type { WatchlistAddress } from 'types/api/account';
|
|
|
|
import useApiFetch from 'lib/api/useApiFetch';
|
|
import useIsMobile from 'lib/hooks/useIsMobile';
|
|
import DeleteModal from 'ui/shared/DeleteModal';
|
|
|
|
type Props = {
|
|
open: boolean;
|
|
onOpenChange: ({ open }: { open: boolean }) => void;
|
|
onSuccess: () => Promise<void>;
|
|
data: Pick<WatchlistAddress, 'address_hash' | 'id'>;
|
|
};
|
|
|
|
const DeleteAddressModal: React.FC<Props> = ({ open, onOpenChange, onSuccess, data }) => {
|
|
const isMobile = useIsMobile();
|
|
const apiFetch = useApiFetch();
|
|
|
|
const mutationFn = useCallback(() => {
|
|
return apiFetch('general:watchlist', {
|
|
pathParams: { id: String(data.id) },
|
|
fetchParams: { method: 'DELETE' },
|
|
});
|
|
}, [ data?.id, apiFetch ]);
|
|
|
|
const address = data?.address_hash;
|
|
|
|
const renderModalContent = useCallback(() => {
|
|
const addressString = isMobile ? [ address.slice(0, 4), address.slice(-4) ].join('...') : address;
|
|
return (
|
|
<Text>Address <Text fontWeight="700" as="span"> { addressString || 'address' }</Text> will be deleted</Text>
|
|
);
|
|
}, [ address, isMobile ]);
|
|
|
|
return (
|
|
<DeleteModal
|
|
open={ open }
|
|
onOpenChange={ onOpenChange }
|
|
title="Remove address from watch list"
|
|
renderContent={ renderModalContent }
|
|
mutationFn={ mutationFn }
|
|
onSuccess={ onSuccess }
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default DeleteAddressModal;
|