dev
dart 2,348 lines 96.1 KB
Raw
1 import 'dart:async';
2 import 'dart:convert';
3 import 'dart:io';
4
5 import 'package:cake_wallet/bitcoin/bitcoin.dart';
6 import 'package:cake_wallet/core/utilities.dart';
7 import 'package:cake_wallet/decred/decred.dart';
8 import 'package:cake_wallet/dogecoin/dogecoin.dart';
9 import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
10 import 'package:cake_wallet/core/secure_storage.dart';
11 import 'package:cake_wallet/di.dart';
12 import 'package:cake_wallet/entities/action_list_display_mode.dart';
13 import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart';
14 import 'package:cake_wallet/entities/balance_display_mode.dart';
15 import 'package:cake_wallet/entities/bitcoin_amount_display_mode.dart';
16 import 'package:cake_wallet/entities/cake_2fa_preset_options.dart';
17 import 'package:cake_wallet/entities/country.dart';
18 import 'package:cake_wallet/entities/default_settings_migration.dart';
19 import 'package:cake_wallet/entities/exchange_api_mode.dart';
20 import 'package:cake_wallet/entities/fiat_api_mode.dart';
21 import 'package:cake_wallet/entities/fiat_currency.dart';
22 import 'package:cake_wallet/entities/language_service.dart';
23 import 'package:cake_wallet/entities/pin_code_required_duration.dart';
24 import 'package:cake_wallet/entities/preferences_key.dart';
25 import 'package:cake_wallet/entities/secret_store_key.dart';
26 import 'package:cake_wallet/entities/seed_phrase_length.dart';
27 import 'package:cake_wallet/entities/seed_type.dart';
28 import 'package:cake_wallet/entities/sort_balance_types.dart';
29 import 'package:cake_wallet/entities/sync_status_display_mode.dart';
30 import 'package:cake_wallet/entities/wallet_list_order_types.dart';
31 import 'package:cake_wallet/evm/evm.dart';
32 import 'package:cake_wallet/reactions/wallet_connect.dart';
33 import 'package:cake_wallet/wownero/wownero.dart';
34 import 'package:cake_wallet/zano/zano.dart';
35 import 'package:cake_wallet/zcash/zcash.dart';
36 import 'package:cw_core/transaction_priority.dart';
37 import 'package:cake_wallet/exchange/provider/trocador_exchange_provider.dart';
38 import 'package:cake_wallet/monero/monero.dart';
39 import 'package:cake_wallet/utils/device_info.dart';
40 import 'package:cake_wallet/utils/package_info.dart';
41 import 'package:cake_wallet/view_model/settings/sync_mode.dart';
42 import 'package:cw_core/node.dart';
43 import 'package:cw_core/set_app_secure_native.dart';
44 import 'package:cw_core/utils/print_verbose.dart';
45 import 'package:cw_core/wallet_type.dart';
46 import 'package:device_info_plus/device_info_plus.dart';
47 import 'package:flutter_daemon/flutter_daemon.dart';
48 import 'package:hive/hive.dart';
49 import 'package:mobx/mobx.dart';
50 import 'package:shared_preferences/shared_preferences.dart';
51
52 part 'settings_store.g.dart';
53
54 class SettingsStore = SettingsStoreBase with _$SettingsStore;
55
56 abstract class SettingsStoreBase with Store {
57 SettingsStoreBase(
58 {required SecureStorage secureStorage,
59 required SharedPreferences sharedPreferences,
60 required bool initialShouldShowMarketPlaceInDashboard,
61 required bool initialShowAddressBookPopupEnabled,
62 required SyncStatusDisplayMode initialSyncStatusDisplayMode,
63 required FiatCurrency initialFiatCurrency,
64 required BalanceDisplayMode initialBalanceDisplayMode,
65 required bool initialSaveRecipientAddress,
66 required AutoGenerateSubaddressStatus initialAutoGenerateSubaddressStatus,
67 required MoneroSeedType initialMoneroSeedType,
68 required BitcoinSeedType initialBitcoinSeedType,
69 required NanoSeedType initialNanoSeedType,
70 required bool initialAppSecure,
71 required bool initialDisableTrade,
72 required bool initialDisableAutomaticExchangeStatusUpdates,
73 required FilterListOrderType initialWalletListOrder,
74 required FilterListOrderType initialContactListOrder,
75 required bool initialDisableBulletin,
76 required this.useBlinkProtection,
77 required bool initialWalletListAscending,
78 required bool initialContactListAscending,
79 required FiatApiMode initialFiatMode,
80 required bool initialAllowBiometricalAuthentication,
81 required bool initialEnableDuressPin,
82 required String initialTotpSecretKey,
83 required bool initialUseTOTP2FA,
84 required int initialFailedTokenTrial,
85 required ExchangeApiMode initialExchangeStatus,
86 required int initialPinLength,
87 required String initialLanguageCode,
88 required SyncMode initialSyncMode,
89 required bool initialSyncAll,
90 required bool initialBuiltinTor,
91 // required String initialCurrentLocale,
92 required this.appVersion,
93 required this.deviceName,
94 required Map<WalletType, Node> nodes,
95 required Map<WalletType, Node> powNodes,
96 required this.displayAmountsInSatoshi,
97 required this.shouldShowYatPopup,
98 required this.shouldShowDEuroDisclaimer,
99 required this.shouldShowRepWarning,
100 required this.isBitcoinBuyEnabled,
101 required this.actionlistDisplayMode,
102 required this.pinTimeOutDuration,
103 required this.seedPhraseLength,
104 required Cake2FAPresetsOptions initialCake2FAPresetOptions,
105 required bool initialShouldRequireTOTP2FAForAccessingWallet,
106 required bool initialShouldRequireTOTP2FAForSendsToContact,
107 required bool initialShouldRequireTOTP2FAForSendsToNonContact,
108 required bool initialShouldRequireTOTP2FAForSendsToInternalWallets,
109 required bool initialShouldRequireTOTP2FAForExchangesToInternalWallets,
110 required bool initialShouldRequireTOTP2FAForExchangesToExternalWallets,
111 required bool initialShouldRequireTOTP2FAForAddingContacts,
112 required bool initialShouldRequireTOTP2FAForCreatingNewWallets,
113 required bool initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings,
114 required this.forceDecentralizedExchanges,
115 required this.decentralizedExchangesPromptDismissed,
116 required this.sortBalanceBy,
117 required this.pinNativeTokenAtTop,
118 required this.useEtherscan,
119 required this.useBaseScan,
120 required this.useArbiScan,
121 required this.useBscScan,
122 required this.usePolygonScan,
123 required this.useTronGrid,
124 required this.useMempoolFeeAPI,
125 required List<int> initialEvmHiddenChainIds,
126 required this.defaultNanoRep,
127 required this.defaultBananoRep,
128 required this.lookupsTwitter,
129 required this.lookupsZanoAlias,
130 required this.lookupsMastodon,
131 required this.lookupsYatService,
132 required this.lookupsUnstoppableDomains,
133 required this.lookupsOpenAlias,
134 required this.lookupsENS,
135 required this.lookupsZcashNames,
136 required this.lookupsZcashAddress,
137 required this.lookupsWellKnown,
138 required this.lookupsFio,
139 required this.lookupsNostr,
140 required this.lookupsThorChain,
141 required this.lookupsBip353,
142 required this.lookupsLNUrl,
143 required this.usePayjoin,
144 required this.showPayjoinCard,
145 required this.customBitcoinFeeRate,
146 required this.silentPaymentsCardDisplay,
147 required this.mwebAlwaysScan,
148 required this.mwebCardDisplay,
149 required this.showZcashMissingFundsCard,
150 required this.mwebEnabled,
151 required this.hasEnabledMwebBefore,
152 required this.mwebNodeUri,
153 required this.mwebAdDismissed,
154 required this.balanceHideCounter,
155 required this.zcashMigrationModalViewed,
156 required bool initialEnableAutomaticNodeSwitching,
157 required String initialBackgroundImage,
158 TransactionPriority? initialBitcoinTransactionPriority,
159 TransactionPriority? initialMoneroTransactionPriority,
160 TransactionPriority? initialWowneroTransactionPriority,
161 TransactionPriority? initialHavenTransactionPriority,
162 TransactionPriority? initialLitecoinTransactionPriority,
163 TransactionPriority? initialEthereumTransactionPriority,
164 TransactionPriority? initialEVMTransactionPriority,
165 TransactionPriority? initialPolygonTransactionPriority,
166 TransactionPriority? initialBaseTransactionPriority,
167 TransactionPriority? initialBscTransactionPriority,
168 TransactionPriority? initialBitcoinCashTransactionPriority,
169 TransactionPriority? initialZanoTransactionPriority,
170 TransactionPriority? initialDecredTransactionPriority,
171 TransactionPriority? initialZcashTransactionPriority,
172 TransactionPriority? initialDogecoinTransactionPriority,
173 Country? initialCakePayCountry})
174 : nodes = ObservableMap<WalletType, Node>.of(nodes),
175 powNodes = ObservableMap<WalletType, Node>.of(powNodes),
176 _secureStorage = secureStorage,
177 _sharedPreferences = sharedPreferences,
178 fiatCurrency = initialFiatCurrency,
179 balanceDisplayMode = initialBalanceDisplayMode,
180 shouldSaveRecipientAddress = initialSaveRecipientAddress,
181 autoGenerateSubaddressStatus = initialAutoGenerateSubaddressStatus,
182 moneroSeedType = initialMoneroSeedType,
183 bitcoinSeedType = initialBitcoinSeedType,
184 nanoSeedType = initialNanoSeedType,
185 fiatApiMode = initialFiatMode,
186 allowBiometricalAuthentication = initialAllowBiometricalAuthentication,
187 enableDuressPin = initialEnableDuressPin,
188 selectedCake2FAPreset = initialCake2FAPresetOptions,
189 totpSecretKey = initialTotpSecretKey,
190 useTOTP2FA = initialUseTOTP2FA,
191 numberOfFailedTokenTrials = initialFailedTokenTrial,
192 isAppSecure = initialAppSecure,
193 disableTradeOption = initialDisableTrade,
194 disableAutomaticExchangeStatusUpdates = initialDisableAutomaticExchangeStatusUpdates,
195 disableBulletin = initialDisableBulletin,
196 walletListOrder = initialWalletListOrder,
197 contactListOrder = initialContactListOrder,
198 walletListAscending = initialWalletListAscending,
199 contactListAscending = initialContactListAscending,
200 shouldShowMarketPlaceInDashboard = initialShouldShowMarketPlaceInDashboard,
201 showAddressBookPopupEnabled = initialShowAddressBookPopupEnabled,
202 syncStatusDisplayMode = initialSyncStatusDisplayMode,
203 exchangeStatus = initialExchangeStatus,
204 pinCodeLength = initialPinLength,
205 languageCode = initialLanguageCode,
206 shouldRequireTOTP2FAForAccessingWallet = initialShouldRequireTOTP2FAForAccessingWallet,
207 shouldRequireTOTP2FAForSendsToContact = initialShouldRequireTOTP2FAForSendsToContact,
208 shouldRequireTOTP2FAForSendsToNonContact = initialShouldRequireTOTP2FAForSendsToNonContact,
209 shouldRequireTOTP2FAForSendsToInternalWallets =
210 initialShouldRequireTOTP2FAForSendsToInternalWallets,
211 shouldRequireTOTP2FAForExchangesToInternalWallets =
212 initialShouldRequireTOTP2FAForExchangesToInternalWallets,
213 shouldRequireTOTP2FAForExchangesToExternalWallets =
214 initialShouldRequireTOTP2FAForExchangesToExternalWallets,
215 shouldRequireTOTP2FAForAddingContacts = initialShouldRequireTOTP2FAForAddingContacts,
216 shouldRequireTOTP2FAForCreatingNewWallets =
217 initialShouldRequireTOTP2FAForCreatingNewWallets,
218 shouldRequireTOTP2FAForAllSecurityAndBackupSettings =
219 initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings,
220 currentSyncMode = initialSyncMode,
221 currentSyncAll = initialSyncAll,
222 currentBuiltinTor = initialBuiltinTor,
223 enableAutomaticNodeSwitching = initialEnableAutomaticNodeSwitching,
224 backgroundImage = initialBackgroundImage,
225 evmHiddenChainIds = ObservableSet.of(initialEvmHiddenChainIds),
226 priority = ObservableMap<WalletType, TransactionPriority>() {
227 //this.nodes = ObservableMap<WalletType, Node>.of(nodes);
228
229 if (initialMoneroTransactionPriority != null) {
230 priority[WalletType.monero] = initialMoneroTransactionPriority;
231 }
232
233 if (initialWowneroTransactionPriority != null) {
234 priority[WalletType.wownero] = initialWowneroTransactionPriority;
235 }
236
237 if (initialBitcoinTransactionPriority != null) {
238 priority[WalletType.bitcoin] = initialBitcoinTransactionPriority;
239 }
240
241 if (initialHavenTransactionPriority != null) {
242 priority[WalletType.haven] = initialHavenTransactionPriority;
243 }
244
245 if (initialLitecoinTransactionPriority != null) {
246 priority[WalletType.litecoin] = initialLitecoinTransactionPriority;
247 }
248
249 if (initialEthereumTransactionPriority != null) {
250 priority[WalletType.ethereum] = initialEthereumTransactionPriority;
251 }
252
253 if (initialPolygonTransactionPriority != null) {
254 priority[WalletType.polygon] = initialPolygonTransactionPriority;
255 }
256
257 if (initialBaseTransactionPriority != null) {
258 priority[WalletType.base] = initialBaseTransactionPriority;
259 }
260
261 if (initialBscTransactionPriority != null) {
262 priority[WalletType.bsc] = initialBscTransactionPriority;
263 }
264
265 if (initialBitcoinCashTransactionPriority != null) {
266 priority[WalletType.bitcoinCash] = initialBitcoinCashTransactionPriority;
267 }
268
269 if (initialZanoTransactionPriority != null) {
270 priority[WalletType.zano] = initialZanoTransactionPriority;
271 }
272 if (initialDecredTransactionPriority != null) {
273 priority[WalletType.decred] = initialDecredTransactionPriority;
274 }
275 if (initialZcashTransactionPriority != null) {
276 priority[WalletType.zcash] = initialZcashTransactionPriority;
277 }
278 if (initialDogecoinTransactionPriority != null) {
279 priority[WalletType.dogecoin] = initialDogecoinTransactionPriority;
280 }
281
282 if (initialCakePayCountry != null) {
283 selectedCakePayCountry = initialCakePayCountry;
284 }
285
286 reaction(
287 (_) => fiatCurrency,
288 (FiatCurrency fiatCurrency) => sharedPreferences.setString(
289 PreferencesKey.currentFiatCurrencyKey, fiatCurrency.serialize()));
290
291 reaction((_) => selectedCakePayCountry, (Country? country) {
292 if (country != null) {
293 sharedPreferences.setString(PreferencesKey.currentCakePayCountry, country.raw);
294 }
295 });
296
297 reaction(
298 (_) => shouldShowYatPopup,
299 (bool shouldShowYatPopup) =>
300 sharedPreferences.setBool(PreferencesKey.shouldShowYatPopup, shouldShowYatPopup));
301
302 reaction(
303 (_) => shouldShowDEuroDisclaimer,
304 (bool shouldShowDEuroDisclaimer) => sharedPreferences.setBool(
305 PreferencesKey.shouldShowDEuroDisclaimer, shouldShowDEuroDisclaimer));
306
307 reaction((_) => shouldShowRepWarning,
308 (bool val) => sharedPreferences.setBool(PreferencesKey.shouldShowRepWarning, val));
309
310 reaction((_) => mwebAdDismissed,
311 (val) => sharedPreferences.setBool(PreferencesKey.mwebAdDismissed, val));
312
313 priority.observe((change) {
314 final String? key;
315 switch (change.key) {
316 case WalletType.monero:
317 case WalletType.wownero:
318 key = PreferencesKey.moneroTransactionPriority;
319 break;
320 case WalletType.bitcoin:
321 key = PreferencesKey.bitcoinTransactionPriority;
322 break;
323 case WalletType.litecoin:
324 key = PreferencesKey.litecoinTransactionPriority;
325 break;
326 case WalletType.haven:
327 key = PreferencesKey.havenTransactionPriority;
328 break;
329 case WalletType.ethereum:
330 key = PreferencesKey.ethereumTransactionPriority;
331 break;
332 case WalletType.bitcoinCash:
333 key = PreferencesKey.bitcoinCashTransactionPriority;
334 break;
335 case WalletType.polygon:
336 key = PreferencesKey.polygonTransactionPriority;
337 break;
338 case WalletType.base:
339 key = PreferencesKey.baseTransactionPriority;
340 break;
341 case WalletType.bsc:
342 key = PreferencesKey.bscTransactionPriority;
343 break;
344 case WalletType.zano:
345 key = PreferencesKey.zanoTransactionPriority;
346 break;
347 case WalletType.decred:
348 key = PreferencesKey.decredTransactionPriority;
349 break;
350 case WalletType.zcash:
351 key = PreferencesKey.zcashTransactionPriority;
352 break;
353 case WalletType.dogecoin:
354 key = PreferencesKey.dogecoinTransactionPriority;
355 break;
356 default:
357 key = null;
358 }
359
360 if (change.newValue != null && key != null) {
361 sharedPreferences.setInt(key, change.newValue!.serialize());
362 }
363 });
364
365 reaction(
366 (_) => shouldSaveRecipientAddress,
367 (bool shouldSaveRecipientAddress) => sharedPreferences.setBool(
368 PreferencesKey.shouldSaveRecipientAddressKey, shouldSaveRecipientAddress));
369
370 if (DeviceInfo.instance.isMobile) {
371 unawaited(setIsAppSecureNative(isAppSecure));
372
373 reaction((_) => isAppSecure, (bool isAppSecure) {
374 sharedPreferences.setBool(PreferencesKey.isAppSecureKey, isAppSecure);
375 unawaited(setIsAppSecureNative(isAppSecure));
376 });
377 }
378
379 reaction(
380 (_) => disableTradeOption,
381 (bool disableTradeOption) =>
382 sharedPreferences.setBool(PreferencesKey.disableTradeOption, disableTradeOption));
383
384 reaction(
385 (_) => disableAutomaticExchangeStatusUpdates,
386 (bool disableAutomaticExchangeStatusUpdates) => sharedPreferences.setBool(
387 PreferencesKey.disableAutomaticExchangeStatusUpdates,
388 disableAutomaticExchangeStatusUpdates));
389
390 reaction(
391 (_) => disableBulletin,
392 (bool disableBulletin) =>
393 sharedPreferences.setBool(PreferencesKey.disableBulletinKey, disableBulletin));
394
395 reaction(
396 (_) => walletListOrder,
397 (FilterListOrderType walletListOrder) =>
398 sharedPreferences.setInt(PreferencesKey.walletListOrder, walletListOrder.index));
399
400 reaction(
401 (_) => contactListOrder,
402 (FilterListOrderType contactListOrder) =>
403 sharedPreferences.setInt(PreferencesKey.contactListOrder, contactListOrder.index));
404
405 reaction(
406 (_) => walletListAscending,
407 (bool walletListAscending) =>
408 sharedPreferences.setBool(PreferencesKey.walletListAscending, walletListAscending));
409
410 reaction(
411 (_) => contactListAscending,
412 (bool contactListAscending) =>
413 sharedPreferences.setBool(PreferencesKey.contactListAscending, contactListAscending));
414
415 reaction(
416 (_) => autoGenerateSubaddressStatus,
417 (AutoGenerateSubaddressStatus autoGenerateSubaddressStatus) => sharedPreferences.setInt(
418 PreferencesKey.autoGenerateSubaddressStatusKey, autoGenerateSubaddressStatus.value));
419
420 reaction(
421 (_) => moneroSeedType,
422 (MoneroSeedType moneroSeedType) =>
423 sharedPreferences.setInt(PreferencesKey.moneroSeedType, moneroSeedType.raw));
424
425 reaction(
426 (_) => bitcoinSeedType,
427 (BitcoinSeedType bitcoinSeedType) =>
428 sharedPreferences.setInt(PreferencesKey.bitcoinSeedType, bitcoinSeedType.raw));
429
430 reaction(
431 (_) => nanoSeedType,
432 (NanoSeedType nanoSeedType) =>
433 sharedPreferences.setInt(PreferencesKey.nanoSeedType, nanoSeedType.raw));
434
435 reaction(
436 (_) => fiatApiMode,
437 (FiatApiMode mode) =>
438 sharedPreferences.setInt(PreferencesKey.currentFiatApiModeKey, mode.serialize()));
439
440 reaction(
441 (_) => numberOfFailedTokenTrials,
442 (int failedTokenTrail) =>
443 sharedPreferences.setInt(PreferencesKey.failedTotpTokenTrials, failedTokenTrail));
444
445 reaction(
446 (_) => shouldShowMarketPlaceInDashboard,
447 (bool value) =>
448 sharedPreferences.setBool(PreferencesKey.shouldShowMarketPlaceInDashboard, value));
449
450 reaction(
451 (_) => showAddressBookPopupEnabled,
452 (bool value) =>
453 sharedPreferences.setBool(PreferencesKey.showAddressBookPopupEnabled, value));
454
455 reaction(
456 (_) => syncStatusDisplayMode,
457 (SyncStatusDisplayMode value) =>
458 sharedPreferences.setString(PreferencesKey.syncStatusDisplayMode, value.toJson()));
459
460 reaction((_) => pinCodeLength,
461 (int pinLength) => sharedPreferences.setInt(PreferencesKey.currentPinLength, pinLength));
462
463 reaction(
464 (_) => languageCode,
465 (String languageCode) =>
466 sharedPreferences.setString(PreferencesKey.currentLanguageCode, languageCode));
467
468 reaction(
469 (_) => seedPhraseLength,
470 (SeedPhraseLength seedPhraseWordCount) => sharedPreferences.setInt(
471 PreferencesKey.currentSeedPhraseLength, seedPhraseWordCount.value));
472
473 reaction(
474 (_) => balanceDisplayMode,
475 (BalanceDisplayMode mode) => sharedPreferences.setInt(
476 PreferencesKey.currentBalanceDisplayModeKey, mode.serialize()));
477
478 reaction(
479 (_) => displayAmountsInSatoshi,
480 (BitcoinAmountDisplayMode displayAmountsInSatoshi) => sharedPreferences.setInt(
481 PreferencesKey.displayAmountsInSatoshi, displayAmountsInSatoshi.raw));
482
483 reaction((_) => currentSyncMode, (SyncMode syncMode) {
484 sharedPreferences.setInt(PreferencesKey.syncModeKey, syncMode.type.index);
485 FlutterDaemon().startBackgroundSync(syncMode.frequency.inMinutes);
486 });
487
488 reaction((_) => currentSyncAll, (bool syncAll) {
489 sharedPreferences.setBool(PreferencesKey.syncAllKey, syncAll);
490 });
491
492 reaction((_) => currentBuiltinTor, (bool builtinTor) {
493 sharedPreferences.setBool(PreferencesKey.builtinTorKey, builtinTor);
494 });
495
496 reaction(
497 (_) => exchangeStatus,
498 (ExchangeApiMode mode) =>
499 sharedPreferences.setInt(PreferencesKey.exchangeStatusKey, mode.serialize()));
500
501 reaction(
502 (_) => sortBalanceBy,
503 (SortBalanceBy sortBalanceBy) =>
504 _sharedPreferences.setInt(PreferencesKey.sortBalanceBy, sortBalanceBy.index));
505
506 reaction(
507 (_) => pinNativeTokenAtTop,
508 (bool pinNativeTokenAtTop) =>
509 _sharedPreferences.setBool(PreferencesKey.pinNativeTokenAtTop, pinNativeTokenAtTop));
510
511 reaction(
512 (_) => useEtherscan,
513 (bool useEtherscan) =>
514 _sharedPreferences.setBool(PreferencesKey.useEtherscan, useEtherscan));
515
516 reaction(
517 (_) => usePolygonScan,
518 (bool usePolygonScan) =>
519 _sharedPreferences.setBool(PreferencesKey.usePolygonScan, usePolygonScan));
520
521 reaction((_) => useBaseScan,
522 (bool useBaseScan) => _sharedPreferences.setBool(PreferencesKey.useBaseScan, useBaseScan));
523
524 reaction((_) => useArbiScan,
525 (bool useArbiScan) => _sharedPreferences.setBool(PreferencesKey.useArbiScan, useArbiScan));
526
527 reaction((_) => useBscScan,
528 (bool useBscScan) => _sharedPreferences.setBool(PreferencesKey.useBscScan, useBscScan));
529
530 reaction((_) => useTronGrid,
531 (bool useTronGrid) => _sharedPreferences.setBool(PreferencesKey.useTronGrid, useTronGrid));
532
533 reaction(
534 (_) => useMempoolFeeAPI,
535 (bool useMempoolFeeAPI) =>
536 _sharedPreferences.setBool(PreferencesKey.useMempoolFeeAPI, useMempoolFeeAPI));
537
538 reaction((_) => useBlinkProtection,
539 (bool value) => _sharedPreferences.setBool(PreferencesKey.useBlinkProtection, value));
540
541 reaction((_) => defaultNanoRep,
542 (String nanoRep) => _sharedPreferences.setString(PreferencesKey.defaultNanoRep, nanoRep));
543
544 reaction(
545 (_) => defaultBananoRep,
546 (String bananoRep) =>
547 _sharedPreferences.setString(PreferencesKey.defaultBananoRep, bananoRep));
548 reaction(
549 (_) => lookupsTwitter,
550 (bool looksUpTwitter) =>
551 _sharedPreferences.setBool(PreferencesKey.lookupsTwitter, looksUpTwitter));
552 reaction(
553 (_) => lookupsZanoAlias,
554 (bool lookupsZanoAlias) =>
555 _sharedPreferences.setBool(PreferencesKey.lookupsZanoAlias, lookupsZanoAlias));
556
557 reaction(
558 (_) => lookupsMastodon,
559 (bool looksUpMastodon) =>
560 _sharedPreferences.setBool(PreferencesKey.lookupsMastodon, looksUpMastodon));
561
562 reaction(
563 (_) => lookupsYatService,
564 (bool looksUpYatService) =>
565 _sharedPreferences.setBool(PreferencesKey.lookupsYatService, looksUpYatService));
566
567 reaction(
568 (_) => lookupsUnstoppableDomains,
569 (bool looksUpUnstoppableDomains) => _sharedPreferences.setBool(
570 PreferencesKey.lookupsUnstoppableDomains, looksUpUnstoppableDomains));
571
572 reaction(
573 (_) => lookupsOpenAlias,
574 (bool looksUpOpenAlias) =>
575 _sharedPreferences.setBool(PreferencesKey.lookupsOpenAlias, looksUpOpenAlias));
576
577 reaction((_) => lookupsENS,
578 (bool looksUpENS) => _sharedPreferences.setBool(PreferencesKey.lookupsENS, looksUpENS));
579
580 reaction(
581 (_) => lookupsZcashNames,
582 (bool looksUpZcashNames) =>
583 _sharedPreferences.setBool(PreferencesKey.lookupsZcashNames, looksUpZcashNames));
584
585 reaction(
586 (_) => lookupsZcashAddress,
587 (bool lookupsZcashAddress) =>
588 _sharedPreferences.setBool(PreferencesKey.lookupsZcashAddress, lookupsZcashAddress));
589
590 reaction(
591 (_) => lookupsWellKnown,
592 (bool looksUpWellKnown) =>
593 _sharedPreferences.setBool(PreferencesKey.lookupsWellKnown, looksUpWellKnown));
594
595 reaction((_) => lookupsFio,
596 (bool lookupsFio) => _sharedPreferences.setBool(PreferencesKey.lookupsFio, lookupsFio));
597
598 reaction(
599 (_) => lookupsNostr,
600 (bool lookupsNostr) =>
601 _sharedPreferences.setBool(PreferencesKey.lookupsNostr, lookupsNostr));
602
603 reaction(
604 (_) => lookupsThorChain,
605 (bool lookupsThorChain) =>
606 _sharedPreferences.setBool(PreferencesKey.lookupsThorChain, lookupsThorChain));
607
608 reaction(
609 (_) => lookupsBip353,
610 (bool lookupsBip353) =>
611 _sharedPreferences.setBool(PreferencesKey.lookupsBip353, lookupsBip353));
612
613 reaction(
614 (_) => lookupsLNUrl,
615 (bool lookupsLNUrl) =>
616 _sharedPreferences.setBool(PreferencesKey.lookupsLNUrl, lookupsLNUrl));
617
618 reaction((_) => usePayjoin,
619 (bool usePayjoin) => _sharedPreferences.setBool(PreferencesKey.usePayjoin, usePayjoin));
620
621 reaction(
622 (_) => showPayjoinCard,
623 (bool showPayjoinCard) =>
624 _sharedPreferences.setBool(PreferencesKey.showPayjoinCard, showPayjoinCard));
625
626 // secure storage keys:
627 reaction(
628 (_) => allowBiometricalAuthentication,
629 (bool biometricalAuthentication) => secureStorage.write(
630 key: SecureKey.allowBiometricalAuthenticationKey,
631 value: biometricalAuthentication.toString()));
632
633 reaction(
634 (_) => enableDuressPin,
635 (bool enableDuressPin) =>
636 secureStorage.write(key: SecureKey.enableDuressPin, value: enableDuressPin.toString()));
637
638 reaction(
639 (_) => selectedCake2FAPreset,
640 (Cake2FAPresetsOptions selectedCake2FAPreset) => secureStorage.write(
641 key: SecureKey.selectedCake2FAPreset,
642 value: selectedCake2FAPreset.serialize().toString()));
643
644 reaction(
645 (_) => shouldRequireTOTP2FAForAccessingWallet,
646 (bool requireTOTP2FAForAccessingWallet) => secureStorage.write(
647 key: SecureKey.shouldRequireTOTP2FAForAccessingWallet,
648 value: requireTOTP2FAForAccessingWallet.toString()));
649
650 reaction(
651 (_) => shouldRequireTOTP2FAForSendsToContact,
652 (bool requireTOTP2FAForSendsToContact) => secureStorage.write(
653 key: SecureKey.shouldRequireTOTP2FAForSendsToContact,
654 value: requireTOTP2FAForSendsToContact.toString()));
655
656 reaction(
657 (_) => shouldRequireTOTP2FAForSendsToNonContact,
658 (bool requireTOTP2FAForSendsToNonContact) => secureStorage.write(
659 key: SecureKey.shouldRequireTOTP2FAForSendsToNonContact,
660 value: requireTOTP2FAForSendsToNonContact.toString()));
661
662 reaction(
663 (_) => shouldRequireTOTP2FAForSendsToInternalWallets,
664 (bool requireTOTP2FAForSendsToInternalWallets) => secureStorage.write(
665 key: SecureKey.shouldRequireTOTP2FAForSendsToInternalWallets,
666 value: requireTOTP2FAForSendsToInternalWallets.toString()));
667
668 reaction(
669 (_) => shouldRequireTOTP2FAForExchangesToInternalWallets,
670 (bool requireTOTP2FAForExchangesToInternalWallets) => secureStorage.write(
671 key: SecureKey.shouldRequireTOTP2FAForExchangesToInternalWallets,
672 value: requireTOTP2FAForExchangesToInternalWallets.toString()));
673
674 reaction(
675 (_) => shouldRequireTOTP2FAForExchangesToExternalWallets,
676 (bool requireTOTP2FAForExchangesToExternalWallets) => secureStorage.write(
677 key: SecureKey.shouldRequireTOTP2FAForExchangesToExternalWallets,
678 value: requireTOTP2FAForExchangesToExternalWallets.toString()));
679
680 reaction(
681 (_) => shouldRequireTOTP2FAForAddingContacts,
682 (bool requireTOTP2FAForAddingContacts) => secureStorage.write(
683 key: SecureKey.shouldRequireTOTP2FAForAddingContacts,
684 value: requireTOTP2FAForAddingContacts.toString()));
685
686 reaction(
687 (_) => shouldRequireTOTP2FAForCreatingNewWallets,
688 (bool requireTOTP2FAForCreatingNewWallets) => secureStorage.write(
689 key: SecureKey.shouldRequireTOTP2FAForCreatingNewWallets,
690 value: requireTOTP2FAForCreatingNewWallets.toString()));
691
692 reaction(
693 (_) => shouldRequireTOTP2FAForAllSecurityAndBackupSettings,
694 (bool requireTOTP2FAForAllSecurityAndBackupSettings) => secureStorage.write(
695 key: SecureKey.shouldRequireTOTP2FAForAllSecurityAndBackupSettings,
696 value: requireTOTP2FAForAllSecurityAndBackupSettings.toString()));
697
698 reaction((_) => useTOTP2FA,
699 (bool use) => secureStorage.write(key: SecureKey.useTOTP2FA, value: use.toString()));
700
701 reaction((_) => totpSecretKey,
702 (String totpKey) => secureStorage.write(key: SecureKey.totpSecretKey, value: totpKey));
703
704 reaction(
705 (_) => pinTimeOutDuration,
706 (PinCodeRequiredDuration pinCodeInterval) => secureStorage.write(
707 key: SecureKey.pinTimeOutDuration, value: pinCodeInterval.value.toString()));
708
709 reaction(
710 (_) => customBitcoinFeeRate,
711 (int customBitcoinFeeRate) =>
712 _sharedPreferences.setInt(PreferencesKey.customBitcoinFeeRate, customBitcoinFeeRate));
713
714 reaction((_) => silentPaymentsCardDisplay, (bool silentPaymentsCardDisplay) {
715 _sharedPreferences.setBool(
716 PreferencesKey.silentPaymentsCardDisplay, silentPaymentsCardDisplay);
717 });
718
719 reaction(
720 (_) => mwebAlwaysScan,
721 (bool mwebAlwaysScan) =>
722 _sharedPreferences.setBool(PreferencesKey.mwebAlwaysScan, mwebAlwaysScan));
723
724 reaction(
725 (_) => evmHiddenChainIds.toList(growable: false),
726 (List<int> hiddenIds) => _sharedPreferences.setStringList(
727 PreferencesKey.evmHiddenChainIds, hiddenIds.map((id) => id.toString()).toList()));
728
729 reaction(
730 (_) => mwebCardDisplay,
731 (bool mwebCardDisplay) =>
732 _sharedPreferences.setBool(PreferencesKey.mwebCardDisplay, mwebCardDisplay));
733
734 reaction(
735 (_) => showZcashMissingFundsCard,
736 (bool showZcashMissingFundsCard) => _sharedPreferences.setBool(
737 PreferencesKey.showZcashMissingFundsCard, showZcashMissingFundsCard));
738
739 reaction((_) => mwebEnabled,
740 (bool mwebEnabled) => _sharedPreferences.setBool(PreferencesKey.mwebEnabled, mwebEnabled));
741
742 reaction(
743 (_) => hasEnabledMwebBefore,
744 (bool hasEnabledMwebBefore) =>
745 _sharedPreferences.setBool(PreferencesKey.hasEnabledMwebBefore, hasEnabledMwebBefore));
746
747 reaction(
748 (_) => mwebNodeUri,
749 (String mwebNodeUri) =>
750 _sharedPreferences.setString(PreferencesKey.mwebNodeUri, mwebNodeUri));
751
752 reaction(
753 (_) => enableAutomaticNodeSwitching,
754 (bool enableAutomaticNodeSwitching) => _sharedPreferences.setBool(
755 PreferencesKey.enableAutomaticNodeSwitching, enableAutomaticNodeSwitching));
756
757 reaction(
758 (_) => backgroundImage,
759 (String backgroundImage) =>
760 _sharedPreferences.setString(PreferencesKey.backgroundImage, backgroundImage));
761
762 reaction(
763 (_) => forceDecentralizedExchanges,
764 (bool forceDecentralizedExchanges) => _sharedPreferences.setBool(
765 PreferencesKey.forceDecentralizedExchanges, forceDecentralizedExchanges));
766
767 reaction(
768 (_) => decentralizedExchangesPromptDismissed,
769 (bool decentralizedExchangesPromptDismissed) => _sharedPreferences.setBool(
770 PreferencesKey.decentralizedExchangesPromptDismissed,
771 decentralizedExchangesPromptDismissed));
772
773 reaction(
774 (_) => balanceHideCounter,
775 (int balanceHideCounter) =>
776 _sharedPreferences.setInt(PreferencesKey.balanceHideCounter, balanceHideCounter));
777
778 reaction((_) => zcashMigrationModalViewed,
779 (val) => _sharedPreferences.setBool(PreferencesKey.zcashMigrationModalViewed, val));
780
781 this.nodes.observe((change) {
782 if (change.newValue != null && change.key != null) {
783 _saveCurrentNode(change.newValue!, change.key!);
784 }
785 });
786
787 this.powNodes.observe((change) {
788 if (change.newValue != null && change.key != null) {
789 _saveCurrentPowNode(change.newValue!, change.key!);
790 }
791 });
792 }
793
794 static const defaultPinLength = 4;
795 static const defaultActionsMode = 11;
796 static const defaultPinCodeTimeOutDuration = PinCodeRequiredDuration.tenMinutes;
797 static const defaultAutoGenerateSubaddressStatus = AutoGenerateSubaddressStatus.initialized;
798 static final walletPasswordDirectInput = Platform.isLinux;
799 static const defaultSeedPhraseLength = SeedPhraseLength.twelveWords;
800 static const defaultMoneroSeedType = MoneroSeedType.defaultSeedType;
801 static const defaultBitcoinSeedType = BitcoinSeedType.defaultDerivationType;
802 static const defaultNanoSeedType = NanoSeedType.defaultDerivationType;
803
804 @observable
805 FiatCurrency fiatCurrency;
806
807 @observable
808 Country? selectedCakePayCountry;
809
810 @observable
811 bool shouldShowYatPopup;
812
813 @observable
814 bool shouldShowDEuroDisclaimer;
815
816 @observable
817 bool shouldShowRepWarning;
818
819 @observable
820 bool shouldShowMarketPlaceInDashboard;
821
822 @observable
823 bool showAddressBookPopupEnabled;
824
825 @observable
826 SyncStatusDisplayMode syncStatusDisplayMode;
827
828 @observable
829 ObservableList<ActionListDisplayMode> actionlistDisplayMode;
830
831 @observable
832 BalanceDisplayMode balanceDisplayMode;
833
834 @observable
835 int balanceHideCounter;
836
837 @observable
838 BitcoinAmountDisplayMode displayAmountsInSatoshi;
839
840 @observable
841 FiatApiMode fiatApiMode;
842
843 @observable
844 bool shouldSaveRecipientAddress;
845
846 @observable
847 AutoGenerateSubaddressStatus autoGenerateSubaddressStatus;
848
849 @observable
850 MoneroSeedType moneroSeedType;
851
852 @observable
853 BitcoinSeedType bitcoinSeedType;
854
855 @observable
856 NanoSeedType nanoSeedType;
857
858 @observable
859 bool isAppSecure;
860
861 @observable
862 bool disableTradeOption;
863
864 @observable
865 bool disableAutomaticExchangeStatusUpdates;
866
867 @observable
868 bool useBlinkProtection;
869
870 @observable
871 FilterListOrderType contactListOrder;
872
873 @observable
874 bool disableBulletin;
875
876 @observable
877 FilterListOrderType walletListOrder;
878
879 @observable
880 bool walletListAscending;
881
882 @observable
883 bool contactListAscending;
884
885 @observable
886 bool allowBiometricalAuthentication;
887
888 @observable
889 bool enableDuressPin;
890
891 @observable
892 bool shouldRequireTOTP2FAForAccessingWallet;
893
894 @observable
895 bool shouldRequireTOTP2FAForSendsToContact;
896
897 @observable
898 bool shouldRequireTOTP2FAForSendsToNonContact;
899
900 @observable
901 bool shouldRequireTOTP2FAForSendsToInternalWallets;
902
903 @observable
904 bool shouldRequireTOTP2FAForExchangesToInternalWallets;
905
906 @observable
907 bool shouldRequireTOTP2FAForExchangesToExternalWallets;
908
909 @observable
910 Cake2FAPresetsOptions selectedCake2FAPreset;
911
912 @observable
913 bool shouldRequireTOTP2FAForAddingContacts;
914
915 @observable
916 bool shouldRequireTOTP2FAForCreatingNewWallets;
917
918 @observable
919 bool shouldRequireTOTP2FAForAllSecurityAndBackupSettings;
920
921 @observable
922 bool useTOTP2FA;
923
924 @observable
925 String totpSecretKey;
926
927 @observable
928 int numberOfFailedTokenTrials;
929
930 @observable
931 ExchangeApiMode exchangeStatus;
932
933 @observable
934 int pinCodeLength;
935
936 @observable
937 PinCodeRequiredDuration pinTimeOutDuration;
938
939 @observable
940 SeedPhraseLength seedPhraseLength;
941
942 @observable
943 String languageCode;
944
945 @observable
946 ObservableMap<WalletType, TransactionPriority> priority;
947
948 @observable
949 ObservableMap<String, bool> trocadorProviderStates = ObservableMap<String, bool>();
950
951 @observable
952 SortBalanceBy sortBalanceBy;
953
954 @observable
955 bool pinNativeTokenAtTop;
956
957 @observable
958 bool useEtherscan;
959
960 @observable
961 bool usePolygonScan;
962
963 @observable
964 bool useBaseScan;
965
966 @observable
967 bool useArbiScan;
968
969 @observable
970 bool useBscScan;
971
972 @observable
973 bool useTronGrid;
974
975 @observable
976 bool useMempoolFeeAPI;
977
978 @observable
979 ObservableSet<int> evmHiddenChainIds;
980
981 @observable
982 String defaultNanoRep;
983
984 @observable
985 String defaultBananoRep;
986
987 @observable
988 bool lookupsTwitter;
989
990 @observable
991 bool lookupsZanoAlias;
992
993 @observable
994 bool lookupsMastodon;
995
996 @observable
997 bool lookupsYatService;
998
999 @observable
1000 bool lookupsUnstoppableDomains;
1001
1002 @observable
1003 bool lookupsOpenAlias;
1004
1005 @observable
1006 bool lookupsENS;
1007
1008 @observable
1009 bool lookupsZcashNames;
1010
1011 @observable
1012 bool lookupsZcashAddress;
1013
1014 @observable
1015 bool lookupsWellKnown;
1016
1017 @observable
1018 bool lookupsFio;
1019
1020 @observable
1021 bool lookupsNostr;
1022
1023 @observable
1024 bool lookupsThorChain;
1025
1026 @observable
1027 bool lookupsBip353;
1028
1029 @observable
1030 bool lookupsLNUrl;
1031
1032 @observable
1033 bool usePayjoin;
1034
1035 @observable
1036 bool showPayjoinCard;
1037
1038 @observable
1039 SyncMode currentSyncMode;
1040
1041 @observable
1042 bool currentSyncAll;
1043
1044 @observable
1045 bool currentBuiltinTor;
1046
1047 String appVersion;
1048
1049 String deviceName;
1050
1051 @observable
1052 int customBitcoinFeeRate;
1053
1054 @observable
1055 bool silentPaymentsCardDisplay;
1056
1057 @observable
1058 bool mwebAlwaysScan;
1059
1060 @observable
1061 bool mwebCardDisplay;
1062
1063 @observable
1064 bool showZcashMissingFundsCard;
1065
1066 @observable
1067 bool mwebEnabled;
1068
1069 @observable
1070 bool hasEnabledMwebBefore;
1071
1072 @observable
1073 String mwebNodeUri;
1074
1075 @observable
1076 bool enableAutomaticNodeSwitching;
1077
1078 @observable
1079 String backgroundImage;
1080
1081 @observable
1082 bool forceDecentralizedExchanges;
1083
1084 @observable
1085 bool decentralizedExchangesPromptDismissed;
1086
1087 @observable
1088 bool mwebAdDismissed;
1089
1090 @observable
1091 bool zcashMigrationModalViewed;
1092
1093 final SecureStorage _secureStorage;
1094 final SharedPreferences _sharedPreferences;
1095
1096 ObservableMap<WalletType, Node> nodes;
1097 ObservableMap<WalletType, Node> powNodes;
1098
1099 Node getCurrentNode(WalletType walletType, {int? chainId}) {
1100 if (chainId != null && isEVMCompatibleChain(walletType)) {
1101 final preferenceKey = _getEVMNodePreferenceKey(chainId);
1102 final nodeId = _sharedPreferences.getInt(preferenceKey);
1103
1104 if (nodeId != null) {
1105 final walletTypeForChain = evm!.getWalletTypeByChainId(chainId);
1106 if (walletTypeForChain != null) {
1107 final node = nodes[walletTypeForChain];
1108 if (node != null) return node;
1109 }
1110 }
1111
1112 throw Exception('No node found for EVM wallet type with chainId: $chainId');
1113 }
1114
1115 final node = nodes[walletType];
1116 if (node == null) {
1117 throw Exception('No node found for wallet type: ${walletType.toString()}');
1118 }
1119 if (node.type != walletType) {
1120 throw Exception("Node is not valid for $walletType (found: ${node.type}");
1121 }
1122
1123 return node;
1124 }
1125
1126 String _getEVMNodePreferenceKey(int chainId) {
1127 switch (chainId) {
1128 case 1:
1129 return PreferencesKey.currentEthereumNodeIdKey;
1130 case 137:
1131 return PreferencesKey.currentPolygonNodeIdKey;
1132 case 8453:
1133 return PreferencesKey.currentBaseNodeIdKey;
1134 case 42161:
1135 return PreferencesKey.currentArbitrumNodeIdKey;
1136 case 56:
1137 return PreferencesKey.currentBscNodeIdKey;
1138 default:
1139 // Default to Ethereum for unknown chainIds
1140 return PreferencesKey.currentEthereumNodeIdKey;
1141 }
1142 }
1143
1144 Node getCurrentPowNode(WalletType walletType) {
1145 final node = powNodes[walletType];
1146
1147 if (node == null) {
1148 throw Exception('No pow node found for wallet type: ${walletType.toString()}');
1149 }
1150
1151 return node;
1152 }
1153
1154 TransactionPriority? getPriority(WalletType walletType, {int? chainId}) {
1155 if (isEVMCompatibleChain(walletType)) {
1156 if (chainId != null && !evm!.hasPriorityFee(chainId)) return null;
1157 return priority[walletType];
1158 }
1159
1160 return priority[walletType];
1161 }
1162
1163 void setPriority(WalletType walletType, TransactionPriority priority, {int? chainId}) =>
1164 this.priority[walletType] = priority;
1165
1166 bool isBitcoinBuyEnabled;
1167
1168 bool get shouldShowReceiveWarning =>
1169 _sharedPreferences.getBool(PreferencesKey.shouldShowReceiveWarning) ?? true;
1170
1171 Future<void> setShouldShowReceiveWarning(bool value) async =>
1172 _sharedPreferences.setBool(PreferencesKey.shouldShowReceiveWarning, value);
1173
1174 static Future<SettingsStore> load(
1175 {required bool isBitcoinBuyEnabled,
1176 FiatCurrency initialFiatCurrency = FiatCurrency.usd,
1177 BalanceDisplayMode initialBalanceDisplayMode = BalanceDisplayMode.availableBalance}) async {
1178 final sharedPreferences = await getIt.getAsync<SharedPreferences>();
1179 final secureStorage = await getIt.get<SecureStorage>();
1180 final currentFiatCurrency = FiatCurrency.deserialize(
1181 raw: sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey)!);
1182 final savedCakePayCountryRaw =
1183 sharedPreferences.getString(PreferencesKey.currentCakePayCountry);
1184 final currentCakePayCountry =
1185 savedCakePayCountryRaw != null ? Country.deserialize(raw: savedCakePayCountryRaw) : null;
1186
1187 TransactionPriority? moneroTransactionPriority = monero?.deserializeMoneroTransactionPriority(
1188 raw: sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!);
1189 TransactionPriority? bitcoinTransactionPriority =
1190 bitcoin?.deserializeBitcoinTransactionPriority(
1191 sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority)!);
1192
1193 TransactionPriority? havenTransactionPriority;
1194 TransactionPriority? litecoinTransactionPriority;
1195 TransactionPriority? ethereumTransactionPriority;
1196 TransactionPriority? evmTransactionPriority;
1197 TransactionPriority? polygonTransactionPriority;
1198 TransactionPriority? baseTransactionPriority;
1199 TransactionPriority? bscTransactionPriority;
1200 TransactionPriority? bitcoinCashTransactionPriority;
1201 TransactionPriority? wowneroTransactionPriority;
1202 TransactionPriority? zanoTransactionPriority;
1203 TransactionPriority? decredTransactionPriority;
1204 TransactionPriority? zcashTransactionPriority;
1205 TransactionPriority? dogecoinTransactionPriority;
1206
1207 if (sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) {
1208 havenTransactionPriority = monero?.deserializeMoneroTransactionPriority(
1209 raw: sharedPreferences.getInt(PreferencesKey.havenTransactionPriority)!);
1210 }
1211 if (sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority) != null) {
1212 litecoinTransactionPriority = bitcoin?.deserializeLitecoinTransactionPriority(
1213 sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority)!);
1214 }
1215 if (sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority) != null) {
1216 ethereumTransactionPriority = evm?.deserializeEVMTransactionPriority(
1217 sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!);
1218 evmTransactionPriority = evm?.deserializeEVMTransactionPriority(
1219 sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!);
1220 }
1221 if (sharedPreferences.getInt(PreferencesKey.polygonTransactionPriority) != null) {
1222 polygonTransactionPriority = evm?.deserializeEVMTransactionPriority(
1223 sharedPreferences.getInt(PreferencesKey.polygonTransactionPriority)!);
1224 }
1225 if (sharedPreferences.getInt(PreferencesKey.baseTransactionPriority) != null) {
1226 baseTransactionPriority = evm?.deserializeEVMTransactionPriority(
1227 sharedPreferences.getInt(PreferencesKey.baseTransactionPriority)!);
1228 }
1229 if (sharedPreferences.getInt(PreferencesKey.bscTransactionPriority) != null) {
1230 bscTransactionPriority = evm?.deserializeEVMTransactionPriority(
1231 sharedPreferences.getInt(PreferencesKey.bscTransactionPriority)!);
1232 }
1233 if (sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority) != null) {
1234 bitcoinCashTransactionPriority = bitcoinCash?.deserializeBitcoinCashTransactionPriority(
1235 sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority)!);
1236 }
1237 if (sharedPreferences.getInt(PreferencesKey.wowneroTransactionPriority) != null) {
1238 wowneroTransactionPriority = wownero?.deserializeWowneroTransactionPriority(
1239 raw: sharedPreferences.getInt(PreferencesKey.wowneroTransactionPriority)!);
1240 }
1241 if (sharedPreferences.getInt(PreferencesKey.zanoTransactionPriority) != null) {
1242 zanoTransactionPriority = monero?.deserializeMoneroTransactionPriority(
1243 raw: sharedPreferences.getInt(PreferencesKey.zanoTransactionPriority)!);
1244 }
1245 if (sharedPreferences.getInt(PreferencesKey.decredTransactionPriority) != null) {
1246 decredTransactionPriority = decred?.deserializeDecredTransactionPriority(
1247 sharedPreferences.getInt(PreferencesKey.decredTransactionPriority)!);
1248 }
1249 if (sharedPreferences.getInt(PreferencesKey.zcashTransactionPriority) != null) {
1250 zcashTransactionPriority = zcash?.deserializeZcashTransactionPriority(
1251 raw: sharedPreferences.getInt(PreferencesKey.zcashTransactionPriority)!);
1252 }
1253 if (sharedPreferences.getInt(PreferencesKey.dogecoinTransactionPriority) != null) {
1254 dogecoinTransactionPriority = dogecoin?.deserializeDogeCoinTransactionPriority(
1255 sharedPreferences.getInt(PreferencesKey.dogecoinTransactionPriority)!);
1256 }
1257
1258 moneroTransactionPriority ??= monero?.getDefaultTransactionPriority();
1259 bitcoinTransactionPriority ??= bitcoin?.getMediumTransactionPriority();
1260 havenTransactionPriority ??= monero?.getDefaultTransactionPriority();
1261 litecoinTransactionPriority ??= bitcoin?.getLitecoinTransactionPriorityMedium();
1262 ethereumTransactionPriority ??= evm?.getDefaultTransactionPriority();
1263 evmTransactionPriority ??= evm?.getDefaultTransactionPriority();
1264 bitcoinCashTransactionPriority ??= bitcoinCash?.getDefaultTransactionPriority();
1265 wowneroTransactionPriority ??= wownero?.getDefaultTransactionPriority();
1266 decredTransactionPriority ??= decred?.getDecredTransactionPriorityMedium();
1267 polygonTransactionPriority ??= evm?.getDefaultTransactionPriority();
1268 baseTransactionPriority ??= evm?.getDefaultTransactionPriority();
1269 bscTransactionPriority ??= evm?.getDefaultTransactionPriority();
1270 zanoTransactionPriority ??= zano?.getDefaultTransactionPriority();
1271 zcashTransactionPriority ??= zcash?.getDefaultTransactionPriority();
1272 dogecoinTransactionPriority ??= dogecoin?.getDefaultTransactionPriority();
1273
1274 final currentBalanceDisplayMode = BalanceDisplayMode.deserialize(
1275 raw: sharedPreferences.getInt(PreferencesKey.currentBalanceDisplayModeKey)!);
1276 final displayAmountsInSatoshi = BitcoinAmountDisplayMode.deserialize(
1277 raw: sharedPreferences.getInt(PreferencesKey.displayAmountsInSatoshi) ?? 0);
1278 // FIX-ME: Check for which default value we should have here
1279 final shouldSaveRecipientAddress =
1280 sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ?? false;
1281 final isAppSecure = sharedPreferences.getBool(PreferencesKey.isAppSecureKey) ?? false;
1282 final disableTradeOption =
1283 sharedPreferences.getBool(PreferencesKey.disableTradeOption) ?? false;
1284 final disableAutomaticExchangeStatusUpdates =
1285 sharedPreferences.getBool(PreferencesKey.disableAutomaticExchangeStatusUpdates) ?? false;
1286 final disableBulletin = sharedPreferences.getBool(PreferencesKey.disableBulletinKey) ?? false;
1287 final walletListOrder =
1288 FilterListOrderType.values[sharedPreferences.getInt(PreferencesKey.walletListOrder) ?? 0];
1289 final contactListOrder =
1290 FilterListOrderType.values[sharedPreferences.getInt(PreferencesKey.contactListOrder) ?? 0];
1291 final walletListAscending =
1292 sharedPreferences.getBool(PreferencesKey.walletListAscending) ?? true;
1293 final contactListAscending =
1294 sharedPreferences.getBool(PreferencesKey.contactListAscending) ?? true;
1295 final currentFiatApiMode = FiatApiMode.deserialize(
1296 raw: sharedPreferences.getInt(PreferencesKey.currentFiatApiModeKey) ??
1297 FiatApiMode.enabled.raw);
1298 final tokenTrialNumber = sharedPreferences.getInt(PreferencesKey.failedTotpTokenTrials) ?? 0;
1299 final shouldShowMarketPlaceInDashboard =
1300 sharedPreferences.getBool(PreferencesKey.shouldShowMarketPlaceInDashboard) ?? true;
1301 final showAddressBookPopupEnabled =
1302 sharedPreferences.getBool(PreferencesKey.showAddressBookPopupEnabled) ?? true;
1303 final forceDecentralizedExchanges =
1304 await sharedPreferences.getBool(PreferencesKey.forceDecentralizedExchanges) ?? false;
1305 final decentralizedExchangesPromptDismissed =
1306 await sharedPreferences.getBool(PreferencesKey.decentralizedExchangesPromptDismissed) ??
1307 false;
1308 final syncStatusDisplayMode = SyncStatusDisplayModeExtension.fromString(
1309 sharedPreferences.getString(PreferencesKey.syncStatusDisplayMode) ??
1310 SyncStatusDisplayMode.blocksRemaining.name);
1311 final exchangeStatus = ExchangeApiMode.deserialize(
1312 raw: sharedPreferences.getInt(PreferencesKey.exchangeStatusKey) ??
1313 ExchangeApiMode.enabled.raw);
1314 final actionListDisplayMode = ObservableList<ActionListDisplayMode>();
1315 actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
1316 sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ?? defaultActionsMode));
1317 var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength);
1318 final sortBalanceBy =
1319 SortBalanceBy.values[sharedPreferences.getInt(PreferencesKey.sortBalanceBy) ?? 0];
1320 final pinNativeTokenAtTop =
1321 sharedPreferences.getBool(PreferencesKey.pinNativeTokenAtTop) ?? true;
1322 final seedPhraseCount = sharedPreferences.getInt(PreferencesKey.currentSeedPhraseLength);
1323 final seedPhraseWordCount = seedPhraseCount != null
1324 ? SeedPhraseLength.deserialize(raw: seedPhraseCount)
1325 : defaultSeedPhraseLength;
1326 final useEtherscan = sharedPreferences.getBool(PreferencesKey.useEtherscan) ?? true;
1327 final usePolygonScan = sharedPreferences.getBool(PreferencesKey.usePolygonScan) ?? true;
1328 final useBaseScan = sharedPreferences.getBool(PreferencesKey.useBaseScan) ?? true;
1329 final useArbiScan = sharedPreferences.getBool(PreferencesKey.useArbiScan) ?? true;
1330 final useBscScan = sharedPreferences.getBool(PreferencesKey.useBscScan) ?? true;
1331 final useTronGrid = sharedPreferences.getBool(PreferencesKey.useTronGrid) ?? true;
1332 final useMempoolFeeAPI = sharedPreferences.getBool(PreferencesKey.useMempoolFeeAPI) ?? true;
1333 final useBlinkProtection = sharedPreferences.getBool(PreferencesKey.useBlinkProtection) ?? true;
1334 final evmHiddenChainIdsRaw =
1335 sharedPreferences.getStringList(PreferencesKey.evmHiddenChainIds) ?? const <String>[];
1336 final evmHiddenChainIds =
1337 evmHiddenChainIdsRaw.map((value) => int.tryParse(value)).whereType<int>().toList();
1338 final defaultNanoRep = sharedPreferences.getString(PreferencesKey.defaultNanoRep) ?? "";
1339 final defaultBananoRep = sharedPreferences.getString(PreferencesKey.defaultBananoRep) ?? "";
1340 final lookupsTwitter = sharedPreferences.getBool(PreferencesKey.lookupsTwitter) ?? true;
1341 final lookupsZanoAlias = sharedPreferences.getBool(PreferencesKey.lookupsZanoAlias) ?? true;
1342 final lookupsMastodon = sharedPreferences.getBool(PreferencesKey.lookupsMastodon) ?? true;
1343 final lookupsYatService = sharedPreferences.getBool(PreferencesKey.lookupsYatService) ?? true;
1344 final lookupsUnstoppableDomains =
1345 sharedPreferences.getBool(PreferencesKey.lookupsUnstoppableDomains) ?? true;
1346 final lookupsOpenAlias = sharedPreferences.getBool(PreferencesKey.lookupsOpenAlias) ?? true;
1347 final lookupsENS = sharedPreferences.getBool(PreferencesKey.lookupsENS) ?? true;
1348 final lookupsZcashNames = sharedPreferences.getBool(PreferencesKey.lookupsZcashNames) ?? true;
1349 final lookupsZcashAddress =
1350 sharedPreferences.getBool(PreferencesKey.lookupsZcashAddress) ?? true;
1351 final lookupsWellKnown = sharedPreferences.getBool(PreferencesKey.lookupsWellKnown) ?? true;
1352 final lookupsFio = sharedPreferences.getBool(PreferencesKey.lookupsFio) ?? true;
1353 final lookupsNostr = sharedPreferences.getBool(PreferencesKey.lookupsNostr) ?? true;
1354 final lookupsThorChain = sharedPreferences.getBool(PreferencesKey.lookupsThorChain) ?? false;
1355 final lookupsBip353 = sharedPreferences.getBool(PreferencesKey.lookupsBip353) ?? true;
1356 final lookupsLNUrl = sharedPreferences.getBool(PreferencesKey.lookupsLNUrl) ?? true;
1357 final usePayjoin = sharedPreferences.getBool(PreferencesKey.usePayjoin) ?? false;
1358 final showPayjoinCard = sharedPreferences.getBool(PreferencesKey.showPayjoinCard) ?? true;
1359 final customBitcoinFeeRate = sharedPreferences.getInt(PreferencesKey.customBitcoinFeeRate) ?? 1;
1360 final silentPaymentsCardDisplay =
1361 sharedPreferences.getBool(PreferencesKey.silentPaymentsCardDisplay) ?? true;
1362 final mwebAlwaysScan = sharedPreferences.getBool(PreferencesKey.mwebAlwaysScan) ?? false;
1363 final mwebCardDisplay = sharedPreferences.getBool(PreferencesKey.mwebCardDisplay) ?? true;
1364 final showZcashMissingFundsCard =
1365 sharedPreferences.getBool(PreferencesKey.showZcashMissingFundsCard) ?? true;
1366 final mwebEnabled = sharedPreferences.getBool(PreferencesKey.mwebEnabled) ?? false;
1367 final hasEnabledMwebBefore =
1368 sharedPreferences.getBool(PreferencesKey.hasEnabledMwebBefore) ?? false;
1369 final mwebNodeUri = sharedPreferences.getString(PreferencesKey.mwebNodeUri) ??
1370 "ltc-electrum.cakewallet.com:9333";
1371 final enableAutomaticNodeSwitching =
1372 sharedPreferences.getBool(PreferencesKey.enableAutomaticNodeSwitching) ?? true;
1373 final backgroundImage = sharedPreferences.getString(PreferencesKey.backgroundImage) ?? '';
1374 final zcashMigrationModalViewed = sharedPreferences.getBool(PreferencesKey.zcashMigrationModalViewed) ?? false;
1375
1376 // If no value
1377 if (pinLength == null || pinLength == 0) {
1378 pinLength = defaultPinLength;
1379 }
1380
1381 final savedLanguageCode = sharedPreferences.getString(PreferencesKey.currentLanguageCode) ??
1382 await LanguageService.localeDetection();
1383 final nodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
1384 final bitcoinElectrumServerId =
1385 sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
1386 final litecoinElectrumServerId =
1387 sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
1388 final bitcoinCashElectrumServerId =
1389 sharedPreferences.getInt(PreferencesKey.currentBitcoinCashNodeIdKey);
1390 final ethereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey);
1391 final polygonNodeId = sharedPreferences.getInt(PreferencesKey.currentPolygonNodeIdKey);
1392 final baseNodeId = sharedPreferences.getInt(PreferencesKey.currentBaseNodeIdKey);
1393 final arbitrumNodeId = sharedPreferences.getInt(PreferencesKey.currentArbitrumNodeIdKey);
1394 final bscNodeId = sharedPreferences.getInt(PreferencesKey.currentBscNodeIdKey);
1395 final nanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey);
1396 final nanoPowNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoPowNodeIdKey);
1397 final solanaNodeId = sharedPreferences.getInt(PreferencesKey.currentSolanaNodeIdKey);
1398 final tronNodeId = sharedPreferences.getInt(PreferencesKey.currentTronNodeIdKey);
1399 final wowneroNodeId = sharedPreferences.getInt(PreferencesKey.currentWowneroNodeIdKey);
1400 final zanoNodeId = sharedPreferences.getInt(PreferencesKey.currentZanoNodeIdKey);
1401 final zcashNodeId = sharedPreferences.getInt(PreferencesKey.currentZcashNodeIdKey);
1402 final decredNodeId = sharedPreferences.getInt(PreferencesKey.currentDecredNodeIdKey);
1403 final dogecoinNodeId = sharedPreferences.getInt(PreferencesKey.currentDogecoinNodeIdKey);
1404
1405 final nodeSource = await Node.getAll();
1406 final powNodeSource = await Node.getAllPow();
1407
1408 /// get the selected node, if null, then use the default
1409 final moneroNode = nodeSource.firstWhereOrNull((e) => e.id == nodeId) ??
1410 nodeSource.firstWhereOrNull((e) => e.uriRaw == newCakeWalletMoneroUri);
1411 final bitcoinElectrumServer =
1412 nodeSource.firstWhereOrNull((e) => e.id == bitcoinElectrumServerId) ??
1413 nodeSource.firstWhereOrNull((e) => e.uriRaw == newCakeWalletBitcoinUri);
1414 final litecoinElectrumServer =
1415 nodeSource.firstWhereOrNull((e) => e.id == litecoinElectrumServerId) ??
1416 nodeSource.firstWhereOrNull((e) => e.uriRaw == cakeWalletLitecoinElectrumUri);
1417 final ethereumNode = nodeSource.firstWhereOrNull((e) => e.id == ethereumNodeId) ??
1418 nodeSource.firstWhereOrNull((e) => e.uriRaw == ethereumDefaultNodeUri);
1419 final polygonNode = nodeSource.firstWhereOrNull((e) => e.id == polygonNodeId) ??
1420 nodeSource.firstWhereOrNull((e) => e.uriRaw == polygonDefaultNodeUri);
1421 final baseNode = nodeSource.firstWhereOrNull((e) => e.id == baseNodeId) ??
1422 nodeSource.firstWhereOrNull((e) => e.uriRaw == baseDefaultNodeUri);
1423 final arbitrumNode = nodeSource.firstWhereOrNull((e) => e.id == arbitrumNodeId) ??
1424 nodeSource.firstWhereOrNull((e) => e.uriRaw == arbitrumDefaultNodeUri);
1425 final bitcoinCashElectrumServer =
1426 nodeSource.firstWhereOrNull((e) => e.id == bitcoinCashElectrumServerId) ??
1427 nodeSource.firstWhereOrNull((e) => e.uriRaw == cakeWalletBitcoinCashDefaultNodeUri);
1428 final nanoNode = nodeSource.firstWhereOrNull((e) => e.id == nanoNodeId) ??
1429 nodeSource.firstWhereOrNull((e) => e.uriRaw == nanoDefaultNodeUri);
1430 final decredNode = nodeSource.firstWhereOrNull((e) => e.id == decredNodeId) ??
1431 nodeSource.firstWhereOrNull((e) => e.uriRaw == decredDefaultUri);
1432 final nanoPowNode = powNodeSource.firstWhereOrNull((e) => e.id == nanoPowNodeId) ??
1433 powNodeSource.firstWhereOrNull((e) => e.uriRaw == nanoDefaultPowNodeUri);
1434 final solanaNode = nodeSource.firstWhereOrNull((e) => e.id == solanaNodeId) ??
1435 nodeSource.firstWhereOrNull((e) => e.uriRaw == solanaDefaultNodeUri);
1436 final tronNode = nodeSource.firstWhereOrNull((e) => e.id == tronNodeId) ??
1437 nodeSource.firstWhereOrNull((e) => e.uriRaw == tronDefaultNodeUri);
1438 final wowneroNode = nodeSource.firstWhereOrNull((e) => e.id == wowneroNodeId) ??
1439 nodeSource.firstWhereOrNull((e) => e.uriRaw == wowneroDefaultNodeUri);
1440 final zanoNode = nodeSource.firstWhereOrNull((e) => e.id == zanoNodeId) ??
1441 nodeSource.firstWhereOrNull((e) => e.uriRaw == zanoDefaultNodeUri);
1442 final dogecoinNode = nodeSource.firstWhereOrNull((e) => e.id == dogecoinNodeId) ??
1443 nodeSource.firstWhereOrNull((e) => e.uriRaw == dogecoinDefaultNodeUri);
1444 final zcashNode = nodeSource.firstWhereOrNull((e) => e.id == zcashNodeId) ??
1445 nodeSource.firstWhereOrNull((e) => e.uriRaw == zcashDefaultNodeUri);
1446 final bscNode = nodeSource.firstWhereOrNull((e) => e.id == bscNodeId) ??
1447 nodeSource.firstWhereOrNull((e) => e.uriRaw == bscDefaultNodeUri);
1448
1449 final packageInfo = await PackageInfo.fromPlatform();
1450 final deviceName = await _getDeviceName() ?? '';
1451 final shouldShowYatPopup = sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? true;
1452 final shouldShowDEuroDisclaimer =
1453 sharedPreferences.getBool(PreferencesKey.shouldShowDEuroDisclaimer) ?? true;
1454 final shouldShowRepWarning =
1455 sharedPreferences.getBool(PreferencesKey.shouldShowRepWarning) ?? true;
1456
1457 final generateSubaddresses =
1458 sharedPreferences.getInt(PreferencesKey.autoGenerateSubaddressStatusKey);
1459
1460 final autoGenerateSubaddressStatus = generateSubaddresses != null
1461 ? AutoGenerateSubaddressStatus.deserialize(raw: generateSubaddresses)
1462 : defaultAutoGenerateSubaddressStatus;
1463
1464 final _moneroSeedType = sharedPreferences.getInt(PreferencesKey.moneroSeedType);
1465
1466 final moneroSeedType = _moneroSeedType != null
1467 ? MoneroSeedType.deserialize(raw: _moneroSeedType)
1468 : defaultMoneroSeedType;
1469
1470 final _bitcoinSeedType = sharedPreferences.getInt(PreferencesKey.bitcoinSeedType);
1471
1472 final bitcoinSeedType = _bitcoinSeedType != null
1473 ? BitcoinSeedType.deserialize(raw: _bitcoinSeedType)
1474 : defaultBitcoinSeedType;
1475
1476 final _nanoSeedType = sharedPreferences.getInt(PreferencesKey.nanoSeedType);
1477
1478 final nanoSeedType =
1479 _nanoSeedType != null ? NanoSeedType.deserialize(raw: _nanoSeedType) : defaultNanoSeedType;
1480
1481 final nodes = <WalletType, Node>{};
1482 final powNodes = <WalletType, Node>{};
1483
1484 if (moneroNode != null) {
1485 nodes[WalletType.monero] = moneroNode;
1486 }
1487
1488 if (bitcoinElectrumServer != null) {
1489 nodes[WalletType.bitcoin] = bitcoinElectrumServer;
1490 }
1491
1492 if (litecoinElectrumServer != null) {
1493 nodes[WalletType.litecoin] = litecoinElectrumServer;
1494 }
1495
1496 if (ethereumNode != null) {
1497 nodes[WalletType.ethereum] = ethereumNode;
1498 }
1499
1500 if (polygonNode != null) {
1501 nodes[WalletType.polygon] = polygonNode;
1502 }
1503
1504 if (baseNode != null) {
1505 nodes[WalletType.base] = baseNode;
1506 }
1507
1508 if (arbitrumNode != null) {
1509 nodes[WalletType.arbitrum] = arbitrumNode;
1510 }
1511
1512 if (bscNode != null) {
1513 nodes[WalletType.bsc] = bscNode;
1514 }
1515
1516 if (bitcoinCashElectrumServer != null) {
1517 nodes[WalletType.bitcoinCash] = bitcoinCashElectrumServer;
1518 }
1519
1520 if (nanoNode != null) {
1521 nodes[WalletType.nano] = nanoNode;
1522 }
1523
1524 if (nanoPowNode != null) {
1525 powNodes[WalletType.nano] = nanoPowNode;
1526 }
1527
1528 if (solanaNode != null) {
1529 nodes[WalletType.solana] = solanaNode;
1530 }
1531
1532 if (tronNode != null) {
1533 nodes[WalletType.tron] = tronNode;
1534 }
1535
1536 if (wowneroNode != null) {
1537 nodes[WalletType.wownero] = wowneroNode;
1538 }
1539
1540 if (zanoNode != null) {
1541 nodes[WalletType.zano] = zanoNode;
1542 }
1543
1544 if (zcashNode != null) {
1545 nodes[WalletType.zcash] = zcashNode;
1546 }
1547
1548 if (decredNode != null) {
1549 nodes[WalletType.decred] = decredNode;
1550 }
1551
1552 if (dogecoinNode != null) {
1553 nodes[WalletType.dogecoin] = dogecoinNode;
1554 }
1555
1556 final savedSyncMode = SyncMode.all.firstWhere((element) {
1557 return element.type.index ==
1558 (sharedPreferences.getInt(PreferencesKey.syncModeKey) ?? 2); // default to 2 - daily sync
1559 });
1560 final savedSyncAll = sharedPreferences.getBool(PreferencesKey.syncAllKey) ?? true;
1561 final builtinTor = sharedPreferences.getBool(PreferencesKey.builtinTorKey) ?? false;
1562
1563 // migrated to secure:
1564 final timeOutDuration = await SecureKey.getInt(
1565 secureStorage: secureStorage,
1566 sharedPreferences: sharedPreferences,
1567 key: SecureKey.pinTimeOutDuration,
1568 );
1569
1570 final pinCodeTimeOutDuration = timeOutDuration != null
1571 ? PinCodeRequiredDuration.deserialize(raw: timeOutDuration)
1572 : defaultPinCodeTimeOutDuration;
1573
1574 final allowBiometricalAuthentication = await SecureKey.getBool(
1575 secureStorage: secureStorage,
1576 sharedPreferences: sharedPreferences,
1577 key: SecureKey.allowBiometricalAuthenticationKey,
1578 ) ??
1579 false;
1580
1581 final enableDuressPin = await SecureKey.getBool(
1582 secureStorage: secureStorage,
1583 sharedPreferences: sharedPreferences,
1584 key: SecureKey.enableDuressPin,
1585 ) ??
1586 false;
1587
1588 final selectedCake2FAPreset = Cake2FAPresetsOptions.deserialize(
1589 raw: await SecureKey.getInt(
1590 secureStorage: secureStorage,
1591 sharedPreferences: sharedPreferences,
1592 key: SecureKey.selectedCake2FAPreset,
1593 ) ??
1594 Cake2FAPresetsOptions.normal.raw);
1595
1596 final shouldRequireTOTP2FAForAccessingWallet = await SecureKey.getBool(
1597 secureStorage: secureStorage,
1598 sharedPreferences: sharedPreferences,
1599 key: SecureKey.shouldRequireTOTP2FAForAccessingWallet,
1600 ) ??
1601 false;
1602 final shouldRequireTOTP2FAForSendsToContact = await SecureKey.getBool(
1603 secureStorage: secureStorage,
1604 sharedPreferences: sharedPreferences,
1605 key: SecureKey.shouldRequireTOTP2FAForSendsToContact,
1606 ) ??
1607 false;
1608 final shouldRequireTOTP2FAForSendsToNonContact = await SecureKey.getBool(
1609 secureStorage: secureStorage,
1610 sharedPreferences: sharedPreferences,
1611 key: SecureKey.shouldRequireTOTP2FAForSendsToNonContact,
1612 ) ??
1613 false;
1614 final shouldRequireTOTP2FAForSendsToInternalWallets = await SecureKey.getBool(
1615 secureStorage: secureStorage,
1616 sharedPreferences: sharedPreferences,
1617 key: SecureKey.shouldRequireTOTP2FAForSendsToInternalWallets,
1618 ) ??
1619 false;
1620 final shouldRequireTOTP2FAForExchangesToInternalWallets = await SecureKey.getBool(
1621 secureStorage: secureStorage,
1622 sharedPreferences: sharedPreferences,
1623 key: SecureKey.shouldRequireTOTP2FAForExchangesToInternalWallets,
1624 ) ??
1625 false;
1626 final shouldRequireTOTP2FAForExchangesToExternalWallets = await SecureKey.getBool(
1627 secureStorage: secureStorage,
1628 sharedPreferences: sharedPreferences,
1629 key: SecureKey.shouldRequireTOTP2FAForExchangesToExternalWallets,
1630 ) ??
1631 false;
1632 final shouldRequireTOTP2FAForAddingContacts = await SecureKey.getBool(
1633 secureStorage: secureStorage,
1634 sharedPreferences: sharedPreferences,
1635 key: SecureKey.shouldRequireTOTP2FAForAddingContacts,
1636 ) ??
1637 false;
1638 final shouldRequireTOTP2FAForCreatingNewWallets = await SecureKey.getBool(
1639 secureStorage: secureStorage,
1640 sharedPreferences: sharedPreferences,
1641 key: SecureKey.shouldRequireTOTP2FAForCreatingNewWallets,
1642 ) ??
1643 false;
1644 final shouldRequireTOTP2FAForAllSecurityAndBackupSettings = await SecureKey.getBool(
1645 secureStorage: secureStorage,
1646 sharedPreferences: sharedPreferences,
1647 key: SecureKey.shouldRequireTOTP2FAForAllSecurityAndBackupSettings,
1648 ) ??
1649 false;
1650 final useTOTP2FA = await SecureKey.getBool(
1651 secureStorage: secureStorage,
1652 sharedPreferences: sharedPreferences,
1653 key: SecureKey.useTOTP2FA,
1654 ) ??
1655 false;
1656 final totpSecretKey = await SecureKey.getString(
1657 secureStorage: secureStorage,
1658 sharedPreferences: sharedPreferences,
1659 key: SecureKey.totpSecretKey,
1660 ) ??
1661 '';
1662
1663 final mwebAdDismissed =
1664 await sharedPreferences.getBool(PreferencesKey.mwebAdDismissed) ?? false;
1665
1666 final balanceHideCounter =
1667 await sharedPreferences.getInt(PreferencesKey.balanceHideCounter) ?? 0;
1668
1669 return SettingsStore(
1670 secureStorage: secureStorage,
1671 sharedPreferences: sharedPreferences,
1672 initialShouldShowMarketPlaceInDashboard: shouldShowMarketPlaceInDashboard,
1673 initialShowAddressBookPopupEnabled: showAddressBookPopupEnabled,
1674 initialSyncStatusDisplayMode: syncStatusDisplayMode,
1675 nodes: nodes,
1676 powNodes: powNodes,
1677 appVersion: packageInfo.version,
1678 deviceName: deviceName,
1679 displayAmountsInSatoshi: displayAmountsInSatoshi,
1680 isBitcoinBuyEnabled: isBitcoinBuyEnabled,
1681 initialFiatCurrency: currentFiatCurrency,
1682 initialCakePayCountry: currentCakePayCountry,
1683 initialBalanceDisplayMode: currentBalanceDisplayMode,
1684 initialSaveRecipientAddress: shouldSaveRecipientAddress,
1685 initialAutoGenerateSubaddressStatus: autoGenerateSubaddressStatus,
1686 initialMoneroSeedType: moneroSeedType,
1687 initialBitcoinSeedType: bitcoinSeedType,
1688 initialNanoSeedType: nanoSeedType,
1689 initialAppSecure: isAppSecure,
1690 initialDisableTrade: disableTradeOption,
1691 initialDisableAutomaticExchangeStatusUpdates: disableAutomaticExchangeStatusUpdates,
1692 initialDisableBulletin: disableBulletin,
1693 initialWalletListOrder: walletListOrder,
1694 initialWalletListAscending: walletListAscending,
1695 initialContactListOrder: contactListOrder,
1696 initialContactListAscending: contactListAscending,
1697 initialFiatMode: currentFiatApiMode,
1698 initialAllowBiometricalAuthentication: allowBiometricalAuthentication,
1699 initialEnableDuressPin: enableDuressPin,
1700 initialCake2FAPresetOptions: selectedCake2FAPreset,
1701 initialUseTOTP2FA: useTOTP2FA,
1702 initialTotpSecretKey: totpSecretKey,
1703 initialFailedTokenTrial: tokenTrialNumber,
1704 initialExchangeStatus: exchangeStatus,
1705 actionlistDisplayMode: actionListDisplayMode,
1706 initialPinLength: pinLength,
1707 pinTimeOutDuration: pinCodeTimeOutDuration,
1708 seedPhraseLength: seedPhraseWordCount,
1709 initialLanguageCode: savedLanguageCode,
1710 sortBalanceBy: sortBalanceBy,
1711 pinNativeTokenAtTop: pinNativeTokenAtTop,
1712 useEtherscan: useEtherscan,
1713 usePolygonScan: usePolygonScan,
1714 useBaseScan: useBaseScan,
1715 useArbiScan: useArbiScan,
1716 useBscScan: useBscScan,
1717 useTronGrid: useTronGrid,
1718 useMempoolFeeAPI: useMempoolFeeAPI,
1719 useBlinkProtection: useBlinkProtection,
1720 initialEvmHiddenChainIds: evmHiddenChainIds,
1721 defaultNanoRep: defaultNanoRep,
1722 defaultBananoRep: defaultBananoRep,
1723 lookupsTwitter: lookupsTwitter,
1724 lookupsZanoAlias: lookupsZanoAlias,
1725 lookupsMastodon: lookupsMastodon,
1726 lookupsYatService: lookupsYatService,
1727 lookupsUnstoppableDomains: lookupsUnstoppableDomains,
1728 lookupsOpenAlias: lookupsOpenAlias,
1729 lookupsENS: lookupsENS,
1730 lookupsZcashNames: lookupsZcashNames,
1731 lookupsZcashAddress: lookupsZcashAddress,
1732 lookupsWellKnown: lookupsWellKnown,
1733 lookupsFio: lookupsFio,
1734 lookupsNostr: lookupsNostr,
1735 lookupsThorChain: lookupsThorChain,
1736 lookupsBip353: lookupsBip353,
1737 lookupsLNUrl: lookupsLNUrl,
1738 usePayjoin: usePayjoin,
1739 showPayjoinCard: showPayjoinCard,
1740 customBitcoinFeeRate: customBitcoinFeeRate,
1741 silentPaymentsCardDisplay: silentPaymentsCardDisplay,
1742 mwebAlwaysScan: mwebAlwaysScan,
1743 mwebCardDisplay: mwebCardDisplay,
1744 showZcashMissingFundsCard: showZcashMissingFundsCard,
1745 mwebEnabled: mwebEnabled,
1746 mwebNodeUri: mwebNodeUri,
1747 hasEnabledMwebBefore: hasEnabledMwebBefore,
1748 forceDecentralizedExchanges: forceDecentralizedExchanges,
1749 decentralizedExchangesPromptDismissed: decentralizedExchangesPromptDismissed,
1750 initialEnableAutomaticNodeSwitching: enableAutomaticNodeSwitching,
1751 initialBackgroundImage: backgroundImage,
1752 initialMoneroTransactionPriority: moneroTransactionPriority,
1753 initialWowneroTransactionPriority: wowneroTransactionPriority,
1754 initialZanoTransactionPriority: zanoTransactionPriority,
1755 initialBitcoinTransactionPriority: bitcoinTransactionPriority,
1756 initialHavenTransactionPriority: havenTransactionPriority,
1757 initialLitecoinTransactionPriority: litecoinTransactionPriority,
1758 initialBitcoinCashTransactionPriority: bitcoinCashTransactionPriority,
1759 initialDecredTransactionPriority: decredTransactionPriority,
1760 initialZcashTransactionPriority: zcashTransactionPriority,
1761 initialDogecoinTransactionPriority: dogecoinTransactionPriority,
1762 initialShouldRequireTOTP2FAForAccessingWallet: shouldRequireTOTP2FAForAccessingWallet,
1763 initialShouldRequireTOTP2FAForSendsToContact: shouldRequireTOTP2FAForSendsToContact,
1764 initialShouldRequireTOTP2FAForSendsToNonContact: shouldRequireTOTP2FAForSendsToNonContact,
1765 initialShouldRequireTOTP2FAForSendsToInternalWallets:
1766 shouldRequireTOTP2FAForSendsToInternalWallets,
1767 initialShouldRequireTOTP2FAForExchangesToInternalWallets:
1768 shouldRequireTOTP2FAForExchangesToInternalWallets,
1769 initialShouldRequireTOTP2FAForExchangesToExternalWallets:
1770 shouldRequireTOTP2FAForExchangesToExternalWallets,
1771 initialShouldRequireTOTP2FAForAddingContacts: shouldRequireTOTP2FAForAddingContacts,
1772 initialShouldRequireTOTP2FAForCreatingNewWallets: shouldRequireTOTP2FAForCreatingNewWallets,
1773 initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings:
1774 shouldRequireTOTP2FAForAllSecurityAndBackupSettings,
1775 initialEthereumTransactionPriority: ethereumTransactionPriority,
1776 initialEVMTransactionPriority: evmTransactionPriority,
1777 initialPolygonTransactionPriority: polygonTransactionPriority,
1778 initialBaseTransactionPriority: baseTransactionPriority,
1779 initialBscTransactionPriority: bscTransactionPriority,
1780 initialSyncMode: savedSyncMode,
1781 initialSyncAll: savedSyncAll,
1782 shouldShowYatPopup: shouldShowYatPopup,
1783 shouldShowDEuroDisclaimer: shouldShowDEuroDisclaimer,
1784 shouldShowRepWarning: shouldShowRepWarning,
1785 initialBuiltinTor: builtinTor,
1786 mwebAdDismissed: mwebAdDismissed,
1787 balanceHideCounter: balanceHideCounter,
1788 zcashMigrationModalViewed: zcashMigrationModalViewed
1789 );
1790 }
1791
1792 Future<void> reload() async {
1793 final sharedPreferences = await getIt.getAsync<SharedPreferences>();
1794
1795 final savedFiatCurrency = sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey);
1796 if (savedFiatCurrency != null) {
1797 fiatCurrency = FiatCurrency.deserialize(raw: savedFiatCurrency);
1798 }
1799
1800 if (monero != null &&
1801 sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority) != null) {
1802 priority[WalletType.monero] = monero!.deserializeMoneroTransactionPriority(
1803 raw: sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!);
1804 }
1805
1806 if (wownero != null &&
1807 sharedPreferences.getInt(PreferencesKey.wowneroTransactionPriority) != null) {
1808 priority[WalletType.wownero] = wownero!.deserializeWowneroTransactionPriority(
1809 raw: sharedPreferences.getInt(PreferencesKey.wowneroTransactionPriority)!);
1810 }
1811
1812 if (bitcoin != null &&
1813 sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority) != null) {
1814 priority[WalletType.bitcoin] = bitcoin!.deserializeBitcoinTransactionPriority(
1815 sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority)!);
1816 }
1817
1818 if (monero != null &&
1819 sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) {
1820 priority[WalletType.haven] = monero!.deserializeMoneroTransactionPriority(
1821 raw: sharedPreferences.getInt(PreferencesKey.havenTransactionPriority)!);
1822 }
1823 if (bitcoin != null &&
1824 sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority) != null) {
1825 priority[WalletType.litecoin] = bitcoin!.deserializeLitecoinTransactionPriority(
1826 sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority)!);
1827 }
1828 if (evm != null &&
1829 sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority) != null) {
1830 priority[WalletType.ethereum] = evm!.deserializeEVMTransactionPriority(
1831 sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!);
1832 }
1833 if (evm != null &&
1834 sharedPreferences.getInt(PreferencesKey.polygonTransactionPriority) != null) {
1835 priority[WalletType.polygon] = evm!.deserializeEVMTransactionPriority(
1836 sharedPreferences.getInt(PreferencesKey.polygonTransactionPriority)!);
1837 }
1838 if (evm != null && sharedPreferences.getInt(PreferencesKey.baseTransactionPriority) != null) {
1839 priority[WalletType.base] = evm!.deserializeEVMTransactionPriority(
1840 sharedPreferences.getInt(PreferencesKey.baseTransactionPriority)!);
1841 }
1842 if (evm != null && sharedPreferences.getInt(PreferencesKey.bscTransactionPriority) != null) {
1843 priority[WalletType.bsc] = evm!.deserializeEVMTransactionPriority(
1844 sharedPreferences.getInt(PreferencesKey.bscTransactionPriority)!);
1845 }
1846 if (bitcoinCash != null &&
1847 sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority) != null) {
1848 priority[WalletType.bitcoinCash] = bitcoinCash!.deserializeBitcoinCashTransactionPriority(
1849 sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority)!);
1850 }
1851 if (zano != null && sharedPreferences.getInt(PreferencesKey.zanoTransactionPriority) != null) {
1852 priority[WalletType.zano] = zano!.deserializeMoneroTransactionPriority(
1853 raw: sharedPreferences.getInt(PreferencesKey.zanoTransactionPriority)!);
1854 }
1855 if (decred != null &&
1856 sharedPreferences.getInt(PreferencesKey.decredTransactionPriority) != null) {
1857 priority[WalletType.decred] = decred!.deserializeDecredTransactionPriority(
1858 sharedPreferences.getInt(PreferencesKey.decredTransactionPriority)!);
1859 }
1860 if (zcash != null &&
1861 sharedPreferences.getInt(PreferencesKey.zcashTransactionPriority) != null) {
1862 priority[WalletType.zcash] = zcash!.deserializeZcashTransactionPriority(
1863 raw: sharedPreferences.getInt(PreferencesKey.zcashTransactionPriority)!);
1864 }
1865 if (dogecoin != null &&
1866 sharedPreferences.getInt(PreferencesKey.dogecoinTransactionPriority) != null) {
1867 priority[WalletType.dogecoin] = dogecoin!.deserializeDogeCoinTransactionPriority(
1868 sharedPreferences.getInt(PreferencesKey.dogecoinTransactionPriority)!);
1869 }
1870
1871 final generateSubaddresses =
1872 sharedPreferences.getInt(PreferencesKey.autoGenerateSubaddressStatusKey);
1873
1874 autoGenerateSubaddressStatus = generateSubaddresses != null
1875 ? AutoGenerateSubaddressStatus.deserialize(raw: generateSubaddresses)
1876 : defaultAutoGenerateSubaddressStatus;
1877
1878 final _moneroSeedType = sharedPreferences.getInt(PreferencesKey.moneroSeedType);
1879
1880 moneroSeedType = _moneroSeedType != null
1881 ? MoneroSeedType.deserialize(raw: _moneroSeedType)
1882 : defaultMoneroSeedType;
1883
1884 final _bitcoinSeedType = sharedPreferences.getInt(PreferencesKey.bitcoinSeedType);
1885
1886 bitcoinSeedType = _bitcoinSeedType != null
1887 ? BitcoinSeedType.deserialize(raw: _bitcoinSeedType)
1888 : defaultBitcoinSeedType;
1889
1890 final _nanoSeedType = sharedPreferences.getInt(PreferencesKey.nanoSeedType);
1891
1892 nanoSeedType =
1893 _nanoSeedType != null ? NanoSeedType.deserialize(raw: _nanoSeedType) : defaultNanoSeedType;
1894
1895 balanceDisplayMode = BalanceDisplayMode.deserialize(
1896 raw: sharedPreferences.getInt(PreferencesKey.currentBalanceDisplayModeKey)!);
1897 shouldSaveRecipientAddress =
1898 sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ??
1899 shouldSaveRecipientAddress;
1900 numberOfFailedTokenTrials =
1901 sharedPreferences.getInt(PreferencesKey.failedTotpTokenTrials) ?? numberOfFailedTokenTrials;
1902 isAppSecure = sharedPreferences.getBool(PreferencesKey.isAppSecureKey) ?? isAppSecure;
1903 disableTradeOption =
1904 sharedPreferences.getBool(PreferencesKey.disableTradeOption) ?? disableTradeOption;
1905 disableAutomaticExchangeStatusUpdates =
1906 sharedPreferences.getBool(PreferencesKey.disableAutomaticExchangeStatusUpdates) ??
1907 disableAutomaticExchangeStatusUpdates;
1908 disableBulletin =
1909 sharedPreferences.getBool(PreferencesKey.disableBulletinKey) ?? disableBulletin;
1910 walletListOrder =
1911 FilterListOrderType.values[sharedPreferences.getInt(PreferencesKey.walletListOrder) ?? 0];
1912 contactListOrder =
1913 FilterListOrderType.values[sharedPreferences.getInt(PreferencesKey.contactListOrder) ?? 0];
1914 walletListAscending = sharedPreferences.getBool(PreferencesKey.walletListAscending) ?? true;
1915 contactListAscending = sharedPreferences.getBool(PreferencesKey.contactListAscending) ?? true;
1916 shouldShowMarketPlaceInDashboard =
1917 sharedPreferences.getBool(PreferencesKey.shouldShowMarketPlaceInDashboard) ??
1918 shouldShowMarketPlaceInDashboard;
1919 showAddressBookPopupEnabled =
1920 sharedPreferences.getBool(PreferencesKey.showAddressBookPopupEnabled) ??
1921 showAddressBookPopupEnabled;
1922 syncStatusDisplayMode = SyncStatusDisplayModeExtension.fromString(
1923 sharedPreferences.getString(PreferencesKey.syncStatusDisplayMode) ??
1924 SyncStatusDisplayMode.blocksRemaining.name);
1925 exchangeStatus = ExchangeApiMode.deserialize(
1926 raw: sharedPreferences.getInt(PreferencesKey.exchangeStatusKey) ??
1927 ExchangeApiMode.enabled.raw);
1928 actionlistDisplayMode = ObservableList<ActionListDisplayMode>();
1929 actionlistDisplayMode.addAll(deserializeActionlistDisplayModes(
1930 sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ?? defaultActionsMode));
1931 enableAutomaticNodeSwitching =
1932 sharedPreferences.getBool(PreferencesKey.enableAutomaticNodeSwitching) ??
1933 enableAutomaticNodeSwitching;
1934 var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength);
1935 // If no value
1936 if (pinLength == null || pinLength == 0) {
1937 pinLength = pinCodeLength;
1938 }
1939 pinCodeLength = pinLength;
1940
1941 languageCode = sharedPreferences.getString(PreferencesKey.currentLanguageCode) ?? languageCode;
1942 shouldShowYatPopup =
1943 sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? shouldShowYatPopup;
1944 shouldShowDEuroDisclaimer =
1945 sharedPreferences.getBool(PreferencesKey.shouldShowDEuroDisclaimer) ??
1946 shouldShowDEuroDisclaimer;
1947 shouldShowRepWarning =
1948 sharedPreferences.getBool(PreferencesKey.shouldShowRepWarning) ?? shouldShowRepWarning;
1949 sortBalanceBy = SortBalanceBy
1950 .values[sharedPreferences.getInt(PreferencesKey.sortBalanceBy) ?? sortBalanceBy.index];
1951 pinNativeTokenAtTop = sharedPreferences.getBool(PreferencesKey.pinNativeTokenAtTop) ?? true;
1952 useEtherscan = sharedPreferences.getBool(PreferencesKey.useEtherscan) ?? true;
1953 usePolygonScan = sharedPreferences.getBool(PreferencesKey.usePolygonScan) ?? true;
1954 useBaseScan = sharedPreferences.getBool(PreferencesKey.useBaseScan) ?? true;
1955 useArbiScan = sharedPreferences.getBool(PreferencesKey.useArbiScan) ?? true;
1956 useBscScan = sharedPreferences.getBool(PreferencesKey.useBscScan) ?? true;
1957 useTronGrid = sharedPreferences.getBool(PreferencesKey.useTronGrid) ?? true;
1958 useMempoolFeeAPI = sharedPreferences.getBool(PreferencesKey.useMempoolFeeAPI) ?? true;
1959 useBlinkProtection = sharedPreferences.getBool(PreferencesKey.useBlinkProtection) ?? true;
1960 final hiddenChainIdsRaw =
1961 sharedPreferences.getStringList(PreferencesKey.evmHiddenChainIds) ?? const <String>[];
1962 evmHiddenChainIds
1963 ..clear()
1964 ..addAll(hiddenChainIdsRaw.map((value) => int.tryParse(value)).whereType<int>());
1965 defaultNanoRep = sharedPreferences.getString(PreferencesKey.defaultNanoRep) ?? "";
1966 defaultBananoRep = sharedPreferences.getString(PreferencesKey.defaultBananoRep) ?? "";
1967 lookupsTwitter = sharedPreferences.getBool(PreferencesKey.lookupsTwitter) ?? true;
1968 lookupsZanoAlias = sharedPreferences.getBool(PreferencesKey.lookupsZanoAlias) ?? true;
1969 lookupsMastodon = sharedPreferences.getBool(PreferencesKey.lookupsMastodon) ?? true;
1970 lookupsYatService = sharedPreferences.getBool(PreferencesKey.lookupsYatService) ?? true;
1971 lookupsUnstoppableDomains =
1972 sharedPreferences.getBool(PreferencesKey.lookupsUnstoppableDomains) ?? true;
1973 lookupsOpenAlias = sharedPreferences.getBool(PreferencesKey.lookupsOpenAlias) ?? true;
1974 lookupsENS = sharedPreferences.getBool(PreferencesKey.lookupsENS) ?? true;
1975 lookupsZcashNames = sharedPreferences.getBool(PreferencesKey.lookupsZcashNames) ?? true;
1976 lookupsWellKnown = sharedPreferences.getBool(PreferencesKey.lookupsWellKnown) ?? true;
1977 customBitcoinFeeRate = sharedPreferences.getInt(PreferencesKey.customBitcoinFeeRate) ?? 1;
1978 silentPaymentsCardDisplay =
1979 sharedPreferences.getBool(PreferencesKey.silentPaymentsCardDisplay) ?? true;
1980 mwebAlwaysScan = sharedPreferences.getBool(PreferencesKey.mwebAlwaysScan) ?? false;
1981 mwebCardDisplay = sharedPreferences.getBool(PreferencesKey.mwebCardDisplay) ?? true;
1982 showZcashMissingFundsCard =
1983 sharedPreferences.getBool(PreferencesKey.showZcashMissingFundsCard) ?? true;
1984 mwebEnabled = sharedPreferences.getBool(PreferencesKey.mwebEnabled) ?? false;
1985 hasEnabledMwebBefore = sharedPreferences.getBool(PreferencesKey.hasEnabledMwebBefore) ?? false;
1986 final nodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
1987 final bitcoinElectrumServerId =
1988 sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
1989 final litecoinElectrumServerId =
1990 sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
1991 final bitcoinCashElectrumServerId =
1992 sharedPreferences.getInt(PreferencesKey.currentBitcoinCashNodeIdKey);
1993 final havenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey);
1994 final ethereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey);
1995 final polygonNodeId = sharedPreferences.getInt(PreferencesKey.currentPolygonNodeIdKey);
1996 final baseNodeId = sharedPreferences.getInt(PreferencesKey.currentBaseNodeIdKey);
1997 final arbitrumNodeId = sharedPreferences.getInt(PreferencesKey.currentArbitrumNodeIdKey);
1998 final bscNodeId = sharedPreferences.getInt(PreferencesKey.currentBscNodeIdKey);
1999 final nanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey);
2000 final solanaNodeId = sharedPreferences.getInt(PreferencesKey.currentSolanaNodeIdKey);
2001 final tronNodeId = sharedPreferences.getInt(PreferencesKey.currentTronNodeIdKey);
2002 final wowneroNodeId = sharedPreferences.getInt(PreferencesKey.currentWowneroNodeIdKey);
2003 final zanoNodeId = sharedPreferences.getInt(PreferencesKey.currentZanoNodeIdKey);
2004 final zcashNodeId = sharedPreferences.getInt(PreferencesKey.currentZcashNodeIdKey);
2005 final decredNodeId = sharedPreferences.getInt(PreferencesKey.currentDecredNodeIdKey);
2006 final dogecoinNodeId = sharedPreferences.getInt(PreferencesKey.currentDogecoinNodeIdKey);
2007 final moneroNode = await Node.get(nodeId ?? -1);
2008 final bitcoinElectrumServer = await Node.get(bitcoinElectrumServerId ?? -1);
2009 final litecoinElectrumServer = await Node.get(litecoinElectrumServerId ?? -1);
2010 final havenNode = await Node.get(havenNodeId ?? -1);
2011 final ethereumNode = await Node.get(ethereumNodeId ?? -1);
2012 final polygonNode = await Node.get(polygonNodeId ?? -1);
2013 final baseNode = await Node.get(baseNodeId ?? -1);
2014 final arbitrumNode = await Node.get(arbitrumNodeId ?? -1);
2015 final bscNode = await Node.get(bscNodeId ?? -1);
2016 final bitcoinCashNode = await Node.get(bitcoinCashElectrumServerId ?? -1);
2017 final nanoNode = await Node.get(nanoNodeId ?? -1);
2018 final solanaNode = await Node.get(solanaNodeId ?? -1);
2019 final tronNode = await Node.get(tronNodeId ?? -1);
2020 final wowneroNode = await Node.get(wowneroNodeId ?? -1);
2021 final zanoNode = await Node.get(zanoNodeId ?? -1);
2022 final zcashNode = await Node.get(zcashNodeId ?? -1);
2023 final decredNode = await Node.get(decredNodeId ?? -1);
2024 final dogecoinNode = await Node.get(dogecoinNodeId ?? -1);
2025
2026 if (moneroNode != null) {
2027 nodes[WalletType.monero] = moneroNode;
2028 }
2029
2030 if (bitcoinElectrumServer != null) {
2031 nodes[WalletType.bitcoin] = bitcoinElectrumServer;
2032 }
2033
2034 if (litecoinElectrumServer != null) {
2035 nodes[WalletType.litecoin] = litecoinElectrumServer;
2036 }
2037
2038 if (havenNode != null) {
2039 nodes[WalletType.haven] = havenNode;
2040 }
2041
2042 if (ethereumNode != null) {
2043 nodes[WalletType.ethereum] = ethereumNode;
2044 }
2045
2046 if (polygonNode != null) {
2047 nodes[WalletType.polygon] = polygonNode;
2048 }
2049
2050 if (baseNode != null) {
2051 nodes[WalletType.base] = baseNode;
2052 }
2053
2054 if (arbitrumNode != null) {
2055 nodes[WalletType.arbitrum] = arbitrumNode;
2056 }
2057
2058 if (bscNode != null) {
2059 nodes[WalletType.bsc] = bscNode;
2060 }
2061
2062 if (bitcoinCashNode != null) {
2063 nodes[WalletType.bitcoinCash] = bitcoinCashNode;
2064 }
2065
2066 if (nanoNode != null) {
2067 nodes[WalletType.nano] = nanoNode;
2068 }
2069
2070 if (solanaNode != null) {
2071 nodes[WalletType.solana] = solanaNode;
2072 }
2073
2074 if (tronNode != null) {
2075 nodes[WalletType.tron] = tronNode;
2076 }
2077
2078 if (wowneroNode != null) {
2079 nodes[WalletType.wownero] = wowneroNode;
2080 }
2081
2082 if (zanoNode != null) {
2083 nodes[WalletType.zano] = zanoNode;
2084 }
2085
2086 if (zcashNode != null) {
2087 nodes[WalletType.zcash] = zcashNode;
2088 }
2089
2090 if (decredNode != null) {
2091 nodes[WalletType.decred] = decredNode;
2092 }
2093
2094 if (dogecoinNode != null) {
2095 nodes[WalletType.dogecoin] = dogecoinNode;
2096 }
2097
2098 // MIGRATED:
2099
2100 useTOTP2FA = await SecureKey.getBool(
2101 secureStorage: _secureStorage,
2102 sharedPreferences: sharedPreferences,
2103 key: SecureKey.useTOTP2FA,
2104 ) ??
2105 useTOTP2FA;
2106
2107 totpSecretKey = await SecureKey.getString(
2108 secureStorage: _secureStorage,
2109 sharedPreferences: sharedPreferences,
2110 key: SecureKey.totpSecretKey,
2111 ) ??
2112 totpSecretKey;
2113
2114 final timeOutDuration = await SecureKey.getInt(
2115 secureStorage: _secureStorage,
2116 sharedPreferences: sharedPreferences,
2117 key: SecureKey.pinTimeOutDuration,
2118 );
2119
2120 pinTimeOutDuration = timeOutDuration != null
2121 ? PinCodeRequiredDuration.deserialize(raw: timeOutDuration)
2122 : defaultPinCodeTimeOutDuration;
2123
2124 allowBiometricalAuthentication = await SecureKey.getBool(
2125 secureStorage: _secureStorage,
2126 sharedPreferences: sharedPreferences,
2127 key: SecureKey.allowBiometricalAuthenticationKey,
2128 ) ??
2129 allowBiometricalAuthentication;
2130
2131 selectedCake2FAPreset = Cake2FAPresetsOptions.deserialize(
2132 raw: await SecureKey.getInt(
2133 secureStorage: _secureStorage,
2134 sharedPreferences: sharedPreferences,
2135 key: SecureKey.selectedCake2FAPreset,
2136 ) ??
2137 Cake2FAPresetsOptions.normal.raw);
2138
2139 shouldRequireTOTP2FAForAccessingWallet = await SecureKey.getBool(
2140 secureStorage: _secureStorage,
2141 sharedPreferences: sharedPreferences,
2142 key: SecureKey.shouldRequireTOTP2FAForAccessingWallet,
2143 ) ??
2144 false;
2145 shouldRequireTOTP2FAForSendsToContact = await SecureKey.getBool(
2146 secureStorage: _secureStorage,
2147 sharedPreferences: sharedPreferences,
2148 key: SecureKey.shouldRequireTOTP2FAForSendsToContact,
2149 ) ??
2150 false;
2151
2152 shouldRequireTOTP2FAForSendsToNonContact = await SecureKey.getBool(
2153 secureStorage: _secureStorage,
2154 sharedPreferences: sharedPreferences,
2155 key: SecureKey.shouldRequireTOTP2FAForSendsToNonContact,
2156 ) ??
2157 false;
2158 shouldRequireTOTP2FAForSendsToInternalWallets = await SecureKey.getBool(
2159 secureStorage: _secureStorage,
2160 sharedPreferences: sharedPreferences,
2161 key: SecureKey.shouldRequireTOTP2FAForSendsToInternalWallets,
2162 ) ??
2163 false;
2164 shouldRequireTOTP2FAForExchangesToInternalWallets = await SecureKey.getBool(
2165 secureStorage: _secureStorage,
2166 sharedPreferences: sharedPreferences,
2167 key: SecureKey.shouldRequireTOTP2FAForExchangesToInternalWallets,
2168 ) ??
2169 false;
2170 shouldRequireTOTP2FAForExchangesToExternalWallets = await SecureKey.getBool(
2171 secureStorage: _secureStorage,
2172 sharedPreferences: sharedPreferences,
2173 key: SecureKey.shouldRequireTOTP2FAForExchangesToExternalWallets,
2174 ) ??
2175 false;
2176 shouldRequireTOTP2FAForAddingContacts = await SecureKey.getBool(
2177 secureStorage: _secureStorage,
2178 sharedPreferences: sharedPreferences,
2179 key: SecureKey.shouldRequireTOTP2FAForAddingContacts,
2180 ) ??
2181 false;
2182 shouldRequireTOTP2FAForCreatingNewWallets = await SecureKey.getBool(
2183 secureStorage: _secureStorage,
2184 sharedPreferences: sharedPreferences,
2185 key: SecureKey.shouldRequireTOTP2FAForCreatingNewWallets,
2186 ) ??
2187 false;
2188 shouldRequireTOTP2FAForAllSecurityAndBackupSettings = await SecureKey.getBool(
2189 secureStorage: _secureStorage,
2190 sharedPreferences: sharedPreferences,
2191 key: SecureKey.shouldRequireTOTP2FAForAllSecurityAndBackupSettings,
2192 ) ??
2193 false;
2194 }
2195
2196 Future<void> _saveCurrentNode(Node node, WalletType walletType) async {
2197 switch (walletType) {
2198 case WalletType.bitcoin:
2199 await _sharedPreferences.setInt(PreferencesKey.currentBitcoinElectrumSererIdKey, node.id);
2200 break;
2201 case WalletType.litecoin:
2202 await _sharedPreferences.setInt(PreferencesKey.currentLitecoinElectrumSererIdKey, node.id);
2203 break;
2204 case WalletType.monero:
2205 await _sharedPreferences.setInt(PreferencesKey.currentNodeIdKey, node.id);
2206 break;
2207 case WalletType.haven:
2208 await _sharedPreferences.setInt(PreferencesKey.currentHavenNodeIdKey, node.id);
2209 break;
2210 case WalletType.ethereum:
2211 case WalletType.polygon:
2212 case WalletType.base:
2213 case WalletType.arbitrum:
2214 case WalletType.bsc:
2215 final chainId = evm!.getChainIdByWalletType(node.type);
2216 final preferenceKey = _getEVMNodePreferenceKey(chainId);
2217 await _sharedPreferences.setInt(preferenceKey, node.id);
2218 nodes[node.type] = node;
2219 break;
2220 case WalletType.bitcoinCash:
2221 await _sharedPreferences.setInt(PreferencesKey.currentBitcoinCashNodeIdKey, node.id);
2222 break;
2223 case WalletType.nano:
2224 await _sharedPreferences.setInt(PreferencesKey.currentNanoNodeIdKey, node.id);
2225 break;
2226 case WalletType.solana:
2227 await _sharedPreferences.setInt(PreferencesKey.currentSolanaNodeIdKey, node.id);
2228 break;
2229 case WalletType.tron:
2230 await _sharedPreferences.setInt(PreferencesKey.currentTronNodeIdKey, node.id);
2231 break;
2232 case WalletType.wownero:
2233 await _sharedPreferences.setInt(PreferencesKey.currentWowneroNodeIdKey, node.id);
2234 break;
2235 case WalletType.decred:
2236 await _sharedPreferences.setInt(PreferencesKey.currentDecredNodeIdKey, node.id);
2237 break;
2238 case WalletType.zano:
2239 await _sharedPreferences.setInt(PreferencesKey.currentZanoNodeIdKey, node.id);
2240 break;
2241 case WalletType.dogecoin:
2242 await _sharedPreferences.setInt(PreferencesKey.currentDogecoinNodeIdKey, node.id);
2243 break;
2244 case WalletType.zcash:
2245 await _sharedPreferences.setInt(PreferencesKey.currentZcashNodeIdKey, node.id);
2246 break;
2247 case WalletType.none:
2248 throw UnimplementedError();
2249 case WalletType.banano:
2250 throw UnimplementedError();
2251 }
2252
2253 nodes[walletType] = node;
2254 }
2255
2256 Future<void> _saveCurrentPowNode(Node node, WalletType walletType) async {
2257 switch (walletType) {
2258 case WalletType.nano:
2259 await _sharedPreferences.setInt(PreferencesKey.currentNanoPowNodeIdKey, node.id);
2260 break;
2261 default:
2262 break;
2263 }
2264
2265 powNodes[walletType] = node;
2266 }
2267
2268 @action
2269 void setEvmHiddenChainIds(Set<int> chainIds) {
2270 evmHiddenChainIds
2271 ..clear()
2272 ..addAll(chainIds);
2273 }
2274
2275 @action
2276 Future<void> updateAllTrocadorProviderStates(List<String> availableProviders) async {
2277 final jsonKey = PreferencesKey.trocadorProviderStatesKey;
2278 String? serializedData = await _sharedPreferences.getString(jsonKey);
2279
2280 if (serializedData == null) {
2281 final Map<String, bool> migratedStates = {};
2282 for (final provider in TrocadorExchangeProvider.availableProviders) {
2283 final oldState = _sharedPreferences.getBool(provider) ?? true;
2284 migratedStates[provider] = oldState;
2285 }
2286
2287 trocadorProviderStates
2288 ..clear()
2289 ..addAll(migratedStates);
2290
2291 await saveMapToString(jsonKey, trocadorProviderStates);
2292 } else {
2293 final decodedMap = json.decode(serializedData) as Map<String, dynamic>;
2294 final oldMap = decodedMap.map((k, v) => MapEntry(k, v == true));
2295
2296 final Map<String, bool> newStates = {
2297 for (final provider in availableProviders) provider: oldMap[provider] ?? true
2298 };
2299
2300 trocadorProviderStates
2301 ..clear()
2302 ..addAll(newStates);
2303 await saveMapToString(jsonKey, trocadorProviderStates);
2304 }
2305 }
2306
2307 @action
2308 Future<void> setTrocadorProviderState(String providerName, bool state) async {
2309 trocadorProviderStates[providerName] = state;
2310 await saveMapToString(PreferencesKey.trocadorProviderStatesKey, trocadorProviderStates);
2311 }
2312
2313 Future<void> saveMapToString(String key, Map<String, bool> map) async {
2314 String serializedData = json.encode(map);
2315 await _sharedPreferences.setString(key, serializedData);
2316 }
2317
2318 static Future<String?> _getDeviceName() async {
2319 String? deviceName = '';
2320 final deviceInfoPlugin = DeviceInfoPlugin();
2321
2322 if (Platform.isAndroid) {
2323 final androidInfo = await deviceInfoPlugin.androidInfo;
2324 deviceName = '${androidInfo.brand}%20${androidInfo.manufacturer}%20${androidInfo.model}';
2325 } else if (Platform.isIOS) {
2326 final iosInfo = await deviceInfoPlugin.iosInfo;
2327 deviceName = iosInfo.model;
2328 } else if (Platform.isLinux) {
2329 final linuxInfo = await deviceInfoPlugin.linuxInfo;
2330 deviceName = linuxInfo.prettyName;
2331 } else if (Platform.isMacOS) {
2332 final macInfo = await deviceInfoPlugin.macOsInfo;
2333 deviceName = macInfo.computerName;
2334 } else if (Platform.isWindows) {
2335 try {
2336 final windowsInfo = await deviceInfoPlugin.windowsInfo;
2337 deviceName = windowsInfo.productName;
2338 } catch (e) {
2339 printV(e);
2340 printV(
2341 'likely digitalProductId is null wait till https://github.com/fluttercommunity/plus_plugins/pull/3188 is merged');
2342 deviceName = "Windows Device";
2343 }
2344 }
2345
2346 return deviceName;
2347 }
2348 }