-
Notifications
You must be signed in to change notification settings - Fork 57
feat(walletui): rename accounts #1588
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
147 changes: 147 additions & 0 deletions
147
applications/tari_walletd/web_ui/src/components/AccountName.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,147 @@ | ||
| // Copyright 2025. 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 React, { useState } from "react"; | ||
| import { Box, TextField, IconButton } from "@mui/material"; | ||
| import { IoCheckmark, IoClose } from "react-icons/io5"; | ||
| import { ComponentAddress } from "@tari-project/typescript-bindings"; | ||
| import { useAccountsRename } from "../services/api/hooks/useAccounts"; | ||
| import { LuPencilLine } from "react-icons/lu"; | ||
| import { useTheme } from "@mui/material/styles"; | ||
|
|
||
| export interface AccountNameProps { | ||
| accountAddress: ComponentAddress; | ||
| currentName?: string | null; | ||
| showRenameButton?: boolean; | ||
| onRenameSuccess?: (newName: string) => void; | ||
| onRenameError?: (error: any) => void; | ||
| } | ||
|
|
||
| const AccountName: React.FC<AccountNameProps> = ({ | ||
| accountAddress, | ||
| currentName, | ||
| showRenameButton = true, | ||
| onRenameSuccess, | ||
| onRenameError, | ||
| }) => { | ||
| const [isEditingName, setIsEditingName] = useState(false); | ||
| const [newName, setNewName] = useState(""); | ||
|
|
||
| const renameAccountMutation = useAccountsRename(); | ||
|
|
||
| const theme = useTheme(); | ||
|
|
||
| const handleStartEdit = () => { | ||
| setIsEditingName(true); | ||
| setNewName(currentName || ""); | ||
| }; | ||
|
|
||
| const handleCancelEdit = () => { | ||
| setIsEditingName(false); | ||
| setNewName(""); | ||
| }; | ||
|
|
||
| const handleSaveRename = () => { | ||
| if (newName.trim() && newName !== currentName) { | ||
| renameAccountMutation.mutate( | ||
| { | ||
| account: accountAddress, | ||
| newName: newName.trim(), | ||
| }, | ||
| { | ||
| onSuccess: () => { | ||
| const trimmedName = newName.trim(); | ||
| setIsEditingName(false); | ||
| setNewName(""); | ||
| onRenameSuccess?.(trimmedName); | ||
| }, | ||
| onError: (error: any) => { | ||
| console.error("Error renaming account:", error); | ||
| onRenameError?.(error); | ||
| }, | ||
| }, | ||
| ); | ||
| } else { | ||
| handleCancelEdit(); | ||
| } | ||
| }; | ||
|
|
||
| const handleKeyPress = (event: React.KeyboardEvent) => { | ||
| if (event.key === "Enter") { | ||
| handleSaveRename(); | ||
| } else if (event.key === "Escape") { | ||
| handleCancelEdit(); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Box display="flex" alignItems="center" gap={1}> | ||
| {isEditingName ? ( | ||
| <TextField | ||
| value={newName} | ||
| onChange={(e) => setNewName(e.target.value)} | ||
| onKeyDown={handleKeyPress} | ||
| size="small" | ||
| autoFocus | ||
| disabled={renameAccountMutation.isPending} | ||
| placeholder="Account name" | ||
| /> | ||
| ) : ( | ||
| <span>{currentName || "<No Name>"}</span> | ||
| )} | ||
| {showRenameButton && ( | ||
| <> | ||
| {isEditingName ? ( | ||
| <Box display="flex" gap={0.5}> | ||
| <IconButton | ||
| size="small" | ||
| onClick={handleSaveRename} | ||
| disabled={renameAccountMutation.isPending} | ||
| title="Save" | ||
| > | ||
| <IoCheckmark /> | ||
| </IconButton> | ||
| <IconButton | ||
| size="small" | ||
| onClick={handleCancelEdit} | ||
| disabled={renameAccountMutation.isPending} | ||
| title="Cancel" | ||
| > | ||
| <IoClose /> | ||
| </IconButton> | ||
| </Box> | ||
| ) : ( | ||
| <IconButton size="small" onClick={handleStartEdit} title="Rename account"> | ||
| <LuPencilLine | ||
| style={{ | ||
| color: theme.palette.primary.main, | ||
| }} | ||
| /> | ||
| </IconButton> | ||
| )} | ||
| </> | ||
| )} | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default AccountName; |
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
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.
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.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Likely wrong imports from types-only package.
substateIdToString is a local util, not from @tari-project/typescript-bindings. Also verify decodeOotleAddressOrNull is coming from a runtime module.
Based on learnings
Suggested fix for substateIdToString:
🏁 Script executed:
Length of output: 18528
🏁 Script executed:
Length of output: 291
Correct imports in AccountDetails.tsx
📝 Committable suggestion
🤖 Prompt for AI Agents