Skip to content

Commit

Permalink
merging #163 changes into release branch
Browse files Browse the repository at this point in the history
  • Loading branch information
devhawk committed Jun 12, 2023
1 parent 385e45d commit cba65cf
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ deps
.DS_Store
.tools/
obj
.idea/
9 changes: 7 additions & 2 deletions src/extension/panelControllers/contractPanelController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ContractViewRequest from "../../shared/messages/contractViewRequest";
import ContractViewState from "../../shared/viewState/contractViewState";
import Log from "../util/log";
import PanelControllerBase from "./panelControllerBase";
import { reverseHex } from "@cityofzion/neon-core/lib/u";

const LOG_PREFIX = "ContractPanelController";

Expand Down Expand Up @@ -38,9 +39,13 @@ export default class ContractPanelController extends PanelControllerBase<
protected async onRequest(request: ContractViewRequest) {
Log.log(LOG_PREFIX, "Request:", request);
if (request.copyHash) {
await vscode.env.clipboard.writeText(this.contractHash);
let scriptHash = this.contractHash;
if (request.reverse) {
scriptHash = `0x${reverseHex(scriptHash.substring(2))}`;
}
await vscode.env.clipboard.writeText(scriptHash);
vscode.window.showInformationMessage(
`Contract hash copied to clipboard: ${this.contractHash}`
`Contract hash copied to clipboard: ${scriptHash}`
);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/panel/components/Hash.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { reverseHex } from "@cityofzion/neon-core/lib/u";
import React from "react";

type Props = {
hash: string;
reverse?: boolean;
};

export default function Hash({ hash }: Props) {
export default function Hash({ hash, reverse }: Props) {
return (
<span
style={{
fontFamily: "monospace",
wordBreak: "break-all",
}}
>
{hash}
{ (!reverse) ? hash : `0x${reverseHex(hash.substring(2))}`}
</span>
);
}
69 changes: 68 additions & 1 deletion src/panel/components/views/Contract.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { CSSProperties } from "react";

import ContractViewState from "../../../shared/viewState/contractViewState";
import ContractViewRequest from "../../../shared/messages/contractViewRequest";
Expand All @@ -23,6 +23,47 @@ export default function Contract({ viewState, postMessage }: Props) {
viewState.autoCompleteData.contractPaths[hash] ||
viewState.autoCompleteData.contractPaths[name] ||
[];

const [hovering, setHovering] = React.useState(false);

const tooltipStyle: CSSProperties = {
visibility: hovering ? "visible" : "hidden",
minWidth: "300px", // adjust this value as needed or keep as 'auto'
maxWidth: "600px", // prevent the tooltip from becoming too wide
backgroundColor: "#555",
color: "#fff",
textAlign: "center",
borderRadius: "6px",
padding: "5px",

/* Position the tooltip */
position: "absolute",
zIndex: 1,
bottom: "150%" /* Place tooltip above the element */,
left: "50%",
transform: "translateX(-30%)", // Use transform to center the tooltip

opacity: hovering ? 1 : 0,
transition: "opacity 0.3s",
};

const iconStyle: CSSProperties = {
position: "relative",
display: "inline-flex",
justifyContent: "center",
alignItems: "center",
width: "15px",
height: "15px",
cursor: "pointer",
fontSize: "12px",
fontWeight: "bold",
borderRadius: "50%",
backgroundColor: hovering ? "grey" : "white",
color: "black",
transition: "background-color 0.3s",
marginLeft: "5px",
};

return (
<div style={{ padding: 10 }}>
<h1>{name}</h1>
Expand Down Expand Up @@ -57,6 +98,32 @@ export default function Contract({ viewState, postMessage }: Props) {
<em> &mdash; click to copy contract hash to clipboard</em>
</div>
</p>
<p style={{ paddingLeft: 20 }}>
<div style={{ fontWeight: "bold", marginBottom: 10, marginTop: 15 }}>
<span>Hash (reversed):</span>
<span
style={iconStyle}
onMouseEnter={() => setHovering(true)}
onMouseLeave={() => setHovering(false)}
>
?
<span style={tooltipStyle}>
Various tools in the Neo N3 ecosystem expect different byte order
for contract hash strings. Please check the byte order expected by
the tools you are using.
</span>
</span>
</div>
<div
style={{ cursor: "pointer", paddingLeft: 20 }}
onClick={() => postMessage({ copyHash: true, reverse: true })}
>
<strong>
<Hash hash={hash} reverse={true} />
</strong>{" "}
<em> &mdash; click to copy contract hash to clipboard</em>
</div>
</p>
{!!supportedStandards.length && (
<p style={{ paddingLeft: 20 }}>
<div style={{ fontWeight: "bold", marginBottom: 10, marginTop: 15 }}>
Expand Down
5 changes: 4 additions & 1 deletion src/shared/messages/contractViewRequest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
type ContractViewRequest = { copyHash?: boolean };
type ContractViewRequest = {
copyHash?: boolean,
reverse?: boolean
};

export default ContractViewRequest;

0 comments on commit cba65cf

Please sign in to comment.