115 lines
3.4 KiB
Dart
115 lines
3.4 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../data/config_repository.dart';
|
|
import '../domain/models.dart';
|
|
|
|
class AppConfigController extends StateNotifier<AppConfig> {
|
|
AppConfigController(this._repository, AppConfig initial)
|
|
: super(initial.copyWith(minimizeToTray: false, startMinimized: false));
|
|
|
|
final ConfigRepository _repository;
|
|
|
|
Future<void> updateConfig(AppConfig config) async {
|
|
state = config;
|
|
await _repository.saveConfig(state);
|
|
}
|
|
|
|
Future<void> setLastWallet(WalletInfo? wallet) async {
|
|
await updateConfig(state.copyWith(lastWallet: wallet));
|
|
}
|
|
|
|
Future<void> setNodeConfig(NodeConfig nodeConfig) async {
|
|
await updateConfig(state.copyWith(nodeConfig: nodeConfig));
|
|
}
|
|
|
|
Future<void> setMinimizeToTray(bool value) async {
|
|
await updateConfig(state.copyWith(minimizeToTray: value));
|
|
}
|
|
|
|
Future<void> setStartMinimized(bool value) async {
|
|
await updateConfig(state.copyWith(startMinimized: value));
|
|
}
|
|
|
|
Future<void> setAutoSync(bool value) async {
|
|
await updateConfig(state.copyWith(autoSync: value));
|
|
}
|
|
|
|
Future<void> setAutoSyncInterval(Duration interval) async {
|
|
await updateConfig(state.copyWith(autoSyncInterval: interval));
|
|
}
|
|
|
|
Future<void> setLanguage(LanguagePreference preference) async {
|
|
await updateConfig(state.copyWith(languagePreference: preference));
|
|
}
|
|
|
|
Future<void> setLocalNodeArgs(List<String> args) async {
|
|
await updateConfig(state.copyWith(localNodeArgs: args));
|
|
}
|
|
|
|
Future<void> setP2poolStratum(String value) async {
|
|
await updateConfig(state.copyWith(p2poolStratum: value));
|
|
}
|
|
|
|
Future<void> setP2poolP2p(String value) async {
|
|
await updateConfig(state.copyWith(p2poolP2p: value));
|
|
}
|
|
|
|
Future<void> setP2poolStartMining(bool value) async {
|
|
await updateConfig(state.copyWith(p2poolStartMining: value));
|
|
}
|
|
|
|
Future<void> setP2poolMiningThreads(int value) async {
|
|
await updateConfig(state.copyWith(p2poolMiningThreads: value));
|
|
}
|
|
|
|
Future<void> hideSubaddress({
|
|
required String walletPath,
|
|
required String address,
|
|
}) async {
|
|
if (walletPath.isEmpty || address.isEmpty) {
|
|
return;
|
|
}
|
|
final updated = Map<String, List<String>>.from(state.hiddenSubaddresses);
|
|
final current = Set<String>.from(updated[walletPath] ?? const []);
|
|
current.add(address);
|
|
updated[walletPath] = current.toList();
|
|
await updateConfig(state.copyWith(hiddenSubaddresses: updated));
|
|
}
|
|
|
|
Future<void> unhideSubaddress({
|
|
required String walletPath,
|
|
required String address,
|
|
}) async {
|
|
if (walletPath.isEmpty || address.isEmpty) {
|
|
return;
|
|
}
|
|
final updated = Map<String, List<String>>.from(state.hiddenSubaddresses);
|
|
final current = Set<String>.from(updated[walletPath] ?? const []);
|
|
if (!current.remove(address)) {
|
|
return;
|
|
}
|
|
if (current.isEmpty) {
|
|
updated.remove(walletPath);
|
|
} else {
|
|
updated[walletPath] = current.toList();
|
|
}
|
|
await updateConfig(state.copyWith(hiddenSubaddresses: updated));
|
|
}
|
|
|
|
Future<void> setHiddenSubaddresses({
|
|
required String walletPath,
|
|
required List<String> addresses,
|
|
}) async {
|
|
if (walletPath.isEmpty) {
|
|
return;
|
|
}
|
|
final updated = Map<String, List<String>>.from(state.hiddenSubaddresses);
|
|
if (addresses.isEmpty) {
|
|
updated.remove(walletPath);
|
|
} else {
|
|
updated[walletPath] = addresses;
|
|
}
|
|
await updateConfig(state.copyWith(hiddenSubaddresses: updated));
|
|
}
|
|
}
|