From 76950877e41a965901cc867a743be0a4140b5b06 Mon Sep 17 00:00:00 2001 From: JunichiSugiura Date: Thu, 5 Dec 2024 18:01:52 +0000 Subject: [PATCH] Set expiresAt based on selected duration --- .../keychain/src/components/connect/CreateSession.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/keychain/src/components/connect/CreateSession.tsx b/packages/keychain/src/components/connect/CreateSession.tsx index ac67c4094..08d1ff83f 100644 --- a/packages/keychain/src/components/connect/CreateSession.tsx +++ b/packages/keychain/src/components/connect/CreateSession.tsx @@ -6,7 +6,7 @@ import { useCallback, useEffect, useMemo, useState } from "react"; import { useConnection } from "hooks/connection"; import { ControllerErrorAlert } from "components/ErrorAlert"; import { SessionConsent } from "components/connect"; -import { DEFAULT_SESSION_DURATION, SESSION_EXPIRATION } from "const"; +import { DEFAULT_SESSION_DURATION } from "const"; import { Upgrade } from "./Upgrade"; import { ErrorCode } from "@cartridge/account-wasm"; import { SessionSummary } from "components/SessionSummary"; @@ -24,9 +24,7 @@ export function CreateSession({ const [isConnecting, setIsConnecting] = useState(false); const [isDisabled, setIsDisabled] = useState(false); const [duration, setDuration] = useState(DEFAULT_SESSION_DURATION); - const expiresAt = useMemo(() => { - return SESSION_EXPIRATION - }, []) + const expiresAt = useMemo(() => duration + BigInt(Math.floor(Date.now() / 1000)), [duration]) const [maxFee] = useState(); const [error, setError] = useState(); @@ -35,7 +33,7 @@ export function CreateSession({ const normalizedChainId = normalizeChainId(chainId); const violatingPolicy = policies.messages?.find( - (policy) => + (policy: TypedDataPolicy) => "domain" in policy && (!policy.domain.chainId || normalizeChainId(policy.domain.chainId) !== normalizedChainId), @@ -105,7 +103,7 @@ export function CreateSession({
Expires in{" "}