forked from comit-network/xmr-btc-swap
-
Notifications
You must be signed in to change notification settings - Fork 82
feat(gui): wallet setup wizard, named wallets, and wallet switcher #1148
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
Open
binarybaron
wants to merge
7
commits into
master
Choose a base branch
from
feat/wallet-setup-wizard
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3584b48
feat(gui): wallet setup wizard, named wallets, and wallet switcher
486eace
refactor(gui,swap): review fixes for wallet wizard and switcher
271d058
refactor: trim wallet switcher and pending-wallet restart logic
99882c5
refactor: remove seed phrase autocompletion
3100afd
refactor(swap): drive wallet setup with a Rust state machine
83997da
feat(gui): ask for wallet name before password when creating
9059f90
fix(gui): backup confirmation checkbox kept unchecking itself
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
48 changes: 48 additions & 0 deletions
48
src-gui/src/renderer/components/modal/seed-selection/BackupSeedStep.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,48 @@ | ||
| import { Box, Checkbox, FormControlLabel, Typography } from "@mui/material"; | ||
| import ActionableMonospaceTextBox from "renderer/components/other/ActionableMonospaceTextBox"; | ||
| import { PrivateKeyScamAlert } from "renderer/components/other/PrivateKeyWarning"; | ||
|
|
||
| /// Shown while the backend blocks startup on its SeedBackup approval: the | ||
| /// freshly created wallet's seed is displayed once so the user records it | ||
| /// before continuing. | ||
| export default function BackupSeedStep({ | ||
| seed, | ||
| restoreHeight, | ||
| confirmed, | ||
| onConfirmedChange, | ||
| }: { | ||
| seed: string; | ||
| restoreHeight: number; | ||
| confirmed: boolean; | ||
| onConfirmedChange: (confirmed: boolean) => void; | ||
| }) { | ||
| return ( | ||
| <Box sx={{ display: "flex", flexDirection: "column", gap: 2 }}> | ||
| <PrivateKeyScamAlert /> | ||
| <Typography variant="body2" color="text.secondary"> | ||
| Write down your seed phrase and restore height. They are the only way to | ||
| recover this wallet if you lose access to this device. | ||
| </Typography> | ||
| <ActionableMonospaceTextBox | ||
| content={seed} | ||
| displayCopyIcon={true} | ||
| enableQrCode={false} | ||
| spoilerText="Press to reveal" | ||
| /> | ||
| <ActionableMonospaceTextBox | ||
| content={restoreHeight.toString()} | ||
| displayCopyIcon={true} | ||
| enableQrCode={false} | ||
| /> | ||
| <FormControlLabel | ||
| control={ | ||
| <Checkbox | ||
| checked={confirmed} | ||
| onChange={(e) => onConfirmedChange(e.target.checked)} | ||
| /> | ||
| } | ||
| label="I have written down my seed phrase and restore height" | ||
| /> | ||
| </Box> | ||
| ); | ||
| } |
62 changes: 62 additions & 0 deletions
62
src-gui/src/renderer/components/modal/seed-selection/NameLocationStep.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,62 @@ | ||
| import { Box, TextField, Typography } from "@mui/material"; | ||
| import { open } from "@tauri-apps/plugin-dialog"; | ||
| import SearchIcon from "@mui/icons-material/Search"; | ||
| import PromiseInvokeButton from "renderer/components/PromiseInvokeButton"; | ||
|
|
||
| export default function NameLocationStep({ | ||
| name, | ||
| setName, | ||
| directory, | ||
| setDirectory, | ||
| }: { | ||
| name: string; | ||
| setName: (name: string) => void; | ||
| directory: string; | ||
| setDirectory: (directory: string) => void; | ||
| }) { | ||
| const selectDirectory = async () => { | ||
| const selected = await open({ multiple: false, directory: true }); | ||
| if (selected) setDirectory(selected); | ||
| }; | ||
|
|
||
| return ( | ||
| <Box sx={{ display: "flex", flexDirection: "column", gap: 1 }}> | ||
| <Typography variant="body2" color="text.secondary"> | ||
| Choose a name for the wallet file and where to store it on this device. | ||
| </Typography> | ||
| <TextField | ||
| fullWidth | ||
| autoFocus | ||
| label="Wallet name" | ||
| value={name} | ||
| onChange={(e) => setName(e.target.value)} | ||
| placeholder="my-wallet" | ||
| error={name.length > 0 && name.trim().length === 0} | ||
| helperText={ | ||
| name.length > 0 && name.trim().length === 0 | ||
| ? "Enter a wallet name" | ||
| : "" | ||
| } | ||
| /> | ||
| <Box sx={{ display: "flex", gap: 1, alignItems: "center" }}> | ||
| <TextField | ||
| fullWidth | ||
| label="Save location" | ||
| value={directory} | ||
| placeholder="Select a folder..." | ||
| InputProps={{ readOnly: true }} | ||
| /> | ||
| <PromiseInvokeButton | ||
| variant="outlined" | ||
| onInvoke={selectDirectory} | ||
| contextRequirement={false} | ||
| displayErrorSnackbar | ||
| sx={{ minWidth: "120px", height: "56px" }} | ||
| startIcon={<SearchIcon />} | ||
| > | ||
| Browse | ||
| </PromiseInvokeButton> | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| } |
156 changes: 156 additions & 0 deletions
156
src-gui/src/renderer/components/modal/seed-selection/OpenWalletStep.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,156 @@ | ||
| import { | ||
| Box, | ||
| Divider, | ||
| List, | ||
| ListItem, | ||
| ListItemButton, | ||
| ListItemText, | ||
| Typography, | ||
| } from "@mui/material"; | ||
| import { useEffect, useState } from "react"; | ||
| import { open } from "@tauri-apps/plugin-dialog"; | ||
| import { getCurrentWebview } from "@tauri-apps/api/webview"; | ||
| import FolderOpenIcon from "@mui/icons-material/FolderOpen"; | ||
|
|
||
| export default function OpenWalletStep({ | ||
| walletPath, | ||
| setWalletPath, | ||
| recentWallets, | ||
| }: { | ||
| walletPath: string; | ||
| setWalletPath: (path: string) => void; | ||
| recentWallets: string[]; | ||
| }) { | ||
| const [isDragging, setIsDragging] = useState(false); | ||
|
|
||
| // Tauri delivers dropped file paths through the webview drag-drop event | ||
| // rather than the DOM, so we subscribe to it while this step is mounted. | ||
| useEffect(() => { | ||
| let active = true; | ||
| let unlisten: (() => void) | undefined; | ||
|
|
||
| getCurrentWebview() | ||
| .onDragDropEvent((event) => { | ||
| if (event.payload.type === "drop") { | ||
| setIsDragging(false); | ||
| const path = event.payload.paths[0]; | ||
| // Users commonly pick the `<name>.keys` file; the wallet is the | ||
| // file without that extension. | ||
| if (path) setWalletPath(path.replace(/\.keys$/, "")); | ||
| } else if (event.payload.type === "leave") { | ||
| setIsDragging(false); | ||
| } else { | ||
| setIsDragging(true); | ||
| } | ||
| }) | ||
| .then((fn) => { | ||
| if (active) unlisten = fn; | ||
| else fn(); | ||
| }); | ||
|
|
||
| return () => { | ||
| active = false; | ||
| unlisten?.(); | ||
| }; | ||
| }, [setWalletPath]); | ||
|
|
||
| const selectWalletFile = async () => { | ||
| const selected = await open({ multiple: false, directory: false }); | ||
| if (selected) setWalletPath(selected.replace(/\.keys$/, "")); | ||
| }; | ||
|
|
||
| return ( | ||
| <Box sx={{ gap: 2, display: "flex", flexDirection: "column" }}> | ||
| <Box | ||
| onClick={selectWalletFile} | ||
| sx={{ | ||
| display: "flex", | ||
| flexDirection: "column", | ||
| alignItems: "center", | ||
| justifyContent: "center", | ||
| gap: 1, | ||
| py: 4, | ||
| px: 2, | ||
| cursor: "pointer", | ||
| borderRadius: 2, | ||
| border: "2px dashed", | ||
| borderColor: isDragging ? "primary.main" : "divider", | ||
| backgroundColor: isDragging ? "action.hover" : "transparent", | ||
| transition: "border-color 0.15s, background-color 0.15s", | ||
| "&:hover": { borderColor: "primary.main" }, | ||
| }} | ||
| > | ||
| <FolderOpenIcon sx={{ fontSize: 40, color: "text.secondary" }} /> | ||
| <Typography variant="body2" color="text.secondary"> | ||
| Drag a wallet file here, or click to browse | ||
| </Typography> | ||
| </Box> | ||
|
|
||
| {recentWallets.length > 0 && ( | ||
| <Box | ||
| sx={{ | ||
| border: 1, | ||
| borderColor: "divider", | ||
| borderRadius: 1, | ||
| maxHeight: 200, | ||
| overflowY: "scroll", | ||
| "&::-webkit-scrollbar": { | ||
| display: "block !important", | ||
| width: "8px !important", | ||
| }, | ||
| "&::-webkit-scrollbar-track": { | ||
| display: "block !important", | ||
| background: "rgba(255,255,255,.1) !important", | ||
| borderRadius: "4px", | ||
| }, | ||
| "&::-webkit-scrollbar-thumb": { | ||
| display: "block !important", | ||
| background: "rgba(255,255,255,.6) !important", | ||
| borderRadius: "4px", | ||
| minHeight: "20px !important", | ||
| }, | ||
| "&::-webkit-scrollbar-thumb:hover": { | ||
| background: "rgba(255,255,255,.8) !important", | ||
| }, | ||
| "&::-webkit-scrollbar-corner": { | ||
| background: "transparent !important", | ||
| }, | ||
| scrollbarWidth: "thin", | ||
| scrollbarColor: "rgba(255,255,255,.6) rgba(255,255,255,.1)", | ||
| }} | ||
| > | ||
| <List disablePadding> | ||
| {recentWallets.map((path, index) => ( | ||
| <Box key={path}> | ||
| <ListItem disablePadding> | ||
| <ListItemButton | ||
| selected={walletPath === path} | ||
| onClick={() => setWalletPath(path)} | ||
| > | ||
| <ListItemText | ||
| primary={path.split(/[/\\]/).pop() || path} | ||
| secondary={path} | ||
| primaryTypographyProps={{ | ||
| fontWeight: walletPath === path ? 600 : 400, | ||
| fontSize: "0.9rem", | ||
| }} | ||
| secondaryTypographyProps={{ | ||
| fontSize: "0.75rem", | ||
| sx: { | ||
| overflow: "hidden", | ||
| textOverflow: "ellipsis", | ||
| whiteSpace: "nowrap", | ||
| }, | ||
| }} | ||
| /> | ||
| </ListItemButton> | ||
| </ListItem> | ||
| {index < recentWallets.length - 1 && <Divider />} | ||
| </Box> | ||
| ))} | ||
| </List> | ||
| </Box> | ||
| )} | ||
| </Box> | ||
| ); | ||
| } | ||
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.
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.
Keys suffix strips wallet basename
Medium Severity
Drag-and-drop and the file picker always remove a trailing
.keysfrom the chosen path. That is correct when the user selects the keys sidecar, but if the wallet’s on-disk name itself ends with.keys(allowed by the name step), selecting the main wallet file strips that suffix and sends the wrongwallet_pathto open.Additional Locations (1)
src-gui/src/renderer/components/modal/seed-selection/OpenWalletStep.tsx#L58-L59Reviewed by Cursor Bugbot for commit 99882c5. Configure here.