@@ -87,7 +87,7 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> with TrezorAuthMixin {
87
87
88
88
final weakPasswordsAllowed = await _areWeakPasswordsAllowed ();
89
89
90
- final authStream = _kdfSdk.auth.signInStream (
90
+ await _kdfSdk.auth.signIn (
91
91
walletName: event.wallet.name,
92
92
password: event.password,
93
93
options: AuthOptions (
@@ -97,28 +97,14 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> with TrezorAuthMixin {
97
97
allowWeakPassword: weakPasswordsAllowed,
98
98
),
99
99
);
100
-
101
- await for (final authState in authStream) {
102
- if (authState.status == AuthenticationStatus .completed) {
103
- final user = authState.user;
104
- if (user != null ) {
105
- _log.info ('logged in from a wallet' );
106
- emit (AuthBlocState .loggedIn (user));
107
- _listenToAuthStateChanges ();
108
- } else {
109
- emit (AuthBlocState .error (AuthException .notSignedIn ()));
110
- }
111
- break ;
112
- } else if (authState.status == AuthenticationStatus .error) {
113
- emit (AuthBlocState .error (
114
- AuthException (authState.message ?? 'Login failed' ,
115
- type: AuthExceptionType .generalAuthError),
116
- ));
117
- break ;
118
- } else {
119
- emit (AuthBlocState .loading ());
120
- }
100
+ final KdfUser ? currentUser = await _kdfSdk.auth.currentUser;
101
+ if (currentUser == null ) {
102
+ return emit (AuthBlocState .error (AuthException .notSignedIn ()));
121
103
}
104
+
105
+ _log.info ('logged in from a wallet' );
106
+ emit (AuthBlocState .loggedIn (currentUser));
107
+ _listenToAuthStateChanges ();
122
108
} catch (e, s) {
123
109
if (e is AuthException ) {
124
110
// Preserve the original error type for specific errors like incorrect password
@@ -171,7 +157,7 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> with TrezorAuthMixin {
171
157
172
158
final weakPasswordsAllowed = await _areWeakPasswordsAllowed ();
173
159
174
- final authStream = _kdfSdk.auth.registerStream (
160
+ await _kdfSdk.auth.register (
175
161
password: event.password,
176
162
walletName: event.wallet.name,
177
163
options: AuthOptions (
@@ -182,33 +168,17 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> with TrezorAuthMixin {
182
168
),
183
169
);
184
170
185
- await for (final authState in authStream) {
186
- if (authState.status == AuthenticationStatus .completed) {
187
- final user = authState.user;
188
- if (user != null ) {
189
- _log.info ('registered from a wallet' );
190
- await _kdfSdk.setWalletType (event.wallet.config.type);
191
- await _kdfSdk.confirmSeedBackup (hasBackup: false );
192
- await _kdfSdk.addActivatedCoins (enabledByDefaultCoins);
193
- emit (AuthBlocState .loggedIn (user));
194
- _listenToAuthStateChanges ();
195
- } else {
196
- emit (AuthBlocState .error (
197
- AuthException ('Registration failed' ,
198
- type: AuthExceptionType .generalAuthError),
199
- ));
200
- }
201
- break ;
202
- } else if (authState.status == AuthenticationStatus .error) {
203
- emit (AuthBlocState .error (
204
- AuthException (authState.message ?? 'Registration failed' ,
205
- type: AuthExceptionType .generalAuthError),
206
- ));
207
- break ;
208
- } else {
209
- emit (AuthBlocState .loading ());
210
- }
171
+ _log.info ('registered from a wallet' );
172
+ await _kdfSdk.setWalletType (event.wallet.config.type);
173
+ await _kdfSdk.confirmSeedBackup (hasBackup: false );
174
+ await _kdfSdk.addActivatedCoins (enabledByDefaultCoins);
175
+
176
+ final currentUser = await _kdfSdk.auth.currentUser;
177
+ if (currentUser == null ) {
178
+ throw Exception ('Registration failed: user is not signed in' );
211
179
}
180
+ emit (AuthBlocState .loggedIn (currentUser));
181
+ _listenToAuthStateChanges ();
212
182
} catch (e, s) {
213
183
final errorMsg = 'Failed to register wallet ${event .wallet .name }' ;
214
184
_log.shout (errorMsg, e, s);
@@ -235,7 +205,7 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> with TrezorAuthMixin {
235
205
236
206
final weakPasswordsAllowed = await _areWeakPasswordsAllowed ();
237
207
238
- final authStream = _kdfSdk.auth.registerStream (
208
+ await _kdfSdk.auth.register (
239
209
password: event.password,
240
210
walletName: event.wallet.name,
241
211
mnemonic: Mnemonic .plaintext (event.seed),
@@ -247,40 +217,16 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> with TrezorAuthMixin {
247
217
),
248
218
);
249
219
250
- await for (final authState in authStream) {
251
- if (authState.status == AuthenticationStatus .completed) {
252
- final user = authState.user;
253
- if (user != null ) {
254
- _log.info ('restored from a wallet' );
255
- await _kdfSdk.setWalletType (event.wallet.config.type);
256
- await _kdfSdk.confirmSeedBackup (
257
- hasBackup: event.wallet.config.hasBackup);
258
- await _kdfSdk.addActivatedCoins (enabledByDefaultCoins);
259
- emit (AuthBlocState .loggedIn (user));
260
-
261
- if (event.wallet.isLegacyWallet) {
262
- await _kdfSdk
263
- .addActivatedCoins (event.wallet.config.activatedCoins);
264
- await _walletsRepository.deleteWallet (event.wallet);
265
- }
266
- _listenToAuthStateChanges ();
267
- } else {
268
- emit (AuthBlocState .error (
269
- AuthException ('Restoration failed' ,
270
- type: AuthExceptionType .generalAuthError),
271
- ));
272
- }
273
- break ;
274
- } else if (authState.status == AuthenticationStatus .error) {
275
- emit (AuthBlocState .error (
276
- AuthException (authState.message ?? 'Restoration failed' ,
277
- type: AuthExceptionType .generalAuthError),
278
- ));
279
- break ;
280
- } else {
281
- emit (AuthBlocState .loading ());
282
- }
220
+ _log.info ('restored from a wallet' );
221
+ await _kdfSdk.setWalletType (event.wallet.config.type);
222
+ await _kdfSdk.confirmSeedBackup (hasBackup: event.wallet.config.hasBackup);
223
+ await _kdfSdk.addActivatedCoins (enabledByDefaultCoins);
224
+
225
+ final currentUser = await _kdfSdk.auth.currentUser;
226
+ if (currentUser == null ) {
227
+ throw Exception ('Registration failed: user is not signed in' );
283
228
}
229
+ emit (AuthBlocState .loggedIn (currentUser));
284
230
285
231
// Delete legacy wallet on successful restoration & login to avoid
286
232
// duplicates in the wallet list
0 commit comments