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 = "Surrender Document Success",
ACCEPT_SURRENDER_DOCUMENT = "Surrender Accepted",
REJECT_SURRENDER_DOCUMENT = "Surrender Rejected",
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",
}
const ButtonClose: FunctionComponent = () => {
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;
}
export const DocumentTransferMessage: FunctionComponent<
DocumentTransferMessageProps
> = ({
isButtonMetamaskInstall,
isConfirmationMessage,
onConfirmationAction,
children,
...props
}) => {
const documentTransferButton = (): ReactNode => {
if (isButtonMetamaskInstall) {
return ;
}
if (isConfirmationMessage && onConfirmationAction) {
return (
{ButtonConfirmAction(onConfirmationAction)}
);
}
return ;
};
return (
{children}
{documentTransferButton()}
);
};
interface MessageProps {
address?: string;
error?: string;
beneficiaryAddress?: 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 Bill of Lading has been surrendered, pending acceptance of issuer.
);
};
export const AcceptSurrender: FunctionComponent = () => {
return (
Surrender for this Bill of Lading has been accepted.
);
};
export const RejectSurrender: FunctionComponent = () => {
return (
Surrender for this Bill of Lading has been rejected.
);
};
export const MessageRejectSurrenderConfirmation: FunctionComponent<
MessageProps
> = ({ beneficiaryAddress, holderAddress }) => {
return (
<>
Restore document to Owner:
{beneficiaryAddress && (
)}
and to Holder:
{holderAddress && }
>
);
};
export const MessageBeneficiarySuccess: FunctionComponent = ({
address,
}) => {
return (
<>
Current Owner
{address && }
>
);
};
export const MessageHolderSuccess: FunctionComponent = ({
address,
}) => {
return (
<>
Current Holder
{address && }
>
);
};
export const MessageNominateBeneficiaryHolderSuccess: FunctionComponent =
() => {
return (
Document has been nominated successfully. Please notify holder to
execute transfer.
);
};
export const MessageEndorseTransferSuccess: FunctionComponent = ({
beneficiaryAddress,
holderAddress,
}) => {
return (
<>
Current Owner
{beneficiaryAddress && (
)}
Current Holder
{holderAddress && }
>
);
};
interface ShowDocumentTransferMessageOptionProps {
isSuccess: boolean;
error?: string;
beneficiaryAddress?: string;
holderAddress?: string;
isButtonMetamaskInstall?: boolean;
onConfirmationAction?: () => void;
isConfirmationMessage?: boolean;
}
export const showDocumentTransferMessage = (
title: string,
option: ShowDocumentTransferMessageOptionProps
): 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 && (
)}
);
};