import React, { FunctionComponent, ReactNode } from "react"; import { useOverlayContext } from "../../../../common/context/OverlayContext"; import { Button, LinkButton } from "../../Button"; import { OverlayContent, OverlayContentProps } from "./index"; import { MessageAddressResolver } from "./MessageAddressResolver"; export enum MessageTitle { NO_METAMASK = "Metamask not installed", NO_MANAGE_ACCESS = "No manage assets access", NO_USER_AUTHORIZATION = "User denied account authorization", // this error message must match error message from metamask extension itself TRANSACTION_ERROR = "Error - Failed transaction", SURRENDER_DOCUMENT_SUCCESS = "Return of ETR successful", ACCEPT_SURRENDER_DOCUMENT = "Return of ETR accepted", REJECT_SURRENDER_DOCUMENT = "Return of this ETR has been rejected by the Issuer", CONFIRM_REJECT_SURRENDER_DOCUMENT = "Confirm Document Return", CHANGE_BENEFICIARY_SUCCESS = "Change Owner Success", NOMINATE_BENEFICIARY_HOLDER_SUCCESS = "Nomination Success", TRANSFER_HOLDER_SUCCESS = "Transfer Holder Success", ENDORSE_TRANSFER_SUCCESS = "Endorse Ownership/Holdership Success", } interface ButtonCloseProps { className?: string; } export const ButtonClose: FunctionComponent = ({ className, }) => { const { closeOverlay } = useOverlayContext(); return ( ); }; const ButtonMetamaskInstall: FunctionComponent = () => { return ( Install Metamask ); }; const ButtonConfirmAction = (handleOnClick: () => void): ReactNode => { const { closeOverlay } = useOverlayContext(); const onClick = (): void => { handleOnClick(); closeOverlay(); }; return ( ); }; interface DocumentTransferMessageProps extends OverlayContentProps { children: React.ReactNode; isButtonMetamaskInstall?: boolean; isConfirmationMessage?: boolean; onConfirmationAction?: () => void; footer?: React.ReactNode; } export const DocumentTransferMessage: FunctionComponent< DocumentTransferMessageProps > = ({ isButtonMetamaskInstall, isConfirmationMessage, onConfirmationAction, children, footer, ...props }) => { const documentTransferButton = (): ReactNode => { if (isButtonMetamaskInstall) { return ; } if (isConfirmationMessage && onConfirmationAction) { return (
{ButtonConfirmAction(onConfirmationAction)}
); } return footer ? footer : ; }; return (
{children}
{documentTransferButton()}
); }; interface MessageProps { address?: string; error?: string; beneficiaryTitle?: string; beneficiaryAddress?: string; holderTitle?: string; holderAddress?: string; } export const MessageNoMetamask: FunctionComponent = () => { return ( <>

Oops! It seems like you have not installed the Metamask extension.

You would need to install it before proceeding.

); }; export const MessageNoManageAccess: FunctionComponent = () => { return (

Oops! It seems like you do not have access to manage assets.

); }; export const MessageNoUserAuthorization: FunctionComponent = () => { return ( <>

Oops! It seems like you did not authorize to use Metamask extension.

); }; export const MessageTransactionError: FunctionComponent = ({ error, }) => { return ( <>

Oops! It seems like there's a failed transaction.

{error}

Please try again.

); }; export const MessageSurrenderSuccess: FunctionComponent = () => { return (

This ETR has been returned, pending acceptance by the Issuer.

); }; export const AcceptSurrender: FunctionComponent = () => { return (

This ETR has been taken out of circulation by the Issuer.

); }; export const RejectSurrender: FunctionComponent = () => { return (

Return for this ETR has been rejected by the Issuer.

); }; export const MessageRejectSurrenderConfirmation: FunctionComponent< MessageProps > = ({ beneficiaryAddress, holderAddress }) => { return ( ); }; export const MessageBeneficiarySuccess: FunctionComponent = ({ address, }) => { return ; }; export const MessageHolderSuccess: FunctionComponent = ({ address, }) => { return ; }; export const MessageNominateBeneficiaryHolderSuccess: FunctionComponent = () => { return (

Document has been nominated successfully. Please notify holder to execute transfer.

); }; export const MessageEndorseTransferSuccess: FunctionComponent = ({ beneficiaryAddress, holderAddress, }) => { return ( ); }; export const MessageTransferSuccess: FunctionComponent = ({ beneficiaryTitle = "Current Owner", beneficiaryAddress, holderTitle = "Current Holder", holderAddress, }) => { return ( <> {beneficiaryAddress && ( <>
{beneficiaryTitle}
{beneficiaryAddress && ( )} )} {holderAddress && ( <>
{holderTitle}
{holderAddress && } )} ); }; interface ShowDocumentTransferMessageOptionProps { isSuccess: boolean; error?: string; beneficiaryTitle?: string; beneficiaryAddress?: string; holderTitle?: string; holderAddress?: string; isButtonMetamaskInstall?: boolean; onConfirmationAction?: () => void; isConfirmationMessage?: boolean; } export const showDocumentTransferMessage = ( title: string, option: ShowDocumentTransferMessageOptionProps, footer?: React.ReactNode, ): ReactNode => { return ( {title === MessageTitle.NO_METAMASK && } {title === MessageTitle.NO_MANAGE_ACCESS && } {title === MessageTitle.NO_USER_AUTHORIZATION && ( )} {title === MessageTitle.TRANSACTION_ERROR && ( )} {title === MessageTitle.SURRENDER_DOCUMENT_SUCCESS && ( )} {title === MessageTitle.ACCEPT_SURRENDER_DOCUMENT && } {title === MessageTitle.REJECT_SURRENDER_DOCUMENT && } {title === MessageTitle.CONFIRM_REJECT_SURRENDER_DOCUMENT && ( )} {title === MessageTitle.CHANGE_BENEFICIARY_SUCCESS && ( )} {title === MessageTitle.NOMINATE_BENEFICIARY_HOLDER_SUCCESS && ( )} {title === MessageTitle.TRANSFER_HOLDER_SUCCESS && ( )} {title === MessageTitle.ENDORSE_TRANSFER_SUCCESS && ( )} {!(Object.values(MessageTitle) as string[]).includes(title) && title?.length > 0 && } ); };