From 1172d9cd41589711c182542a0f9f9fe5507d42d3 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Wed, 22 Apr 2020 22:01:56 +0800 Subject: [PATCH] Make more things copyable --- explorer/src/components/AccountModal.tsx | 9 ++++-- explorer/src/components/AccountsCard.tsx | 10 +++++- explorer/src/components/Copyable.tsx | 34 +++++++++++++------- explorer/src/components/TransactionModal.tsx | 25 +++++++++++--- explorer/src/scss/_solana.scss | 16 ++++++--- 5 files changed, 70 insertions(+), 24 deletions(-) diff --git a/explorer/src/components/AccountModal.tsx b/explorer/src/components/AccountModal.tsx index 0608e8db23..9a8fedf311 100644 --- a/explorer/src/components/AccountModal.tsx +++ b/explorer/src/components/AccountModal.tsx @@ -7,6 +7,7 @@ import { Status } from "../providers/accounts"; import { TransactionError } from "@solana/web3.js"; +import Copyable from "./Copyable"; function AccountModal() { const selected = useSelectedAccount(); @@ -135,9 +136,11 @@ function ListGroupItem({
-
- {signature} -
+ +
+ {signature} +
+
diff --git a/explorer/src/components/AccountsCard.tsx b/explorer/src/components/AccountsCard.tsx index 7427d9f4e4..a0a015c8e2 100644 --- a/explorer/src/components/AccountsCard.tsx +++ b/explorer/src/components/AccountsCard.tsx @@ -209,7 +209,15 @@ const renderAccountRow = ( {balance} {data} - {owner === "-" ? owner : {owner}} + + {owner === "-" ? ( + owner + ) : ( + + {owner} + + )} + {renderDetails()} ); diff --git a/explorer/src/components/Copyable.tsx b/explorer/src/components/Copyable.tsx index 5c1d790e0c..594afceb05 100644 --- a/explorer/src/components/Copyable.tsx +++ b/explorer/src/components/Copyable.tsx @@ -5,27 +5,39 @@ type CopyableProps = { children: ReactNode; }; -const popover = ( -
-
-
Copied!
-
-); +type State = "hide" | "copy" | "copied"; + +function Popover({ state }: { state: State }) { + if (state === "hide") return null; + const text = state === "copy" ? "Copy" : "Copied!"; + return ( +
+
+
{text}
+
+ ); +} function Copyable({ text, children }: CopyableProps) { - const [showPopover, setShowPopover] = useState(false); + const [state, setState] = useState("hide"); const copyToClipboard = () => navigator.clipboard.writeText(text); const handleClick = () => copyToClipboard().then(() => { - setShowPopover(true); - setTimeout(setShowPopover.bind(null, false), 2500); + setState("copied"); + setTimeout(() => setState("hide"), 1000); }); return (
-
{children}
- {showPopover && popover} +
setState("copy")} + onMouseOut={() => state === "copy" && setState("hide")} + > + {children} +
+
); } diff --git a/explorer/src/components/TransactionModal.tsx b/explorer/src/components/TransactionModal.tsx index b870006e23..78cfccad37 100644 --- a/explorer/src/components/TransactionModal.tsx +++ b/explorer/src/components/TransactionModal.tsx @@ -13,6 +13,7 @@ import { CreateAccountParams, TransactionInstruction } from "@solana/web3.js"; +import Copyable from "./Copyable"; function TransactionModal() { const { selected } = useTransactions(); @@ -106,15 +107,21 @@ function TransferDetails({ transfer: TransferParams; index: number; }) { + const from = transfer.fromPubkey.toBase58(); + const to = transfer.toPubkey.toBase58(); return (

{`Instruction #${index + 1} (Transfer)`}

- {transfer.fromPubkey.toBase58()} + + {from} + - {transfer.toPubkey.toBase58()} + + {to} + {`◎${(1.0 * transfer.lamports) / LAMPORTS_PER_SOL}`} @@ -131,16 +138,22 @@ function CreateDetails({ create: CreateAccountParams; index: number; }) { + const from = create.fromPubkey.toBase58(); + const newKey = create.newAccountPubkey.toBase58(); return (

{`Instruction #${index + 1} (Create Account)`}

- {create.fromPubkey.toBase58()} + + {from} + - {create.newAccountPubkey.toBase58()} + + {newKey} + {`◎${(1.0 * create.lamports) / LAMPORTS_PER_SOL}`} @@ -167,7 +180,9 @@ function InstructionDetails({
{ix.keys.map(({ pubkey }, keyIndex) => ( - {pubkey.toBase58()} + + {pubkey.toBase58()} + ))} {ix.data.length} diff --git a/explorer/src/scss/_solana.scss b/explorer/src/scss/_solana.scss index ac34b49f73..37091dcde5 100644 --- a/explorer/src/scss/_solana.scss +++ b/explorer/src/scss/_solana.scss @@ -17,10 +17,18 @@ code { cursor: pointer; } - .popover { - top: -1rem; - right: -5.12rem; - left: auto; + .popover.bs-popover-top { + background-color: $dark; + top: -4rem; + left: 40%; + + .popover-body { + color: white; + } + + .arrow::after { + border-top-color: $dark; + } } }