useNotify.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. // FIXME(https://github.com/mui/material-ui/issues/35233)
  3. Launch as LaunchIcon,
  4. } from '@mui/icons-material';
  5. import { Link } from '@mui/material';
  6. import { styled } from '@mui/material/styles';
  7. import type { VariantType } from 'notistack';
  8. import { useSnackbar } from 'notistack';
  9. import React, { useCallback } from 'react';
  10. const Notification = styled('span')(() => ({
  11. display: 'flex',
  12. alignItems: 'center',
  13. }));
  14. const StyledLink = styled(Link)(() => ({
  15. color: '#ffffff',
  16. display: 'flex',
  17. alignItems: 'center',
  18. marginLeft: 16,
  19. textDecoration: 'underline',
  20. '&:hover': {
  21. color: '#000000',
  22. },
  23. }));
  24. const StyledLaunchIcon = styled(LaunchIcon)(() => ({
  25. fontSize: 20,
  26. marginLeft: 8,
  27. }));
  28. export function useNotify() {
  29. const { enqueueSnackbar } = useSnackbar();
  30. return useCallback(
  31. (variant: VariantType, message: string, signature?: string) => {
  32. enqueueSnackbar(
  33. <Notification>
  34. {message}
  35. {signature && (
  36. <StyledLink href={`https://explorer.solana.com/tx/${signature}?cluster=devnet`} target="_blank">
  37. Transaction
  38. <StyledLaunchIcon />
  39. </StyledLink>
  40. )}
  41. </Notification>,
  42. { variant }
  43. );
  44. },
  45. [enqueueSnackbar]
  46. );
  47. }