diff --git a/src/ActionLink.tsx b/src/ActionLink.tsx index b98fccb..ec9d4d6 100644 --- a/src/ActionLink.tsx +++ b/src/ActionLink.tsx @@ -1,4 +1,4 @@ -import React, {HTMLProps, SyntheticEvent, useCallback} from 'react'; +import {HTMLProps, SyntheticEvent, useCallback} from 'react'; type HTMLAnchorProps = Omit, 'href' | 'onClick'>; diff --git a/src/App.tsx b/src/App.tsx index 1f69e27..bbc10e1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import React, {useCallback, useEffect, useMemo, useState} from 'react'; +import {useCallback, useEffect, useMemo, useState} from 'react'; import base32Decode from 'base32-decode'; import {NumberInput, TextInput} from './Input'; import OTPOutput from './OTPOutput'; @@ -6,6 +6,7 @@ import Select from './Select'; import Collapsible from './Collapsible'; import ActionLink from './ActionLink'; import {defaults, serializeState, deserializeState} from './state'; +import {HashAlgorithm} from './algorithms.tsx'; function parseState() { if (window.location.hash.startsWith('#!')) { @@ -78,7 +79,7 @@ function App() { ); const setAlgorithm = useCallback( - (algorithm: string) => setState((state) => ({...state, algorithm})), + (algorithm: HashAlgorithm) => setState((state) => ({...state, algorithm})), [], ); @@ -107,7 +108,7 @@ function App() {
- + {advanced ? Hide advanced options : Show advanced options} @@ -124,7 +125,7 @@ function App() {
- {valid && } + {valid && decoded && } ); } diff --git a/src/Collapsible.tsx b/src/Collapsible.tsx index fe034fb..ad7ca25 100644 --- a/src/Collapsible.tsx +++ b/src/Collapsible.tsx @@ -1,4 +1,4 @@ -import React, {ReactNode, useEffect, useId} from 'react'; +import {ReactNode, useEffect, useId} from 'react'; import {Collapse} from 'bootstrap'; export default function Collapsible({children, show}: { children: ReactNode; show: boolean }) { diff --git a/src/CopyButton.tsx b/src/CopyButton.tsx index 80a3c9b..9a853f0 100644 --- a/src/CopyButton.tsx +++ b/src/CopyButton.tsx @@ -1,4 +1,4 @@ -import React, {useCallback, useEffect, useId, useState} from 'react'; +import {useCallback, useEffect, useId, useState} from 'react'; import Copy from './copy.svg?react'; import {Popover} from 'bootstrap'; diff --git a/src/Input.tsx b/src/Input.tsx index e51e667..3ef56b6 100644 --- a/src/Input.tsx +++ b/src/Input.tsx @@ -1,4 +1,4 @@ -import React, {ReactNode, HTMLProps, useCallback, useId} from 'react'; +import {ChangeEvent, ReactNode, HTMLProps, useCallback, useId} from 'react'; import classNames from 'classnames'; type CommonProps = { diff --git a/src/OTPOutput.tsx b/src/OTPOutput.tsx index f4e71ea..561f666 100644 --- a/src/OTPOutput.tsx +++ b/src/OTPOutput.tsx @@ -1,4 +1,4 @@ -import React, {useMemo} from 'react'; +import {useMemo} from 'react'; import {HOTP, HOTPOptions} from '@otplib/core'; import {createDigest} from '@otplib/plugin-crypto-js'; import classNames from 'classnames'; @@ -20,7 +20,7 @@ function OTPCode({code, delta}: { code: string; delta: number }) { } export default function OTPOutput({secret, offset, algorithm, digits}: { - secret: string; + secret: ArrayBuffer; offset: number; algorithm: HashAlgorithm; digits: number; @@ -35,7 +35,12 @@ export default function OTPOutput({secret, offset, algorithm, digits}: { {[...Array(21).keys()].map((i) => { const delta = i - 10; const current = offset + delta; - return ; + return ; })} ; } diff --git a/src/Select.tsx b/src/Select.tsx index 160a19b..efe308c 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -1,4 +1,4 @@ -import React, {ChangeEvent, ReactNode, useCallback, useId} from 'react'; +import {ChangeEvent, ReactNode, useCallback, useId} from 'react'; export default function Select({label, options, value, onChange}: { label: ReactNode; diff --git a/src/state.tsx b/src/state.tsx index f2e5f39..c508926 100644 --- a/src/state.tsx +++ b/src/state.tsx @@ -1,4 +1,3 @@ - import {ALGORITHMS, HashAlgorithm} from './algorithms.tsx'; export type State = { @@ -16,7 +15,7 @@ export const defaults: State = { } as const; export function serializeState(state: State): string { - const values = ['secret', 'step', 'digits', 'algorithm'].map( + const values = (['secret', 'step', 'digits', 'algorithm'] as Array).map( (key) => state[key] !== defaults[key] ? encodeURIComponent(state[key]) : '', ); while (values[values.length - 1] === '') { @@ -31,6 +30,6 @@ export function deserializeState(data: string): State { secret: values[0] || defaults.secret, step: +values[1] || defaults.step, digits: +values[2] || defaults.digits, - algorithm: ALGORITHMS[values[3]] !== undefined ? values[3] : defaults.algorithm, + algorithm: values[3] in ALGORITHMS !== undefined ? values[3] as HashAlgorithm : defaults.algorithm, }; }