|
36 | 36 | </template> |
37 | 37 | </CommonAlert> |
38 | 38 |
|
| 39 | + <CommonAlert |
| 40 | + v-if="sessionsFetchError" |
| 41 | + class="mb-4" |
| 42 | + type="error" |
| 43 | + > |
| 44 | + <template #icon> |
| 45 | + <InformationCircleIcon aria-hidden="true" /> |
| 46 | + </template> |
| 47 | + <template #default> |
| 48 | + <p class="text-sm font-semibold"> |
| 49 | + Failed to load sessions |
| 50 | + </p> |
| 51 | + <p class="text-xs mt-1"> |
| 52 | + {{ sessionsFetchError.message }} |
| 53 | + </p> |
| 54 | + </template> |
| 55 | + </CommonAlert> |
| 56 | + |
39 | 57 | <span |
40 | | - v-if="!sessions?.length && !sessionsInProgress" |
41 | | - class="font-thin block text-2xl text-neutral-500 text-center" |
42 | | - >No sessions yet...</span> |
| 58 | + v-if="!sessions?.length && !sessionsInProgress && !sessionsFetchError" |
| 59 | + data-testid="empty-sessions-message" |
| 60 | + class="font-thin block text 2xl text-neutral-500 text-center" |
| 61 | + >No active sessions...</span> |
43 | 62 | <div |
44 | 63 | v-else |
45 | 64 | class="border rounded-3xl divide-y bg-white border-neutral-200 divide-neutral-200 dark:bg-neutral-950 dark:border-neutral-900 dark:divide-neutral-900" |
|
52 | 71 | </template> |
53 | 72 | <template v-else> |
54 | 73 | <SessionRow |
55 | | - v-for="(item, index) in (sessions || [])" |
56 | | - :key="item.sessionId" |
57 | | - :index="((sessions?.length || 0) - index)" |
58 | | - :session-id="item.sessionId" |
59 | | - :session="item.session" |
60 | | - :transaction-hash="item.transactionHash" |
61 | | - :block-number="item.blockNumber" |
62 | | - :timestamp="item.timestamp" |
| 74 | + v-for="item in (sessions || [])" |
| 75 | + :key="item.sessionHash" |
| 76 | + :session-hash="item.sessionHash" |
| 77 | + :session-spec="item.sessionSpec" |
63 | 78 | /> |
64 | 79 | </template> |
65 | 80 | </div> |
66 | | - |
67 | | - <CommonAlert |
68 | | - v-if="defaultChain.id === localhost.id && sessions?.length" |
69 | | - class="mt-4" |
70 | | - > |
71 | | - <template #icon> |
72 | | - <InformationCircleIcon aria-hidden="true" /> |
73 | | - </template> |
74 | | - <template #default> |
75 | | - <p class="text-sm"> |
76 | | - Timestamps on {{ localhost.name }} start from 0 and incremented by 1 with each block. Therefore session time isn't accurate. |
77 | | - </p> |
78 | | - </template> |
79 | | - </CommonAlert> |
80 | 81 | </div> |
81 | 82 | </template> |
82 | 83 |
|
83 | 84 | <script setup lang="ts"> |
84 | 85 | import { InformationCircleIcon } from "@heroicons/vue/20/solid"; |
85 | 86 | import type { Hex } from "viem"; |
86 | | -import { localhost } from "viem/chains"; |
87 | | -import { SessionKeyValidatorAbi } from "zksync-sso-4337/abi"; |
| 87 | +import { listActiveSessions } from "zksync-sso-4337"; |
88 | 88 | import type { SessionConfig } from "zksync-sso-4337/client"; |
89 | 89 |
|
90 | | -const { defaultChain, getPublicClient } = useClientStore(); |
| 90 | +const { defaultChain } = useClientStore(); |
91 | 91 | const { address } = storeToRefs(useAccountStore()); |
92 | 92 |
|
93 | 93 | const { |
94 | 94 | result: sessions, |
95 | 95 | inProgress: sessionsInProgress, |
96 | | - // error: sessionsFetchError, |
| 96 | + error: sessionsFetchError, |
97 | 97 | execute: sessionsFetch, |
98 | 98 | } = useAsync(async () => { |
99 | 99 | const contracts = contractsByChain[defaultChain.id]; |
100 | | - const publicClient = getPublicClient({ chainId: defaultChain.id }); |
101 | | - const logs = await publicClient.getContractEvents({ |
102 | | - abi: SessionKeyValidatorAbi, |
103 | | - address: contracts.session, |
104 | | - eventName: "SessionCreated", |
105 | | - args: { |
106 | | - account: address.value, |
| 100 | +
|
| 101 | + // Get RPC URL from the chain configuration |
| 102 | + const rpcUrl = defaultChain.rpcUrls.default.http[0]; |
| 103 | +
|
| 104 | + // Use the new listActiveSessions function from the SDK |
| 105 | + const { sessions: activeSessions } = await listActiveSessions({ |
| 106 | + account: address.value, |
| 107 | + rpcUrl, |
| 108 | + contracts: { |
| 109 | + sessionValidator: contracts.sessionValidator, |
| 110 | + entryPoint: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", // Standard EntryPoint v0.8 |
| 111 | + accountFactory: contracts.factory, |
| 112 | + webauthnValidator: contracts.webauthnValidator, |
| 113 | + eoaValidator: contracts.eoaValidator, |
| 114 | + guardianExecutor: contracts.guardianExecutor || "0x0000000000000000000000000000000000000000", |
107 | 115 | }, |
108 | | - fromBlock: 0n, |
109 | 116 | }); |
110 | | - const data = logs |
111 | | - .filter((log) => log.args.sessionSpec && log.args.sessionHash) |
112 | | - .map((log) => ({ |
113 | | - session: log.args.sessionSpec! as SessionConfig, |
114 | | - sessionId: log.args.sessionHash!, |
115 | | - transactionHash: log.transactionHash, |
116 | | - blockNumber: log.blockNumber, |
117 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
118 | | - timestamp: new Date(parseInt((log as any).blockTimestamp as Hex, 16) * 1000).getTime(), |
119 | | - })).sort((a, b) => { |
120 | | - if (a.blockNumber < b.blockNumber) return 1; |
121 | | - if (a.blockNumber > b.blockNumber) return -1; |
122 | | - return 0; |
123 | | - }); |
124 | | - return data; |
| 117 | +
|
| 118 | + return activeSessions.map((item: { sessionHash: Hex; sessionSpec: SessionConfig }) => ({ |
| 119 | + sessionHash: item.sessionHash, |
| 120 | + sessionSpec: item.sessionSpec, |
| 121 | + })); |
125 | 122 | }); |
126 | 123 |
|
127 | 124 | sessionsFetch(); |
|
0 commit comments