Files
hash-wallet/lib/view_model/settings/display_settings_view_model.dart
T
jwinterm 04203654f1 Rename Flutter project + binary: cake_wallet -> hash_wallet
The big one. Touches 760+ files. Locks in the user's decision to break
import-line compatibility with upstream cake-tech/cake_wallet in exchange
for a binary named hash_wallet on every platform.

Changes:
- pubspec_description.yaml: project name cake_wallet -> hash_wallet
- 762 Dart files: every 'package:cake_wallet/...' import rewritten to
  'package:hash_wallet/...' (lib/, cw_*/lib/, tool/, test/, integration_test/)
- linux/CMakeLists.txt: BINARY_NAME cake_wallet -> hash_wallet
- windows/CMakeLists.txt: project + BINARY_NAME (CakeWallet -> HashWallet)
- windows/runner/Runner.rc: company / file / product strings to Hash Wallet
  + Such Software LLC copyright
- macos/Runner.xcodeproj/project_base.pbxproj: cake_wallet_new.app refs
  -> hash_wallet.app (macOS output bundle name)
- com.suchsoftware.HashWallet.yml (Flatpak): all binary path refs
  cake_wallet -> hash_wallet (e.g. /app/hash_wallet/hash_wallet)
- linux/com.suchsoftware.HashWallet.desktop: Exec=hash_wallet
- scripts/android/copy_monero_deps.sh: CW_DIR target path
- configure_hash_wallet.sh: error message typo (old filename)

INTENTIONALLY UNCHANGED:
- cw_* subpackage names (cw_core, cw_bitcoin, cw_wownero, etc.) — they
  remain as the historical 'cake wallet' naming; renaming them would
  cascade through every sub-package's internal structure
- Method channel name 'com.cake_wallet/native_utils' in iOS/macOS/Android
  AppDelegates and MainActivity — it's a string identifier that has to
  match the Dart side exactly. Renaming requires both-sides change; it's
  internal-only and not user-visible.
- ghcr.io/cake-tech/cake_wallet:debian13-... docker image references in
  build scripts — that's Cake Labs' published image we use as the build
  environment, not ours.

User data directory now follows the new binary name:
  ~/.local/share/hash_wallet/  (was ~/.local/share/cake_wallet/)
  ~/.config/hash_wallet/       (was ~/.config/cake_wallet/)
Existing users on the old name will need migration if any exist.
2026-05-16 11:33:25 -04:00

270 lines
8.5 KiB
Dart

