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

chore(lld): remove unused zxcvbn lib #6122

Merged
merged 1 commit into from
Feb 8, 2024
Merged
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
4 changes: 1 addition & 3 deletions apps/ledger-live-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@
"winston": "^3.2.1",
"winston-transport": "^4.3.0",
"write-file-atomic": "^5.0.0",
"xstate": "^4.30.2",
"zxcvbn": "^4.4.2"
"xstate": "^4.30.2"
},
"devDependencies": {
"@electron/notarize": "^2.2.1",
Expand Down Expand Up @@ -186,7 +185,6 @@
"@types/trust__keyto": "^1.0.0",
"@types/uuid": "^8.3.4",
"@types/write-file-atomic": "^4.0.0",
"@types/zxcvbn": "^4.4.1",
"@vitejs/plugin-react": "^3.1.0",
"allure-playwright": "2.12.0",
"axios": "^1.3.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React, { PureComponent } from "react";
import styled from "styled-components";
import { withTranslation } from "react-i18next";
import { TFunction } from "i18next";
import zxcvbn from "zxcvbn";
import debounce from "lodash/debounce";
import noop from "lodash/noop";
import Box from "~/renderer/components/Box";
import Input, { Props as InputProps } from "~/renderer/components/Input";
Expand All @@ -20,36 +18,8 @@ const InputRight = styled(Box).attrs(() => ({
}
`;

const Strength = styled(Box).attrs<{
activated: boolean;
warning: boolean;
}>(p => ({
bg: p.activated ? (p.warning ? "alertRed" : "positiveGreen") : "palette.divider",
grow: true,
}))<{
activated: boolean;
warning: boolean;
}>`
border-radius: 13px;
height: 4px;
`;

type WarningProps = {
passwordStrength: zxcvbn.ZXCVBNScore;
};

const Warning = styled(Box).attrs<WarningProps>(p => ({
alignItems: "flex-end",
color: p.passwordStrength <= 1 ? "alertRed" : "positiveGreen",
ff: "Inter|SemiBold",
fontSize: 3,
}))<WarningProps>``;

const getPasswordStrength = (v: string) => zxcvbn(v).score;

type State = {
inputType: "text" | "password";
passwordStrength: zxcvbn.ZXCVBNScore;
};

type Props = {
Expand All @@ -67,7 +37,6 @@ class InputPassword extends PureComponent<Props, State> {

state: State = {
inputType: "password",
passwordStrength: getPasswordStrength(this.props.value),
};

componentWillUnmount() {
Expand All @@ -80,23 +49,13 @@ class InputPassword extends PureComponent<Props, State> {
inputType: prev.inputType === "text" ? "password" : "text",
}));

debouncePasswordStrength = debounce(v => {
if (this._isUnmounted) return;
this.setState({
passwordStrength: getPasswordStrength(v),
});
}, 150);

handleChange = (v: string) => {
const { onChange } = this.props;
onChange(v);
this.debouncePasswordStrength(v);
};

render() {
const { t, value, withStrength } = this.props;
const { passwordStrength, inputType } = this.state;
const hasValue = value.trim() !== "";
const { inputType } = this.state;
return (
<Box flow={1}>
<Input
Expand All @@ -114,24 +73,6 @@ class InputPassword extends PureComponent<Props, State> {
</InputRight>
}
/>
{withStrength && (
<>
<Box flow={1} horizontal>
{[0, 1, 2].map(v => (
<Strength
key={v}
warning={passwordStrength <= 1}
activated={hasValue && passwordStrength >= v}
/>
))}
</Box>
{hasValue && (
<Warning passwordStrength={passwordStrength}>
{t(`password.warning_${passwordStrength}`)}
</Warning>
)}
</>
)}
</Box>
);
}
Expand Down
Loading
Loading