import { ErrorCode , ScreenName } from '@ulangi/ulangi-common/enums' ; import { ErrorBag } from '@ulangi/ulangi-common/interfaces' ; import { boundClass } from 'autobind-decorator' ; import { RemoteLogger } from '../../RemoteLogger' ; import { AuthDelegate } from '../auth/AuthDelegate' ; import { DialogDelegate } from '../dialog/DialogDelegate' ; import { NavigatorDelegate } from '../navigator/NavigatorDelegate' ; @ boundClass export class WelcomeScreenDelegate { private authDelegate : AuthDelegate ; private navigatorDelegate : NavigatorDelegate ; private dialogDelegate : DialogDelegate ; public constructor ( authDelegate , navigatorDelegate , dialogDelegate ) { this . authDelegate = authDelegate ; this . navigatorDelegate = navigatorDelegate ; this . dialogDelegate = dialogDelegate ; } public signInAsGuest ( ) { RemoteLogger . logEvent ( 'sign_in_as_guest' ) ; this . authDelegate . signInAsGuest ( { onSigningInAsGuest : this . showSigningInAsGuestDialog , onSignInAsGuestSucceeded : ( ) : void => { this . navigatorDelegate . dismissLightBox ( ) ; this . navigatorDelegate . resetTo ( ScreenName . CREATE_FIRST_SET_SCREEN , { } ) ; } , onSignInAsGuestFailed : ( errorBag ) : void => { if ( errorBag . errorCode === ErrorCode . USER__EMAIL_ALREADY_REGISTERED ) { this . signInAsGuest ( ) ; } else { this . showSigningInAsGuestFailedDialog ( errorBag ) ; } } , } ) ; } public navigateToSignInScreen ( ) { this . navigatorDelegate . push ( ScreenName . SIGN_IN_SCREEN , { } ) ; } private showSigningInAsGuestDialog ( ) { this . dialogDelegate . show ( { message : 'Setting up. Please wait...' , } ) ; } private showSigningInAsGuestFailedDialog ( errorBag ) { this . dialogDelegate . showFailedDialog ( errorBag , { title : 'FAILED TO SIGN IN AS GUEST' , } ) ; } }