Skip to content

Commit 3314f23

Browse files
authored
feat: Session management (#1722)
Depends on https://github.com/cartridge-gg/internal/pull/3080
1 parent fc568ab commit 3314f23

File tree

11 files changed

+399
-240
lines changed

11 files changed

+399
-240
lines changed

.github/workflows/e2e.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ on:
55
types:
66
- 'vercel.deployment.success'
77
jobs:
8-
debug-event:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- name: Debug Event Information
12-
run: |
13-
echo "Event name: ${{ github.event_name }}"
14-
echo "Event action: ${{ github.event.action }}"
15-
echo "Client payload: ${{ toJson(github.event.client_payload) }}"
16-
echo "Full event: ${{ toJson(github.event) }}"
17-
188
run-e2es:
199
permissions:
2010
contents: read
@@ -30,14 +20,14 @@ jobs:
3020
- name: Install dependencies
3121
run: npm install -g pnpm && pnpm install
3222
- name: Install Playwright Browsers
33-
run: pnpm exec playwright install --with-deps
23+
run: npx playwright install --with-deps
3424
- name: Run Playwright tests
35-
run: pnpm exec playwright test
25+
run: npx playwright test
3626
env:
3727
BASE_URL: ${{ github.event.client_payload.url }}
3828
- uses: actions/upload-artifact@v4
39-
if: always()
29+
if: ${{ !cancelled() }}
4030
with:
4131
name: playwright-report
4232
path: playwright-report/
43-
retention-days: 30
33+
retention-days: 30

packages/keychain/src/components/settings/index.tsx

Lines changed: 13 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ import {
1515
SheetFooter,
1616
SheetTrigger,
1717
SignOutIcon,
18-
Skeleton,
1918
} from "@cartridge/ui";
20-
import {
21-
CredentialMetadata,
22-
useControllerQuery,
23-
} from "@cartridge/ui/utils/api/cartridge";
19+
import { useControllerQuery } from "@cartridge/ui/utils/api/cartridge";
2420
import { useCallback, useMemo, useState } from "react";
2521
import { constants } from "starknet";
2622
import CurrencySelect from "./currency-select";
@@ -31,8 +27,8 @@ import {
3127
RegisteredAccountCard,
3228
} from "./registered-account-card";
3329
import { SectionHeader } from "./section-header";
34-
import { Session, SessionCard } from "./session-card";
35-
import { SignerCard } from "./signer-card";
30+
import { SessionsSection } from "./sessions/sessions-section";
31+
import { SignersSection } from "./signers/signers-section";
3632

3733
enum State {
3834
SETTINGS,
@@ -42,23 +38,11 @@ enum State {
4238

4339
// Feature flag configuration
4440
interface FeatureFlags {
45-
sessions: boolean;
4641
signers: boolean;
4742
registeredAccounts: boolean;
4843
currency: boolean;
4944
}
5045

51-
// MOCK DATA
52-
const sessions: Session[] = [
53-
{
54-
sessionName: "Session 1",
55-
expiresAt: BigInt(14400), // 4 hours in seconds
56-
},
57-
{
58-
sessionName: "Session 2",
59-
expiresAt: BigInt(7200), // 2 hours in seconds
60-
},
61-
];
6246
const registeredAccounts: RegisteredAccount[] = [
6347
{
6448
accountName: "clicksave.stark",
@@ -74,18 +58,20 @@ export function Settings() {
7458
// Feature flags - can be moved to environment variables or API config later
7559
const featureFlags = useMemo<FeatureFlags>(
7660
() => ({
77-
sessions: false,
7861
signers: true,
7962
registeredAccounts: false,
8063
currency: false,
8164
}),
8265
[],
8366
);
8467

85-
const data = useControllerQuery({
86-
username: controller?.username() ?? "",
87-
chainId: constants.NetworkName.SN_MAIN,
88-
});
68+
const controllerQuery = useControllerQuery(
69+
{
70+
username: controller?.username() ?? "",
71+
chainId: constants.NetworkName.SN_MAIN,
72+
},
73+
{ refetchOnMount: "always" },
74+
);
8975

9076
const handleLogout = useCallback(() => {
9177
try {
@@ -114,76 +100,10 @@ export function Settings() {
114100
/>
115101

116102
<LayoutContent className="gap-6">
117-
{/* SESSION */}
118-
{featureFlags.sessions && (
119-
<section className="space-y-4">
120-
<SectionHeader
121-
title="Session Key(s)"
122-
description="Sessions grant permission to your Controller to perform certain game actions on your behalf"
123-
showStatus={true}
124-
/>
125-
<div className="space-y-3">
126-
{sessions.map((i, index) => (
127-
<SessionCard
128-
key={index}
129-
sessionName={i.sessionName}
130-
expiresAt={i.expiresAt}
131-
/>
132-
))}
133-
</div>
134-
<Button
135-
type="button"
136-
variant="outline"
137-
className="py-2.5 px-3 text-foreground-300 gap-1"
138-
>
139-
<PlusIcon size="sm" variant="line" />
140-
<span className="normal-case font-normal font-sans text-sm">
141-
Create Session
142-
</span>
143-
</Button>
144-
</section>
145-
)}
146-
147-
{/* SIGNER */}
148103
{featureFlags.signers && (
149-
<section className="space-y-4">
150-
<SectionHeader
151-
title="Signer(s)"
152-
description="Information associated with registered accounts can be made available to games and applications."
153-
/>
154-
<div className="space-y-3">
155-
{data.isLoading ? (
156-
<Skeleton className="w-full h-10 bg-background-200" />
157-
) : data.isError ? (
158-
<div>Error</div>
159-
) : data.isSuccess && data.data ? (
160-
data.data?.controller?.signers?.map((i, signerIndex) => {
161-
return (
162-
<SignerCard
163-
key={`${signerIndex}`}
164-
signer={i.metadata as CredentialMetadata}
165-
/>
166-
);
167-
})
168-
) : (
169-
<div>No data</div>
170-
)}
171-
</div>
172-
{/* disabled until add signer functionality is implemented */}
173-
{/* <Button */}
174-
{/* type="button" */}
175-
{/* variant="outline" */}
176-
{/* className="py-2.5 px-3 text-foreground-300 gap-1" */}
177-
{/* > */}
178-
{/* <PlusIcon size="sm" variant="line" /> */}
179-
{/* <span className="normal-case font-normal font-sans text-sm"> */}
180-
{/* Add Signer */}
181-
{/* </span> */}
182-
{/* </Button> */}
183-
</section>
104+
<SignersSection controllerQuery={controllerQuery} />
184105
)}
185106

186-
{/* REGISTERED ACCOUNT */}
187107
{featureFlags.registeredAccounts && (
188108
<section className="space-y-4">
189109
<SectionHeader
@@ -212,7 +132,6 @@ export function Settings() {
212132
</section>
213133
)}
214134

215-
{/* CURRENCY */}
216135
{featureFlags.currency && (
217136
<section className="space-y-4">
218137
<SectionHeader
@@ -222,6 +141,8 @@ export function Settings() {
222141
<CurrencySelect />
223142
</section>
224143
)}
144+
145+
<SessionsSection controllerQuery={controllerQuery} />
225146
</LayoutContent>
226147

227148
<LayoutFooter>
Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
1+
import { cn } from "@cartridge/ui/utils";
12
import React from "react";
23
import { Status } from "./status";
3-
import { cn } from "@cartridge/ui/utils";
44

55
export interface SectionHeaderProps {
66
title: string;
77
description: string;
88
showStatus?: boolean;
9+
isActive?: boolean;
10+
extraContent?: React.ReactNode;
911
}
1012

1113
export const SectionHeader = React.forwardRef<
1214
HTMLDivElement,
1315
React.HTMLAttributes<HTMLDivElement> & SectionHeaderProps
14-
>(({ className, title, description, showStatus = false, ...props }, ref) => {
15-
return (
16-
<div ref={ref} className={cn("space-y-2", className)} {...props}>
17-
<div className="flex flex-row items-center justify-between">
18-
<h1 className="text-foreground-200 text-sm font-medium">{title}</h1>
19-
{showStatus && <Status isActive={false} />}
16+
>(
17+
(
18+
{
19+
className,
20+
title,
21+
description,
22+
showStatus = false,
23+
isActive = false,
24+
extraContent,
25+
...props
26+
},
27+
ref,
28+
) => {
29+
return (
30+
<div ref={ref} className={cn("space-y-2", className)} {...props}>
31+
<div className="flex flex-row items-center justify-between">
32+
<h1 className="text-foreground-200 text-sm font-medium">{title}</h1>
33+
{showStatus && <Status isActive={isActive} />}
34+
{extraContent}
35+
</div>
36+
<p className="text-foreground-300 text-xs font-normal">{description}</p>
2037
</div>
21-
<p className="text-foreground-300 text-xs font-normal">{description}</p>
22-
</div>
23-
);
24-
});
38+
);
39+
},
40+
);
2541

2642
SectionHeader.displayName = "SectionHeader";

packages/keychain/src/components/settings/session-card.tsx

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)