@@ -25,14 +25,8 @@ import Theme
2525 @State private var isPresentedManageSubscription = false
2626 @State var isLogoutConfirmationDisplayed = false
2727 @State var isLogoutLoading = false
28- @State var isPinCodeDisplayed = false
2928 @State var isLinkAccountAvailable = false
30- @State var pinCode : String = " "
31- @State var isAutologinLoading = false
32- @State var isAutologinError = false
33- @State var autologinErrorMessage = " "
34- @State var autologinURL = " "
35- @State var autologinTask : Task < Void , Never > ?
29+ @State var autologinState = AutologinState ( )
3630
3731 @Binding private var path : NavigationPath
3832
@@ -75,15 +69,7 @@ import Theme
7569#if os(iOS)
7670 . manageSubscriptionsSheet( isPresented: $isPresentedManageSubscription)
7771#endif
78- . overlay {
79- if isPinCodeDisplayed, !pinCode. isEmpty {
80- PinCodeView (
81- isDisplayed: $isPinCodeDisplayed,
82- pinCode: $pinCode,
83- url: $autologinURL
84- )
85- }
86- }
72+ . autologinOverlay( state: autologinState, onRetry: { navigateToAccount ( ) } )
8773 . background {
8874 NymColor . background
8975 . ignoresSafeArea ( )
@@ -100,29 +86,6 @@ import Theme
10086 )
10187 }
10288 }
103- . overlay {
104- if isAutologinLoading {
105- ActionDialogView (
106- viewModel: ActionDialogViewModel (
107- isDisplayed: $isAutologinLoading,
108- configuration: autologinLoadingConfiguration,
109- impactGenerator: . shared,
110- isLoading: . constant( true )
111- )
112- )
113- }
114- }
115- . overlay {
116- if isAutologinError {
117- ActionDialogView (
118- viewModel: ActionDialogViewModel (
119- isDisplayed: $isAutologinError,
120- configuration: autologinErrorConfiguration,
121- impactGenerator: . shared
122- )
123- )
124- }
125- }
12689 . task {
12790 await updateIsAccountLinkAvailable ( )
12891 }
@@ -338,45 +301,18 @@ extension AccountAndDevicesView {
338301
339302 func navigateToAccount( ) {
340303 impactGenerator. softImpact ( )
341- isAutologinLoading = true
342-
343- autologinTask = Task {
344- await autologin ( kind: . autologinView)
345- }
304+ autologinState. start ( kind: . autologinView, using: credentialsManager)
346305 }
347306
348307 func navigateToPlanPurchase( ) {
349308 impactGenerator. softImpact ( )
350309#if os(iOS)
351310 path. append ( SettingLink . generatePassphrase ( displayPurchaseView: true ) )
352311#elseif os(macOS)
353- isAutologinLoading = true
354-
355- autologinTask = Task {
356- await autologin ( kind: . autologinRenew)
357- }
312+ autologinState. start ( kind: . autologinRenew, using: credentialsManager)
358313#endif
359314 }
360315
361- func autologin( kind: NymDeeplinkKind ) async {
362- do {
363- guard let result = try await credentialsManager. autologin ( kind: kind) else {
364- isAutologinLoading = false
365- return
366- }
367- isAutologinLoading = false
368- pinCode = result. pinCode
369- autologinURL = result. url
370- isPinCodeDisplayed = true
371- } catch is CancellationError {
372- isAutologinLoading = false
373- } catch {
374- isAutologinLoading = false
375- autologinErrorMessage = error. localizedDescription
376- isAutologinError = true
377- }
378- }
379-
380316 func linkAccount( ) async {
381317 impactGenerator. softImpact ( )
382318 let link = try ? await credentialsManager. privyLogin ( kind: . privyLink)
0 commit comments