Potential fix for the race condition of loading a wallet while the name in the shared prefs hasn't updated yet (#1801)
Omar Hatem committed
Nov 13, 2024 at 11:55 UTC
ed5e701d801cd88d4905a06a6f9e2b3aa6dca510
2 files changed
+7
-7
lib/reactions/on_current_wallet_change.dart
-7
@@ -10,9 +10,6 @@ import 'package:cw_core/transaction_history.dart';
10
import 'package:cw_core/balance.dart';
11
import 'package:cw_core/transaction_info.dart';
12
import 'package:mobx/mobx.dart';
13
-import 'package:shared_preferences/shared_preferences.dart';
14
-import 'package:cake_wallet/di.dart';
15
-import 'package:cake_wallet/entities/preferences_key.dart';
13
import 'package:cake_wallet/reactions/check_connection.dart';
14
import 'package:cake_wallet/reactions/on_wallet_sync_status_change.dart';
15
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
@@ -65,10 +62,6 @@ void startCurrentWalletChangeReaction(
62
63
startWalletSyncStatusChangeReaction(wallet, fiatConversionStore);
64
startCheckConnectionReaction(wallet, settingsStore);
68
- await getIt.get<SharedPreferences>().setString(PreferencesKey.currentWalletName, wallet.name);
69
- await getIt
70
- .get<SharedPreferences>()
71
- .setInt(PreferencesKey.currentWalletType, serializeToInt(wallet.type));
65
66
if (wallet.type == WalletType.monero ||
67
wallet.type == WalletType.wownero ||
lib/store/app_store.dart
+7
@@ -1,8 +1,10 @@
1
import 'package:cake_wallet/core/wallet_connect/web3wallet_service.dart';
2
import 'package:cake_wallet/di.dart';
3
+import 'package:cake_wallet/entities/preferences_key.dart';
4
import 'package:cake_wallet/reactions/wallet_connect.dart';
5
import 'package:cake_wallet/utils/exception_handler.dart';
6
import 'package:cw_core/transaction_info.dart';
7
+import 'package:cw_core/wallet_type.dart';
8
import 'package:mobx/mobx.dart';
9
import 'package:cw_core/balance.dart';
10
import 'package:cw_core/wallet_base.dart';
@@ -11,6 +13,7 @@ import 'package:cake_wallet/store/wallet_list_store.dart';
13
import 'package:cake_wallet/store/authentication_store.dart';
14
import 'package:cake_wallet/store/settings_store.dart';
15
import 'package:cake_wallet/store/node_list_store.dart';
16
+import 'package:shared_preferences/shared_preferences.dart';
17
18
part 'app_store.g.dart';
19
@@ -47,5 +50,9 @@ abstract class AppStoreBase with Store {
50
getIt.get<Web3WalletService>().create();
51
await getIt.get<Web3WalletService>().init();
52
}
53
+ await getIt.get<SharedPreferences>().setString(PreferencesKey.currentWalletName, wallet.name);
54
+ await getIt
55
+ .get<SharedPreferences>()
56
+ .setInt(PreferencesKey.currentWalletType, serializeToInt(wallet.type));
57
}
58
}