2020-08-02 10:44:47 -07:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
import { TransactionSignature } from "@solana/web3.js";
|
|
|
|
import { clusterPath } from "utils/url";
|
|
|
|
|
|
|
|
type CopyState = "copy" | "copied";
|
2020-08-04 05:44:16 -07:00
|
|
|
type Props = {
|
|
|
|
signature: TransactionSignature;
|
|
|
|
alignRight?: boolean;
|
|
|
|
link?: boolean;
|
|
|
|
};
|
2020-08-02 10:44:47 -07:00
|
|
|
|
2020-08-07 23:45:57 -07:00
|
|
|
export function Signature({ signature, alignRight, link }: Props) {
|
2020-08-02 10:44:47 -07:00
|
|
|
const [state, setState] = useState<CopyState>("copy");
|
|
|
|
|
|
|
|
const copyToClipboard = () => navigator.clipboard.writeText(signature);
|
|
|
|
const handleClick = () =>
|
|
|
|
copyToClipboard().then(() => {
|
|
|
|
setState("copied");
|
|
|
|
setTimeout(() => setState("copy"), 1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
const copyIcon =
|
|
|
|
state === "copy" ? (
|
|
|
|
<span className="fe fe-copy" onClick={handleClick}></span>
|
|
|
|
) : (
|
|
|
|
<span className="fe fe-check-circle"></span>
|
|
|
|
);
|
|
|
|
|
|
|
|
const copyButton = (
|
|
|
|
<span className="c-pointer font-size-tiny mr-2">{copyIcon}</span>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2020-08-04 05:44:16 -07:00
|
|
|
<div
|
|
|
|
className={`d-flex align-items-center ${
|
|
|
|
alignRight ? "justify-content-end" : ""
|
|
|
|
}`}
|
|
|
|
>
|
2020-08-02 10:44:47 -07:00
|
|
|
{copyButton}
|
|
|
|
<span className="text-monospace">
|
|
|
|
{link ? (
|
|
|
|
<Link className="" to={clusterPath(`/tx/${signature}`)}>
|
|
|
|
{signature}
|
|
|
|
</Link>
|
|
|
|
) : (
|
|
|
|
signature
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|