-
Notifications
You must be signed in to change notification settings - Fork 87
feat: Ability to display/export the private key #3290
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
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f7e99b8
feat: Ability to display/export the private key
devchenyan 6ccc0f0
feat: test
devchenyan ea6b9a7
fix: comment
devchenyan 691b194
fix: check
devchenyan 2f12303
fix: test
devchenyan 2e55f73
fix: test
devchenyan f1d2f75
fix: check
devchenyan 2da3fb3
fix: check
devchenyan 68d2c2c
fix: comment
devchenyan 63d00ed
fix: comment
devchenyan 506c144
Merge branch 'develop' into feat-424
devchenyan 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
145 changes: 145 additions & 0 deletions
145
packages/neuron-ui/src/components/ViewPrivateKey/index.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,145 @@ | ||
| import React, { useCallback, useEffect, useState } from 'react' | ||
| import { useTranslation } from 'react-i18next' | ||
| import { useState as useGlobalState } from 'states' | ||
| import Dialog from 'widgets/Dialog' | ||
| import TextField from 'widgets/TextField' | ||
| import Alert from 'widgets/Alert' | ||
| import { errorFormatter, useCopy, isSuccessResponse } from 'utils' | ||
| import { Attention, Copy } from 'widgets/Icons/icon' | ||
| import { getPrivateKeyByAddress } from 'services/remote' | ||
| import styles from './viewPrivateKey.module.scss' | ||
|
|
||
| const ViewPrivateKey = ({ onClose, address }: { onClose?: () => void; address?: string }) => { | ||
| const [t] = useTranslation() | ||
| const [password, setPassword] = useState('') | ||
| const [error, setError] = useState('') | ||
| const [privateKey, setPrivateKey] = useState('') | ||
| const [isLoading, setIsLoading] = useState(false) | ||
| const { copied, onCopy, copyTimes } = useCopy() | ||
| const { | ||
| wallet: { id: walletID = '' }, | ||
| } = useGlobalState() | ||
|
|
||
| useEffect(() => { | ||
| setPassword('') | ||
| setError('') | ||
| }, [setError, setPassword]) | ||
|
|
||
| const onChange = useCallback( | ||
| (e: React.SyntheticEvent<HTMLInputElement>) => { | ||
| const { value } = e.target as HTMLInputElement | ||
| setPassword(value) | ||
| setError('') | ||
| }, | ||
| [setPassword, setError] | ||
| ) | ||
|
|
||
| const onSubmit = useCallback( | ||
| async (e?: React.FormEvent) => { | ||
| if (e) { | ||
| e.preventDefault() | ||
| } | ||
| if (!password) { | ||
| return | ||
| } | ||
| setIsLoading(true) | ||
| try { | ||
| const res = await getPrivateKeyByAddress({ | ||
| walletID, | ||
| address, | ||
| password, | ||
| }) | ||
|
|
||
| setIsLoading(false) | ||
|
|
||
| if (!isSuccessResponse(res)) { | ||
| setError(errorFormatter(res.message, t)) | ||
| return | ||
| } | ||
| setPrivateKey(res.result) | ||
| } catch (err) { | ||
| setIsLoading(false) | ||
yanguoyu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }, | ||
| [walletID, password, setError, t] | ||
| ) | ||
|
|
||
| if (privateKey) { | ||
| return ( | ||
| <Dialog | ||
| show | ||
| title={t('addresses.view-private-key')} | ||
| onConfirm={onClose} | ||
| onCancel={onClose} | ||
| showCancel={false} | ||
| confirmText={t('common.close')} | ||
| className={styles.dialog} | ||
| > | ||
| <div> | ||
| <div className={styles.tip}> | ||
| <Attention /> | ||
| {t('addresses.view-private-key-tip')} | ||
| </div> | ||
|
|
||
| <TextField | ||
| className={styles.passwordInput} | ||
| placeholder={t('password-request.placeholder')} | ||
| width="100%" | ||
| label={<span className={styles.label}>{t('addresses.private-key')}</span>} | ||
| value={privateKey} | ||
| field="password" | ||
| type="password" | ||
| disabled | ||
| suffix={ | ||
| <div className={styles.copy}> | ||
| <Copy onClick={() => onCopy(privateKey)} /> | ||
| </div> | ||
| } | ||
| /> | ||
|
|
||
| {copied ? ( | ||
| <Alert status="success" className={styles.notice} key={copyTimes.toString()}> | ||
| {t('common.copied')} | ||
| </Alert> | ||
| ) : null} | ||
| </div> | ||
| </Dialog> | ||
| ) | ||
| } | ||
| return ( | ||
| <Dialog | ||
| show | ||
| title={t('addresses.view-private-key')} | ||
| onCancel={onClose} | ||
| onConfirm={onSubmit} | ||
| confirmText={t('wizard.next')} | ||
| isLoading={isLoading} | ||
| disabled={!password || isLoading} | ||
| className={styles.dialog} | ||
| > | ||
| <div> | ||
| <div className={styles.tip}> | ||
| <Attention /> | ||
| {t('addresses.view-private-key-tip')} | ||
| </div> | ||
|
|
||
| <TextField | ||
| className={styles.passwordInput} | ||
| placeholder={t('password-request.placeholder')} | ||
| width="100%" | ||
| label={t('wizard.password')} | ||
| value={password} | ||
| field="password" | ||
| type="password" | ||
| onChange={onChange} | ||
| autoFocus | ||
| error={error} | ||
| /> | ||
| </div> | ||
| </Dialog> | ||
| ) | ||
| } | ||
|
|
||
| ViewPrivateKey.displayName = 'ViewPrivateKey' | ||
|
|
||
| export default ViewPrivateKey | ||
39 changes: 39 additions & 0 deletions
39
packages/neuron-ui/src/components/ViewPrivateKey/viewPrivateKey.module.scss
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,39 @@ | ||
| @import '../../styles/mixin.scss'; | ||
|
|
||
| .passwordInput { | ||
| margin-top: 16px; | ||
| } | ||
|
|
||
| .dialog { | ||
| width: 700px; | ||
| } | ||
|
|
||
| .tip { | ||
| color: var(--warn-text-color); | ||
| background: var(--warn-background-color); | ||
| margin: -20px -16px 0; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| height: 32px; | ||
| font-size: 12px; | ||
| gap: 4px; | ||
| font-weight: 500; | ||
| border-bottom: 1px solid var(--warn-border-color); | ||
| } | ||
|
|
||
| .label { | ||
| font-weight: 500; | ||
| color: var(--main-text-color); | ||
| font-size: 14px; | ||
| } | ||
|
|
||
| .copy { | ||
| display: flex; | ||
| align-items: center; | ||
| margin-left: 6px; | ||
| } | ||
|
|
||
| .notice { | ||
| @include dialog-copy-animation; | ||
| } |
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.