Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Start revisions of UI Tool layout
Browse files Browse the repository at this point in the history
  • Loading branch information
LL782 committed Oct 1, 2024
1 parent b67b12d commit 4763a56
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 98 deletions.
28 changes: 28 additions & 0 deletions developer-preview/src/app/ContractInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { formatShortAddress } from "~/app/formatShortAddress";
import { UI } from "~/app/UI";
import { type Deploymnent, type PreviewData } from "~/types/PreviewData";

export const ContractInfo = ({ data }: { data: PreviewData }) => {
return (
<div>
<UI.HeadingField>Contract</UI.HeadingField>
<div>
{data.contract.name}
{data.contract.deployments.map(({ address }: Deploymnent) => (
<span key={address}>
{" "}
(
<UI.BlueLink
href={`https://etherscan.io/address/${address}`}
title={address}
target="_blank"
>
{formatShortAddress(address)}
</UI.BlueLink>
)
</span>
))}
</div>
</div>
);
};
2 changes: 1 addition & 1 deletion developer-preview/src/app/DevicesDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const DevicesDemo = ({
return (
<>
<DeviceContext.Provider value={selectedDevice}>
<div className="overflow-x-scroll bg-[#383838] p-16">
<div className="overflow-x-scroll p-16">
<div className="flex w-fit space-x-10 pe-16 font-inter text-sm">
<Screens
chainId={chainId}
Expand Down
64 changes: 0 additions & 64 deletions developer-preview/src/app/PreviewForm.tsx

This file was deleted.

65 changes: 41 additions & 24 deletions developer-preview/src/app/PreviewTool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import { useEffect, useState } from "react";
import { DevicesDemo } from "~/app/DevicesDemo";
import { PreviewForm } from "~/app/PreviewForm";
import { ContractInfo } from "~/app/ContractInfo";
import { UI } from "~/app/UI";
import { SelectMetadataFile } from "~/app/SelectMetadataFile";

import { type PreviewData } from "~/types/PreviewData";
import { getPreviewData } from "~/utils/getPreviewData";
import { type ERC7730Schema } from "~/types";
import { SelectDevice } from "~/app/SelectDevice";
import { SelectOperation } from "~/app/SelectOperation";
import { SelectValues } from "~/app/SelectValues";

interface Props {
jsonInRegistry: string[];
Expand Down Expand Up @@ -73,41 +75,56 @@ export default function PreviewTool({ jsonInRegistry }: Props) {
}

return (
<main>
<div className="container p-16 text-lg">
<UI.Heading1>Open Clear Signing Format preview</UI.Heading1>
<form className="flex flex-col gap-6">
<>
<div className="border-b border-[#fff2] bg-[#fff1]">
<UI.Container as="header">
<UI.Heading1>Open Clear Signing Format preview</UI.Heading1>
</UI.Container>

<UI.Container className="flex gap-3">
<SelectMetadataFile
fileKey={fileKey}
jsonInRegistry={jsonInRegistry}
setFileKey={setFileKey}
/>

{previewData && (
<PreviewForm
data={previewData}
selectedOperation={selectedOperation}
setSelectedOperation={setSelectedOperation}
/>
<>
<SelectValues />
<SelectOperation
data={previewData}
selectedOperation={selectedOperation}
setSelectedOperation={setSelectedOperation}
/>
<ContractInfo data={previewData} />
</>
)}
{previewData && (
<SelectDevice
selectedDevice={selectedDevice}
setSelectedDevice={setSelectedDevice}
/>
)}
</form>
{errorMessage && <UI.Error>{errorMessage}</UI.Error>}
</UI.Container>

{errorMessage && (
<UI.Container>
<UI.Error>{errorMessage}</UI.Error>
</UI.Container>
)}
</div>

{previewData && (
<>
<DevicesDemo
data={previewData}
selectedDevice={selectedDevice}
selectedOperation={selectedOperation}
/>
<div className="bg-tool-background">
<UI.Container>
<SelectDevice
selectedDevice={selectedDevice}
setSelectedDevice={setSelectedDevice}
/>
</UI.Container>
<DevicesDemo
data={previewData}
selectedDevice={selectedDevice}
selectedOperation={selectedOperation}
/>
</div>
</>
)}
</main>
</>
);
}
11 changes: 4 additions & 7 deletions developer-preview/src/app/SelectDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ export const SelectDevice = ({
};

return (
<div>
<UI.HeadingField>Preview on</UI.HeadingField>
<UI.Select defaultValue={selectedDevice} onChange={onChangeDevice}>
<option value="flex">Ledger Flex</option>
<option value="stax">Ledger Stax</option>
</UI.Select>
</div>
<UI.Select defaultValue={selectedDevice} onChange={onChangeDevice}>
<option value="flex">Ledger Flex</option>
<option value="stax">Ledger Stax</option>
</UI.Select>
);
};
32 changes: 32 additions & 0 deletions developer-preview/src/app/SelectOperation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { type Dispatch, type SetStateAction } from "react";
import { UI } from "~/app/UI";
import { type PreviewData } from "~/types/PreviewData";

export const SelectOperation = ({
data,
selectedOperation,
setSelectedOperation,
}: {
data: PreviewData;
selectedOperation: string;
setSelectedOperation: Dispatch<SetStateAction<string>>;
}) => {
const onChangeOperation = (e: React.ChangeEvent<HTMLSelectElement>) => {
const selection = e.target.value;
localStorage.setItem("selectedOperation", selection);
setSelectedOperation(selection);
};

return (
<div>
<UI.HeadingField>Operation</UI.HeadingField>
<UI.Select defaultValue={selectedOperation} onChange={onChangeOperation}>
{data.operations.map(({ id, intent }) => (
<UI.Option key={`${data.contract.name}-${id}`} value={id}>
{intent}
</UI.Option>
))}
</UI.Select>
</div>
);
};
12 changes: 12 additions & 0 deletions developer-preview/src/app/SelectValues.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { UI } from "~/app/UI";

export const SelectValues = () => {
return (
<div>
<UI.HeadingField>Preview with</UI.HeadingField>
<UI.Select disabled onChange={() => null}>
<UI.Option value="">Placeholder values</UI.Option>
</UI.Select>
</div>
);
};
17 changes: 15 additions & 2 deletions developer-preview/src/app/UI.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ReactElement } from "react";
import type { ReactElement, ReactNode } from "react";
import { cn } from "~/utils/cn";

export const UI = {
BlueLink: ({
Expand All @@ -11,11 +12,23 @@ export const UI = {
{children}
</a>
),
Container: ({
as = "div",
children,
className,
}: {
as?: keyof HTMLElementTagNameMap;
children: ReactNode;
className?: string;
}) => {
const El = as;
return <El className={cn("p-4", className)}>{children}</El>;
},
HeadingField: ({ children }: { children: string }) => (
<div className="mb-2 text-sm uppercase text-neutral-400">{children}</div>
),
Heading1: ({ children }: { children: string }) => (
<h1 className="mb-10 text-3xl font-medium">{children}</h1>
<h1 className="text-sm font-medium">{children}</h1>
),
Option: ({
children,
Expand Down
4 changes: 4 additions & 0 deletions developer-preview/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default {
colors: {
"light-grey": "#E0E0E0",
"dark-grey": "#959595",
"tool-background": "#131214",
"tool-neutral": {
70: "#949494",
},
},
},
},
Expand Down

0 comments on commit 4763a56

Please sign in to comment.