1
import 'dart:io';
2
3
import 'package:cake_wallet/bitcoin/bitcoin.dart';
4
+import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
5
import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart';
6
import 'package:cake_wallet/entities/buy_provider_types.dart';
7
import 'package:cake_wallet/entities/cake_2fa_preset_options.dart';
86
TransactionPriority? initialMoneroTransactionPriority,
87
TransactionPriority? initialHavenTransactionPriority,
88
TransactionPriority? initialLitecoinTransactionPriority,
88
- TransactionPriority? initialEthereumTransactionPriority})
89
+ TransactionPriority? initialEthereumTransactionPriority,
90
+ TransactionPriority? initialBitcoinCashTransactionPriority})
91
: nodes = ObservableMap<WalletType, Node>.of(nodes),
92
powNodes = ObservableMap<WalletType, Node>.of(powNodes),
93
_sharedPreferences = sharedPreferences,
148
priority[WalletType.ethereum] = initialEthereumTransactionPriority;
149
}
150
151
+ if (initialBitcoinCashTransactionPriority != null) {
152
+ priority[WalletType.bitcoinCash] = initialBitcoinCashTransactionPriority;
153
+ }
154
+
155
reaction(
156
(_) => fiatCurrency,
157
(FiatCurrency fiatCurrency) => sharedPreferences.setString(
180
case WalletType.ethereum:
181
key = PreferencesKey.ethereumTransactionPriority;
182
break;
183
+ case WalletType.bitcoinCash:
184
+ key = PreferencesKey.bitcoinCashTransactionPriority;
185
+ break;
186
default:
187
key = null;
188
}
535
TransactionPriority? moneroTransactionPriority = monero?.deserializeMoneroTransactionPriority(
536
raw: sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!);
537
TransactionPriority? bitcoinTransactionPriority =
529
- bitcoin?.deserializeBitcoinTransactionPriority(
530
- sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority)!);
538
+ bitcoin?.deserializeBitcoinTransactionPriority(
539
+ sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority)!);
540
541
TransactionPriority? havenTransactionPriority;
542
TransactionPriority? litecoinTransactionPriority;
543
TransactionPriority? ethereumTransactionPriority;
544
+ TransactionPriority? bitcoinCashTransactionPriority;
545
546
if (sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) {
547
havenTransactionPriority = monero?.deserializeMoneroTransactionPriority(
555
ethereumTransactionPriority = bitcoin?.deserializeLitecoinTransactionPriority(
556
sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!);
557
}
558
+ if (sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority) != null) {
559
+ bitcoinCashTransactionPriority = bitcoinCash?.deserializeBitcoinCashTransactionPriority(
560
+ sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority)!);
561
+ }
562
563
moneroTransactionPriority ??= monero?.getDefaultTransactionPriority();
564
bitcoinTransactionPriority ??= bitcoin?.getMediumTransactionPriority();
565
havenTransactionPriority ??= monero?.getDefaultTransactionPriority();
566
litecoinTransactionPriority ??= bitcoin?.getLitecoinTransactionPriorityMedium();
567
ethereumTransactionPriority ??= ethereum?.getDefaultTransactionPriority();
568
+ bitcoinCashTransactionPriority ??= bitcoinCash?.getDefaultTransactionPriority();
569
570
final currentBalanceDisplayMode = BalanceDisplayMode.deserialize(
571
raw: sharedPreferences.getInt(PreferencesKey.currentBalanceDisplayModeKey)!);
575
final isAppSecure = sharedPreferences.getBool(PreferencesKey.isAppSecureKey) ?? false;
576
final disableBuy = sharedPreferences.getBool(PreferencesKey.disableBuyKey) ?? false;
577
final disableSell = sharedPreferences.getBool(PreferencesKey.disableSellKey) ?? false;
563
- final defaultBuyProvider = BuyProviderType.values[sharedPreferences.getInt(PreferencesKey.defaultBuyProvider) ?? 0];
578
+ final defaultBuyProvider = BuyProviderType.values[sharedPreferences.getInt(
579
+ PreferencesKey.defaultBuyProvider) ?? 0];
580
final currentFiatApiMode = FiatApiMode.deserialize(
581
raw: sharedPreferences.getInt(PreferencesKey.currentFiatApiModeKey) ??
582
FiatApiMode.enabled.raw);
595
sharedPreferences.getBool(PreferencesKey.shouldRequireTOTP2FAForSendsToInternalWallets) ??
596
false;
597
final shouldRequireTOTP2FAForExchangesToInternalWallets = sharedPreferences
582
- .getBool(PreferencesKey.shouldRequireTOTP2FAForExchangesToInternalWallets) ??
598
+ .getBool(PreferencesKey.shouldRequireTOTP2FAForExchangesToInternalWallets) ??
599
false;
600
final shouldRequireTOTP2FAForAddingContacts =
601
sharedPreferences.getBool(PreferencesKey.shouldRequireTOTP2FAForAddingContacts) ?? false;
603
sharedPreferences.getBool(PreferencesKey.shouldRequireTOTP2FAForCreatingNewWallets) ??
604
false;
605
final shouldRequireTOTP2FAForAllSecurityAndBackupSettings = sharedPreferences
590
- .getBool(PreferencesKey.shouldRequireTOTP2FAForAllSecurityAndBackupSettings) ??
606
+ .getBool(PreferencesKey.shouldRequireTOTP2FAForAllSecurityAndBackupSettings) ??
607
false;
608
final useTOTP2FA = sharedPreferences.getBool(PreferencesKey.useTOTP2FA) ?? false;
609
final totpSecretKey = sharedPreferences.getString(PreferencesKey.totpSecretKey) ?? '';
628
? PinCodeRequiredDuration.deserialize(raw: timeOutDuration)
629
: defaultPinCodeTimeOutDuration;
630
final sortBalanceBy =
615
- SortBalanceBy.values[sharedPreferences.getInt(PreferencesKey.sortBalanceBy) ?? 0];
631
+ SortBalanceBy.values[sharedPreferences.getInt(PreferencesKey.sortBalanceBy) ?? 0];
632
final pinNativeTokenAtTop =
633
sharedPreferences.getBool(PreferencesKey.pinNativeTokenAtTop) ?? true;
634
final useEtherscan = sharedPreferences.getBool(PreferencesKey.useEtherscan) ?? true;
642
await LanguageService.localeDetection();
643
final nodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
644
final bitcoinElectrumServerId =
629
- sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
645
+ sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
646
final litecoinElectrumServerId =
631
- sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
647
+ sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
648
+ final bitcoinCashElectrumServerId =
649
+ sharedPreferences.getInt(PreferencesKey.currentBitcoinCashNodeIdKey);
650
final havenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey);
651
final ethereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey);
652
final nanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey);
656
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
657
final havenNode = nodeSource.get(havenNodeId);
658
final ethereumNode = nodeSource.get(ethereumNodeId);
659
+ final bitcoinCashElectrumServer = nodeSource.get(bitcoinCashElectrumServerId);
660
final nanoNode = nodeSource.get(nanoNodeId);
661
final nanoPowNode = powNodeSource.get(nanoPowNodeId);
662
final packageInfo = await PackageInfo.fromPlatform();
663
final deviceName = await _getDeviceName() ?? '';
664
final shouldShowYatPopup = sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? true;
665
final generateSubaddresses =
647
- sharedPreferences.getInt(PreferencesKey.autoGenerateSubaddressStatusKey);
666
+ sharedPreferences.getInt(PreferencesKey.autoGenerateSubaddressStatusKey);
667
668
final autoGenerateSubaddressStatus = generateSubaddresses != null
669
? AutoGenerateSubaddressStatus.deserialize(raw: generateSubaddresses)
691
nodes[WalletType.ethereum] = ethereumNode;
692
}
693
694
+ if (bitcoinCashElectrumServer != null) {
695
+ nodes[WalletType.bitcoinCash] = bitcoinCashElectrumServer;
696
+ }
697
+
698
if (nanoNode != null) {
699
nodes[WalletType.nano] = nanoNode;
700
}
701
+
702
if (nanoPowNode != null) {
703
powNodes[WalletType.nano] = nanoPowNode;
704
}
705
682
- final savedSyncMode = SyncMode.all.firstWhere((element) {
683
- return element.type.index == (sharedPreferences.getInt(PreferencesKey.syncModeKey) ?? 1);
684
- });
685
- final savedSyncAll = sharedPreferences.getBool(PreferencesKey.syncAllKey) ?? true;
686
-
687
- return SettingsStore(
688
- sharedPreferences: sharedPreferences,
689
- initialShouldShowMarketPlaceInDashboard: shouldShowMarketPlaceInDashboard,
690
- nodes: nodes,
691
- powNodes: powNodes,
692
- appVersion: packageInfo.version,
693
- deviceName: deviceName,
694
- isBitcoinBuyEnabled: isBitcoinBuyEnabled,
695
- initialFiatCurrency: currentFiatCurrency,
696
- initialBalanceDisplayMode: currentBalanceDisplayMode,
697
- initialSaveRecipientAddress: shouldSaveRecipientAddress,
698
- initialAutoGenerateSubaddressStatus: autoGenerateSubaddressStatus,
699
- initialAppSecure: isAppSecure,
700
- initialDisableBuy: disableBuy,
701
- initialDisableSell: disableSell,
702
- initialDefaultBuyProvider: defaultBuyProvider,
703
- initialFiatMode: currentFiatApiMode,
704
- initialAllowBiometricalAuthentication: allowBiometricalAuthentication,
705
- initialCake2FAPresetOptions: selectedCake2FAPreset,
706
- initialUseTOTP2FA: useTOTP2FA,
707
- initialTotpSecretKey: totpSecretKey,
708
- initialFailedTokenTrial: tokenTrialNumber,
709
- initialExchangeStatus: exchangeStatus,
710
- initialTheme: savedTheme,
711
- actionlistDisplayMode: actionListDisplayMode,
712
- initialPinLength: pinLength,
713
- pinTimeOutDuration: pinCodeTimeOutDuration,
714
- initialLanguageCode: savedLanguageCode,
715
- sortBalanceBy: sortBalanceBy,
716
- pinNativeTokenAtTop: pinNativeTokenAtTop,
717
- useEtherscan: useEtherscan,
718
- initialMoneroTransactionPriority: moneroTransactionPriority,
719
- initialBitcoinTransactionPriority: bitcoinTransactionPriority,
720
- initialHavenTransactionPriority: havenTransactionPriority,
721
- initialLitecoinTransactionPriority: litecoinTransactionPriority,
722
- initialShouldRequireTOTP2FAForAccessingWallet: shouldRequireTOTP2FAForAccessingWallet,
723
- initialShouldRequireTOTP2FAForSendsToContact: shouldRequireTOTP2FAForSendsToContact,
724
- initialShouldRequireTOTP2FAForSendsToNonContact: shouldRequireTOTP2FAForSendsToNonContact,
725
- initialShouldRequireTOTP2FAForSendsToInternalWallets:
726
- shouldRequireTOTP2FAForSendsToInternalWallets,
727
- initialShouldRequireTOTP2FAForExchangesToInternalWallets:
728
- shouldRequireTOTP2FAForExchangesToInternalWallets,
729
- initialShouldRequireTOTP2FAForAddingContacts: shouldRequireTOTP2FAForAddingContacts,
730
- initialShouldRequireTOTP2FAForCreatingNewWallets: shouldRequireTOTP2FAForCreatingNewWallets,
731
- initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings:
732
- shouldRequireTOTP2FAForAllSecurityAndBackupSettings,
733
- initialEthereumTransactionPriority: ethereumTransactionPriority,
734
- backgroundTasks: backgroundTasks,
735
- initialSyncMode: savedSyncMode,
736
- initialSyncAll: savedSyncAll,
737
- shouldShowYatPopup: shouldShowYatPopup);
738
- }
706
+ final savedSyncMode = SyncMode.all.firstWhere((element) {
707
+ return element.type.index == (sharedPreferences.getInt(PreferencesKey.syncModeKey) ?? 1);
708
+ });
709
+ final savedSyncAll = sharedPreferences.getBool(PreferencesKey.syncAllKey) ?? true;
710
+
711
+ return SettingsStore(
712
+ sharedPreferences: sharedPreferences,
713
+ initialShouldShowMarketPlaceInDashboard: shouldShowMarketPlaceInDashboard,
714
+ nodes: nodes,
715
+ powNodes: powNodes,
716
+ appVersion: packageInfo.version,
717
+ deviceName: deviceName,
718
+ isBitcoinBuyEnabled: isBitcoinBuyEnabled,
719
+ initialFiatCurrency: currentFiatCurrency,
720
+ initialBalanceDisplayMode: currentBalanceDisplayMode,
721
+ initialSaveRecipientAddress: shouldSaveRecipientAddress,
722
+ initialAutoGenerateSubaddressStatus: autoGenerateSubaddressStatus,
723
+ initialAppSecure: isAppSecure,
724
+ initialDisableBuy: disableBuy,
725
+ initialDisableSell: disableSell,
726
+ initialDefaultBuyProvider: defaultBuyProvider,
727
+ initialFiatMode: currentFiatApiMode,
728
+ initialAllowBiometricalAuthentication: allowBiometricalAuthentication,
729
+ initialCake2FAPresetOptions: selectedCake2FAPreset,
730
+ initialUseTOTP2FA: useTOTP2FA,
731
+ initialTotpSecretKey: totpSecretKey,
732
+ initialFailedTokenTrial: tokenTrialNumber,
733
+ initialExchangeStatus: exchangeStatus,
734
+ initialTheme: savedTheme,
735
+ actionlistDisplayMode: actionListDisplayMode,
736
+ initialPinLength: pinLength,
737
+ pinTimeOutDuration: pinCodeTimeOutDuration,
738
+ initialLanguageCode: savedLanguageCode,
739
+ sortBalanceBy: sortBalanceBy,
740
+ pinNativeTokenAtTop: pinNativeTokenAtTop,
741
+ useEtherscan: useEtherscan,
742
+ initialMoneroTransactionPriority: moneroTransactionPriority,
743
+ initialBitcoinTransactionPriority: bitcoinTransactionPriority,
744
+ initialHavenTransactionPriority: havenTransactionPriority,
745
+ initialLitecoinTransactionPriority: litecoinTransactionPriority,
746
+ initialBitcoinCashTransactionPriority: bitcoinCashTransactionPriority,
747
+ initialShouldRequireTOTP2FAForAccessingWallet: shouldRequireTOTP2FAForAccessingWallet,
748
+ initialShouldRequireTOTP2FAForSendsToContact: shouldRequireTOTP2FAForSendsToContact,
749
+ initialShouldRequireTOTP2FAForSendsToNonContact: shouldRequireTOTP2FAForSendsToNonContact,
750
+ initialShouldRequireTOTP2FAForSendsToInternalWallets:
751
+ shouldRequireTOTP2FAForSendsToInternalWallets,
752
+ initialShouldRequireTOTP2FAForExchangesToInternalWallets:
753
+ shouldRequireTOTP2FAForExchangesToInternalWallets,
754
+ initialShouldRequireTOTP2FAForAddingContacts: shouldRequireTOTP2FAForAddingContacts,
755
+ initialShouldRequireTOTP2FAForCreatingNewWallets: shouldRequireTOTP2FAForCreatingNewWallets,
756
+ initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings:
757
+ shouldRequireTOTP2FAForAllSecurityAndBackupSettings,
758
+ initialEthereumTransactionPriority: ethereumTransactionPriority,
759
+ backgroundTasks: backgroundTasks,
760
+ initialSyncMode: savedSyncMode,
761
+ initialSyncAll: savedSyncAll,
762
+ shouldShowYatPopup: shouldShowYatPopup);
763
+ }
764
765
Future<void> reload({required Box<Node> nodeSource}) async {
766
final sharedPreferences = await getIt.getAsync<SharedPreferences>();
769
raw: sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey)!);
770
771
priority[WalletType.monero] = monero?.deserializeMoneroTransactionPriority(
747
- raw: sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!) ??
772
+ raw: sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!) ??
773
priority[WalletType.monero]!;
774
priority[WalletType.bitcoin] = bitcoin?.deserializeBitcoinTransactionPriority(
750
- sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!) ??
775
+ sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!) ??
776
priority[WalletType.bitcoin]!;
777
778
if (sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) {
779
priority[WalletType.haven] = monero?.deserializeMoneroTransactionPriority(
755
- raw: sharedPreferences.getInt(PreferencesKey.havenTransactionPriority)!) ??
780
+ raw: sharedPreferences.getInt(PreferencesKey.havenTransactionPriority)!) ??
781
priority[WalletType.haven]!;
782
}
783
if (sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority) != null) {
784
priority[WalletType.litecoin] = bitcoin?.deserializeLitecoinTransactionPriority(
760
- sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority)!) ??
785
+ sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority)!) ??
786
priority[WalletType.litecoin]!;
787
}
788
if (sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority) != null) {
789
priority[WalletType.ethereum] = ethereum?.deserializeEthereumTransactionPriority(
765
- sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!) ??
790
+ sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!) ??
791
priority[WalletType.ethereum]!;
792
}
793
+ if (sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority) != null) {
794
+ priority[WalletType.bitcoinCash] = bitcoinCash?.deserializeBitcoinCashTransactionPriority(
795
+ sharedPreferences.getInt(PreferencesKey.bitcoinCashTransactionPriority)!) ??
796
+ priority[WalletType.bitcoinCash]!;
797
+ }
798
799
final generateSubaddresses =
770
- sharedPreferences.getInt(PreferencesKey.autoGenerateSubaddressStatusKey);
800
+ sharedPreferences.getInt(PreferencesKey.autoGenerateSubaddressStatusKey);
801
802
autoGenerateSubaddressStatus = generateSubaddresses != null
803
? AutoGenerateSubaddressStatus.deserialize(raw: generateSubaddresses)
815
isAppSecure = sharedPreferences.getBool(PreferencesKey.isAppSecureKey) ?? isAppSecure;
816
disableBuy = sharedPreferences.getBool(PreferencesKey.disableBuyKey) ?? disableBuy;
817
disableSell = sharedPreferences.getBool(PreferencesKey.disableSellKey) ?? disableSell;
788
- defaultBuyProvider = BuyProviderType.values[sharedPreferences.getInt(PreferencesKey.defaultBuyProvider) ?? 0];
818
+ defaultBuyProvider =
819
+ BuyProviderType.values[sharedPreferences.getInt(PreferencesKey.defaultBuyProvider) ?? 0];
820
allowBiometricalAuthentication =
821
sharedPreferences.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ??
822
allowBiometricalAuthentication;
833
sharedPreferences.getBool(PreferencesKey.shouldRequireTOTP2FAForSendsToInternalWallets) ??
834
false;
835
shouldRequireTOTP2FAForExchangesToInternalWallets = sharedPreferences
805
- .getBool(PreferencesKey.shouldRequireTOTP2FAForExchangesToInternalWallets) ??
836
+ .getBool(PreferencesKey.shouldRequireTOTP2FAForExchangesToInternalWallets) ??
837
false;
838
shouldRequireTOTP2FAForAddingContacts =
839
sharedPreferences.getBool(PreferencesKey.shouldRequireTOTP2FAForAddingContacts) ?? false;
841
sharedPreferences.getBool(PreferencesKey.shouldRequireTOTP2FAForCreatingNewWallets) ??
842
false;
843
shouldRequireTOTP2FAForAllSecurityAndBackupSettings = sharedPreferences
813
- .getBool(PreferencesKey.shouldRequireTOTP2FAForAllSecurityAndBackupSettings) ??
844
+ .getBool(PreferencesKey.shouldRequireTOTP2FAForAllSecurityAndBackupSettings) ??
845
false;
846
shouldShowMarketPlaceInDashboard =
847
sharedPreferences.getBool(PreferencesKey.shouldShowMarketPlaceInDashboard) ??
877
878
final nodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
879
final bitcoinElectrumServerId =
849
- sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
880
+ sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
881
final litecoinElectrumServerId =
851
- sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
882
+ sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
883
+ final bitcoinCashElectrumServerId =
884
+ sharedPreferences.getInt(PreferencesKey.currentBitcoinCashNodeIdKey);
885
final havenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey);
886
final ethereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey);
887
final nanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey);
891
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
892
final havenNode = nodeSource.get(havenNodeId);
893
final ethereumNode = nodeSource.get(ethereumNodeId);
894
+ final bitcoinCashNode = nodeSource.get(bitcoinCashElectrumServerId);
895
final nanoNode = nodeSource.get(nanoNodeId);
896
897
if (moneroNode != null) {
914
nodes[WalletType.ethereum] = ethereumNode;
915
}
916
917
+ if (bitcoinCashNode != null) {
918
+ nodes[WalletType.bitcoinCash] = bitcoinCashNode;
919
+ }
920
+
921
if (nanoNode != null) {
922
nodes[WalletType.nano] = nanoNode;
923
}
942
case WalletType.ethereum:
943
await _sharedPreferences.setInt(PreferencesKey.currentEthereumNodeIdKey, node.key as int);
944
break;
945
+ case WalletType.bitcoinCash:
946
+ await _sharedPreferences.setInt(PreferencesKey.currentBitcoinCashNodeIdKey, node.key as int);
947
+ break;
948
case WalletType.nano:
949
await _sharedPreferences.setInt(PreferencesKey.currentNanoNodeIdKey, node.key as int);
950
break;