Take 1 (incorrect)

This commit is contained in:
Manav Rathi 2024-05-24 09:27:28 +05:30
parent d814b6cdf0
commit 0a01cac57b
No known key found for this signature in database
4 changed files with 11 additions and 29 deletions

View file

@ -46,14 +46,11 @@ const AuthenticatorCodesPage = () => {
appContext.showNavBar(false);
}, []);
const lcSearch = searchTerm.toLowerCase();
const filteredCodes = codes.filter(
(secret) =>
(secret.issuer ?? "")
.toLowerCase()
.includes(searchTerm.toLowerCase()) ||
(secret.account ?? "")
.toLowerCase()
.includes(searchTerm.toLowerCase()),
(code) =>
code.issuer?.toLowerCase().includes(lcSearch) ||
code.account?.toLowerCase().includes(lcSearch),
);
if (!hasFetched) {
@ -270,7 +267,7 @@ const OTPDisplay: React.FC<OTPDisplayProps> = ({ code, otp, nextOTP }) => {
textAlign: "left",
}}
>
{code.issuer}
{code.issuer ?? ""}
</p>
<p
style={{
@ -283,7 +280,7 @@ const OTPDisplay: React.FC<OTPDisplayProps> = ({ code, otp, nextOTP }) => {
color: "grey",
}}
>
{code.account}
{code.account ?? ""}
</p>
<p
style={{

View file

@ -12,7 +12,7 @@ export interface Code {
/** The type of the code. */
type: "totp" | "hotp";
/** The user's account or email for which this code is used. */
account: string;
account?: string;
/** The name of the entity that issued this code. */
issuer: string;
/** Number of digits in the generated OTP. */
@ -52,7 +52,7 @@ export const codeFromURIString = (id: string, uriString: string): Code => {
return {
id,
type: parseType(url),
account: _getAccount(uriPath),
account: parseAccount(url),
issuer: _getIssuer(uriPath, uriParams),
digits: parseDigits(url),
period: parsePeriod(url),
@ -68,18 +68,9 @@ const parseType = (url: URL): Code["type"] => {
throw new Error(`Unsupported code with host ${t}`);
};
const _getAccount = (uriPath: string): string => {
try {
const path = decodeURIComponent(uriPath);
if (path.includes(":")) {
return path.split(":")[1];
} else if (path.includes("/")) {
return path.split("/")[1];
}
} catch (e) {
return "";
}
};
/** Convert the pathname from "/ACME:user@example.org" => "user@example.org" */
const parseAccount = (url: URL): string =>
url.pathname.split(":").at(-1).split("/").at(-1);
const _getIssuer = (uriPath: string, uriParams: { get?: any }): string => {
try {

View file

@ -43,7 +43,6 @@
"similarity-transformation": "^0.0.1",
"transformation-matrix": "^2.16",
"uuid": "^9.0.1",
"vscode-uri": "^3.0.7",
"xml-js": "^1.6.11",
"zxcvbn": "^4.4.2"
},

View file

@ -4804,11 +4804,6 @@ void-elements@3.1.0:
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-3.1.0.tgz#614f7fbf8d801f0bb5f0661f5b2f5785750e4f09"
integrity sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==
vscode-uri@^3.0.7:
version "3.0.8"
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-3.0.8.tgz#1770938d3e72588659a172d0fd4642780083ff9f"
integrity sha512-AyFQ0EVmsOZOlAnxoFOGOq1SQDWAB7C6aqMGS23svWAllfOaxbuFvcT8D1i8z3Gyn8fraVeZNNmN6e9bxxXkKw==
webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"