From b755f380a011ded621426412230ee67efca3c6e2 Mon Sep 17 00:00:00 2001 From: Junichi Sugiura Date: Wed, 8 Jan 2025 22:31:55 +0900 Subject: [PATCH] Fix session summary style (#1256) --- .../connect/CreateSession.stories.tsx | 110 ++++++------- .../src/components/session/AccordionCard.tsx | 9 +- .../src/components/session/AggregateCard.tsx | 148 ++++++------------ .../src/components/session/ContractCard.tsx | 7 +- .../src/components/session/MessageCard.tsx | 31 ++-- 5 files changed, 134 insertions(+), 171 deletions(-) diff --git a/packages/keychain/src/components/connect/CreateSession.stories.tsx b/packages/keychain/src/components/connect/CreateSession.stories.tsx index d08e5aa61..558d0d07f 100644 --- a/packages/keychain/src/components/connect/CreateSession.stories.tsx +++ b/packages/keychain/src/components/connect/CreateSession.stories.tsx @@ -19,6 +19,60 @@ export default meta; type Story = StoryObj; +const messages = [ + { + types: { + StarknetDomain: [ + { + name: "name", + type: "shortstring", + }, + { + name: "version", + type: "shortstring", + }, + { + name: "chainId", + type: "shortstring", + }, + { + name: "revision", + type: "shortstring", + }, + ], + "eternum-Message": [ + { + name: "identity", + type: "ContractAddress", + }, + { + name: "channel", + type: "shortstring", + }, + { + name: "content", + type: "string", + }, + { + name: "timestamp", + type: "felt", + }, + { + name: "salt", + type: "felt", + }, + ], + }, + primaryType: "eternum-Message", + domain: { + name: "Eternum", + version: "1", + chainId: "SN_SEPOLIA", + revision: "1", + }, + }, +]; + export const Default: Story = { args: { policies: parseSessionPolicies({ @@ -113,59 +167,7 @@ export const Default: Story = { ], }, }, - messages: [ - { - types: { - StarknetDomain: [ - { - name: "name", - type: "shortstring", - }, - { - name: "version", - type: "shortstring", - }, - { - name: "chainId", - type: "shortstring", - }, - { - name: "revision", - type: "shortstring", - }, - ], - "eternum-Message": [ - { - name: "identity", - type: "ContractAddress", - }, - { - name: "channel", - type: "shortstring", - }, - { - name: "content", - type: "string", - }, - { - name: "timestamp", - type: "felt", - }, - { - name: "salt", - type: "felt", - }, - ], - }, - primaryType: "eternum-Message", - domain: { - name: "Eternum", - version: "1", - chainId: "SN_SEPOLIA", - revision: "1", - }, - }, - ], + messages, }, }), onConnect: () => {}, @@ -179,7 +181,7 @@ export const WithPreset: Story = { args: { policies: parseSessionPolicies({ verified: true, - policies: controllerConfigs["dope-wars"].policies!, + policies: { ...controllerConfigs["dope-wars"].policies!, messages }, }), onConnect: () => {}, }, diff --git a/packages/keychain/src/components/session/AccordionCard.tsx b/packages/keychain/src/components/session/AccordionCard.tsx index f0fb4fb2f..42c442841 100644 --- a/packages/keychain/src/components/session/AccordionCard.tsx +++ b/packages/keychain/src/components/session/AccordionCard.tsx @@ -7,6 +7,7 @@ import { AccordionContent, AccordionItem, AccordionTrigger, + cn, } from "@cartridge/ui-next"; interface AccordionCardProps { @@ -16,6 +17,7 @@ interface AccordionCardProps { children: React.ReactNode; trigger?: React.ReactNode; isExpanded?: boolean; + className?: string; } export function AccordionCard({ @@ -25,10 +27,11 @@ export function AccordionCard({ children, trigger, isExpanded, + className, }: AccordionCardProps) { return ( - +
{typeof title === "string" ? ( {title} @@ -45,12 +48,12 @@ export function AccordionCard({ collapsible defaultValue={isExpanded ? "item" : undefined} > - + {trigger} - + {children} diff --git a/packages/keychain/src/components/session/AggregateCard.tsx b/packages/keychain/src/components/session/AggregateCard.tsx index 2f2b8f462..4cf0eb9d7 100644 --- a/packages/keychain/src/components/session/AggregateCard.tsx +++ b/packages/keychain/src/components/session/AggregateCard.tsx @@ -1,7 +1,5 @@ -import React, { Fragment } from "react"; -import { Card } from "@cartridge/ui-next"; +import React from "react"; 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"; @@ -9,6 +7,7 @@ import { useChainId } from "@/hooks/connection"; import { ParsedSessionPolicies } from "@/hooks/session"; import { Link } from "react-router-dom"; import { AccordionCard } from "./AccordionCard"; +import { MessageContent } from "./MessageCard"; interface AggregateCardProps { title: string; @@ -42,109 +41,54 @@ export function AggregateCard({ title, icon, policies }: AggregateCardProps) {
} + className="gap-2" > - - {Object.entries(policies.contracts || {}).map( - ([address, { name, methods }]) => ( - - - - {name} - - - - {formatAddress(address, { first: 5, last: 5 })} - - - } + {Object.entries(policies.contracts || {}).map( + ([address, { name, methods }]) => ( +
+
+
{name}
+ - {methods.map((method: Method) => ( - - - - {method.name} - - - - {method.entrypoint} - - - {method.description && ( - - {method.description} - - )} - - ))} - - - ), - )} + {formatAddress(address, { first: 5, last: 5 })} + +
- {policies.messages?.map((message) => ( - - - Messages - - } - w="full" - > - {Object.entries(message.types).map(([typeName, fields]) => ( - - - - {typeName} - - - {fields.map((field) => ( - - - {field.name} - - - - {field.type} - - - ))} - +
+ {methods.map((method: Method) => ( +
+
+
+ {method.name} +
+
+ {method.entrypoint} +
+
+ {method.description && ( +
+ {method.description} +
+ )} +
))} - - - ))} - +
+
+ ), + )} + + {policies.messages && } ); } diff --git a/packages/keychain/src/components/session/ContractCard.tsx b/packages/keychain/src/components/session/ContractCard.tsx index 109bf1165..b530eb086 100644 --- a/packages/keychain/src/components/session/ContractCard.tsx +++ b/packages/keychain/src/components/session/ContractCard.tsx @@ -54,17 +54,18 @@ export function ContractCard({ } + className="bg-background gap-px rounded overflow-auto border border-background" > {methods.map((method) => (
-
+
{method.name ?? humanizeString(method.entrypoint)}
-
{method.entrypoint}
+
{method.entrypoint}
{method.description && (
{method.description}
diff --git a/packages/keychain/src/components/session/MessageCard.tsx b/packages/keychain/src/components/session/MessageCard.tsx index cadf29b26..253f89fba 100644 --- a/packages/keychain/src/components/session/MessageCard.tsx +++ b/packages/keychain/src/components/session/MessageCard.tsx @@ -32,13 +32,26 @@ export function MessageCard({ messages, isExpanded }: MessageCardProps) { } isExpanded={isExpanded} > + + + ); +} + +export function MessageContent({ + messages, +}: { + messages: SignMessagePolicy[]; +}) { + return ( + <> {messages.map((m, i) => (
-
{m.name ?? `Message ${i + 1}`}
-
+
{m.name ?? `Message ${i + 1}`}
+ +
{/* Domain section */} {Object.values(m.domain).filter((f) => typeof f !== "undefined") .length > 0 && ( @@ -81,7 +94,7 @@ export function MessageCard({ messages, isExpanded }: MessageCardProps) {
))} - + ); } @@ -101,7 +114,7 @@ export function CollapsibleRow({ title, children }: CollapsibleRowProps) { variant={value ? "minus-line" : "plus-line"} size="sm" /> -
{title}
+
{title}
@@ -119,12 +132,12 @@ interface ValueRowProps { export function ValueRow({ values }: ValueRowProps) { return ( -
- +
+
{values.map((f) => ( -
- {f.name}: {f.value} +
+ {f.name}: {f.value}
))}