Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions app/src/components/Copyable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import IconButton from "@mui/material/IconButton";
import Tooltip from "@mui/material/Tooltip";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
Expand All @@ -11,19 +11,28 @@ export interface CopyableProps {
href?: boolean;
}

async function handleCopy(value: string) {
async function handleCopy(value: string, onSuccess: () => void) {
await navigator.clipboard.writeText(value);
onSuccess();
}

function Copyable({ value, label, tooltip, href }: CopyableProps) {
const { themeColor } = useTheme();
const [copied, setCopied] = useState(false);

const handleCopyClick = async () => {
await handleCopy(value, () => {
setCopied(true);
setTimeout(() => setCopied(false), 2000);
});
};

return (
<div
style={{ cursor: "pointer", color: themeColor("gray1") }}
onClick={() => handleCopy(value)}
onClick={handleCopyClick}
>
<Tooltip title={`Click to copy ${tooltip}`}>
<Tooltip title={copied ? "Copied!" : `Click to copy ${tooltip}`}>
<span>
{href ? (
<a
Expand Down
7 changes: 6 additions & 1 deletion app/src/components/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ export const ButtonSpinner = () => (
export const CopyableHex = ({
hex,
tooltip,
slice,
}: {
hex: string;
tooltip: string;
slice: boolean;
}) => {
const formattedHex = hex.slice(0, 6) + "..." + hex.slice(-4, hex.length);
let formattedHex = "...";
if (slice) {
formattedHex = hex.slice(0, 6) + "..." + hex.slice(-4, hex.length);
}
return <Copyable value={hex} label={formattedHex} tooltip={tooltip} />;
};
3 changes: 2 additions & 1 deletion app/src/features/editor/hooks/useCompile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ function toResults(
return [
<div key={"bytecode"}>
<b>Bytecode</b>:<br />
<CopyableHex hex={prefixedBytecode} tooltip="bytecode" />
<CopyableHex hex={prefixedBytecode} slice={true} tooltip="bytecode" />
<br />
<br />
</div>,
<div key={"abi"}>
<b>ABI:</b>
<CopyableHex hex={abi} slice={false} tooltip="ABI" />
<br />
{abi}
</div>,
Expand Down
2 changes: 1 addition & 1 deletion app/src/features/interact/components/ContractInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function ContractInterface({
>
Contract Interface
</div>
<CopyableHex hex={contractId} tooltip="contract ID" />
<CopyableHex hex={contractId} slice={true} tooltip="contract ID" />
</div>

{functionInterfaces}
Expand Down