-
Notifications
You must be signed in to change notification settings - Fork 472
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
[Seedless-Onboarding] export account #2610
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
118af61
feat: signer account page to enable MFA, deviceFactor recovery on login"
schmanu fc4995f
feat: export account key
schmanu ef1baed
Merge branch 'web3authcoresdk' into seedless-export-pk
schmanu 339e8ae
fix: small tweaks
schmanu f4b6615
fix: review issues
schmanu 0eb4d19
fix: update sdk
schmanu 6c59117
feat: check recovery password before exporting account
schmanu 09a1626
fix: export account key in modal dialog
schmanu 8d0fa0c
fix: review issues, error handling
schmanu b55ea55
Merge remote-tracking branch 'origin/web3authcoresdk' into seedless-e…
schmanu f68667b
fix: margins in account export section
schmanu 2dfe922
fix: margin in modal
schmanu ad3e34f
fix: review issues
schmanu 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 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
127 changes: 127 additions & 0 deletions
127
src/components/settings/ExportMPCAccount/ExportMPCAccountModal.tsx
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,127 @@ | ||
import { MpcWalletContext } from '@/components/common/ConnectWallet/MPCWalletProvider' | ||
import CopyButton from '@/components/common/CopyButton' | ||
import ModalDialog from '@/components/common/ModalDialog' | ||
import { Box, Button, DialogContent, DialogTitle, IconButton, TextField, Typography } from '@mui/material' | ||
import { useContext, useState } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import { Visibility, VisibilityOff, Close } from '@mui/icons-material' | ||
import css from './styles.module.css' | ||
import ErrorCodes from '@/services/exceptions/ErrorCodes' | ||
import { logError } from '@/services/exceptions' | ||
import ErrorMessage from '@/components/tx/ErrorMessage' | ||
import { asError } from '@/services/exceptions/utils' | ||
|
||
enum ExportFieldNames { | ||
password = 'password', | ||
pk = 'pk', | ||
} | ||
|
||
type ExportFormData = { | ||
[ExportFieldNames.password]: string | ||
[ExportFieldNames.pk]: string | undefined | ||
} | ||
|
||
const ExportMPCAccountModal = ({ onClose, open }: { onClose: () => void; open: boolean }) => { | ||
const { exportPk } = useContext(MpcWalletContext) | ||
const [error, setError] = useState<string>() | ||
|
||
const [showPassword, setShowPassword] = useState(false) | ||
const formMethods = useForm<ExportFormData>({ | ||
mode: 'all', | ||
defaultValues: { | ||
[ExportFieldNames.password]: '', | ||
}, | ||
}) | ||
const { register, formState, handleSubmit, setValue, watch, reset } = formMethods | ||
|
||
const exportedKey = watch(ExportFieldNames.pk) | ||
|
||
const onSubmit = async (data: ExportFormData) => { | ||
try { | ||
setError(undefined) | ||
const pk = await exportPk(data[ExportFieldNames.password]) | ||
setValue(ExportFieldNames.pk, pk) | ||
} catch (err) { | ||
logError(ErrorCodes._305, err) | ||
setError(asError(err).message) | ||
} | ||
} | ||
|
||
const handleClose = () => { | ||
setError(undefined) | ||
reset() | ||
onClose() | ||
} | ||
return ( | ||
<ModalDialog open={open} onClose={handleClose}> | ||
<DialogTitle> | ||
<Typography variant="h6" fontWeight={700}> | ||
Export your account | ||
</Typography> | ||
</DialogTitle> | ||
<IconButton className={css.close} aria-label="close" onClick={handleClose} size="small"> | ||
<Close fontSize="large" /> | ||
</IconButton> | ||
|
||
<DialogContent> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<Box display="flex" flexDirection="column" gap={2} alignItems="flex-start" sx={{ width: '100%' }}> | ||
<Typography>For security reasons you have to enter your password to reveal your account key.</Typography> | ||
|
||
{exportedKey ? ( | ||
<Box display="flex" flexDirection="row" alignItems="center" gap={1} width="100%"> | ||
<TextField | ||
fullWidth | ||
multiline={showPassword} | ||
maxRows={3} | ||
label="Private key" | ||
type="password" | ||
InputProps={{ | ||
readOnly: true, | ||
endAdornment: ( | ||
<> | ||
<IconButton size="small" onClick={() => setShowPassword((prev) => !prev)}> | ||
{showPassword ? <VisibilityOff fontSize="small" /> : <Visibility fontSize="small" />} | ||
</IconButton> | ||
<CopyButton text={exportedKey} /> | ||
</> | ||
), | ||
}} | ||
{...register(ExportFieldNames.pk)} | ||
/> | ||
</Box> | ||
) : ( | ||
<> | ||
<TextField | ||
placeholder="Password" | ||
label="Password" | ||
type="password" | ||
fullWidth | ||
error={!!formState.errors[ExportFieldNames.password]} | ||
helperText={formState.errors[ExportFieldNames.password]?.message} | ||
{...register(ExportFieldNames.password, { | ||
required: true, | ||
})} | ||
/> | ||
</> | ||
)} | ||
{error && <ErrorMessage className={css.modalError}>{error}</ErrorMessage>} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the |
||
|
||
<Box display="flex" flexDirection="row" justifyContent="space-between" alignItems="center" width="100%"> | ||
<Button variant="outlined" onClick={handleClose}> | ||
Close | ||
</Button> | ||
{exportedKey === undefined && ( | ||
<Button color="primary" variant="contained" disabled={formState.isSubmitting} type="submit"> | ||
Export | ||
</Button> | ||
)} | ||
</Box> | ||
</Box> | ||
</form> | ||
</DialogContent> | ||
</ModalDialog> | ||
) | ||
} | ||
|
||
export default ExportMPCAccountModal |
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,27 @@ | ||
import { Alert, Box, Button, Typography } from '@mui/material' | ||
import { useState } from 'react' | ||
import ExportMPCAccountModal from './ExportMPCAccountModal' | ||
|
||
const ExportMPCAccount = () => { | ||
const [isModalOpen, setIsModalOpen] = useState(false) | ||
|
||
return ( | ||
<> | ||
<Box display="flex" flexDirection="column" gap={2} alignItems="flex-start"> | ||
<Typography> | ||
Accounts created via Google can be exported and imported to any non-custodial wallet outside of Safe. | ||
</Typography> | ||
<Alert severity="warning"> | ||
Never disclose your keys or seed phrase to anyone. If someone gains access to them, they have full access over | ||
your signer account. | ||
</Alert> | ||
<Button color="primary" variant="contained" disabled={isModalOpen} onClick={() => setIsModalOpen(true)}> | ||
Reveal private key | ||
</Button> | ||
</Box> | ||
<ExportMPCAccountModal onClose={() => setIsModalOpen(false)} open={isModalOpen} /> | ||
</> | ||
) | ||
} | ||
|
||
export default ExportMPCAccount |
10 changes: 10 additions & 0 deletions
10
src/components/settings/ExportMPCAccount/styles.module.css
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,10 @@ | ||
.close { | ||
position: absolute; | ||
right: var(--space-1); | ||
top: var(--space-1); | ||
} | ||
|
||
.modalError { | ||
width: 100%; | ||
margin: 0; | ||
} |
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
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
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.
nit: Just found out we can even use RHF to display an error separate from its input https://react-hook-form.com/docs/useformstate/errormessage
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.
Although on second thought if we set the error via RHF it will not be persisted afair so this is probably better.