@@ -26,7 +26,7 @@ class CoinsBloc extends Bloc<CoinsEvent, CoinsState> {
26
26
this ._mm2Api,
27
27
) : super (CoinsState .initial ()) {
28
28
on < CoinsStarted > (_onCoinsStarted, transformer: droppable ());
29
- // TODO: move auth listener to ui layer: bloclistener fires auth events
29
+ // TODO: move auth listener to ui layer: bloclistener should fire auth events
30
30
on < CoinsBalanceMonitoringStarted > (_onCoinsBalanceMonitoringStarted);
31
31
on < CoinsBalanceMonitoringStopped > (_onCoinsBalanceMonitoringStopped);
32
32
on < CoinsBalancesRefreshed > (_onCoinsRefreshed, transformer: droppable ());
@@ -81,7 +81,7 @@ class CoinsBloc extends Bloc<CoinsEvent, CoinsState> {
81
81
if (coin == null ) return ;
82
82
83
83
// Get pubkeys from the SDK through the repo
84
- final asset = _kdfSdk.assets.assetsFromTicker (event.coinId).single ;
84
+ final asset = _kdfSdk.assets.available[coin.id] ! ;
85
85
final pubkeys = await _kdfSdk.pubkeys.getPubkeys (asset);
86
86
87
87
// Update state with new pubkeys
@@ -323,13 +323,22 @@ class CoinsBloc extends Bloc<CoinsEvent, CoinsState> {
323
323
CoinsSessionStarted event,
324
324
Emitter <CoinsState > emit,
325
325
) async {
326
- _coinsRepo.flushCache ();
327
- _currentUserCache = event.signedInUser;
328
- await _activateLoginWalletCoins (emit);
329
- emit (state.copyWith (loginActivationFinished: true ));
326
+ try {
327
+ _coinsRepo.flushCache ();
328
+ _currentUserCache = event.signedInUser;
329
+ await _activateLoginWalletCoins (emit);
330
+ emit (state.copyWith (loginActivationFinished: true ));
330
331
331
- add (CoinsBalancesRefreshed ());
332
- add (CoinsBalanceMonitoringStarted ());
332
+ add (CoinsBalancesRefreshed ());
333
+ add (CoinsBalanceMonitoringStarted ());
334
+ } catch (e, s) {
335
+ log (
336
+ 'Error on login: $e ' ,
337
+ isError: true ,
338
+ trace: s,
339
+ path: 'coins_bloc => _onLogin' ,
340
+ ).ignore ();
341
+ }
333
342
}
334
343
335
344
Future <void > _onLogout (
@@ -376,21 +385,20 @@ class CoinsBloc extends Bloc<CoinsEvent, CoinsState> {
376
385
Iterable <String > coins,
377
386
Emitter <CoinsState > emit,
378
387
) async {
379
- // Start off by emitting the newly activated coins so that they all appear
380
- // in the list at once, rather than one at a time as they are activated
381
- _prePopulateListWithActivatingCoins (coins, emit);
382
-
383
388
try {
389
+ // Start off by emitting the newly activated coins so that they all appear
390
+ // in the list at once, rather than one at a time as they are activated
391
+ emit (_prePopulateListWithActivatingCoins (coins));
392
+
384
393
await _kdfSdk.addActivatedCoins (coins);
385
394
} catch (e, s) {
386
395
log (
387
- 'Failed to activate coins in SDK: $e ' ,
396
+ 'Failed to add activated coins to SDK metadata field : $e ' ,
388
397
isError: true ,
389
398
path: 'coins_bloc => _activateCoins' ,
390
399
trace: s,
391
400
).ignore ();
392
- // Update state to reflect failure
393
- return [];
401
+ rethrow ;
394
402
}
395
403
396
404
final enabledAssets = await _kdfSdk.assets.getEnabledCoins ();
@@ -414,10 +422,7 @@ class CoinsBloc extends Bloc<CoinsEvent, CoinsState> {
414
422
return results;
415
423
}
416
424
417
- void _prePopulateListWithActivatingCoins (
418
- Iterable <String > coins,
419
- Emitter <CoinsState > emit,
420
- ) {
425
+ CoinsState _prePopulateListWithActivatingCoins (Iterable <String > coins) {
421
426
final activatingCoins = Map <String , Coin >.fromIterable (
422
427
coins
423
428
.map (
@@ -433,11 +438,9 @@ class CoinsBloc extends Bloc<CoinsEvent, CoinsState> {
433
438
.cast <Coin >(),
434
439
key: (element) => (element as Coin ).abbr,
435
440
);
436
- emit (
437
- state.copyWith (
438
- walletCoins: {...state.walletCoins, ...activatingCoins},
439
- coins: {...state.coins, ...activatingCoins},
440
- ),
441
+ return state.copyWith (
442
+ walletCoins: {...state.walletCoins, ...activatingCoins},
443
+ coins: {...state.coins, ...activatingCoins},
441
444
);
442
445
}
443
446
@@ -466,10 +469,10 @@ class CoinsBloc extends Bloc<CoinsEvent, CoinsState> {
466
469
}
467
470
} catch (e, s) {
468
471
log (
469
- 'Error activating coin ${coin !.id . toString () }' ,
472
+ 'Error activating coin ${coin !.id }' ,
470
473
isError: true ,
471
474
trace: s,
472
- );
475
+ ). ignore () ;
473
476
}
474
477
475
478
return coin;
@@ -478,7 +481,7 @@ class CoinsBloc extends Bloc<CoinsEvent, CoinsState> {
478
481
Future <Coin > _activateTrezorCoin (Coin coin, String coinId) async {
479
482
final asset = _kdfSdk.assets.available[coin.id];
480
483
if (asset == null ) {
481
- log ('Failed to find asset for coin: ${coin .id }' , isError: true );
484
+ log ('Failed to find asset for coin: ${coin .id }' , isError: true ). ignore () ;
482
485
return coin.copyWith (state: CoinState .suspended);
483
486
}
484
487
final accounts = await _trezorBloc.activateCoin (asset);
@@ -525,8 +528,9 @@ class CoinsBloc extends Bloc<CoinsEvent, CoinsState> {
525
528
.map ((coin) => coin.abbr)
526
529
.toList ();
527
530
528
- coinsToBeActivated.addAll (suspended);
529
- coinsToBeActivated.addAll (_getUnactivatedWalletCoins ());
531
+ coinsToBeActivated
532
+ ..addAll (suspended)
533
+ ..addAll (_getUnactivatedWalletCoins ());
530
534
531
535
if (coinsToBeActivated.isEmpty) return ;
532
536
yield await _activateCoins (coinsToBeActivated, emit);
0 commit comments