import 'package:hash_wallet/entities/balance_display_mode.dart';
import 'package:hash_wallet/entities/bitcoin_amount_display_mode.dart';
import 'package:hash_wallet/entities/fiat_currency.dart';
import 'package:hash_wallet/entities/sync_status_display_mode.dart';
import 'package:hash_wallet/store/app_store.dart';
import 'package:hash_wallet/store/settings_store.dart';
import 'package:hash_wallet/themes/core/material_base_theme.dart';
import 'package:hash_wallet/themes/theme_classes/black_theme.dart';
import 'package:hash_wallet/themes/utils/theme_list.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
import 'package:hash_wallet/entities/fiat_api_mode.dart';
import 'package:hash_wallet/themes/core/theme_store.dart';
import 'package:flutter/material.dart';
part 'display_settings_view_model.g.dart';
class DisplaySettingsViewModel = DisplaySettingsViewModelBase with _$DisplaySettingsViewModel;
abstract class DisplaySettingsViewModelBase with Store {
DisplaySettingsViewModelBase(this._appStore, this._themeStore);
final AppStore _appStore;
SettingsStore get _settingsStore => _appStore.settingsStore;
final ThemeStore _themeStore;
@computed
bool get disableTradeOption => _settingsStore.disableTradeOption;
@computed
FiatCurrency get fiatCurrency => _settingsStore.fiatCurrency;
@computed
String get languageCode => _settingsStore.languageCode;
@computed
BalanceDisplayMode get balanceDisplayMode => _settingsStore.balanceDisplayMode;
@computed
bool get shouldDisplayBalance => balanceDisplayMode == BalanceDisplayMode.displayableBalance;
@computed
bool get shouldShowMarketPlaceInDashboard => _settingsStore.shouldShowMarketPlaceInDashboard;
@computed
BitcoinAmountDisplayMode get displayAmountsInSatoshi => _settingsStore.displayAmountsInSatoshi;
@computed
MaterialThemeBase get currentTheme => _themeStore.currentTheme;
@computed
ThemeMode get themeMode => _themeStore.themeMode;
@computed
bool get isBlackThemeOledEnabled => _themeStore.currentTheme is BlackTheme && _themeStore.isOled;
@computed
bool get disabledFiatApiMode => _settingsStore.fiatApiMode == FiatApiMode.disabled;
@computed
bool get showAddressBookPopup => _settingsStore.showAddressBookPopupEnabled;
@computed
bool get showZcashCard => _settingsStore.showZcashMissingFundsCard;
@computed
SyncStatusDisplayMode get syncStatusDisplayMode => _settingsStore.syncStatusDisplayMode;
@computed
String get backgroundImage => _settingsStore.backgroundImage;
@computed
List<MaterialThemeBase> get availableThemes {
List<MaterialThemeBase> themes;
switch (themeMode) {
case ThemeMode.light:
themes = ThemeList.all.where((theme) => theme.brightness == Brightness.light).toList();
break;
case ThemeMode.dark:
themes = ThemeList.all.where((theme) => theme.brightness == Brightness.dark).toList();
break;
case ThemeMode.system:
final systemBrightness = WidgetsBinding.instance.platformDispatcher.platformBrightness;
themes = ThemeList.all.where((theme) => theme.brightness == systemBrightness).toList();
break;
}
List<MaterialThemeBase> groupedThemes = [];
Set<String> addedThemeFamilies = {};
for (final theme in themes) {
if (theme.hasAccentColors) {
final family = theme.themeFamily!;
if (!addedThemeFamilies.contains(family)) {
groupedThemes.add(theme);
addedThemeFamilies.add(family);
}
} else {
groupedThemes.add(theme);
}
}
return groupedThemes;
}
@computed
List<ThemeAccentColor> get availableAccentColors {
if (!currentTheme.hasAccentColors) return [];
if (currentTheme.themeFamily == 'BlackTheme') {
return BlackThemeAccentColor.values;
}
return [];
}
@action
void setDisableTradeOption(bool value) => _settingsStore.disableTradeOption = value;
@action
void setBalanceDisplayMode(BalanceDisplayMode value) => _settingsStore.balanceDisplayMode = value;
@computed
bool get showDisplayAmountsInSatoshiSetting => _appStore.wallet?.type == WalletType.bitcoin;
@computed
bool get showZcashCardSetting => _appStore.wallet?.type == WalletType.zcash;
@action
void setDisplayAmountsInSatoshi(BitcoinAmountDisplayMode value) => _settingsStore.displayAmountsInSatoshi = value;
@action
void setShowZcashCard(bool value) => _settingsStore.showZcashMissingFundsCard = value;
@action
void setShouldDisplayBalance(bool value) {
if (value) {
_settingsStore.balanceDisplayMode = BalanceDisplayMode.displayableBalance;
} else {
_settingsStore.balanceDisplayMode = BalanceDisplayMode.hiddenBalance;
}
}
@action
void onLanguageSelected(String code) {
_settingsStore.languageCode = code;
}
@action
Future<void> onThemeSelected(MaterialThemeBase newTheme) async {
if (newTheme is BlackTheme && _themeStore.isOled) {
await setTheme(BlackTheme(newTheme.accentColor, isOled: true));
return;
}
await setTheme(newTheme);
}
@action
Future<void> onAccentColorSelected(String accentColorId) async {
if (!currentTheme.hasAccentColors) return;
try {
final newTheme = ThemeList.all.firstWhere(
(theme) =>
theme.hasAccentColors &&
theme.themeFamily == currentTheme.themeFamily &&
theme.accentColorId == accentColorId,
);
if (newTheme != currentTheme) {
if (newTheme is BlackTheme && _themeStore.isOled) {
await onThemeSelected(BlackTheme(newTheme.accentColor, isOled: true));
} else {
await onThemeSelected(newTheme);
}
}
} catch (_) {}
}
@action
Future<void> setBlackThemeOled(bool value) async {
if (_themeStore.currentTheme is BlackTheme) {
await _themeStore.setOledEnabled(value);
}
}
bool isThemeSelected(MaterialThemeBase theme) {
if (!theme.hasAccentColors) return currentTheme == theme;
return currentTheme.hasAccentColors && currentTheme.themeFamily == theme.themeFamily;
}
bool isAccentColorSelected(String accentColorId) {
if (!currentTheme.hasAccentColors) return false;
return currentTheme.accentColorId == accentColorId;
}
@action
Future<void> setTheme(MaterialThemeBase newTheme) async {
await _themeStore.setTheme(newTheme);
}
MaterialThemeBase? getFirstMatchingTheme(ThemeMode mode) {
List<MaterialThemeBase> themes;
switch (mode) {
case ThemeMode.light:
themes = ThemeList.all.where((theme) => theme.brightness == Brightness.light).toList();
break;
case ThemeMode.dark:
themes = ThemeList.all.where((theme) => theme.brightness == Brightness.dark).toList();
break;
case ThemeMode.system:
final systemBrightness = WidgetsBinding.instance.platformDispatcher.platformBrightness;
themes = ThemeList.all.where((theme) => theme.brightness == systemBrightness).toList();
break;
}
return themes.isNotEmpty ? themes.first : null;
}
@action
Future<void> setThemeMode(ThemeMode value) async {
await _themeStore.setThemeMode(value);
// We won't override the saved custom theme when switching to system mode.
// We'll just let the ThemeStore resolve it based on system brightness and saved theme.
if (value != ThemeMode.system) {
final matchingTheme = getFirstMatchingTheme(value);
if (matchingTheme != null) {
await setTheme(matchingTheme);
}
}
}
@action
void setFiatCurrency(FiatCurrency value) => _settingsStore.fiatCurrency = value;
@action
void setShouldShowMarketPlaceInDashbaord(bool value) {
_settingsStore.shouldShowMarketPlaceInDashboard = value;
}
@action
void setShowAddressBookPopup(bool value) => _settingsStore.showAddressBookPopupEnabled = value;
@action
void setSyncStatusDisplayMode(SyncStatusDisplayMode value) =>
_settingsStore.syncStatusDisplayMode = value;
@action
void setBackgroundImage(String path) => _settingsStore.backgroundImage = path;
String getImageForTheme(MaterialThemeBase theme) {
switch (theme.title) {
case 'Dark Theme':
return 'assets/new-ui/dark.svg';
case 'Light Theme':
return 'assets/new-ui/light.svg';
case 'Black Theme (Cake Primary)':
case 'Black Theme (BCH Green)':
case 'Black Theme (Bitcoin Yellow)':
case 'Black Theme (Monero Orange)':
case 'Black Theme (Tron Red)':
case 'Black Theme (Frosting Purple)':
return 'assets/new-ui/black_accent.svg';
default:
return 'assets/new-ui/dark.svg';
}
}
}