fix: use input ref for password value instead of document lookup on pasword modal

pull/3083/head
William Grant 10 months ago
parent 1a13839d9d
commit 2906b3200e

@ -1,6 +1,7 @@
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import styled from 'styled-components'; import styled from 'styled-components';
import { useRef } from 'react';
import { ToastUtils } from '../../session/utils'; import { ToastUtils } from '../../session/utils';
import { matchesHash } from '../../util/passwordUtils'; import { matchesHash } from '../../util/passwordUtils';
@ -25,6 +26,8 @@ export type EnterPasswordModalProps = {
export const EnterPasswordModal = (props: EnterPasswordModalProps) => { export const EnterPasswordModal = (props: EnterPasswordModalProps) => {
const { passwordHash, setPasswordValid, onClickOk, onClickClose, title } = props; const { passwordHash, setPasswordValid, onClickOk, onClickClose, title } = props;
const passwordInputRef = useRef<HTMLInputElement>(null);
const dispatch = useDispatch(); const dispatch = useDispatch();
const onClose = () => { const onClose = () => {
@ -35,15 +38,13 @@ export const EnterPasswordModal = (props: EnterPasswordModalProps) => {
}; };
const confirmPassword = () => { const confirmPassword = () => {
const passwordValue = (document.getElementById('seed-input-password') as any)?.value; const passwordValue = passwordInputRef.current?.value;
const isPasswordValid = matchesHash(passwordValue as string, passwordHash);
if (!passwordValue) { if (!passwordValue) {
ToastUtils.pushToastError('enterPasswordErrorToast', window.i18n('noGivenPassword')); ToastUtils.pushToastError('enterPasswordErrorToast', window.i18n('noGivenPassword'));
return; return;
} }
const isPasswordValid = matchesHash(passwordValue as string, passwordHash);
if (passwordHash && !isPasswordValid) { if (passwordHash && !isPasswordValid) {
ToastUtils.pushToastError('enterPasswordErrorToast', window.i18n('invalidPassword')); ToastUtils.pushToastError('enterPasswordErrorToast', window.i18n('invalidPassword'));
return; return;
@ -76,7 +77,7 @@ export const EnterPasswordModal = (props: EnterPasswordModalProps) => {
<div className="session-modal__input-group"> <div className="session-modal__input-group">
<input <input
type="password" type="password"
id="seed-input-password" ref={passwordInputRef}
data-testid="password-input" data-testid="password-input"
placeholder={window.i18n('enterPassword')} placeholder={window.i18n('enterPassword')}
onKeyUp={onEnter} onKeyUp={onEnter}

Loading…
Cancel
Save