mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-23 19:16:09 +00:00
Update Settings Store attributes within reload function to get latest shared prefs data
This commit is contained in:
parent
8b333f2925
commit
3c1f619395
1 changed files with 68 additions and 24 deletions
|
@ -121,7 +121,7 @@ abstract class SettingsStoreBase with Store {
|
||||||
|
|
||||||
this
|
this
|
||||||
.nodes
|
.nodes
|
||||||
.observe((change) {
|
.observe((change) {
|
||||||
if (change.newValue != null && change.key != null) {
|
if (change.newValue != null && change.key != null) {
|
||||||
_saveCurrentNode(change.newValue!, change.key!);
|
_saveCurrentNode(change.newValue!, change.key!);
|
||||||
}
|
}
|
||||||
|
@ -304,34 +304,78 @@ abstract class SettingsStoreBase with Store {
|
||||||
shouldShowYatPopup: shouldShowYatPopup);
|
shouldShowYatPopup: shouldShowYatPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> reload(
|
Future<void> reload({required Box<Node> nodeSource}) async {
|
||||||
{required Box<Node> nodeSource,
|
|
||||||
FiatCurrency initialFiatCurrency = FiatCurrency.usd,
|
final sharedPreferences = await getIt.getAsync<SharedPreferences>();
|
||||||
TransactionPriority? initialMoneroTransactionPriority,
|
|
||||||
TransactionPriority? initialBitcoinTransactionPriority,
|
fiatCurrency = FiatCurrency.deserialize(
|
||||||
BalanceDisplayMode initialBalanceDisplayMode = BalanceDisplayMode.availableBalance}) async {
|
raw: sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey)!);
|
||||||
if (initialBitcoinTransactionPriority == null) {
|
|
||||||
initialBitcoinTransactionPriority = bitcoin?.getMediumTransactionPriority();
|
priority[WalletType.monero] = monero?.deserializeMoneroTransactionPriority(
|
||||||
|
raw: sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!) ??
|
||||||
|
priority[WalletType.monero]!;
|
||||||
|
priority[WalletType.bitcoin] = bitcoin?.deserializeBitcoinTransactionPriority(
|
||||||
|
sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!) ??
|
||||||
|
priority[WalletType.bitcoin]!;
|
||||||
|
// TODO: Add litecoin and haven after CW-118 is merged
|
||||||
|
|
||||||
|
balanceDisplayMode = BalanceDisplayMode.deserialize(
|
||||||
|
raw: sharedPreferences
|
||||||
|
.getInt(PreferencesKey.currentBalanceDisplayModeKey)!);
|
||||||
|
shouldSaveRecipientAddress =
|
||||||
|
sharedPreferences.getBool(PreferencesKey.shouldSaveRecipientAddressKey) ?? shouldSaveRecipientAddress;
|
||||||
|
allowBiometricalAuthentication = sharedPreferences
|
||||||
|
.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ??
|
||||||
|
allowBiometricalAuthentication;
|
||||||
|
disableExchange = sharedPreferences.getBool(PreferencesKey.disableExchangeKey) ?? disableExchange;
|
||||||
|
final legacyTheme =
|
||||||
|
(sharedPreferences.getBool(PreferencesKey.isDarkThemeLegacy) ?? false)
|
||||||
|
? ThemeType.dark.index
|
||||||
|
: ThemeType.bright.index;
|
||||||
|
currentTheme = ThemeList.deserialize(
|
||||||
|
raw: sharedPreferences.getInt(PreferencesKey.currentTheme) ??
|
||||||
|
legacyTheme);
|
||||||
|
actionlistDisplayMode = ObservableList<ActionListDisplayMode>();
|
||||||
|
actionlistDisplayMode.addAll(deserializeActionlistDisplayModes(
|
||||||
|
sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ??
|
||||||
|
defaultActionsMode));
|
||||||
|
var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength);
|
||||||
|
// If no value
|
||||||
|
if (pinLength == null || pinLength == 0) {
|
||||||
|
pinLength = pinCodeLength;
|
||||||
|
}
|
||||||
|
pinCodeLength = pinLength;
|
||||||
|
|
||||||
|
languageCode = sharedPreferences.getString(PreferencesKey.currentLanguageCode) ?? languageCode;
|
||||||
|
shouldShowYatPopup = sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? shouldShowYatPopup;
|
||||||
|
|
||||||
|
final nodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
|
||||||
|
final bitcoinElectrumServerId = sharedPreferences
|
||||||
|
.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
|
||||||
|
final litecoinElectrumServerId = sharedPreferences
|
||||||
|
.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
|
||||||
|
final havenNodeId = sharedPreferences
|
||||||
|
.getInt(PreferencesKey.currentHavenNodeIdKey);
|
||||||
|
final moneroNode = nodeSource.get(nodeId);
|
||||||
|
final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId);
|
||||||
|
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
|
||||||
|
final havenNode = nodeSource.get(havenNodeId);
|
||||||
|
|
||||||
|
if (moneroNode != null) {
|
||||||
|
nodes[WalletType.monero] = moneroNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialMoneroTransactionPriority == null) {
|
if (bitcoinElectrumServer != null) {
|
||||||
initialMoneroTransactionPriority = monero?.getDefaultTransactionPriority();
|
nodes[WalletType.bitcoin] = bitcoinElectrumServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
final isBitcoinBuyEnabled = (secrets.wyreSecretKey.isNotEmpty) &&
|
if (litecoinElectrumServer != null) {
|
||||||
(secrets.wyreApiKey.isNotEmpty) &&
|
nodes[WalletType.litecoin] = litecoinElectrumServer;
|
||||||
(secrets.wyreAccountId.isNotEmpty);
|
}
|
||||||
|
|
||||||
final settings = await SettingsStoreBase.load(
|
if (havenNode != null) {
|
||||||
nodeSource: nodeSource,
|
nodes[WalletType.haven] = havenNode;
|
||||||
isBitcoinBuyEnabled: isBitcoinBuyEnabled,
|
}
|
||||||
initialBalanceDisplayMode: initialBalanceDisplayMode,
|
|
||||||
initialFiatCurrency: initialFiatCurrency,
|
|
||||||
initialMoneroTransactionPriority: initialMoneroTransactionPriority,
|
|
||||||
initialBitcoinTransactionPriority: initialBitcoinTransactionPriority);
|
|
||||||
|
|
||||||
getIt.unregister<SettingsStore>();
|
|
||||||
getIt.registerSingleton<SettingsStore>(settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _saveCurrentNode(Node node, WalletType walletType) async {
|
Future<void> _saveCurrentNode(Node node, WalletType walletType) async {
|
||||||
|
|
Loading…
Reference in a new issue