diff --git a/packages/keychain/src/components/connect/CreateSession.tsx b/packages/keychain/src/components/connect/CreateSession.tsx index 6d467a7ed..86704818f 100644 --- a/packages/keychain/src/components/connect/CreateSession.tsx +++ b/packages/keychain/src/components/connect/CreateSession.tsx @@ -2,18 +2,24 @@ import { Container, Content, Footer } from "components/layout"; import { BigNumberish, shortString } from "starknet"; import { ControllerError } from "utils/connection"; import { Button, HStack, Text, Checkbox } from "@chakra-ui/react"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useMemo, useState } from "react"; import { useConnection } from "hooks/connection"; import { ControllerErrorAlert } from "components/ErrorAlert"; import { SessionConsent } from "components/connect"; -import { SESSION_EXPIRATION } from "const"; +import { DEFAULT_SESSION_DURATION } from "const"; import { Upgrade } from "./Upgrade"; import { ErrorCode } from "@cartridge/account-wasm"; import { TypedDataPolicy } from "@cartridge/presets"; import { ParsedSessionPolicies } from "hooks/session"; - import { UnverifiedSessionSummary } from "components/session/UnverifiedSessionSummary"; import { VerifiedSessionSummary } from "components/session/VerifiedSessionSummary"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@cartridge/ui-next"; export function CreateSession({ policies, @@ -28,7 +34,11 @@ export function CreateSession({ const [isConnecting, setIsConnecting] = useState(false); const [isDisabled, setIsDisabled] = useState(false); const [isConsent, setIsConsent] = useState(false); - const [expiresAt] = useState(SESSION_EXPIRATION); + const [duration, setDuration] = useState(DEFAULT_SESSION_DURATION); + const expiresAt = useMemo( + () => duration + BigInt(Math.floor(Date.now() / 1000)), + [duration], + ); const [maxFee] = useState(); const [error, setError] = useState(); @@ -36,8 +46,8 @@ export function CreateSession({ if (!chainId) return; const normalizedChainId = normalizeChainId(chainId); - const violatingPolicy = policies?.messages?.find( - (policy) => + const violatingPolicy = policies.messages?.find( + (policy: TypedDataPolicy) => "domain" in policy && (!policy.domain.chainId || normalizeChainId(policy.domain.chainId) !== normalizedChainId), @@ -103,6 +113,29 @@ export function CreateSession({ )}
+
+
Expires in
+ +
+ {!policies?.verified && ( )} + {error && isControllerError(error) && ( )} + + + {!error &&
}
); diff --git a/packages/keychain/src/const.ts b/packages/keychain/src/const.ts index a3852af14..cf3ba415c 100644 --- a/packages/keychain/src/const.ts +++ b/packages/keychain/src/const.ts @@ -2,3 +2,4 @@ export const CARTRIDGE_DISCORD_LINK = "https://discord.gg/cartridge"; export const SESSION_EXPIRATION = BigInt( Math.floor(Date.now() / 1000) + 7 * 24 * 60 * 60, ); // 1 week +export const DEFAULT_SESSION_DURATION = BigInt(7 * 24 * 60 * 60); diff --git a/packages/ui-next/src/components/primitives/select.tsx b/packages/ui-next/src/components/primitives/select.tsx index a1c6ec7dd..359aa2c20 100644 --- a/packages/ui-next/src/components/primitives/select.tsx +++ b/packages/ui-next/src/components/primitives/select.tsx @@ -2,14 +2,14 @@ import * as React from "react"; import { - CaretSortIcon, - CheckIcon, + CheckCircledIcon, ChevronDownIcon, ChevronUpIcon, } from "@radix-ui/react-icons"; import * as SelectPrimitive from "@radix-ui/react-select"; import { cn } from "@/utils"; +import { CaratIcon } from "../icons"; const Select = SelectPrimitive.Root; @@ -24,14 +24,14 @@ const SelectTrigger = React.forwardRef< span]:line-clamp-1", + "flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md bg-secondary px-3 py-2 text-xs font-bold text-foreground placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", className, )} {...props} > {children} - + )); @@ -80,7 +80,7 @@ const SelectContent = React.forwardRef< (({ className, ...props }, ref) => ( )); @@ -123,14 +123,14 @@ const SelectItem = React.forwardRef< - + {children} diff --git a/packages/ui-next/src/themes/dark.css b/packages/ui-next/src/themes/dark.css index d064a347b..062af177e 100644 --- a/packages/ui-next/src/themes/dark.css +++ b/packages/ui-next/src/themes/dark.css @@ -3,13 +3,13 @@ --background: 135 8% 9%; /* bg.background */ --foreground: 0 0% 100%; /* text.primary */ - --popover: 135 8% 9%; /* bg.background */ + --popover: 135 6% 13%; /* bg.primary */ --popover-foreground: 0 0% 100%; /* text.primary */ --primary: 44 96% 61%; /* brand.primary */ --primary-foreground: 135 15% 10%; /* bg.primary */ - --secondary: 135 12% 13%; /* bg.primary */ + --secondary: 135 6% 13%; /* bg.primary */ --secondary-foreground: 0 0% 100%; /* text.primary */ --tertiary: 120 57% 78%; @@ -30,7 +30,7 @@ --destructive: 7 72% 65%; /* text.error */ --destructive-foreground: 7 72% 65%; /* text.error */ - --border: 0 0% 50%; + --border: 135 8% 9%; /* bg.background */ --input: 120 7.5% 15.69%; /* bg.secondary */ --ring: 0 0% 100%; /* text.primary */ diff --git a/packages/ui-next/src/themes/default.css b/packages/ui-next/src/themes/default.css index 88a4878d2..f8749fc70 100644 --- a/packages/ui-next/src/themes/default.css +++ b/packages/ui-next/src/themes/default.css @@ -30,7 +30,7 @@ --destructive: 7 72% 65%; --destructive-foreground: 7 72% 65%; - --border: 0 0% 50%; + --border: 220 60% 99%; --input: 210 2.48% 94.9%; /* bg.secondary */ --ring: 0 0% 0%;