Skip to content
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

security_for_seed_phrase_request #874

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 108 additions & 36 deletions src/components/settings/SeedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export default function SeedModal({ wallet, show, onHide }: SeedModalProps) {
const [seedError, setSeedError] = useState(false)
const [seed, setSeed] = useState(null)
const [isLoading, setIsLoading] = useState(true)
const [showPopup, setShowPopup] = useState(false)
const [password, setPassword] = useState('')
const [errorMessage, setErrorMessage] = useState('')

useEffect(() => {
const loadSeed = async () => {
Expand All @@ -40,44 +43,113 @@ export default function SeedModal({ wallet, show, onHide }: SeedModalProps) {
}
}, [show, wallet])

const handleToggle = (isToggled: boolean) => {
if (isToggled) {
setShowPopup(true)
setErrorMessage('')
} else {
setRevealSeed(false)
}
}

const handlePopupClose = () => {
setShowPopup(false)
setRevealSeed(false)
setErrorMessage('')
setPassword('')
}

const handlePopupEnter = async () => {
setErrorMessage('')

if (!password) {
setErrorMessage(t('settings.password_required'))
return
}

try {
const res = await Api.postWalletUnlock({ walletFileName: wallet.walletFileName }, { password })
if (!res.ok) {
setErrorMessage(t('settings.error_invalid_password'))
return
}

setShowPopup(false)
setRevealSeed(true)
setPassword('')
} catch (error) {
setErrorMessage(t('settings.error_validating_password'))
}
}

return (
<rb.Modal size="lg" show={show} onHide={onHide} keyboard={false} centered={true} animation={true}>
<rb.Modal.Header closeButton>
<rb.Modal.Title>{wallet.displayName}</rb.Modal.Title>
</rb.Modal.Header>
<rb.Modal.Body>
<>
{isLoading && (
<div className="d-flex justify-content-center align-items-center">
<rb.Spinner as="span" animation="border" size="sm" role="status" aria-hidden="true" />
</div>
)}
{seedError && (
<div className="text-danger" style={{ marginLeft: '1rem' }}>
{t('settings.error_loading_seed_failed')}
</div>
)}
{seed && (
<>
<div className="mb-4">{t('settings.seed_modal_info_text')}</div>
<rb.Row className="justify-content-center align-items-center">
<rb.Col xs={12} md={10} className="mb-4">
<Seedphrase seedphrase={seed} centered={true} isBlurred={!revealSeed} />
</rb.Col>
</rb.Row>
<>
<rb.Modal size="lg" show={show} onHide={onHide} keyboard={false} centered>
<rb.Modal.Header closeButton>
<rb.Modal.Title>{wallet.displayName}</rb.Modal.Title>
</rb.Modal.Header>
<rb.Modal.Body>
<>
{isLoading && (
<div className="d-flex justify-content-center align-items-center">
<div className="mb-2">
<ToggleSwitch
label={t('settings.reveal_seed')}
toggledOn={revealSeed}
onToggle={(isToggled) => setRevealSeed(isToggled)}
/>
</div>
<rb.Spinner as="span" animation="border" size="sm" role="status" aria-hidden="true" />
</div>
)}
{seedError && (
<div className="text-danger" style={{ marginLeft: '1rem' }}>
{t('settings.error_loading_seed_failed')}
</div>
</>
)}
</>
</rb.Modal.Body>
</rb.Modal>
)}
{seed && (
<>
<div className="mb-4">{t('settings.seed_modal_info_text')}</div>
<rb.Row className="justify-content-center align-items-center">
<rb.Col xs={12} md={10} className="mb-4">
<Seedphrase seedphrase={seed} centered={true} isBlurred={!revealSeed} />
</rb.Col>
</rb.Row>
<div className="d-flex justify-content-center align-items-center">
<div className="mb-2">
<ToggleSwitch label={t('settings.reveal_seed')} toggledOn={revealSeed} onToggle={handleToggle} />
</div>
</div>
</>
)}
</>
</rb.Modal.Body>
</rb.Modal>

<rb.Modal show={showPopup} onHide={handlePopupClose} centered dialogClassName="password-verify-modal">
<rb.Modal.Header closeButton>
<rb.Modal.Title className="text-center w-100">{t('settings.verify_password')}</rb.Modal.Title>
</rb.Modal.Header>
<rb.Modal.Body>
<div className="text-center">
<rb.Form.Control
type="password"
placeholder={t('settings.enter_password')}
value={password}
onChange={(e) => setPassword(e.target.value)}
className="mb-1 text-center"
isInvalid={!!errorMessage}
/>
{errorMessage && <small className="text-danger d-block mt-2">{errorMessage}</small>}
</div>
</rb.Modal.Body>
<rb.Modal.Footer className="d-flex justify-content-center">
<rb.Button variant="dark" onClick={handlePopupEnter}>
{t('settings.confirm')}
</rb.Button>
</rb.Modal.Footer>
</rb.Modal>

<style>
{`
.password-verify-modal {
max-width: 400px !important;
}
`}
</style>
</>
)
}
5 changes: 5 additions & 0 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@
"button_switch_wallet": "Switch wallet",
"error_loading_seed_failed": "Could not retrieve seed phrase.",
"seed_modal_info_text": "Please write down your seed phrase and password! Without this information you will not be able to access and recover your wallet!",
"verify_password": "Enter your wallet Password",
"enter_password": "Enter Password",
"confirm": "Unlock",
"password_required": "Please Enter Password",
"error_invalid_password": "Invaild Password",
"documentation": "Documentation",
"github": "GitHub",
"matrix": "Matrix",
Expand Down