From 7285b0a33ef270cf3d38e5e35e383af7954e8b9a Mon Sep 17 00:00:00 2001 From: JunichiSugiura Date: Fri, 20 Dec 2024 10:07:11 +0900 Subject: [PATCH 1/5] 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 && ( + + )}
); } From 4fadc5be50863e83fd3fae7fec8446a66b91fb1b Mon Sep 17 00:00:00 2001 From: JunichiSugiura Date: Fri, 20 Dec 2024 10:27:37 +0900 Subject: [PATCH 2/5] Get rid of chakra from ContractCard --- .../src/components/session/ContractCard.tsx | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/packages/keychain/src/components/session/ContractCard.tsx b/packages/keychain/src/components/session/ContractCard.tsx index fd8101a08..397591b97 100644 --- a/packages/keychain/src/components/session/ContractCard.tsx +++ b/packages/keychain/src/components/session/ContractCard.tsx @@ -9,7 +9,6 @@ import { AccordionTrigger, } from "@cartridge/ui-next"; import { formatAddress } from "@cartridge/utils"; -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"; @@ -54,7 +53,7 @@ export function ContractCard({ - + Approve{" "} @@ -62,41 +61,28 @@ export function ContractCard({ - } - > +
{methods.map((method) => ( - - - +
+
{method.name ?? humanizeString(method.entrypoint)} - - - +
+
{method.entrypoint} - - +
+
{method.description && ( - +
{method.description} - +
)} -
+
))} -
+
From 173339a8d2aa5f02f795bff033c269a2538d0483 Mon Sep 17 00:00:00 2001 From: JunichiSugiura Date: Fri, 20 Dec 2024 10:38:49 +0900 Subject: [PATCH 3/5] Add code icon to contract card --- .../src/components/session/ContractCard.tsx | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/packages/keychain/src/components/session/ContractCard.tsx b/packages/keychain/src/components/session/ContractCard.tsx index 397591b97..3ba0273be 100644 --- a/packages/keychain/src/components/session/ContractCard.tsx +++ b/packages/keychain/src/components/session/ContractCard.tsx @@ -1,4 +1,3 @@ -import React from "react"; import { Card, CardContent, @@ -7,6 +6,8 @@ import { AccordionContent, AccordionItem, AccordionTrigger, + CardIcon, + CodeIcon, } from "@cartridge/ui-next"; import { formatAddress } from "@cartridge/utils"; import { useExplorer } from "@starknet-react/core"; @@ -32,7 +33,15 @@ export function ContractCard({ return ( - + + + + ) + } + >
{title}
1 ? "methods" : "method"} - -
- {methods.map((method) => ( -
-
-
- {method.name ?? humanizeString(method.entrypoint)} -
-
- {method.entrypoint} -
+ + {methods.map((method) => ( +
+
+
+ {method.name ?? humanizeString(method.entrypoint)} +
+
+ {method.entrypoint}
- {method.description && ( -
- {method.description} -
- )}
- ))} -
+ {method.description && ( +
+ {method.description} +
+ )} +
+ ))} From 2bd31de75240c12e1b8071cac3cdaf653e0eff4b Mon Sep 17 00:00:00 2001 From: JunichiSugiura Date: Fri, 20 Dec 2024 10:39:40 +0900 Subject: [PATCH 4/5] Style message card with multi messages --- .../src/components/session/MessageCard.tsx | 93 ++++++++++--------- .../session/UnverifiedSessionSummary.tsx | 1 - 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/packages/keychain/src/components/session/MessageCard.tsx b/packages/keychain/src/components/session/MessageCard.tsx index 67c19cd99..6068aa963 100644 --- a/packages/keychain/src/components/session/MessageCard.tsx +++ b/packages/keychain/src/components/session/MessageCard.tsx @@ -1,4 +1,4 @@ -import React, { PropsWithChildren, useState } from "react"; +import { PropsWithChildren, useState } from "react"; import { Card, CardContent, @@ -54,56 +54,59 @@ function MessageContent({ messages }: MessageContentProps) { > Approve{" "} - {messages.length} {messages.length > 1 ? "message" : "messages"} + {messages.length} {messages.length > 1 ? "messages" : "message"} - - {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) => ( + + {messages.map((m, i) => ( +
+
{m.name ?? `Message ${i + 1}`}
+
+ {/* 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) => ( + + ))} + + ))} + +
+
))}
diff --git a/packages/keychain/src/components/session/UnverifiedSessionSummary.tsx b/packages/keychain/src/components/session/UnverifiedSessionSummary.tsx index ec35ed500..f65f1695d 100644 --- a/packages/keychain/src/components/session/UnverifiedSessionSummary.tsx +++ b/packages/keychain/src/components/session/UnverifiedSessionSummary.tsx @@ -1,4 +1,3 @@ -import React from "react"; import { toArray } from "@cartridge/controller"; import { ParsedSessionPolicies } from "@/hooks/session"; From 3c3d266bbdd09f339e8fcf8ba30177f4d59f2dc7 Mon Sep 17 00:00:00 2001 From: JunichiSugiura Date: Fri, 20 Dec 2024 17:53:36 +0900 Subject: [PATCH 5/5] Add key to mapped div --- packages/keychain/src/components/session/MessageCard.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/keychain/src/components/session/MessageCard.tsx b/packages/keychain/src/components/session/MessageCard.tsx index 6068aa963..0ce117c65 100644 --- a/packages/keychain/src/components/session/MessageCard.tsx +++ b/packages/keychain/src/components/session/MessageCard.tsx @@ -60,7 +60,10 @@ function MessageContent({ messages }: MessageContentProps) { {messages.map((m, i) => ( -
+
{m.name ?? `Message ${i + 1}`}
{/* Domain section */}