Files
js/components/shared/DeprecatedAlert.tsx
T
Nacho Iacovino e46ed2e805 Improve DeprecationAlert logic (#2215)
* Fix deprecation alert

* Never showing it when it shouldn't be there
2024-02-16 19:28:30 +00:00

58 lines
1.4 KiB
TypeScript

import {
Alert,
AlertIcon,
Flex,
AlertTitle,
AlertDescription,
} from "@chakra-ui/react";
import { Chain, getChainByChainId } from "@thirdweb-dev/chains";
import { Text } from "tw-components";
interface DeprecatedAlertProps {
chain: Chain;
description?: string;
recommendedChainId?: number;
}
export const DeprecatedAlert: React.FC<DeprecatedAlertProps> = ({
chain,
description = "thirdweb services are not available on this network.",
recommendedChainId,
}) => {
const recommendedChainName = recommendedChainId
? getChainByChainId(recommendedChainId).name
: undefined;
if (chain?.status !== "deprecated" || !chain?.name) {
return null;
}
const cleanedChainName = chain?.name?.replace("Mainnet", "").trim();
return (
<Alert
status="error"
borderRadius="lg"
backgroundColor="backgroundCardHighlight"
borderLeftColor="red.500"
borderLeftWidth={4}
as={Flex}
gap={1}
>
<AlertIcon />
<Flex flexDir="column">
<AlertTitle>{cleanedChainName} is deprecated</AlertTitle>
<AlertDescription as={Text}>
{description}{" "}
{recommendedChainId && (
<>
We recommend switching to <strong>{recommendedChainName}</strong>{" "}
to continue testing your smart contracts.
</>
)}
</AlertDescription>
</Flex>
</Alert>
);
};