Skip to content

Commit cba65cf

Browse files
committed
merging #163 changes into release branch
1 parent 385e45d commit cba65cf

File tree

5 files changed

+84
-6
lines changed

5 files changed

+84
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ deps
77
.DS_Store
88
.tools/
99
obj
10+
.idea/

src/extension/panelControllers/contractPanelController.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ContractViewRequest from "../../shared/messages/contractViewRequest";
55
import ContractViewState from "../../shared/viewState/contractViewState";
66
import Log from "../util/log";
77
import PanelControllerBase from "./panelControllerBase";
8+
import { reverseHex } from "@cityofzion/neon-core/lib/u";
89

910
const LOG_PREFIX = "ContractPanelController";
1011

@@ -38,9 +39,13 @@ export default class ContractPanelController extends PanelControllerBase<
3839
protected async onRequest(request: ContractViewRequest) {
3940
Log.log(LOG_PREFIX, "Request:", request);
4041
if (request.copyHash) {
41-
await vscode.env.clipboard.writeText(this.contractHash);
42+
let scriptHash = this.contractHash;
43+
if (request.reverse) {
44+
scriptHash = `0x${reverseHex(scriptHash.substring(2))}`;
45+
}
46+
await vscode.env.clipboard.writeText(scriptHash);
4247
vscode.window.showInformationMessage(
43-
`Contract hash copied to clipboard: ${this.contractHash}`
48+
`Contract hash copied to clipboard: ${scriptHash}`
4449
);
4550
}
4651
}

src/panel/components/Hash.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
import { reverseHex } from "@cityofzion/neon-core/lib/u";
12
import React from "react";
23

34
type Props = {
45
hash: string;
6+
reverse?: boolean;
57
};
68

7-
export default function Hash({ hash }: Props) {
9+
export default function Hash({ hash, reverse }: Props) {
810
return (
911
<span
1012
style={{
1113
fontFamily: "monospace",
1214
wordBreak: "break-all",
1315
}}
1416
>
15-
{hash}
17+
{ (!reverse) ? hash : `0x${reverseHex(hash.substring(2))}`}
1618
</span>
1719
);
1820
}

src/panel/components/views/Contract.tsx

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { CSSProperties } from "react";
22

33
import ContractViewState from "../../../shared/viewState/contractViewState";
44
import ContractViewRequest from "../../../shared/messages/contractViewRequest";
@@ -23,6 +23,47 @@ export default function Contract({ viewState, postMessage }: Props) {
2323
viewState.autoCompleteData.contractPaths[hash] ||
2424
viewState.autoCompleteData.contractPaths[name] ||
2525
[];
26+
27+
const [hovering, setHovering] = React.useState(false);
28+
29+
const tooltipStyle: CSSProperties = {
30+
visibility: hovering ? "visible" : "hidden",
31+
minWidth: "300px", // adjust this value as needed or keep as 'auto'
32+
maxWidth: "600px", // prevent the tooltip from becoming too wide
33+
backgroundColor: "#555",
34+
color: "#fff",
35+
textAlign: "center",
36+
borderRadius: "6px",
37+
padding: "5px",
38+
39+
/* Position the tooltip */
40+
position: "absolute",
41+
zIndex: 1,
42+
bottom: "150%" /* Place tooltip above the element */,
43+
left: "50%",
44+
transform: "translateX(-30%)", // Use transform to center the tooltip
45+
46+
opacity: hovering ? 1 : 0,
47+
transition: "opacity 0.3s",
48+
};
49+
50+
const iconStyle: CSSProperties = {
51+
position: "relative",
52+
display: "inline-flex",
53+
justifyContent: "center",
54+
alignItems: "center",
55+
width: "15px",
56+
height: "15px",
57+
cursor: "pointer",
58+
fontSize: "12px",
59+
fontWeight: "bold",
60+
borderRadius: "50%",
61+
backgroundColor: hovering ? "grey" : "white",
62+
color: "black",
63+
transition: "background-color 0.3s",
64+
marginLeft: "5px",
65+
};
66+
2667
return (
2768
<div style={{ padding: 10 }}>
2869
<h1>{name}</h1>
@@ -57,6 +98,32 @@ export default function Contract({ viewState, postMessage }: Props) {
5798
<em> &mdash; click to copy contract hash to clipboard</em>
5899
</div>
59100
</p>
101+
<p style={{ paddingLeft: 20 }}>
102+
<div style={{ fontWeight: "bold", marginBottom: 10, marginTop: 15 }}>
103+
<span>Hash (reversed):</span>
104+
<span
105+
style={iconStyle}
106+
onMouseEnter={() => setHovering(true)}
107+
onMouseLeave={() => setHovering(false)}
108+
>
109+
?
110+
<span style={tooltipStyle}>
111+
Various tools in the Neo N3 ecosystem expect different byte order
112+
for contract hash strings. Please check the byte order expected by
113+
the tools you are using.
114+
</span>
115+
</span>
116+
</div>
117+
<div
118+
style={{ cursor: "pointer", paddingLeft: 20 }}
119+
onClick={() => postMessage({ copyHash: true, reverse: true })}
120+
>
121+
<strong>
122+
<Hash hash={hash} reverse={true} />
123+
</strong>{" "}
124+
<em> &mdash; click to copy contract hash to clipboard</em>
125+
</div>
126+
</p>
60127
{!!supportedStandards.length && (
61128
<p style={{ paddingLeft: 20 }}>
62129
<div style={{ fontWeight: "bold", marginBottom: 10, marginTop: 15 }}>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
type ContractViewRequest = { copyHash?: boolean };
1+
type ContractViewRequest = {
2+
copyHash?: boolean,
3+
reverse?: boolean
4+
};
25

36
export default ContractViewRequest;

0 commit comments

Comments
 (0)