2022-06-29 12:38:44 +00:00
|
|
|
import 'package:cake_wallet/entities/language_service.dart';
|
2021-10-01 15:13:10 +00:00
|
|
|
import 'package:cake_wallet/store/yat/yat_store.dart';
|
2022-06-29 12:38:44 +00:00
|
|
|
import 'package:cake_wallet/view_model/settings/choices_list_item.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
2020-09-28 15:47:43 +00:00
|
|
|
import 'package:package_info/package_info.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/routes.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_base.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
2020-09-28 15:47:43 +00:00
|
|
|
import 'package:cake_wallet/entities/biometric_auth.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
|
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/node.dart';
|
|
|
|
import 'package:cake_wallet/monero/monero.dart';
|
2022-03-30 15:57:04 +00:00
|
|
|
import 'package:cake_wallet/haven/haven.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/action_list_display_mode.dart';
|
2020-09-28 15:47:43 +00:00
|
|
|
import 'package:cake_wallet/view_model/settings/version_list_item.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/view_model/settings/picker_list_item.dart';
|
|
|
|
import 'package:cake_wallet/view_model/settings/regular_list_item.dart';
|
|
|
|
import 'package:cake_wallet/view_model/settings/settings_list_item.dart';
|
|
|
|
import 'package:cake_wallet/view_model/settings/switcher_list_item.dart';
|
2020-09-28 15:47:43 +00:00
|
|
|
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
|
|
|
import 'package:cw_core/transaction_history.dart';
|
|
|
|
import 'package:cw_core/balance.dart';
|
|
|
|
import 'package:cw_core/transaction_info.dart';
|
|
|
|
import 'package:cw_core/transaction_priority.dart';
|
2021-05-07 07:36:38 +00:00
|
|
|
import 'package:cake_wallet/themes/theme_base.dart';
|
|
|
|
import 'package:cake_wallet/themes/theme_list.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
|
2022-03-30 15:57:04 +00:00
|
|
|
import 'package:cake_wallet/wallet_type_utils.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
part 'settings_view_model.g.dart';
|
|
|
|
|
|
|
|
class SettingsViewModel = SettingsViewModelBase with _$SettingsViewModel;
|
|
|
|
|
2021-01-27 13:51:51 +00:00
|
|
|
List<TransactionPriority> priorityForWalletType(WalletType type) {
|
|
|
|
switch (type) {
|
|
|
|
case WalletType.monero:
|
2021-12-24 12:37:24 +00:00
|
|
|
return monero.getTransactionPriorities();
|
2021-01-27 13:51:51 +00:00
|
|
|
case WalletType.bitcoin:
|
2021-12-24 12:37:24 +00:00
|
|
|
return bitcoin.getTransactionPriorities();
|
2021-05-07 07:36:38 +00:00
|
|
|
case WalletType.litecoin:
|
2022-01-12 16:13:16 +00:00
|
|
|
return bitcoin.getLitecoinTransactionPriorities();
|
2022-03-30 15:57:04 +00:00
|
|
|
case WalletType.haven:
|
|
|
|
return haven.getTransactionPriorities();
|
2021-01-27 13:51:51 +00:00
|
|
|
default:
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
abstract class SettingsViewModelBase with Store {
|
2021-05-07 07:36:38 +00:00
|
|
|
SettingsViewModelBase(
|
|
|
|
this._settingsStore,
|
2021-10-01 15:13:10 +00:00
|
|
|
this._yatStore,
|
2021-05-07 07:36:38 +00:00
|
|
|
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
|
|
|
|
TransactionInfo>
|
|
|
|
wallet)
|
2020-08-27 16:54:34 +00:00
|
|
|
: itemHeaders = {},
|
2020-09-10 14:51:59 +00:00
|
|
|
_walletType = wallet.type,
|
|
|
|
_biometricAuth = BiometricAuth() {
|
2020-09-07 17:35:34 +00:00
|
|
|
currentVersion = '';
|
2020-09-10 14:51:59 +00:00
|
|
|
PackageInfo.fromPlatform().then(
|
|
|
|
(PackageInfo packageInfo) => currentVersion = packageInfo.version);
|
2021-01-04 15:13:37 +00:00
|
|
|
|
2021-01-27 13:51:51 +00:00
|
|
|
final priority = _settingsStore.priority[wallet.type];
|
|
|
|
final priorities = priorityForWalletType(wallet.type);
|
2021-01-04 15:13:37 +00:00
|
|
|
|
2021-01-27 13:51:51 +00:00
|
|
|
if (!priorities.contains(priority)) {
|
|
|
|
_settingsStore.priority[wallet.type] = priorities.first;
|
2021-01-04 15:13:37 +00:00
|
|
|
}
|
|
|
|
|
2022-01-12 15:38:32 +00:00
|
|
|
//var connectYatUrl = YatLink.baseUrl + YatLink.signInSuffix;
|
|
|
|
//final connectYatUrlParameters =
|
|
|
|
// _yatStore.defineQueryParameters();
|
2022-06-29 12:38:44 +00:00
|
|
|
|
2022-01-12 15:38:32 +00:00
|
|
|
//if (connectYatUrlParameters.isNotEmpty) {
|
|
|
|
// connectYatUrl += YatLink.queryParameter + connectYatUrlParameters;
|
|
|
|
//}
|
2021-11-02 09:17:24 +00:00
|
|
|
|
2022-01-12 15:38:32 +00:00
|
|
|
//var manageYatUrl = YatLink.baseUrl + YatLink.managePath;
|
|
|
|
//final manageYatUrlParameters =
|
|
|
|
// _yatStore.defineQueryParameters();
|
2022-06-29 12:38:44 +00:00
|
|
|
|
2022-01-12 15:38:32 +00:00
|
|
|
//if (manageYatUrlParameters.isNotEmpty) {
|
|
|
|
// manageYatUrl += YatLink.queryParameter + manageYatUrlParameters;
|
|
|
|
//}
|
2021-11-02 09:17:24 +00:00
|
|
|
|
2022-01-12 15:38:32 +00:00
|
|
|
//var createNewYatUrl = YatLink.startFlowUrl;
|
|
|
|
//final createNewYatUrlParameters =
|
|
|
|
// _yatStore.defineQueryParameters();
|
2022-06-29 12:38:44 +00:00
|
|
|
|
2022-01-12 15:38:32 +00:00
|
|
|
//if (createNewYatUrlParameters.isNotEmpty) {
|
|
|
|
// createNewYatUrl += '?sub1=' + createNewYatUrlParameters;
|
|
|
|
//}
|
2021-11-02 09:17:24 +00:00
|
|
|
|
2022-06-29 12:38:44 +00:00
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
sections = [
|
|
|
|
[
|
2022-06-29 12:38:44 +00:00
|
|
|
SwitcherListItem(
|
|
|
|
title: S.current.settings_display_balance,
|
|
|
|
value: () => balanceDisplayMode == BalanceDisplayMode.displayableBalance,
|
|
|
|
onValueChange: (_, bool value) {
|
|
|
|
if (value) {
|
|
|
|
_settingsStore.balanceDisplayMode = BalanceDisplayMode.displayableBalance;
|
|
|
|
} else {
|
|
|
|
_settingsStore.balanceDisplayMode = BalanceDisplayMode.hiddenBalance;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2022-03-30 15:57:04 +00:00
|
|
|
if (!isHaven)
|
|
|
|
PickerListItem(
|
|
|
|
title: S.current.settings_currency,
|
2022-06-29 12:38:44 +00:00
|
|
|
searchHintText: S.current.search_currency,
|
2022-03-30 15:57:04 +00:00
|
|
|
items: FiatCurrency.all,
|
|
|
|
selectedItem: () => fiatCurrency,
|
|
|
|
onItemSelected: (FiatCurrency currency) =>
|
2022-06-29 12:38:44 +00:00
|
|
|
setFiatCurrency(currency),
|
|
|
|
images: FiatCurrency.all.map(
|
|
|
|
(e) => Image.asset("assets/images/flags/${e.countryCode}.png"))
|
|
|
|
.toList(),
|
|
|
|
isGridView: true,
|
|
|
|
matchingCriteria: (FiatCurrency currency, String searchText) {
|
|
|
|
return currency.title.toLowerCase().contains(searchText) || currency.fullName.toLowerCase().contains(searchText);
|
|
|
|
},
|
|
|
|
),
|
2020-07-06 20:09:03 +00:00
|
|
|
PickerListItem(
|
|
|
|
title: S.current.settings_fee_priority,
|
2021-01-27 13:51:51 +00:00
|
|
|
items: priorityForWalletType(wallet.type),
|
2021-02-12 22:38:34 +00:00
|
|
|
displayItem: (dynamic priority) {
|
|
|
|
final _priority = priority as TransactionPriority;
|
|
|
|
|
2021-12-24 12:37:24 +00:00
|
|
|
if (wallet.type == WalletType.bitcoin
|
|
|
|
|| wallet.type == WalletType.litecoin) {
|
|
|
|
final rate = bitcoin.getFeeRate(wallet, _priority);
|
2021-05-11 13:52:48 +00:00
|
|
|
return '${priority.labelWithRate(rate)}';
|
2021-02-12 22:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return priority.toString();
|
|
|
|
},
|
2020-08-25 16:32:40 +00:00
|
|
|
selectedItem: () => transactionPriority,
|
|
|
|
onItemSelected: (TransactionPriority priority) =>
|
2021-01-27 13:51:51 +00:00
|
|
|
_settingsStore.priority[wallet.type] = priority),
|
2020-07-06 20:09:03 +00:00
|
|
|
SwitcherListItem(
|
|
|
|
title: S.current.settings_save_recipient_address,
|
|
|
|
value: () => shouldSaveRecipientAddress,
|
2020-09-10 14:51:59 +00:00
|
|
|
onValueChange: (_, bool value) =>
|
|
|
|
setShouldSaveRecipientAddress(value))
|
2020-07-06 20:09:03 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
RegularListItem(
|
|
|
|
title: S.current.settings_change_pin,
|
|
|
|
handler: (BuildContext context) {
|
2020-10-24 14:35:55 +00:00
|
|
|
Navigator.of(context).pushNamed(Routes.auth, arguments:
|
|
|
|
(bool isAuthenticatedSuccessfully, AuthPageState auth) {
|
|
|
|
auth.close();
|
|
|
|
if (isAuthenticatedSuccessfully) {
|
|
|
|
Navigator.of(context).pushNamed(Routes.setupPin, arguments:
|
|
|
|
(PinCodeState<PinCodeWidget> setupPinContext, String _) {
|
|
|
|
setupPinContext.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-07-06 20:09:03 +00:00
|
|
|
}),
|
2022-06-29 12:38:44 +00:00
|
|
|
PickerListItem(
|
|
|
|
title: S.current.settings_change_language,
|
|
|
|
searchHintText: S.current.search_language,
|
|
|
|
items: LanguageService.list.keys.toList(),
|
|
|
|
displayItem: (dynamic code) {
|
|
|
|
return LanguageService.list[code];
|
|
|
|
},
|
2022-07-01 11:04:00 +00:00
|
|
|
selectedItem: () => _settingsStore.languageCode,
|
2022-06-29 12:38:44 +00:00
|
|
|
onItemSelected: (String code) {
|
2022-07-01 11:04:00 +00:00
|
|
|
_settingsStore.languageCode = code;
|
2022-06-29 12:38:44 +00:00
|
|
|
},
|
|
|
|
images: LanguageService.list.keys.map(
|
|
|
|
(e) => Image.asset("assets/images/flags/${LanguageService.localeCountryCode[e]}.png"))
|
|
|
|
.toList(),
|
|
|
|
matchingCriteria: (String code, String searchText) {
|
|
|
|
return LanguageService.list[code].toLowerCase().contains(searchText);
|
|
|
|
},
|
2020-07-06 20:09:03 +00:00
|
|
|
),
|
|
|
|
SwitcherListItem(
|
|
|
|
title: S.current.settings_allow_biometrical_authentication,
|
|
|
|
value: () => allowBiometricalAuthentication,
|
2020-09-10 14:51:59 +00:00
|
|
|
onValueChange: (BuildContext context, bool value) {
|
|
|
|
if (value) {
|
|
|
|
Navigator.of(context).pushNamed(Routes.auth, arguments:
|
|
|
|
(bool isAuthenticatedSuccessfully,
|
|
|
|
AuthPageState auth) async {
|
|
|
|
if (isAuthenticatedSuccessfully) {
|
|
|
|
if (await _biometricAuth.canCheckBiometrics() &&
|
|
|
|
await _biometricAuth.isAuthenticated()) {
|
|
|
|
setAllowBiometricalAuthentication(
|
|
|
|
isAuthenticatedSuccessfully);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setAllowBiometricalAuthentication(
|
|
|
|
isAuthenticatedSuccessfully);
|
|
|
|
}
|
|
|
|
|
2020-10-24 14:35:55 +00:00
|
|
|
auth.close();
|
2020-09-10 14:51:59 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
setAllowBiometricalAuthentication(value);
|
|
|
|
}
|
|
|
|
}),
|
2022-06-29 12:38:44 +00:00
|
|
|
ChoicesListItem(
|
|
|
|
title: S.current.color_theme,
|
|
|
|
items: ThemeList.all,
|
|
|
|
selectedItem: theme,
|
|
|
|
onItemSelected: (ThemeBase theme) => _settingsStore.currentTheme = theme,
|
|
|
|
),
|
2020-07-06 20:09:03 +00:00
|
|
|
],
|
2021-12-30 17:20:00 +00:00
|
|
|
//[
|
|
|
|
//if (_yatStore.emoji.isNotEmpty) ...[
|
|
|
|
// LinkListItem(
|
|
|
|
// title: S.current.manage_yats,
|
|
|
|
// link: manageYatUrl,
|
|
|
|
// linkTitle: ''),
|
|
|
|
//] else ...[
|
|
|
|
//LinkListItem(
|
|
|
|
// title: S.current.connect_yats,
|
|
|
|
// link: connectYatUrl,
|
|
|
|
// linkTitle: ''),
|
|
|
|
//LinkListItem(
|
|
|
|
// title: 'Create new Yats',
|
|
|
|
// link: createNewYatUrl,
|
|
|
|
// linkTitle: '')
|
|
|
|
//]
|
|
|
|
//],
|
2021-11-02 09:17:24 +00:00
|
|
|
[
|
2020-07-06 20:09:03 +00:00
|
|
|
RegularListItem(
|
|
|
|
title: S.current.settings_terms_and_conditions,
|
|
|
|
handler: (BuildContext context) =>
|
2020-10-08 16:38:33 +00:00
|
|
|
Navigator.of(context).pushNamed(Routes.readDisclaimer),
|
2020-07-06 20:09:03 +00:00
|
|
|
)
|
2020-09-07 17:35:34 +00:00
|
|
|
],
|
2020-09-10 14:51:59 +00:00
|
|
|
[VersionListItem(title: currentVersion)]
|
2020-07-06 20:09:03 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-09-07 17:35:34 +00:00
|
|
|
@observable
|
|
|
|
String currentVersion;
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
@computed
|
2020-08-27 16:54:34 +00:00
|
|
|
Node get node => _settingsStore.getCurrentNode(_walletType);
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
@computed
|
|
|
|
FiatCurrency get fiatCurrency => _settingsStore.fiatCurrency;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
ObservableList<ActionListDisplayMode> get actionlistDisplayMode =>
|
|
|
|
_settingsStore.actionlistDisplayMode;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
TransactionPriority get transactionPriority =>
|
2021-01-27 13:51:51 +00:00
|
|
|
_settingsStore.priority[_walletType];
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
@computed
|
|
|
|
BalanceDisplayMode get balanceDisplayMode =>
|
|
|
|
_settingsStore.balanceDisplayMode;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
bool get shouldSaveRecipientAddress =>
|
|
|
|
_settingsStore.shouldSaveRecipientAddress;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
bool get allowBiometricalAuthentication =>
|
|
|
|
_settingsStore.allowBiometricalAuthentication;
|
|
|
|
|
2020-12-10 17:53:40 +00:00
|
|
|
@computed
|
2020-12-15 19:30:16 +00:00
|
|
|
ThemeBase get theme => _settingsStore.currentTheme;
|
2020-12-10 17:53:40 +00:00
|
|
|
|
2021-03-16 13:20:46 +00:00
|
|
|
bool get isBitcoinBuyEnabled => _settingsStore.isBitcoinBuyEnabled;
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
final Map<String, String> itemHeaders;
|
2020-09-10 14:51:59 +00:00
|
|
|
List<List<SettingsListItem>> sections;
|
2020-07-06 20:09:03 +00:00
|
|
|
final SettingsStore _settingsStore;
|
2021-10-01 15:13:10 +00:00
|
|
|
final YatStore _yatStore;
|
2020-08-27 16:54:34 +00:00
|
|
|
final WalletType _walletType;
|
2020-09-10 14:51:59 +00:00
|
|
|
final BiometricAuth _biometricAuth;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2020-09-07 17:35:34 +00:00
|
|
|
@action
|
2020-09-10 14:51:59 +00:00
|
|
|
void setBalanceDisplayMode(BalanceDisplayMode value) =>
|
2020-09-07 17:35:34 +00:00
|
|
|
_settingsStore.balanceDisplayMode = value;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2020-08-31 08:44:58 +00:00
|
|
|
@action
|
2020-09-10 14:51:59 +00:00
|
|
|
void setFiatCurrency(FiatCurrency value) =>
|
2020-09-07 17:35:34 +00:00
|
|
|
_settingsStore.fiatCurrency = value;
|
2020-09-26 11:17:39 +00:00
|
|
|
|
2020-09-07 17:35:34 +00:00
|
|
|
@action
|
2020-08-31 08:44:58 +00:00
|
|
|
void setShouldSaveRecipientAddress(bool value) =>
|
|
|
|
_settingsStore.shouldSaveRecipientAddress = value;
|
|
|
|
|
|
|
|
@action
|
|
|
|
void setAllowBiometricalAuthentication(bool value) =>
|
|
|
|
_settingsStore.allowBiometricalAuthentication = value;
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
@action
|
|
|
|
void toggleTransactionsDisplay() =>
|
|
|
|
actionlistDisplayMode.contains(ActionListDisplayMode.transactions)
|
|
|
|
? _hideTransaction()
|
|
|
|
: _showTransaction();
|
|
|
|
|
|
|
|
@action
|
|
|
|
void toggleTradesDisplay() =>
|
|
|
|
actionlistDisplayMode.contains(ActionListDisplayMode.trades)
|
|
|
|
? _hideTrades()
|
|
|
|
: _showTrades();
|
|
|
|
|
|
|
|
@action
|
|
|
|
void _hideTransaction() =>
|
|
|
|
actionlistDisplayMode.remove(ActionListDisplayMode.transactions);
|
|
|
|
|
|
|
|
@action
|
|
|
|
void _hideTrades() =>
|
|
|
|
actionlistDisplayMode.remove(ActionListDisplayMode.trades);
|
|
|
|
|
|
|
|
@action
|
|
|
|
void _showTransaction() =>
|
|
|
|
actionlistDisplayMode.add(ActionListDisplayMode.transactions);
|
|
|
|
|
|
|
|
@action
|
|
|
|
void _showTrades() => actionlistDisplayMode.add(ActionListDisplayMode.trades);
|
|
|
|
}
|