Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sunset Chakra UI except layout components #1245

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"jsdom": "^25.0.1",
"playwright": "^1.47.1",
"postcss": "^8.4.35",
"postcss-import": "^16.1.0",
"prettier": "^2.7.1",
"rollup-plugin-visualizer": "^5.12.0",
"start-server-and-test": "^2.0.9",
Expand Down
27 changes: 0 additions & 27 deletions packages/keychain/src/components/Animation.tsx

This file was deleted.

27 changes: 24 additions & 3 deletions packages/keychain/src/components/ControllerErrorAlert.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import { ControllerErrorAlert as CtrlErrAlert } from "./ErrorAlert";
import { VStack } from "@chakra-ui/react";
import { ErrorCode } from "@cartridge/account-wasm/controller";
import { starknetTransactionExecutionErrorTestCases } from "@/utils/errors";

Expand All @@ -17,7 +16,7 @@ export const All: Story = {};

function ControllerErrorAlert() {
return (
<VStack>
<div className="flex flex-col gap-4">
<CtrlErrAlert
error={{ code: ErrorCode.SignError, message: "blah blah blah..." }}
/>
Expand All @@ -37,6 +36,28 @@ function ControllerErrorAlert() {
}}
/>
))}
</VStack>

<CtrlErrAlert
error={{
code: ErrorCode.StarknetTransactionExecutionError,
data: "Invalid json format",
message: "",
}}
/>
<CtrlErrAlert
error={{
code: ErrorCode.StarknetValidationFailure,
data: "Validation failed",
message: "",
}}
/>
<CtrlErrAlert
error={{
code: ErrorCode.StarknetValidationFailure,
data: "Max fee (200) exceeds balance (100)",
message: "",
}}
/>
</div>
);
}
81 changes: 30 additions & 51 deletions packages/keychain/src/components/ErrorAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
AccordionTrigger,
AccordionContent,
cn,
Separator,
} from "@cartridge/ui-next";
import { Text, HStack, VStack, Divider } from "@chakra-ui/react";
import React, {
ReactElement,
useCallback,
Expand Down Expand Up @@ -269,27 +269,25 @@ export function ControllerErrorAlert({
description = <StackTraceDisplay stackTrace={parsedError.stack} />;
} catch {
title = "Execution error";
description = <Text color="inherit">{error.data}</Text>;
description = error.data;
}
break;
case ErrorCode.StarknetValidationFailure: {
const parsedError = parseValidationError(error);
title = parsedError.summary;
copyText = parsedError.raw;
description = (
<VStack align="start" spacing={1} w="full">
{Object.entries(parsedError.details).map(([key, value]) => (
<Text
key={key}
wordBreak="break-all"
color="inherit"
textAlign="left"
>
{key}: {typeof value === "bigint" ? value.toString() : value}
</Text>
))}
</VStack>
);
description =
typeof parsedError.details === "string" ? (
parsedError.details
) : (
<div className="flex flex-col gap-px">
{Object.entries(parsedError.details).map(([key, value]) => (
<div key={key}>
{key}: {typeof value === "bigint" ? value.toString() : value}
</div>
))}
</div>
);
variant = "warning";
isExpanded = true;
break;
Expand Down Expand Up @@ -330,27 +328,17 @@ function StackTraceDisplay({
);

return (
<VStack align="start" spacing={2} w="full">
<div className="flex flex-col gap-2">
{stackTrace.map((trace, i, arr) => (
<React.Fragment key={i}>
<VStack align="start" spacing={1} w="full">
<div className="flex flex-col gap-1">
{Object.entries(trace).map(
([key, value]) =>
value && (
<HStack
key={key}
w="full"
fontSize="xs"
alignItems="flex-start"
>
<Text
color="opacityBlack.700"
textTransform="capitalize"
w="80px"
flexShrink={0}
>
<div key={key} className="flex items-center gap-2">
<div className="w-20 flex-shrink-0 capitalize text-[black]/50">
{key}
</Text>
</div>
{key === "address" || key === "class" ? (
<Link
to={getExplorerUrl(key, value as string)}
Expand All @@ -362,37 +350,28 @@ function StackTraceDisplay({
})}
</Link>
) : key === "selector" ? (
<Text
wordBreak="break-all"
color="inherit"
textAlign="left"
>
<div className="break-all text-left">
{formatAddress(value as string, {
size: "sm",
})}
</Text>
</div>
) : (
<VStack align="start" spacing={1} w="full">
{(value as string[]).map((line, index) => (
<Text
key={index}
wordBreak="break-all"
color="inherit"
textAlign="left"
>
<div className="flex flex-col gap-1">
{(value as string[]).map((line, i) => (
<div key={i} className="break-all text-left">
{line}
</Text>
</div>
))}
</VStack>
</div>
)}
</HStack>
</div>
),
)}
</VStack>
{i !== arr.length - 1 && <Divider borderColor="darkGray.100" />}
</div>
{i !== arr.length - 1 && <Separator />}
</React.Fragment>
))}
</VStack>
</div>
);
}

Expand Down
34 changes: 6 additions & 28 deletions packages/keychain/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { PropsWithChildren, useEffect } from "react";
import { Container, Content, Footer } from "./layout";
import { AlertIcon, ExternalIcon, Button } from "@cartridge/ui-next";
import { HStack, Text } from "@chakra-ui/react";
import { useConnection } from "@/hooks/connection";
import { CARTRIDGE_DISCORD_LINK } from "@/const";
import { usePostHog } from "posthog-js/react";
Expand Down Expand Up @@ -48,33 +47,12 @@ export function ErrorPage({ error }: { error: Error }) {
icon={<AlertIcon size="lg" />}
>
<Content gap={4}>
<HStack
bg="solid.primary"
borderColor="solid.secondary"
borderWidth={1}
w="full"
px={4}
py={6}
borderRadius="base"
>
<Text w="full" fontSize="sm">
{error.message}
</Text>
</HStack>
<div className="flex w-full px-4 py-6 bg-secondary border border-quaternary rounded">
<p className="w-full text-sm">{error.message}</p>
</div>

<HStack
bg="solid.primary"
borderColor="solid.secondary"
borderWidth={1}
w="full"
px={4}
py={6}
borderRadius="base"
justifyContent="space-between"
>
<Text fontSize="sm" fontWeight={600}>
Get help
</Text>
<div className="flex items-center justify-between w-full px-4 py-6 bg-secondary border border-quaternary rounded">
<p className="text-sm font-semibold">Get help</p>

<Link
to={CARTRIDGE_DISCORD_LINK}
Expand All @@ -84,7 +62,7 @@ export function ErrorPage({ error }: { error: Error }) {
<div>Cartridge Discord</div>
<ExternalIcon size="sm" />
</Link>
</HStack>
</div>
</Content>

<Footer>
Expand Down
36 changes: 10 additions & 26 deletions packages/keychain/src/components/Fees.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useState } from "react";
import { HStack, Spacer, Text, VStack } from "@chakra-ui/react";
import { formatUnits } from "viem";
import { useChainId } from "@/hooks/connection";
import { ErrorAlertIcon, EthereumIcon, Spinner } from "@cartridge/ui-next";
Expand Down Expand Up @@ -29,13 +28,7 @@ export function Fees({
}, [chainId, maxFee]);

return (
<VStack
w="full"
overflow="hidden"
borderRadius="base"
spacing="1px"
align="flex-start"
>
<div className="w-full overflow-hidden rounded">
{formattedFee ? (
<LineItem
name="Network Fee"
Expand All @@ -46,7 +39,7 @@ export function Fees({
) : (
<LineItem name="Calculating Fees" isLoading />
)}
</VStack>
</div>
);
}

Expand All @@ -63,29 +56,20 @@ function LineItem({
variant?: Variant;
}) {
return (
<HStack w="full" h="40px" p={4} bg="solid.primary" color="text.secondary">
<Text
fontSize="xs"
color="inherit"
textTransform="uppercase"
fontWeight="bold"
>
{name}
</Text>
<Spacer />
<div className="flex items-center w-full h-10 p-4 bg-secondary text-muted-foreground">
<p className="text-xs uppercase font-bold">{name}</p>
<div className="flex-1" />

{isLoading ? (
<Spinner />
) : (
<HStack gap={0}>
<div className="flex items-center gap-0">
{variant && <ErrorAlertIcon variant={variant} />}
{value !== "FREE" && (
<EthereumIcon className="text-secondary-foreground" />
)}
<Text fontSize={13}>{value}</Text>
</HStack>
{value !== "FREE" && <EthereumIcon className="text-foreground" />}
<p className="text-sm">{value}</p>
</div>
)}
</HStack>
</div>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Meta, StoryObj } from "@storybook/react";

import { AmountSelection } from "./AmountSelection";

const meta = {
component: AmountSelection,
args: {
amount: 1,
enableCustom: true,
},
} satisfies Meta<typeof AmountSelection>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {};
Loading
Loading