This repository has been archived by the owner on Feb 15, 2025. It is now read-only.
forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
explorer: Pretty print instruction data hex strings (solana-labs#19813)
- Loading branch information
Showing
4 changed files
with
49 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { ReactNode } from "react"; | ||
import { Buffer } from "buffer"; | ||
import { Copyable } from "./Copyable"; | ||
|
||
export function HexData({ raw }: { raw: Buffer }) { | ||
if (!raw) { | ||
return <span>No data</span>; | ||
} | ||
|
||
const chunks = []; | ||
const hexString = raw.toString("hex"); | ||
for (let i = 0; i < hexString.length; i += 2) { | ||
chunks.push(hexString.slice(i, i + 2)); | ||
} | ||
|
||
const spans: ReactNode[] = []; | ||
for (let i = 0; i < chunks.length; i += 4) { | ||
const color = i % 8 === 0 ? "text-white" : "text-gray-500"; | ||
spans.push( | ||
<span key={i} className={color}> | ||
{chunks.slice(i, i + 4).join(" ")}  | ||
</span> | ||
); | ||
} | ||
|
||
function Content() { | ||
return ( | ||
<Copyable text={hexString}> | ||
<pre className="d-inline-block text-left mb-0 data-wrap">{spans}</pre> | ||
</Copyable> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="d-none d-lg-flex align-items-center justify-content-end"> | ||
<Content /> | ||
</div> | ||
<div className="d-flex d-lg-none align-items-center"> | ||
<Content /> | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters