@@ -67,6 +67,17 @@ export type LoginToPasskeyArgs = {
6767
6868export type LoginArgs = LoginToWalletArgs | LoginToMnemonicArgs | LoginToPasskeyArgs
6969
70+ export type SignupResult =
71+ | {
72+ type : 'signup'
73+ wallet : Address . Address
74+ }
75+ | {
76+ type : 'login'
77+ wallet : Address . Address
78+ requestId : string
79+ }
80+
7081export function isLoginToWalletArgs ( args : LoginArgs ) : args is LoginToWalletArgs {
7182 return 'wallet' in args
7283}
@@ -356,14 +367,14 @@ export class Wallets {
356367 return commitment . target
357368 }
358369
359- async signUp ( args : SignupArgs ) {
370+ async signUp ( args : SignupArgs ) : Promise < SignupResult > {
360371 const loginSigner = await this . prepareSignUp ( args )
361372
362373 // If there is an existing wallet callback, we check if any wallet already exist for this login signer
363374 if ( this . walletSelectionUiHandler ) {
364375 const existingWallets = await State . getWalletsFor ( this . shared . sequence . stateProvider , loginSigner . signer )
365376 if ( existingWallets . length > 0 ) {
366- const result = await this . walletSelectionUiHandler ( {
377+ const selectedWallet = await this . walletSelectionUiHandler ( {
367378 existingWallets : existingWallets . map ( ( w ) => w . wallet ) ,
368379 signerAddress : await loginSigner . signer . address ,
369380 context : isAuthCodePkceArgs ( args )
@@ -376,9 +387,17 @@ export class Wallets {
376387 } ,
377388 } )
378389
379- if ( result ) {
380- // A wallet was selected, we can exit early
381- return
390+ if ( selectedWallet ) {
391+ // If a wallet was selected, we login to it
392+ const requestId = await this . login ( {
393+ wallet : selectedWallet ,
394+ } )
395+
396+ return {
397+ type : 'login' ,
398+ wallet : selectedWallet ,
399+ requestId,
400+ }
382401 }
383402 }
384403 } else {
@@ -459,10 +478,10 @@ export class Wallets {
459478 useGuard : ! args . noGuard ,
460479 } )
461480
462- return wallet . address
481+ return { type : 'signup' , wallet : wallet . address }
463482 }
464483
465- async login ( args : LoginArgs ) : Promise < string | undefined > {
484+ async login ( args : LoginArgs ) : Promise < string > {
466485 if ( isLoginToWalletArgs ( args ) ) {
467486 const prevWallet = await this . exists ( args . wallet )
468487 if ( prevWallet ) {
0 commit comments