| 1 | import 'dart:io'; |
| 2 | |
| 3 | import 'package:cake_wallet/bitcoin/bitcoin.dart'; |
| 4 | import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart'; |
| 5 | import 'package:cake_wallet/store/settings_store.dart'; |
| 6 | import 'package:cake_wallet/utils/device_info.dart'; |
| 7 | import 'package:cw_core/balance.dart'; |
| 8 | import 'package:cw_core/transaction_history.dart'; |
| 9 | import 'package:cw_core/transaction_info.dart'; |
| 10 | import 'package:cw_core/wallet_base.dart'; |
| 11 | import 'package:cw_core/wallet_type.dart'; |
| 12 | import 'package:mobx/mobx.dart'; |
| 13 | |
| 14 | part 'privacy_settings_view_model.g.dart'; |
| 15 | |
| 16 | class PrivacySettingsViewModel = PrivacySettingsViewModelBase with _$PrivacySettingsViewModel; |
| 17 | |
| 18 | abstract class PrivacySettingsViewModelBase with Store { |
| 19 | PrivacySettingsViewModelBase(this._settingsStore, this._wallet); |
| 20 | |
| 21 | final SettingsStore _settingsStore; |
| 22 | final WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> _wallet; |
| 23 | |
| 24 | @computed |
| 25 | bool get isBitcoin => _wallet.type == WalletType.bitcoin; |
| 26 | |
| 27 | @computed |
| 28 | bool get hasSilentPaymentsScanning => _wallet.hasSilentPaymentsScanning; |
| 29 | |
| 30 | @computed |
| 31 | bool get hasMWEB => |
| 32 | _wallet.type == WalletType.litecoin && (Platform.isIOS || Platform.isAndroid) && |
| 33 | !_wallet.isHardwareWallet; |
| 34 | |
| 35 | @computed |
| 36 | bool get isAutoGenerateSubaddressesEnabled => |
| 37 | _settingsStore.autoGenerateSubaddressStatus != AutoGenerateSubaddressStatus.disabled; |
| 38 | |
| 39 | @action |
| 40 | void setAutoGenerateSubaddresses(bool value) { |
| 41 | _wallet.isEnabledAutoGenerateSubaddress = value; |
| 42 | _settingsStore.autoGenerateSubaddressStatus = |
| 43 | value ? AutoGenerateSubaddressStatus.enabled : AutoGenerateSubaddressStatus.disabled; |
| 44 | } |
| 45 | |
| 46 | bool get isAutoGenerateSubaddressesVisible => [ |
| 47 | WalletType.monero, |
| 48 | WalletType.wownero, |
| 49 | WalletType.bitcoin, |
| 50 | WalletType.litecoin, |
| 51 | WalletType.bitcoinCash, |
| 52 | WalletType.dogecoin, |
| 53 | WalletType.decred |
| 54 | ].contains(_wallet.type); |
| 55 | |
| 56 | @computed |
| 57 | bool get hasCoinControl => [ |
| 58 | WalletType.bitcoin, |
| 59 | WalletType.litecoin, |
| 60 | WalletType.monero, |
| 61 | WalletType.wownero, |
| 62 | WalletType.decred, |
| 63 | WalletType.bitcoinCash, |
| 64 | WalletType.dogecoin |
| 65 | ].contains(_wallet.type); |
| 66 | |
| 67 | bool get isMoneroWallet => _wallet.type == WalletType.monero; |
| 68 | |
| 69 | @computed |
| 70 | bool get shouldSaveRecipientAddress => _settingsStore.shouldSaveRecipientAddress; |
| 71 | |
| 72 | @computed |
| 73 | bool get isAppSecure => _settingsStore.isAppSecure; |
| 74 | |
| 75 | @computed |
| 76 | bool get disableTradeOption => _settingsStore.disableTradeOption; |
| 77 | |
| 78 | @computed |
| 79 | bool get disableAutomaticExchangeStatusUpdates => |
| 80 | _settingsStore.disableAutomaticExchangeStatusUpdates; |
| 81 | |
| 82 | @computed |
| 83 | bool get disableBulletin => _settingsStore.disableBulletin; |
| 84 | |
| 85 | @computed |
| 86 | bool get lookupTwitter => _settingsStore.lookupsTwitter; |
| 87 | |
| 88 | @computed |
| 89 | bool get lookupsZanoAlias => _settingsStore.lookupsZanoAlias; |
| 90 | |
| 91 | @computed |
| 92 | bool get looksUpMastodon => _settingsStore.lookupsMastodon; |
| 93 | |
| 94 | @computed |
| 95 | bool get looksUpYatService => _settingsStore.lookupsYatService; |
| 96 | |
| 97 | @computed |
| 98 | bool get looksUpUnstoppableDomains => _settingsStore.lookupsUnstoppableDomains; |
| 99 | |
| 100 | @computed |
| 101 | bool get looksUpOpenAlias => _settingsStore.lookupsOpenAlias; |
| 102 | |
| 103 | @computed |
| 104 | bool get looksUpENS => _settingsStore.lookupsENS; |
| 105 | |
| 106 | @computed |
| 107 | bool get lookupsZcashNames => _settingsStore.lookupsZcashNames; |
| 108 | |
| 109 | @computed |
| 110 | bool get looksUpWellKnown => _settingsStore.lookupsWellKnown; |
| 111 | |
| 112 | @computed |
| 113 | bool get usePayjoin => _settingsStore.usePayjoin; |
| 114 | |
| 115 | @computed |
| 116 | bool get canUsePayjoin => _wallet.hasPayjoinSupport && DeviceInfo.instance.isMobile; |
| 117 | |
| 118 | @computed |
| 119 | bool get canUseLightning => _wallet.hasLightningSupport; |
| 120 | |
| 121 | @computed |
| 122 | bool get useLightning => _wallet.type == WalletType.bitcoin && bitcoin!.useLightning(_wallet); |
| 123 | |
| 124 | @action |
| 125 | void setShouldSaveRecipientAddress(bool value) => |
| 126 | _settingsStore.shouldSaveRecipientAddress = value; |
| 127 | |
| 128 | @action |
| 129 | void setIsAppSecure(bool value) => _settingsStore.isAppSecure = value; |
| 130 | |
| 131 | @action |
| 132 | void setDisableTradeOption(bool value) => _settingsStore.disableTradeOption = value; |
| 133 | |
| 134 | @action |
| 135 | void setDisableAutomaticExchangeStatusUpdates(bool value) => |
| 136 | _settingsStore.disableAutomaticExchangeStatusUpdates = value; |
| 137 | |
| 138 | @action |
| 139 | void setDisableBulletin(bool value) => _settingsStore.disableBulletin = value; |
| 140 | |
| 141 | @action |
| 142 | void setUseMempoolFeeAPI(bool value) => _settingsStore.useMempoolFeeAPI = value; |
| 143 | |
| 144 | @action |
| 145 | void setUseBlinkProtection(bool value) => _settingsStore.useBlinkProtection = value; |
| 146 | |
| 147 | @action |
| 148 | void setUsePayjoin(bool value) { |
| 149 | _settingsStore.usePayjoin = value; |
| 150 | bitcoin!.updatePayjoinState(_wallet, value); |
| 151 | } |
| 152 | |
| 153 | @action |
| 154 | void setUseLightning(bool value) => bitcoin!.updateUseLightning(_wallet, value); |
| 155 | } |