Skip to content

Commit

Permalink
🚨 (sample) [NO-ISSUE]: Add linter to react files (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
aussedatlo authored Oct 8, 2024
2 parents db2e135 + eb1b5fa commit 8888fd0
Show file tree
Hide file tree
Showing 26 changed files with 1,015 additions and 133 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-teachers-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/device-sdk-sample": patch
---

Add eslint to tsx files
8 changes: 2 additions & 6 deletions apps/sample/src/app/client-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
"use client";

import React from "react";
import React, { PropsWithChildren } from "react";
import { Flex, StyleProvider } from "@ledgerhq/react-ui";
import styled, { DefaultTheme } from "styled-components";

Expand All @@ -19,10 +19,6 @@ import { SdkProvider } from "@/providers/DeviceSdkProvider";
import { DeviceSessionsProvider } from "@/providers/DeviceSessionsProvider";
import { GlobalStyle } from "@/styles/globalstyles";

type ClientRootLayoutProps = {
children: React.ReactNode;
};

const Root = styled(Flex)`
flex-direction: row;
color: ${({ theme }: { theme: DefaultTheme }) => theme.colors.neutral.c90};
Expand All @@ -37,7 +33,7 @@ const PageContainer = styled(Flex)`
flex: 1;
`;

const ClientRootLayout: React.FC<ClientRootLayoutProps> = ({ children }) => {
const ClientRootLayout: React.FC<PropsWithChildren> = ({ children }) => {
return (
<html lang="en">
<SdkProvider>
Expand Down
2 changes: 1 addition & 1 deletion apps/sample/src/app/device-actions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client";
import React from "react";

import { SessionIdWrapper } from "@/components/SessionIdWrapper";
import { AllDeviceActions } from "@/components/DeviceActionsView/AllDeviceActions";
import { SessionIdWrapper } from "@/components/SessionIdWrapper";

const DeviceActions: React.FC = () => {
return <SessionIdWrapper ChildComponent={AllDeviceActions} />;
Expand Down
2 changes: 1 addition & 1 deletion apps/sample/src/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useEffect } from "react";
import React, { useEffect } from "react";
import * as Sentry from "@sentry/nextjs";
import Error, { ErrorProps } from "next/error";

Expand Down
9 changes: 4 additions & 5 deletions apps/sample/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Combines Styled Components Registry with the ClientRootLayout
* for rendering the application.
*/
import React, { PropsWithChildren } from "react";

import { StyledComponentsRegistry } from "@/lib/registry";

import ClientRootLayout from "./client-layout";
Expand All @@ -15,16 +17,13 @@ export const metadata = {
description: "Ledger Device Management Kit Sample App",
};

type RootLayoutProps = {
children: React.ReactNode;
};

const RootLayout: React.FC<RootLayoutProps> = ({ children }) => {
const RootLayout: React.FC<PropsWithChildren> = ({ children }) => {
return (
<StyledComponentsRegistry>
<ClientRootLayout>{children}</ClientRootLayout>
</StyledComponentsRegistry>
);
};

// eslint-disable-next-line no-restricted-syntax
export default RootLayout;
2 changes: 1 addition & 1 deletion apps/sample/src/components/ClickableListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Flex, Text, Icons } from "@ledgerhq/react-ui";
import { Flex, Icons, Text } from "@ledgerhq/react-ui";
import styled from "styled-components";

const ListItemWrapper = styled(Flex)`
Expand Down
21 changes: 10 additions & 11 deletions apps/sample/src/components/CommandsView/Command.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React, { useCallback, useEffect, useState } from "react";

import { Flex, Icons, Button, InfiniteLoader } from "@ledgerhq/react-ui";
import { CommandForm, ValueSelector } from "./CommandForm";
import { FieldType } from "@/hooks/useForm";
import { CommandResponse, CommandResponseProps } from "./CommandResponse";
import { Block } from "../Block";
import { ClickableListItem } from "../ClickableListItem";
import { StyledDrawer } from "../StyledDrawer";
import {
CommandResult,
isSuccessCommandResult,
} from "@ledgerhq/device-management-kit";
import { Button, Flex, Icons, InfiniteLoader } from "@ledgerhq/react-ui";

import { Block } from "@/components/Block";
import { ClickableListItem } from "@/components/ClickableListItem";
import { StyledDrawer } from "@/components/StyledDrawer";
import { FieldType } from "@/hooks/useForm";

import { CommandForm, ValueSelector } from "./CommandForm";
import { CommandResponse, CommandResponseProps } from "./CommandResponse";

export type CommandProps<
CommandArgs extends Record<string, FieldType> | void,
Expand Down Expand Up @@ -81,7 +82,7 @@ export function Command<
.finally(() => {
setLoading(false);
});
}, [values]);
}, [values, sendCommand]);

