From 7285b0a33ef270cf3d38e5e35e383af7954e8b9a Mon Sep 17 00:00:00 2001 From: JunichiSugiura Date: Fri, 20 Dec 2024 10:07:11 +0900 Subject: [PATCH] Show messages in one section --- .../src/components/session/CollapsibleRow.tsx | 33 ---- .../src/components/session/ContractCard.tsx | 48 ++--- .../src/components/session/MessageCard.tsx | 177 +++++++++++------- .../session/UnverifiedSessionSummary.tsx | 6 +- 4 files changed, 124 insertions(+), 140 deletions(-) delete mode 100644 packages/keychain/src/components/session/CollapsibleRow.tsx diff --git a/packages/keychain/src/components/session/CollapsibleRow.tsx b/packages/keychain/src/components/session/CollapsibleRow.tsx deleted file mode 100644 index 8ef1276fb..000000000 --- a/packages/keychain/src/components/session/CollapsibleRow.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React, { PropsWithChildren, useState } from "react"; -import { - Accordion, - AccordionContent, - AccordionItem, - AccordionTrigger, - CheckboxIcon, -} from "@cartridge/ui-next"; - -interface CollapsibleRowProps extends PropsWithChildren { - title: string; -} - -export function CollapsibleRow({ title, children }: CollapsibleRowProps) { - const [value, setValue] = useState(""); - - return ( - - - -
- -
{title}
-
-
- - - {children} - -
-
- ); -} diff --git a/packages/keychain/src/components/session/ContractCard.tsx b/packages/keychain/src/components/session/ContractCard.tsx index be698621e..fd8101a08 100644 --- a/packages/keychain/src/components/session/ContractCard.tsx +++ b/packages/keychain/src/components/session/ContractCard.tsx @@ -9,15 +9,7 @@ import { AccordionTrigger, } from "@cartridge/ui-next"; import { formatAddress } from "@cartridge/utils"; -import { - Divider, - HStack, - Link, - Spacer, - Stack, - Text, - VStack, -} from "@chakra-ui/react"; +import { Divider, HStack, Spacer, Stack, Text, VStack } from "@chakra-ui/react"; import { useExplorer } from "@starknet-react/core"; import { constants } from "starknet"; import { Method } from "@cartridge/presets"; @@ -42,19 +34,10 @@ export function ContractCard({ return ( - - - {title} - - - +
{title}
+ {formatAddress(address, { first: 5, last: 5 })} - -
+ +
+ - - - - Approve{" "} - - {methods.length} {methods.length > 1 ? "methods" : "method"} - - + + + Approve{" "} + + {methods.length} {methods.length > 1 ? "methods" : "method"} + } > {methods.map((method) => ( diff --git a/packages/keychain/src/components/session/MessageCard.tsx b/packages/keychain/src/components/session/MessageCard.tsx index cab41f31f..67c19cd99 100644 --- a/packages/keychain/src/components/session/MessageCard.tsx +++ b/packages/keychain/src/components/session/MessageCard.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { PropsWithChildren, useState } from "react"; import { Card, CardContent, @@ -10,67 +10,17 @@ import { CardIcon, PencilIcon, AccordionTrigger, + CheckboxIcon, } from "@cartridge/ui-next"; import { ArrowTurnDownIcon, Badge } from "@cartridge/ui-next"; import { StarknetEnumType, StarknetMerkleType } from "@starknet-io/types-js"; import { SignMessagePolicy } from "@cartridge/presets"; -import { Text } from "@chakra-ui/react"; - -import { CollapsibleRow } from "./CollapsibleRow"; - -interface MessageContentProps { - message: SignMessagePolicy; -} - -function MessageContent({ message: m }: MessageContentProps) { - return ( - - {/* Domain section */} - {Object.values(m.domain).filter((f) => typeof f !== "undefined").length > - 0 && ( - - {m.domain.name && ( - - )} - {/* ... other domain fields ... */} - - )} - - - - - {Object.entries(m.types).map(([name, types]) => ( - - {types.map((t) => ( - - ))} - - ))} - - - ); -} interface MessageCardProps { - message: SignMessagePolicy; + messages: SignMessagePolicy[]; } -export function MessageCard({ message }: MessageCardProps) { +export function MessageCard({ messages }: MessageCardProps) { return ( Sign Message - - - - - - The application will be able to sign the following message on - your behalf - - - - - - - - - + + + ); } +interface MessageContentProps { + messages: SignMessagePolicy[]; +} + +function MessageContent({ messages }: MessageContentProps) { + return ( + + + + Approve{" "} + + {messages.length} {messages.length > 1 ? "message" : "messages"} + + + + + {messages.map((m) => ( + <> + {/* Domain section */} + {Object.values(m.domain).filter((f) => typeof f !== "undefined") + .length > 0 && ( + + {m.domain.name && ( + + )} + {/* ... other domain fields ... */} + + )} + + + + + {Object.entries(m.types).map(([name, types]) => ( + + {types.map((t) => ( + + ))} + + ))} + + + ))} + + + + ); +} +interface CollapsibleRowProps extends PropsWithChildren { + title: string; +} + +export function CollapsibleRow({ title, children }: CollapsibleRowProps) { + const [value, setValue] = useState(""); + + return ( + + + +
+ +
{title}
+
+
+ + + {children} + +
+
+ ); +} + interface ValueRowProps { values: { name: string; value: string | number }[]; } export function ValueRow({ values }: ValueRowProps) { return ( -
+
{values.map((f) => ( diff --git a/packages/keychain/src/components/session/UnverifiedSessionSummary.tsx b/packages/keychain/src/components/session/UnverifiedSessionSummary.tsx index f9c86e0dd..ec35ed500 100644 --- a/packages/keychain/src/components/session/UnverifiedSessionSummary.tsx +++ b/packages/keychain/src/components/session/UnverifiedSessionSummary.tsx @@ -28,9 +28,9 @@ export function UnverifiedSessionSummary({ ); })} - {policies.messages?.map((message, index) => ( - - ))} + {policies.messages?.length && ( + + )}
); }