-
Notifications
You must be signed in to change notification settings - Fork 57
feat!: adds payref to ootle address #1629
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
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
85 changes: 85 additions & 0 deletions
85
applications/tari_walletd/web_ui/src/components/TransactionsStatusChip.tsx
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,85 @@ | ||
| // Copyright 2022. The Tari Project | ||
| // | ||
| // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
| // following conditions are met: | ||
| // | ||
| // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
| // disclaimer. | ||
| // | ||
| // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the | ||
| // following disclaimer in the documentation and/or other materials provided with the distribution. | ||
| // | ||
| // 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote | ||
| // products derived from this software without specific prior written permission. | ||
| // | ||
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
| // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| import { Chip, Avatar } from "@mui/material"; | ||
| import { IoCheckmarkOutline, IoDiamondOutline, IoReload, IoHourglassOutline, IoCloseOutline } from "react-icons/io5"; | ||
| import { useTheme } from "@mui/material/styles"; | ||
| import type { TransactionStatus } from "@tari-project/typescript-bindings"; | ||
|
|
||
| interface StatusChipProps { | ||
| status: TransactionStatus; | ||
| showTitle?: boolean; | ||
| } | ||
|
|
||
| const colorList: Record<string, string> = { | ||
| Accepted: "#5F9C91", | ||
| Pending: "#ECA86A", | ||
| DryRun: "#318EFA", | ||
| New: "#9D5CF9", | ||
| Rejected: "#DB7E7E", | ||
| InvalidTransaction: "#DB7E7E", | ||
| OnlyFeeAccepted: "#FFA500", | ||
| }; | ||
|
|
||
| export default function TransactionsStatusChip({ status, showTitle = true }: StatusChipProps) { | ||
| const theme = useTheme(); | ||
|
|
||
| const iconList: Record<string, JSX.Element> = { | ||
| Accepted: <IoCheckmarkOutline style={{ height: 14, width: 14 }} color={theme.palette.background.paper} />, | ||
| Pending: <IoHourglassOutline style={{ height: 14, width: 14 }} color={theme.palette.background.paper} />, | ||
| DryRun: <IoReload style={{ height: 14, width: 14 }} color={theme.palette.background.paper} />, | ||
| New: <IoDiamondOutline style={{ height: 14, width: 14 }} color={theme.palette.background.paper} />, | ||
| Rejected: <IoCloseOutline style={{ height: 14, width: 14 }} color={theme.palette.background.paper} />, | ||
| InvalidTransaction: <IoCloseOutline style={{ height: 14, width: 14 }} color={theme.palette.background.paper} />, | ||
| OnlyFeeAccepted: ( | ||
| <> | ||
| <IoCheckmarkOutline style={{ height: 14, width: 14 }} color={theme.palette.background.paper} /> | ||
| <IoCloseOutline style={{ height: 14, width: 14 }} color={theme.palette.background.paper} /> | ||
| </> | ||
| ), | ||
| }; | ||
|
|
||
| let bgColor = colorList[status]; | ||
| let background = null; | ||
|
|
||
| if (status === "OnlyFeeAccepted") { | ||
| const leftColor = colorList["Accepted"]; | ||
| const rightColor = colorList["Rejected"]; | ||
| background = `linear-gradient(to right, ${leftColor} 50%, ${colorList["Rejected"]} 50%)`; | ||
| } | ||
|
|
||
| if (!showTitle) { | ||
| let leftColor = colorList["Accepted"]; | ||
| let rightColor = colorList["Rejected"]; | ||
|
|
||
| return <Avatar sx={{ bgcolor: bgColor, height: 22, width: 22 }}>{iconList[status]}</Avatar>; | ||
| } else { | ||
| return ( | ||
| <Chip | ||
| avatar={<Avatar sx={{ bgcolor: bgColor, background: background }}>{iconList[status]}</Avatar>} | ||
| label={status} | ||
| style={{ color: colorList[status], borderColor: colorList[status] }} | ||
| variant="outlined" | ||
| /> | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle potential None from
new_pay_ref_and_bytes_truncategracefully.The
expect()on line 1002 will panic ifnew_pay_ref_and_bytes_truncatereturnsNone. According to the implementation inmemo.rs, this function returnsNonewhen the pay_ref itself is too large to fit in a memo (exceedsMAX_BYTES_LENGTH - 1). This should be handled with a proper error instead of panicking.Apply this diff to handle the error gracefully:
📝 Committable suggestion
🤖 Prompt for AI Agents
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because payref has maximum of 64 bytes and the rest of truncated, returning None is not possible (or if it does, it's a bug)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 4948
@sdbondi You're absolutely correct! I've verified the implementation and your reasoning is sound:
PayRef::MAX_LEN= 64 bytes (enforced inPayRef::new_checked)Memo::MAX_BYTES_LENGTH= 253 bytesnew_pay_ref_and_bytes_truncateonly returnsNoneifpay_ref.len() > MAX_BYTES_LENGTH - 1(i.e., > 252 bytes)64 < 252, a validPayRefwill never cause this function to returnNoneThe
expect()is safe here because the payref is validated during address decoding, ensuring it never exceeds 64 bytes. The message portion is truncated as needed to fit in the remaining space (253 - 1 byte length prefix - payref length).The only minor note is that the expect message "payref + truncated message fits in memo" is slightly imprecise—it's really about the payref size being valid, but that's a trivial naming detail. The logic is correct.
🧬 Code Graph Analysis Results
[relevant_code_snippets]
File: crates/wallet/crypto/src/memo.rs
Lines: 81-91
Content:
File: bindings/src/types/wallet-daemon-client/TransferOutput.ts
Lines: 6-24
Content:
File: bindings/src/types/wallet-daemon-client/Memo.ts
Lines: 3-3
Content:
✏️ Learnings added