-
Notifications
You must be signed in to change notification settings - Fork 514
Updated transaction details to latest design. #638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,88 @@ | ||
| import { maxBlockWeight } from "../const"; | ||
|
|
||
| const GRID_LENGTH = 15; | ||
|
|
||
| const drawBlockGrid = (canvas, blockWeight) => { | ||
| if ( | ||
| typeof HTMLCanvasElement === "undefined" || | ||
| !(canvas instanceof HTMLCanvasElement) | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| const ctx = canvas.getContext("2d"); | ||
| const rect = canvas.getBoundingClientRect(); | ||
| const dpr = window.devicePixelRatio || 1; | ||
| const width = rect.width; | ||
| const height = rect.height; | ||
| const gap = 2; | ||
| const cellWidth = (width - gap * (GRID_LENGTH - 1)) / GRID_LENGTH; | ||
| const cellHeight = (height - gap * (GRID_LENGTH - 1)) / GRID_LENGTH; | ||
| const fillRatio = Number.isFinite(blockWeight) | ||
| ? Math.min(Math.max(blockWeight / maxBlockWeight, 0), 1) | ||
| : 0; | ||
| const filledCells = Math.round(fillRatio * GRID_LENGTH * GRID_LENGTH); | ||
| const styles = window.getComputedStyle(canvas); | ||
| const emptyColor = | ||
| styles.getPropertyValue("--block-grid-empty-color").trim() || "#141414"; | ||
| const filledColor = styles | ||
| .getPropertyValue("--block-grid-filled-color") | ||
| .trim() || "#FA8A00"; | ||
|
|
||
| canvas.width = Math.max(1, Math.round(width * dpr)); | ||
| canvas.height = Math.max(1, Math.round(height * dpr)); | ||
| ctx.setTransform(dpr, 0, 0, dpr, 0, 0); | ||
| ctx.clearRect(0, 0, width, height); | ||
|
|
||
| for (let index = 0; index < GRID_LENGTH * GRID_LENGTH; index += 1) { | ||
| const row = Math.floor(index / GRID_LENGTH); | ||
| const column = index % GRID_LENGTH; | ||
|
|
||
| ctx.fillStyle = index < filledCells ? filledColor : emptyColor; | ||
| ctx.fillRect( | ||
| column * (cellWidth + gap), | ||
| row * (cellHeight + gap), | ||
| cellWidth, | ||
| cellHeight, | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| const drawGrid = (vnode, blockWeight) => { | ||
| const draw = () => drawBlockGrid(vnode.elm, blockWeight); | ||
|
|
||
| if (typeof window !== "undefined" && window.requestAnimationFrame) { | ||
| window.requestAnimationFrame(draw); | ||
| return; | ||
| } | ||
|
|
||
| draw(); | ||
| }; | ||
|
|
||
| export const BlockGrid = ({ blockWeight } = {}) => { | ||
| const hasBlockWeight = Number.isFinite(blockWeight); | ||
| const percentage = hasBlockWeight | ||
| ? Math.min( | ||
| Math.max( | ||
| Math.round((blockWeight / maxBlockWeight) * 10_000) / 100, | ||
| 0, | ||
| ), | ||
| 100, | ||
| ) | ||
| : 0; | ||
|
|
||
| return ( | ||
| <div className="block-details-card-grid"> | ||
| <canvas | ||
| aria-label={ | ||
| hasBlockWeight | ||
| ? `Block is ${percentage}% full` | ||
| : "Block utilization unavailable" | ||
| } | ||
| role="img" | ||
| hook-insert={(vnode) => drawGrid(vnode, blockWeight)} | ||
| hook-postpatch={(_, vnode) => drawGrid(vnode, blockWeight)} | ||
| ></canvas> | ||
| </div> | ||
| ); | ||
| }; |
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,6 @@ | ||
| export const InfoStat = ({ title, value } = {}) => ( | ||
| <div className="info-stat"> | ||
| <div className="info-stat-title">{title}</div> | ||
| <div className="info-stat-value">{value}</div> | ||
| </div> | ||
| ); |
This file contains hidden or 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 hidden or 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,92 @@ | ||
| import { BlockGrid } from "../components/block-grid"; | ||
| import { InfoStat } from "../components/info-stat"; | ||
| import { ElapsedTime } from "../components/elapsed-time"; | ||
| import { | ||
| formatTime, | ||
| formatVMB, | ||
| getBlockPercentageUsed, | ||
| } from "./util"; | ||
|
|
||
| const formatInteger = (value) => | ||
| Number.isFinite(value) ? value.toLocaleString() : "N/A"; | ||
|
|
||
| const BlockDetailsCard = ({ className, block, confirmed }) => { | ||
| const percentage = block | ||
| ? Math.min(Math.max(getBlockPercentageUsed(block.weight), 0), 100) | ||
| : 0; | ||
|
|
||
| return ( | ||
| <span className={className}> | ||
| <div className="block-details-card-summary"> | ||
| <BlockGrid blockWeight={block && block.weight} /> | ||
|
|
||
| <div className="block-details-card-content"> | ||
| <div className="block-details-card-header"> | ||
| <p className="block-number"> | ||
| {block ? ( | ||
| <a href={`block/${block.id}`}> | ||
| #{block.height.toLocaleString()} | ||
| </a> | ||
| ) : ( | ||
| "-" | ||
| )} | ||
| </p> | ||
|
|
||
| <p | ||
| className="block-details-card-timestamp" | ||
| title={block ? formatTime(block.timestamp) : ""} | ||
| > | ||
| {block ? ( | ||
| <span> | ||
| <ElapsedTime timestamp={block.timestamp} /> ago | ||
| </span> | ||
| ) : ( | ||
| "Loading block..." | ||
| )} | ||
| </p> | ||
|
|
||
| {confirmed ? ( | ||
| <div className="confirmation-status-badge success"> | ||
| <p>Confirmed</p> | ||
| </div> | ||
| ) : null} | ||
| </div> | ||
|
|
||
| <div className="block-details-card-stats"> | ||
| <InfoStat | ||
| title="TRANSACTIONS" | ||
| value={block ? formatInteger(block.tx_count) : "N/A"} | ||
| /> | ||
| <InfoStat | ||
| title="SIZE" | ||
| value={block ? formatVMB(block.size, "MB") : "N/A"} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="block-details-card-progress"> | ||
| <div className="block-details-card-progress-header"> | ||
| <p>BLOCK FILLING</p> | ||
| <p className="usage-number"> | ||
| {block ? `${percentage}%` : "N/A"} | ||
| </p> | ||
| </div> | ||
|
|
||
| <div className="block-details-card-usage-bar"> | ||
| <div | ||
| className="block-details-card-usage-bar-fill" | ||
| style={{ | ||
| width: `${percentage}%`, | ||
| backgroundSize: percentage | ||
| ? `${10_000 / percentage}% 100%` | ||
| : "100% 100%", | ||
| }} | ||
| ></div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </span> | ||
| ); | ||
| }; | ||
|
|
||
| export default BlockDetailsCard; |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.