4747 class =" mt-1"
4848 />
4949
50- <!-- For new accounts, show a simple message -->
50+ <!-- For new accounts creating session in two steps -->
5151 <div
52- v-if =" !isLoggedIn"
52+ v-if =" accountCreated && hasSessionParams"
53+ class =" space-y-2 mt-2"
54+ >
55+ <div class =" bg-neutral-975 rounded-[28px]" >
56+ <div class =" px-5 py-2 text-neutral-400" >
57+ Permissions
58+ </div >
59+ <CommonLine class =" text-neutral-100" >
60+ <div class =" divide-y divide-neutral-800" >
61+ <div class =" flex items-center gap-2 py-3 px-3" >
62+ <IconsFingerprint class =" w-7 h-7" />
63+ <div >Act on your behalf</div >
64+ </div >
65+ <div class =" flex items-center gap-2 py-3 px-3" >
66+ <IconsClock class =" w-7 h-7" />
67+ <div >{{ sessionExpiry }}</div >
68+ </div >
69+ </div >
70+ </CommonLine >
71+ </div >
72+ </div >
73+ <SessionTokens
74+ v-if =" accountCreated && hasSessionParams"
75+ :onchain-actions-count =" onchainActionsCount"
76+ :fetch-tokens-error =" fetchTokensError"
77+ :tokens-loading =" tokensLoading"
78+ :spend-limit-tokens =" spendLimitTokens"
79+ :has-unlimited-spend =" hasUnlimitedSpend"
80+ :total-usd =" totalUsd"
81+ class =" mt-1"
82+ />
83+
84+ <!-- For new accounts without session yet, show a simple message -->
85+ <div
86+ v-if =" !isLoggedIn && !accountCreated"
5387 class =" space-y-2 mt-2"
5488 >
5589 <div class =" bg-neutral-975 rounded-[28px]" >
5993 <CommonLine class =" text-neutral-100" >
6094 <div class =" py-3 px-3" >
6195 <p class =" text-sm text-neutral-300" >
62- A new smart account will be created for you. You can add spending permissions later when needed.
96+ A new smart account will be created for you.
97+ <span v-if =" hasSessionParams" >After that, you'll set up spending permissions.</span >
98+ <span v-else >You can add spending permissions later when needed.</span >
6399 </p >
64100 </div >
65101 </CommonLine >
@@ -168,12 +204,18 @@ const props = defineProps({
168204const { appMeta, appOrigin } = useAppMeta ();
169205const { login } = useAccountStore ();
170206const { isLoggedIn } = storeToRefs (useAccountStore ());
171- const { responseInProgress, requestChainId } = storeToRefs (useRequestsStore ());
172- const { createAccount } = useAccountCreate (requestChainId );
207+ const { responseInProgress, requestChainId, requestPaymaster } = storeToRefs (useRequestsStore ());
208+ const { createAccount, registerInProgress : accountCreationInProgress } = useAccountCreate (requestChainId );
173209const { respond, deny } = useRequestsStore ();
174210const { getClient } = useClientStore ();
175211const runtimeConfig = useRuntimeConfig ();
176212
213+ // Track if we just created an account and need to create session
214+ const accountCreated = ref (false );
215+ const hasSessionParams = computed (() => {
216+ return props .sessionPreferences .contractCalls && props .sessionPreferences .contractCalls .length > 0 ;
217+ });
218+
177219const defaults = {
178220 expiresAt: BigInt (Math .floor (Date .now () / 1000 ) + 60 * 60 * 24 ), // 24 hours
179221 feeLimit: {
@@ -284,7 +326,7 @@ const scrollDown = () => {
284326 behavior: " smooth" ,
285327 });
286328};
287- const isButtonLoading = computed (() => ! appMeta .value || responseInProgress .value || tokensLoading .value );
329+ const isButtonLoading = computed (() => ! appMeta .value || responseInProgress .value || tokensLoading .value || accountCreationInProgress . value );
288330const confirmButtonAvailable = computed (() => arrivedAtBottom .value );
289331const transitionName = ref (" slide-up" );
290332const previousConfirmAvailable = ref (confirmButtonAvailable .value );
@@ -294,36 +336,53 @@ watch(confirmButtonAvailable, (newVal, oldVal) => {
294336 previousConfirmAvailable .value = newVal ;
295337 }
296338});
297- const mainButtonText = computed (() => isLoggedIn .value ? " Connect" : " Create" );
339+ const mainButtonText = computed (() => {
340+ if (isLoggedIn .value ) return " Connect" ;
341+ if (accountCreated .value ) return " Authorize" ;
342+ return " Create" ;
343+ });
298344
299345const confirmConnection = async () => {
300346 let response: RPCResponseMessage <ExtractReturnType <Method >>[" content" ];
301347 sessionError .value = " " ;
302348
303349 try {
304- if (! isLoggedIn .value ) {
305- // Just create the account - session will be created by the dapp separately
350+ if (! isLoggedIn .value && ! accountCreated . value ) {
351+ // Step 1: Create the account
306352 const accountData = await createAccount ();
307353 if (! accountData ) return ;
354+
308355 // Login with the new account
309356 login ({
310357 address: accountData .address ,
311358 credentialId: accountData .credentialId ,
312359 });
313360
314- // Return account info without session - dapp will create session separately
361+ // If session params were provided, show session creation UI
362+ if (hasSessionParams .value ) {
363+ accountCreated .value = true ;
364+ // Force a UI update before returning
365+ await nextTick ();
366+ return ; // Don't respond yet, wait for session creation
367+ }
368+
369+ // No session params, return account info only
315370 response = {
316371 result: constructReturn ({
317372 address: accountData .address ,
318373 chainId: accountData .chainId ,
319- // No session in response - dapp needs to create it separately
320374 prividiumMode: runtimeConfig .public .prividiumMode ,
321375 prividiumProxyUrl: runtimeConfig .public .prividium ?.rpcUrl || " " ,
322376 }),
323377 };
324- } else {
378+ } else if ( accountCreated . value || isLoggedIn . value ) {
325379 // create a new session for the existing account
326- const client = getClient ({ chainId: requestChainId .value });
380+ // Use paymaster if provided (needed for newly created accounts with no ETH)
381+ const client = getClient ({
382+ chainId: requestChainId .value ,
383+ usePaymaster: !! requestPaymaster .value ,
384+ paymasterAddress: requestPaymaster .value ,
385+ });
327386 const sessionKey = generatePrivateKey ();
328387 const session = {
329388 sessionKey ,
0 commit comments