Skip to content

Commit

Permalink
Set expiresAt based on selected duration
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiSugiura committed Dec 5, 2024
1 parent 23ad742 commit 7695087
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/keychain/src/components/connect/CreateSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -24,9 +24,7 @@ export function CreateSession({
const [isConnecting, setIsConnecting] = useState(false);
const [isDisabled, setIsDisabled] = useState(false);
const [duration, setDuration] = useState<bigint>(DEFAULT_SESSION_DURATION);
const expiresAt = useMemo(() => {
return SESSION_EXPIRATION
}, [])
const expiresAt = useMemo(() => duration + BigInt(Math.floor(Date.now() / 1000)), [duration])
const [maxFee] = useState<BigNumberish>();
const [error, setError] = useState<ControllerError | Error>();

Expand All @@ -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),
Expand Down Expand Up @@ -105,7 +103,7 @@ export function CreateSession({
<div>Expires in{" "}</div>
<Select value={duration.toString()}
onValueChange={val => {
console.log(val)
setDuration(BigInt(val))
}}>
<SelectTrigger className="w-28" >
<SelectValue defaultValue={(60 * 60 * 24).toString()} placeholder="1 HR" />
Expand Down

0 comments on commit 7695087

Please sign in to comment.