Skip to content

Commit 1c2a393

Browse files
committed
frontend: prefer arrow functions
Refactored to use arrow functions to provide a more concise syntax and ensure a consistent style across the codebase. Arrow functions are preferred in this context as they do not bind their own this, making them a better fit for functional components and callbacks. Traditional function expressions were retained where necessary, such as for methods requiring their own this context, constructor functions, or where hoisting is necessary. TypeScript's type system helps identify issues related to this binding and potential hoisting problems.
1 parent 40f494b commit 1c2a393

39 files changed

+215
-191
lines changed

frontends/web/src/api/subscribe.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022 Shift Crypto AG
2+
* Copyright 2022-2024 Shift Crypto AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,10 +26,10 @@ export type TSubscriptionCallback<T> = (eventObject: T) => void;
2626
* can push data through. This should be mostly used within api.
2727
* Note there is a subscibe-legacy.ts module that supports older events.
2828
*/
29-
export function subscribeEndpoint<T>(
29+
export const subscribeEndpoint = <T>(
3030
endpoint: string,
3131
cb: TSubscriptionCallback<T>,
32-
): TUnsubscribe {
32+
): TUnsubscribe => {
3333
return apiSubscribe(endpoint, (event: TEvent) => {
3434
switch (event.action) {
3535
case 'replace':
@@ -45,7 +45,7 @@ export function subscribeEndpoint<T>(
4545
throw new Error(`Event: ${event} not supported`);
4646
}
4747
});
48-
}
48+
};
4949

5050
/**
5151
* Subscribes the given function to the backend/connected event.

frontends/web/src/components/dialog/dialog-legacy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ interface DialogButtonsProps {
212212
children: React.ReactNode;
213213
}
214214

215-
function DialogButtons({ children }: DialogButtonsProps) {
215+
const DialogButtons = ({ children }: DialogButtonsProps) => {
216216
return (
217217
<div className={style.dialogButtons}>{children}</div>
218218
);
219-
}
219+
};
220220

221221
export { DialogLegacy, DialogButtons };

frontends/web/src/components/dialog/dialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ interface DialogButtonsProps {
278278
children: React.ReactNode;
279279
}
280280

281-
function DialogButtons({ children }: DialogButtonsProps) {
281+
const DialogButtons = ({ children }: DialogButtonsProps) => {
282282
return (
283283
<div className={style.dialogButtons}>{children}</div>
284284
);
285-
}
285+
};
286286

287287
export { Dialog, DialogButtons };

frontends/web/src/components/forms/field.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright 2018 Shift Devices AG
3-
* Copyright 2021 Shift Crypto AG
3+
* Copyright 2021-2024 Shift Crypto AG
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -17,12 +17,12 @@
1717

1818
import style from './field.module.css';
1919

20-
export function Field({
20+
export const Field = ({
2121
children, ...props
22-
}: JSX.IntrinsicElements['div']) {
22+
}: JSX.IntrinsicElements['div']) => {
2323
return (
2424
<div className={style.field} {...props}>
2525
{children}
2626
</div>
2727
);
28-
}
28+
};

frontends/web/src/components/forms/label.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright 2018 Shift Devices AG
3-
* Copyright 2021 Shift Crypto AG
3+
* Copyright 2021-2024 Shift Crypto AG
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -17,16 +17,16 @@
1717

1818
import style from './label.module.css';
1919

20-
export function Label({
20+
export const Label = ({
2121
className,
2222
children,
2323
id, // TODO: change to htmlFor when mirgated away from preact@8.x
2424
...props
25-
}: JSX.IntrinsicElements['label']) {
25+
}: JSX.IntrinsicElements['label']) => {
2626
const classes = [style.label, className].join(' ');
2727
return (
2828
<label htmlFor={id} className={classes} {...props}>
2929
{children}
3030
</label>
3131
);
32-
}
32+
};

frontends/web/src/components/forms/radio.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ interface IRadioProps {
2323

2424
type TRadioProps = IRadioProps & JSX.IntrinsicElements['input']
2525

26-
export function Radio({
26+
export const Radio = ({
2727
disabled = false,
2828
label,
2929
id,
3030
children,
3131
...props
32-
}: TRadioProps) {
32+
}: TRadioProps) => {
3333
return (
3434
<span className={style.radio}>
3535
<input
@@ -44,4 +44,4 @@ export function Radio({
4444
</label>
4545
</span>
4646
);
47-
}
47+
};

frontends/web/src/components/keystoreconnectprompt.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2023 Shift Crypto AG
2+
* Copyright 2023-2024 Shift Crypto AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ import { useDarkmode } from '../hooks/darkmode';
2525
import { SkipForTesting } from '../routes/device/components/skipfortesting';
2626
import styles from './keystoreconnectprompt.module.css';
2727

28-
export function KeystoreConnectPrompt() {
28+
export const KeystoreConnectPrompt = () => {
2929
const { t } = useTranslation();
3030
const { isDarkMode } = useDarkmode();
3131

@@ -105,4 +105,4 @@ export function KeystoreConnectPrompt() {
105105
default:
106106
return null;
107107
}
108-
}
108+
};

frontends/web/src/components/layout/footer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type TProps = {
2323
children: ReactNode;
2424
}
2525

26-
export function Footer({ children }: TProps) {
26+
export const Footer = ({ children }: TProps) => {
2727
return (
2828
<footer className={[style.footer, 'flex flex-row flex-items-center flex-end'].join(' ')}>
2929
{children}
@@ -33,4 +33,4 @@ export function Footer({ children }: TProps) {
3333
<LanguageSwitch />
3434
</footer>
3535
);
36-
}
36+
};

frontends/web/src/components/message/message.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ export interface Props {
2424
children: ReactNode;
2525
}
2626

27-
export function Message({
27+
export const Message = ({
2828
hidden,
2929
small,
3030
type = 'message',
3131
children,
32-
}: Props) {
32+
}: Props) => {
3333
if (hidden) {
3434
return null;
3535
}
@@ -38,4 +38,4 @@ export function Message({
3838
{children}
3939
</div>
4040
);
41-
}
41+
};

frontends/web/src/components/password.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import { alertUser } from './alert/Alert';
2020
import style from './password.module.css';
2121
import { withTranslation } from 'react-i18next';
2222

23-
export function PasswordInput (props) {
23+
export const PasswordInput = (props) => {
2424
const { seePlaintext, ...rest } = props;
2525
return (
2626
<Input
2727
type={seePlaintext ? 'text' : 'password'}
2828
{...rest}
2929
/>
3030
);
31-
}
31+
};
3232

3333
class PasswordSingleInputClass extends Component {
3434
state = {
@@ -304,19 +304,19 @@ class PasswordRepeatInputClass extends Component {
304304

305305
export const PasswordRepeatInput = withTranslation(null, { withRef: true })(PasswordRepeatInputClass);
306306

307-
function MatchesPattern({ regex, value = '', text }) {
307+
const MatchesPattern = ({ regex, value = '', text }) => {
308308
if (!regex || !value.length || regex.test(value)) {
309309
return null;
310310
}
311311

312312
return (
313313
<p style={{ color: 'var(--color-error)' }}>{text}</p>
314314
);
315-
}
315+
};
316316

317317
const excludeKeys = /^(Shift|Alt|Backspace|CapsLock|Tab)$/i;
318318

319-
function hasCaps({ key }) {
319+
const hasCaps = ({ key }) => {
320320
// will return null, when we cannot clearly detect if capsLock is active or not
321321
if (key.length > 1 || key.toUpperCase() === key.toLowerCase() || excludeKeys.test(key)) {
322322
return null;
@@ -325,4 +325,4 @@ function hasCaps({ key }) {
325325
// @ts-ignore (event can be undefined and shiftKey exists only on MouseEvent but not Event)
326326
// eslint-disable-next-line no-restricted-globals
327327
return key.toUpperCase() === key && key.toLowerCase() !== key && !event.shiftKey;
328-
}
328+
};

0 commit comments

Comments
 (0)