2020-12-15 19:43:50 +00:00
|
|
|
import 'package:cake_wallet/themes/theme_base.dart';
|
|
|
|
import 'package:cake_wallet/themes/theme_list.dart';
|
2020-10-24 14:35:55 +00:00
|
|
|
import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.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';
|
2020-09-28 15:47:43 +00:00
|
|
|
import 'package:cake_wallet/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';
|
|
|
|
import 'package:cake_wallet/entities/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';
|
|
|
|
import 'package:cake_wallet/entities/node.dart';
|
|
|
|
import 'package:cake_wallet/entities/transaction_priority.dart';
|
|
|
|
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/link_list_item.dart';
|
|
|
|
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';
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
part 'settings_view_model.g.dart';
|
|
|
|
|
|
|
|
class SettingsViewModel = SettingsViewModelBase with _$SettingsViewModel;
|
|
|
|
|
|
|
|
abstract class SettingsViewModelBase with Store {
|
2020-08-25 16:32:40 +00:00
|
|
|
SettingsViewModelBase(this._settingsStore, WalletBase 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-06 08:42:21 +00:00
|
|
|
final _priority = _settingsStore.transactionPriority;
|
2021-01-04 15:13:37 +00:00
|
|
|
|
2021-01-06 08:42:21 +00:00
|
|
|
if (!TransactionPriority.forWalletType(_walletType).contains(_priority)) {
|
2021-01-04 15:13:37 +00:00
|
|
|
_settingsStore.transactionPriority =
|
|
|
|
TransactionPriority.forWalletType(_walletType).first;
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
sections = [
|
|
|
|
[
|
2020-12-15 16:29:10 +00:00
|
|
|
if ((wallet.balance.availableModes as List).length > 1)
|
|
|
|
PickerListItem(
|
|
|
|
title: S.current.settings_display_balance_as,
|
|
|
|
items: BalanceDisplayMode.all,
|
|
|
|
selectedItem: () => balanceDisplayMode,
|
|
|
|
onItemSelected: (BalanceDisplayMode mode) =>
|
|
|
|
_settingsStore.balanceDisplayMode = mode),
|
2020-07-06 20:09:03 +00:00
|
|
|
PickerListItem(
|
|
|
|
title: S.current.settings_currency,
|
|
|
|
items: FiatCurrency.all,
|
2020-09-10 14:51:59 +00:00
|
|
|
selectedItem: () => fiatCurrency,
|
|
|
|
onItemSelected: (FiatCurrency currency) =>
|
|
|
|
setFiatCurrency(currency)),
|
2020-07-06 20:09:03 +00:00
|
|
|
PickerListItem(
|
|
|
|
title: S.current.settings_fee_priority,
|
2020-12-03 19:34:56 +00:00
|
|
|
items: TransactionPriority.forWalletType(wallet.type),
|
2020-08-25 16:32:40 +00:00
|
|
|
selectedItem: () => transactionPriority,
|
|
|
|
onItemSelected: (TransactionPriority priority) =>
|
|
|
|
_settingsStore.transactionPriority = 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
|
|
|
}),
|
|
|
|
RegularListItem(
|
|
|
|
title: S.current.settings_change_language,
|
|
|
|
handler: (BuildContext context) =>
|
|
|
|
Navigator.of(context).pushNamed(Routes.changeLanguage),
|
|
|
|
),
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}),
|
2020-12-10 17:53:40 +00:00
|
|
|
PickerListItem(
|
2020-12-10 18:35:11 +00:00
|
|
|
title: S.current.color_theme,
|
2020-12-15 19:30:16 +00:00
|
|
|
items: ThemeList.all,
|
2020-12-10 17:53:40 +00:00
|
|
|
selectedItem: () => theme,
|
2020-12-15 19:30:16 +00:00
|
|
|
onItemSelected: (ThemeBase theme) =>
|
2020-12-10 17:53:40 +00:00
|
|
|
_settingsStore.currentTheme = theme)
|
2020-07-06 20:09:03 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
LinkListItem(
|
|
|
|
title: 'Email',
|
|
|
|
linkTitle: 'support@cakewallet.com',
|
|
|
|
link: 'mailto:support@cakewallet.com'),
|
|
|
|
LinkListItem(
|
|
|
|
title: 'Telegram',
|
|
|
|
icon: 'assets/images/Telegram.png',
|
2020-10-26 17:19:48 +00:00
|
|
|
linkTitle: '@cakewallet_bot',
|
2020-07-06 20:09:03 +00:00
|
|
|
link: 'https:t.me/cakewallet_bot'),
|
|
|
|
LinkListItem(
|
|
|
|
title: 'Twitter',
|
|
|
|
icon: 'assets/images/Twitter.png',
|
2020-11-02 16:11:51 +00:00
|
|
|
linkTitle: '@cakewallet',
|
|
|
|
link: 'https://twitter.com/cakewallet'),
|
2020-07-06 20:09:03 +00:00
|
|
|
LinkListItem(
|
|
|
|
title: 'ChangeNow',
|
|
|
|
icon: 'assets/images/change_now.png',
|
|
|
|
linkTitle: 'support@changenow.io',
|
|
|
|
link: 'mailto:support@changenow.io'),
|
|
|
|
LinkListItem(
|
|
|
|
title: 'Morph',
|
|
|
|
icon: 'assets/images/morph_icon.png',
|
|
|
|
linkTitle: 'support@morphtoken.com',
|
|
|
|
link: 'mailto:support@morphtoken.com'),
|
|
|
|
LinkListItem(
|
|
|
|
title: 'XMR.to',
|
|
|
|
icon: 'assets/images/xmr_btc.png',
|
|
|
|
linkTitle: 'support@xmr.to',
|
|
|
|
link: 'mailto:support@xmr.to'),
|
|
|
|
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-09-07 17:35:34 +00:00
|
|
|
),
|
|
|
|
RegularListItem(
|
|
|
|
title: S.current.faq,
|
|
|
|
handler: (BuildContext context) =>
|
|
|
|
Navigator.pushNamed(context, Routes.faq),
|
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 =>
|
|
|
|
_settingsStore.transactionPriority;
|
|
|
|
|
|
|
|
@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
|
|
|
|
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;
|
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);
|
|
|
|
}
|