const handleClickClear = useCallback(() => {
setResponses([]);
Expand Down Expand Up @@ -159,5 +160,3 @@ export function Command<
</>
);
}

export default Command;
5 changes: 3 additions & 2 deletions apps/sample/src/components/CommandsView/CommandForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect } from "react";
import { Input, Flex, Switch, Text, SelectInput } from "@ledgerhq/react-ui";
import { useForm, FieldType } from "@/hooks/useForm";
import { Flex, Input, SelectInput, Switch, Text } from "@ledgerhq/react-ui";

import { FieldType, useForm } from "@/hooks/useForm";

export type ValueSelector<T extends FieldType> = Record<
string,
Expand Down
5 changes: 3 additions & 2 deletions apps/sample/src/components/CommandsView/CommandResponse.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from "react";
import { Flex, InfiniteLoader, Text, Tooltip } from "@ledgerhq/react-ui";
import { FieldType } from "@/hooks/useForm";
import {
CommandResult,
isSuccessCommandResult,
} from "@ledgerhq/device-management-kit";
import { Flex, InfiniteLoader, Text, Tooltip } from "@ledgerhq/react-ui";

import { FieldType } from "@/hooks/useForm";

export type CommandResponseProps<Response, ErrorCodes> = {
args: Record<string, FieldType>;
Expand Down
29 changes: 15 additions & 14 deletions apps/sample/src/components/CommandsView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import React, { useMemo } from "react";
import { Grid } from "@ledgerhq/react-ui";

import Command, { CommandProps } from "./Command";
import { useSdk } from "@/providers/DeviceSdkProvider";
import {
ListAppsCommand,
ListAppsArgs,
ListAppsResponse,
OpenAppCommand,
OpenAppArgs,
CloseAppCommand,
GetAppAndVersionCommand,
GetAppAndVersionResponse,
GetOsVersionCommand,
GetOsVersionResponse,
GetBatteryStatusCommand,
GetBatteryStatusArgs,
GetBatteryStatusCommand,
GetBatteryStatusResponse,
OpenAppErrorCodes,
GetOsVersionCommand,
GetOsVersionResponse,
ListAppsArgs,
ListAppsCommand,
ListAppsErrorCodes,
ListAppsResponse,
OpenAppArgs,
OpenAppCommand,
OpenAppErrorCodes,
} from "@ledgerhq/device-management-kit";
import { BatteryStatusType } from "@ledgerhq/device-management-kit/src/api/command/os/GetBatteryStatusCommand.js";
import { Grid } from "@ledgerhq/react-ui";

import { PageWithHeader } from "@/components/PageWithHeader";
import { useSdk } from "@/providers/DeviceSdkProvider";

import { Command, CommandProps } from "./Command";
import { getValueSelectorFromEnum } from "./CommandForm";
import { PageWithHeader } from "../PageWithHeader";

export const CommandsView: React.FC<{ sessionId: string }> = ({
sessionId: selectedSessionId,
Expand Down
45 changes: 24 additions & 21 deletions apps/sample/src/components/DeviceActionsView/AllDeviceActions.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
import { useSdk } from "@/providers/DeviceSdkProvider";
import React from "react";
import { useMemo } from "react";
import {
OpenAppDeviceAction,
OpenAppDAOutput,
OpenAppDAInput,
OpenAppDAError,
OpenAppDAIntermediateValue,
GetDeviceStatusDeviceAction,
GetDeviceStatusDAOutput,
GetDeviceStatusDAInput,
GetDeviceStatusDAError,
GetDeviceStatusDAInput,
GetDeviceStatusDAIntermediateValue,
GoToDashboardDeviceAction,
GoToDashboardDAOutput,
GoToDashboardDAInput,
GetDeviceStatusDAOutput,
GetDeviceStatusDeviceAction,
GoToDashboardDAError,
GoToDashboardDAInput,
GoToDashboardDAIntermediateValue,
ListAppsDeviceAction,
ListAppsDAOutput,
ListAppsDAInput,
GoToDashboardDAOutput,
GoToDashboardDeviceAction,
ListAppsDAError,
ListAppsDAInput,
ListAppsDAIntermediateValue,
ListAppsWithMetadataDeviceAction,
ListAppsWithMetadataDAOutput,
ListAppsWithMetadataDAInput,
ListAppsDAOutput,
ListAppsDeviceAction,
ListAppsWithMetadataDAError,
ListAppsWithMetadataDAInput,
ListAppsWithMetadataDAIntermediateValue,
ListAppsWithMetadataDAOutput,
ListAppsWithMetadataDeviceAction,
OpenAppDAError,
OpenAppDAInput,
OpenAppDAIntermediateValue,
OpenAppDAOutput,
OpenAppDeviceAction,
} from "@ledgerhq/device-management-kit";
import { useMemo } from "react";

import { useSdk } from "@/providers/DeviceSdkProvider";

import { DeviceActionsList, UNLOCK_TIMEOUT } from "./DeviceActionsList";
import { DeviceActionProps } from "./DeviceActionTester";
import { UNLOCK_TIMEOUT, DeviceActionsList } from "./DeviceActionsList";

export const AllDeviceActions: React.FC<{ sessionId: string }> = ({
sessionId,
Expand Down Expand Up @@ -151,7 +154,7 @@ export const AllDeviceActions: React.FC<{ sessionId: string }> = ({
ListAppsWithMetadataDAIntermediateValue
>,
],
[],
[deviceModelId, sdk, sessionId],
);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from "react";
import {
type DeviceActionIntermediateValue,
type DeviceActionState,
DeviceActionStatus,
UserInteractionRequired,
} from "@ledgerhq/device-management-kit";
import { FieldType } from "@/hooks/useForm";
import React from "react";
import { Flex, Icons, Tag, Text, Tooltip } from "@ledgerhq/react-ui";
import styled from "styled-components";

import { FieldType } from "@/hooks/useForm";

export type DeviceActionResponseProps<Output, Error, IntermediateValue> = {
args: Record<string, FieldType>;
date: Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Block } from "@/components/Block";
import { ClickableListItem } from "@/components/ClickableListItem";
import { FieldType } from "@/hooks/useForm";
import React from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import type {
DeviceActionIntermediateValue,
ExecuteDeviceActionReturnType,
SdkError,
} from "@ledgerhq/device-management-kit";
import { DeviceModelId } from "@ledgerhq/device-management-kit";
import {
Button,
Divider,
Expand All @@ -16,16 +16,21 @@ import {
Text,
Tooltip,
} from "@ledgerhq/react-ui";
import { useCallback, useEffect, useRef, useState } from "react";
import { CommandForm, ValueSelector } from "../CommandsView/CommandForm";
import styled from "styled-components";

import { Block } from "@/components/Block";
import { ClickableListItem } from "@/components/ClickableListItem";
import {
CommandForm,
ValueSelector,
} from "@/components/CommandsView/CommandForm";
import { FieldType } from "@/hooks/useForm";

import {
DeviceActionResponse,
DeviceActionResponseProps,
} from "./DeviceActionResponse";

import { DeviceModelId } from "@ledgerhq/device-management-kit";
import styled from "styled-components";
import DeviceActionUI from "./DeviceActionUI";
import { DeviceActionUI } from "./DeviceActionUI";

export type DeviceActionProps<
Output,
Expand Down
35 changes: 16 additions & 19 deletions apps/sample/src/components/DeviceActionsView/DeviceActionUI.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from "react";
import Lottie from "react-lottie";
import {
type DeviceActionIntermediateValue,
DeviceActionStatus,
Expand All @@ -12,34 +14,29 @@ import {
Text,
Tooltip,
} from "@ledgerhq/react-ui";
import React from "react";
import Lottie from "react-lottie";
import {
DeviceActionResponseProps,
deviceActionStatusToColor,
} from "./DeviceActionResponse";

import * as PinStaxDark from "./lotties/stax/01_STAX_DARK_PIN.json";
import * as PairingStaxDark from "./lotties/stax/02_STAX_DARK_PAIRING.json";
import * as PairedSuccessStaxDark from "./lotties/stax/03_STAX_DARK_PAIRED_SUCCESS.json";
import * as ContinueOnLedgerStaxDark from "./lotties/stax/04_STAX_DARK_CONTINUE_ON_LEDGER.json";
import * as SignTransactionStaxDark from "./lotties/stax/05_STAX_DARK_SIGN_TRANSACTION.json";
import * as FrontViewStaxDark from "./lotties/stax/06_STAX_DARK_FRONT_VIEW.json";
import styled from "styled-components";

import * as PinFlexDark from "./lotties/flex/01_EUROPA_DARK_PIN.json";
import * as PairingFlexDark from "./lotties/flex/02_EUROPA_DARK_PAIRING.json";
import * as PairedSuccessFlexDark from "./lotties/flex/03_EUROPA_DARK_PAIRED_SUCCESS.json";
import * as ContinueOnLedgerFlexDark from "./lotties/flex/04_EUROPA_DARK_CONTINUE_ON_LEDGER.json";
import * as SignTransactionFlexDark from "./lotties/flex/05_EUROPA_DARK_SIGN_TRANSACTION.json";
import * as FrontViewFlexDark from "./lotties/flex/06_STAX_DARK_FRONT_VIEW.json";

import * as PinNanoSDark from "./lotties/nanosp/01_NANO_S_DARK_PIN.json";
import * as ContinueOnLedgerNanoSDark from "./lotties/nanosp/02_NANO_S_DARK_CONTINUE_ON_YOUR_LEDGER.json";
import * as PinNanoXDark from "./lotties/nanox/01_NANO_X_DARK_PIN.json";
import * as PairingNanoXDark from "./lotties/nanox/02_NANO_X_DARK_PAIRING.json";
import * as ContinueOnLedgerNanoXDark from "./lotties/nanox/03_NANO_X_DARK_CONTINUE_ON_YOUR_LEDGER.json";

import * as PinNanoSDark from "./lotties/nanosp/01_NANO_S_DARK_PIN.json";
import * as ContinueOnLedgerNanoSDark from "./lotties/nanosp/02_NANO_S_DARK_CONTINUE_ON_YOUR_LEDGER.json";
import styled from "styled-components";
import * as PinStaxDark from "./lotties/stax/01_STAX_DARK_PIN.json";
import * as PairingStaxDark from "./lotties/stax/02_STAX_DARK_PAIRING.json";
import * as PairedSuccessStaxDark from "./lotties/stax/03_STAX_DARK_PAIRED_SUCCESS.json";
import * as ContinueOnLedgerStaxDark from "./lotties/stax/04_STAX_DARK_CONTINUE_ON_LEDGER.json";
import * as SignTransactionStaxDark from "./lotties/stax/05_STAX_DARK_SIGN_TRANSACTION.json";
import * as FrontViewStaxDark from "./lotties/stax/06_STAX_DARK_FRONT_VIEW.json";
import {
DeviceActionResponseProps,
deviceActionStatusToColor,
} from "./DeviceActionResponse";

type DeviceAnimationProps = {
userInteractionRequired: UserInteractionRequired | string;
Expand Down Expand Up @@ -183,7 +180,7 @@ const JSONTextPopin: React.FC<{
);
};

export default function DeviceActionUI<
export function DeviceActionUI<
Output,
Error,
IntermediateValue extends DeviceActionIntermediateValue,
Expand Down
Loading

0 comments on commit 8888fd0

Please sign in to comment.